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

Last change on this file since 705 was 705, checked in by davidb, 10 years ago

Some word changes to mouse-status-bar help text

File size: 7.4 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
47 private static final String command(int mod, int button) {
48 String cmd = modifiers[mod] + buttons[button] + separatorString;
49 return commandPadding.substring(cmd.length()) + cmd;
50 }
51
52 private static final String left(Context context, int mod, int other) {
53 switch(context) {
54 case widget: return "Left click widget";
55 case background:
56 if((mod & (control | shift)) != 0) return "Go forward";
57 return "Go back";
58
59 default:
60 if((other & action) != 0 && (mod & control) == 0) return "Run action";
61 if((other & link) != 0) return "Follow link";
62 return "Create link";
63 }
64 }
65
66 private static final String middle(Context context, int mod, int other) {
67 switch(context) {
68 case widget: return "Middle click widget";
69 case background:
70 if((other & cursor) != 0) return FreeItems.hasMultipleVisibleItems() ? "Put down items" : "Put down item";
71 return "Draw line/arrow";
72 case line:
73 if((mod & shift) != 0) return "Extend shape";
74 case dot:
75 if((mod & shift) != 0) return "Pickup unconstrained";
76 case text:
77 if((other & cursor) != 0 && FreeItems.getInstance().size() == 1 && FreeItems.textOnlyAttachedToCursor()) return "Merge text";
78 default:
79 if((other & cursor) != 0) return FreeItems.hasMultipleVisibleItems() ? "Put down items" : "Put down item";
80 if((mod & shift) != 0) return "Draw line/arrow";
81 return FreeItems.hasMultipleVisibleItems() ? "Pickup items" : "Pickup item";
82 }
83 }
84
85 private static final String right(Context context, int mod, int other) {
86 switch(context) {
87 case widget: return "Right click widget";
88 case background:
89 if((other & cursor) != 0) {
90 if(FreeItems.isDrawingPolyLine()) return "Continue polyline";
91 return "Stamp copy";
92 }
93 return "Draw rectangle";
94 case line:
95 if((mod & shift) != 0) return "Add line";
96 default:
97 if((other & cursor) != 0) return "Stamp copy";
98 if((mod & shift) != 0) return "Draw rectangle";
99 if(context == Context.polygon) return "Copy enclosed items";
100 return "Copy item";
101 }
102 }
103
104 private static final String left_right(Context context, int mod, int other) {
105 switch(context) {
106 case widget: return null;
107 default:
108 if((other & cursor) == 0 && (context != Context.polygon)) return "Extract attributes";
109 case background:
110 return "Auto format";
111 }
112 }
113
114 private static final String middle_right(Context context, int mod, int other) {
115 switch(context) {
116 case widget: return null;
117 case text:
118 if((other & cursor) != 0 && FreeItems.getInstance().size() == 1 && FreeItems.textOnlyAttachedToCursor()) return "Swap text";
119 break;
120 case background:
121 if((other & cursor) == 0) return "Undo last delete";
122 break;
123 }
124 return "Delete";
125 }
126
127 private static final String drag_left(Context context, int mod, int other) {
128 switch(context) {
129 case widget: return null;
130 case background:
131 if((mod & shift) != 0 && (other & cursor) == 0 && (other & panning) != 0) return "Drag to pan";
132 break;
133 case text:
134 if((other & cursor) == 0) return "Select text region";
135 break;
136 }
137 return null;
138 }
139
140 private static final String drag_middle(Context context, int mod, int other) {
141 switch(context) {
142 case widget: return null;
143 case text:
144 if((other & cursor) == 0) return "Cut text region";
145 }
146 return null;
147 }
148
149 private static final String drag_right(Context context, int mod, int other) {
150 switch(context) {
151 case widget: return null;
152 case image:
153 return "Crop image";
154 case line:
155 return "Extrude shape";
156 case text:
157 if((other & cursor) == 0) return "Copy text region";
158 }
159 return null;
160 }
161
162
163 public static void updateStatus() {
164 Item current = FrameUtils.getCurrentItem();
165 Collection<Item> currents;
166 Context context;
167 InteractiveWidget iw = null;
168 if(current != null) {
169 if(current instanceof Line) {
170 context = Context.line;
171 } else if(current instanceof Text) {
172 context = Context.text;
173 } else if(current instanceof Picture) {
174 context = Context.image;
175 } else if(current instanceof Dot ) {
176 context = Context.dot;
177 }else {
178 context = Context.item;
179 }
180 } else {
181 currents = FrameUtils.getCurrentItems();
182 if(currents != null) {
183 if(currents.size() >= 4) {
184 for(Item i : currents) {
185 if (i instanceof WidgetCorner) {
186 iw = ((WidgetCorner) i).getWidgetSource();
187 break;
188 } else if (i instanceof WidgetEdge) {
189 iw = ((WidgetEdge) i).getWidgetSource();
190 break;
191 }
192 }
193 }
194 if(iw != null) {
195 context = Context.widget;
196 } else {
197 context = Context.polygon;
198 }
199 } else {
200 context = Context.background;
201 }
202 }
203 int mod = (FrameMouseActions.isControlDown() ? control : 0) | (FrameMouseActions.isShiftDown() ? shift : 0);
204 int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) |
205 (current != null && current.hasAction() ? action : 0)|
206 (current != null && current.hasLink() ? link : 0) |
207 (FreeItems.itemsAttachedToCursor() ? cursor : 0);
208 String status = "";
209
210
211 String l = left(context, mod, other);
212 String m = middle(context, mod, other);
213 String r = right(context, mod, other);
214 String lr = left_right(context, mod, other);
215 String mr = middle_right(context, mod, other);
216 String dl = drag_left(context, mod, other);
217 String dm = drag_middle(context, mod, other);
218 String dr = drag_right(context, mod, other);
219
220 if(l != null || m != null || r != null || lr != null) status += " Click:";
221 if(l != null) status += command(mod, left) + l + padding.substring(l.length());
222 if(m != null) status += command(mod, middle) + m + padding.substring(m.length());
223 if(r != null) status += command(mod, right) + r + padding.substring(r.length());
224 if(lr != null) status += command(mod, left | right) + lr + padding.substring(lr.length());
225 if(mr != null) status += command(mod, middle | right) + mr + padding.substring(mr.length());
226 if(dl != null || dm != null || dr != null || iw != null) status += "\n Drag: ";
227 if(dl != null) status += command(mod, left) + dl + padding.substring(dl.length());
228 if(dm != null) status += command(mod, middle) + dm + padding.substring(dm.length());
229 if(dr != null) status += command(mod, right) + dr + padding.substring(dr.length());
230 if(iw != null) status += commandPadding + "Widget: " + iw.getClass().getSimpleName();
231
232
233 MessageBay.setStatus(status);
234 }
235
236}
Note: See TracBrowser for help on using the repository browser.