source: trunk/src/org/expeditee/gui/Help.java@ 712

Last change on this file since 712 was 712, checked in by jts21, 10 years ago

More changes to help text, now L/M/R/LM/MR are always aligned to the same X value, and fix a couple of help messages

File size: 7.8 KB
Line 
1package org.expeditee.gui;
2
3import java.util.Collection;
4
5import org.expeditee.items.Dot;
6import org.expeditee.items.Item;
7import org.expeditee.items.Line;
8import org.expeditee.items.Picture;
9import org.expeditee.items.Text;
10import org.expeditee.items.widgets.InteractiveWidget;
11import org.expeditee.items.widgets.WidgetCorner;
12import org.expeditee.items.widgets.WidgetEdge;
13import org.expeditee.settings.experimental.ExperimentalFeatures;
14
15
16public class Help {
17
18 // contexts
19 private static enum Context {
20 background,
21 item,
22 polygon,
23 line,
24 dot,
25 text,
26 image,
27 widget
28 };
29
30 // mouse buttons
31 private static final int left = 1, middle = 2, right = 4;
32 private static final String[] buttons = { "", "L", "M", "LM", "R", "LR", "MR" };
33
34 // modifiers
35 private static final int control = 1, shift = 2;
36 private static final String[] modifiers = { "", "^", "+", "^+" };
37
38 // other
39 private static final int panning = 1, action = 2, link = 4, cursor = 8;
40
41 // separator between command and description
42 private static final String separatorString = ": ";
43
44 private static final String commandPadding = " ";
45 private static final String padding = " ";
46 private static final String emptyPadding = commandPadding + padding;
47
48 private static final String command(int mod, int button) {
49 String cmd = modifiers[mod] + buttons[button] + separatorString;
50 return commandPadding.substring(cmd.length()) + cmd;
51 }
52
53 private static final String left(Context context, int mod, int other) {
54 switch(context) {
55 case widget: return "Left click widget";
56 case background:
57 if((mod & (control | shift)) != 0) return "Go forward";
58 return "Go back";
59
60 default:
61 if((other & action) != 0 && (mod & control) == 0) return "Run action";
62 if((other & link) != 0) return "Follow link";
63 return "Create link";
64 }
65 }
66
67 private static final String middle(Context context, int mod, int other) {
68 switch(context) {
69 case widget: return "Middle click widget";
70 case background:
71 if((other & cursor) != 0) return FreeItems.hasMultipleVisibleItems() ? "Put down items" : "Put down item";
72 return "Draw line/arrow";
73 case line:
74 if(FreeItems.isDrawingPolyLine()) return "Spot-weld polyline";
75 if((mod & shift) != 0) return "Extend shape";
76 case dot:
77 if((mod & shift) != 0) return "Pickup unconstrained";
78 case text:
79 if((other & cursor) != 0 && FreeItems.getInstance().size() == 1 && FreeItems.textOnlyAttachedToCursor()) return "Merge text";
80 default:
81 if((other & cursor) != 0) return FreeItems.hasMultipleVisibleItems() ? "Put down items" : "Put down item";
82 if((mod & shift) != 0) return "Draw line/arrow";
83 if(context == Context.polygon) return "Pickup enclo'd items";
84 return "Pickup item";
85 }
86 }
87
88 private static final String right(Context context, int mod, int other) {
89 switch(context) {
90 case widget: return "Right click widget";
91 case background:
92 if((other & cursor) != 0) {
93 if(FreeItems.isDrawingPolyLine()) return "Continue polyline";
94 return "Stamp copy";
95 }
96 return "Draw rectangle";
97 case line:
98 if(FreeItems.isDrawingPolyLine()) return "Spot-weld & continue";
99 if((mod & shift) != 0) return "Add line";
100 break;
101 case dot:
102 if((mod & shift) == 0)return "Extend line";
103 break;
104 }
105 if((other & cursor) != 0) return "Stamp copy";
106 if((mod & shift) != 0) return "Draw rectangle";
107 if(context == Context.polygon) return "Copy enclosed items";
108 return "Copy item";
109 }
110
111 private static final String left_right(Context context, int mod, int other) {
112 switch(context) {
113 case widget: return null;
114 default:
115 if((other & cursor) == 0) return "Extract attributes";
116 return null;
117 case polygon:
118 case background:
119 return "Auto format";
120 }
121 }
122
123 private static final String middle_right(Context context, int mod, int other) {
124 switch(context) {
125 case widget: return null;
126 case text:
127 if((other & cursor) != 0 && FreeItems.getInstance().size() == 1 && FreeItems.textOnlyAttachedToCursor()) return "Swap text";
128 break;
129 case background:
130 if((other & cursor) == 0) return "Undo last delete";
131 break;
132 }
133 return "Delete";
134 }
135
136 private static final String drag_left(Context context, int mod, int other) {
137 switch(context) {
138 case widget: return null;
139 case background:
140 if((mod & shift) != 0 && (other & cursor) == 0 && (other & panning) != 0) return "Drag to pan";
141 break;
142 case text:
143 if((other & cursor) == 0) return "Select text region";
144 break;
145 }
146 return null;
147 }
148
149 private static final String drag_middle(Context context, int mod, int other) {
150 switch(context) {
151 case widget: return null;
152 case text:
153 if((other & cursor) == 0) return "Cut text region";
154 }
155 return null;
156 }
157
158 private static final String drag_right(Context context, int mod, int other) {
159 switch(context) {
160 case widget: return null;
161 case image:
162 return "Crop image";
163 case line:
164 return "Extrude shape";
165 case text:
166 if((other & cursor) == 0) return "Copy text region";
167 }
168 return null;
169 }
170
171
172 public static void updateStatus() {
173 Item current = FrameUtils.getCurrentItem();
174 Collection<Item> currents;
175 Context context;
176 InteractiveWidget iw = null;
177 if(current != null) {
178 if(current instanceof Line) {
179 context = Context.line;
180 } else if(current instanceof Text) {
181 context = Context.text;
182 } else if(current instanceof Picture) {
183 context = Context.image;
184 } else if(current instanceof Dot ) {
185 context = Context.dot;
186 }else {
187 context = Context.item;
188 }
189 } else {
190 currents = FrameUtils.getCurrentItems();
191 if(currents != null) {
192 if(currents.size() >= 4) {
193 for(Item i : currents) {
194 if (i instanceof WidgetCorner) {
195 iw = ((WidgetCorner) i).getWidgetSource();
196 break;
197 } else if (i instanceof WidgetEdge) {
198 iw = ((WidgetEdge) i).getWidgetSource();
199 break;
200 }
201 }
202 }
203 if(iw != null) {
204 context = Context.widget;
205 } else {
206 context = Context.polygon;
207 }
208 } else {
209 context = Context.background;
210 }
211 }
212 int mod = (FrameMouseActions.isControlDown() ? control : 0) | (FrameMouseActions.isShiftDown() ? shift : 0);
213 int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) |
214 (current != null && current.hasAction() ? action : 0)|
215 (current != null && current.hasLink() ? link : 0) |
216 (FreeItems.itemsAttachedToCursor() ? cursor : 0);
217 String status = "";
218
219
220 String l = left(context, mod, other);
221 String m = middle(context, mod, other);
222 String r = right(context, mod, other);
223 String lr = left_right(context, mod, other);
224 String mr = middle_right(context, mod, other);
225 String dl = drag_left(context, mod, other);
226 String dm = drag_middle(context, mod, other);
227 String dr = drag_right(context, mod, other);
228
229 if(l != null || m != null || r != null || lr != null || mr != null) status += " Click:";
230 status += (l != null ? command(mod, left) + l + padding.substring(l.length()) : emptyPadding);
231 status += (m != null ? command(mod, middle) + m + padding.substring(m.length()) : emptyPadding);
232 status += (r != null ? command(mod, right) + r + padding.substring(r.length()) : emptyPadding);
233 status += (lr != null ? command(mod, left | right) + lr + padding.substring(lr.length()) : emptyPadding);
234 status += (mr != null ? command(mod, middle | right) + mr + padding.substring(mr.length()) : emptyPadding);
235 if(iw != null) {
236 status += "\n Widget: " + iw.getClass().getSimpleName();
237 } else {
238 if(dl != null || dm != null || dr != null) status += "\n Drag: ";
239 status += (dl != null ? command(mod, left) + dl + padding.substring(dl.length()) : emptyPadding);
240 status += (dm != null ? command(mod, middle) + dm + padding.substring(dm.length()) : emptyPadding);
241 status += (dr != null ? command(mod, right) + dr + padding.substring(dr.length()) : emptyPadding);
242 }
243
244
245 MessageBay.setStatus(status);
246 }
247
248}
Note: See TracBrowser for help on using the repository browser.