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

Last change on this file since 744 was 744, checked in by jts21, 10 years ago
  • Implement redo buffer (every time you undo the changes get pushed to the redo buffer)
  • Modify undo/redo so each individual undo/redo is either a deletion or a modification, this fixes the problem where undoing a modification to an item whose id had changed would clone the item (now instead it will just not undo that modification, which should be fine since the only way to change an item's ID now is to move it to another frame and back again)
  • Fix issue with copying/cutting when there were items on FreeItems that were connected to items on the Frame (i.e. when you were moving the corner of a shape)
File size: 7.9 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 if((mod & control) != 0) return "Horizontal format";
120 return "Vertical format";
121 }
122 }
123
124 private static final String middle_right(Context context, int mod, int other) {
125 switch(context) {
126 case widget: return null;
127 case text:
128 if((other & cursor) != 0 && FreeItems.getInstance().size() == 1 && FreeItems.textOnlyAttachedToCursor()) return "Swap text";
129 break;
130 case background:
131 if((other & cursor) == 0) {
132 if((mod & control) != 0) return "Redo";
133 return "Undo";
134 }
135 break;
136 }
137 return "Delete";
138 }
139
140 private static final String drag_left(Context context, int mod, int other) {
141 switch(context) {
142 case widget: return null;
143 case background:
144 if((mod & shift) != 0 && (other & cursor) == 0 && (other & panning) != 0) return "Drag to pan";
145 break;
146 case text:
147 if((other & cursor) == 0) return "Select text region";
148 break;
149 }
150 return null;
151 }
152
153 private static final String drag_middle(Context context, int mod, int other) {
154 switch(context) {
155 case widget: return null;
156 case text:
157 if((other & cursor) == 0) return "Cut text region";
158 }
159 return null;
160 }
161
162 private static final String drag_right(Context context, int mod, int other) {
163 switch(context) {
164 case widget: return null;
165 case image:
166 return "Crop image";
167 case line:
168 return "Extrude shape";
169 case text:
170 if((other & cursor) == 0) return "Copy text region";
171 }
172 return null;
173 }
174
175
176 public static void updateStatus() {
177 Item current = FrameUtils.getCurrentItem();
178 Collection<Item> currents;
179 Context context;
180 InteractiveWidget iw = null;
181 if(current != null) {
182 if(current instanceof Line) {
183 context = Context.line;
184 } else if(current instanceof Text) {
185 context = Context.text;
186 } else if(current instanceof Picture) {
187 context = Context.image;
188 } else if(current instanceof Dot ) {
189 context = Context.dot;
190 }else {
191 context = Context.item;
192 }
193 } else {
194 currents = FrameUtils.getCurrentItems();
195 if(currents != null) {
196 if(currents.size() >= 4) {
197 for(Item i : currents) {
198 if (i instanceof WidgetCorner) {
199 iw = ((WidgetCorner) i).getWidgetSource();
200 break;
201 } else if (i instanceof WidgetEdge) {
202 iw = ((WidgetEdge) i).getWidgetSource();
203 break;
204 }
205 }
206 }
207 if(iw != null) {
208 context = Context.widget;
209 } else {
210 context = Context.polygon;
211 }
212 } else {
213 context = Context.background;
214 }
215 }
216 int mod = (FrameMouseActions.isControlDown() ? control : 0) | (FrameMouseActions.isShiftDown() ? shift : 0);
217 int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) |
218 (current != null && current.hasAction() ? action : 0)|
219 (current != null && current.hasLink() ? link : 0) |
220 (FreeItems.itemsAttachedToCursor() ? cursor : 0);
221 String status = "";
222
223
224 String l = left(context, mod, other);
225 String m = middle(context, mod, other);
226 String r = right(context, mod, other);
227 String lr = left_right(context, mod, other);
228 String mr = middle_right(context, mod, other);
229 String dl = drag_left(context, mod, other);
230 String dm = drag_middle(context, mod, other);
231 String dr = drag_right(context, mod, other);
232
233 if(l != null || m != null || r != null || lr != null || mr != null) status += " Click:";
234 status += (l != null ? command(mod, left) + l + padding.substring(l.length()) : emptyPadding);
235 status += (m != null ? command(mod, middle) + m + padding.substring(m.length()) : emptyPadding);
236 status += (r != null ? command(mod, right) + r + padding.substring(r.length()) : emptyPadding);
237 status += (lr != null ? command(mod, left | right) + lr + padding.substring(lr.length()) : emptyPadding);
238 status += (mr != null ? command(mod, middle | right) + mr + padding.substring(mr.length()) : emptyPadding);
239 if(iw != null) {
240 status += "\n Widget: " + iw.getClass().getSimpleName();
241 } else {
242 if(dl != null || dm != null || dr != null) status += "\n Drag: ";
243 status += (dl != null ? command(mod, left) + dl + padding.substring(dl.length()) : emptyPadding);
244 status += (dm != null ? command(mod, middle) + dm + padding.substring(dm.length()) : emptyPadding);
245 status += (dr != null ? command(mod, right) + dr + padding.substring(dr.length()) : emptyPadding);
246 }
247
248
249 MessageBay.setStatus(status);
250 }
251
252}
Note: See TracBrowser for help on using the repository browser.