1 | /**
|
---|
2 | * Help.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.gui;
|
---|
20 |
|
---|
21 | import java.util.Collection;
|
---|
22 |
|
---|
23 | import org.expeditee.items.Dot;
|
---|
24 | import org.expeditee.items.Item;
|
---|
25 | import org.expeditee.items.Line;
|
---|
26 | import org.expeditee.items.Picture;
|
---|
27 | import org.expeditee.items.Text;
|
---|
28 | import org.expeditee.items.widgets.Widget;
|
---|
29 | import org.expeditee.items.widgets.WidgetCorner;
|
---|
30 | import org.expeditee.items.widgets.WidgetEdge;
|
---|
31 | import org.expeditee.settings.experimental.ExperimentalFeatures;
|
---|
32 |
|
---|
33 | public class Help {
|
---|
34 |
|
---|
35 | // contexts
|
---|
36 | private static enum Context {
|
---|
37 | background,
|
---|
38 | item,
|
---|
39 | polygon,
|
---|
40 | line,
|
---|
41 | dot,
|
---|
42 | text,
|
---|
43 | image,
|
---|
44 | widget
|
---|
45 | };
|
---|
46 |
|
---|
47 | // mouse buttons
|
---|
48 | private static final int left = 1, middle = 2, right = 4;
|
---|
49 | private static final String[] buttons = { "", "L", "M", "LM", "R", "LR", "MR" };
|
---|
50 |
|
---|
51 | // modifiers
|
---|
52 | private static final int control = 1, shift = 2;
|
---|
53 | private static final String[] modifiers = { "", "^", "+", "^+" };
|
---|
54 |
|
---|
55 | // other
|
---|
56 | private static final int panning = 1, action = 2, link = 4, cursor = 8;
|
---|
57 |
|
---|
58 | // separator between command and description
|
---|
59 | private static final String separatorString = ": ";
|
---|
60 |
|
---|
61 | private static final String commandPadding = " ";
|
---|
62 | private static final String padding = " ";
|
---|
63 | private static final String emptyPadding = commandPadding + padding;
|
---|
64 |
|
---|
65 | private static final String command(int mod, int button) {
|
---|
66 | String cmd = modifiers[mod] + buttons[button] + separatorString;
|
---|
67 | return commandPadding.substring(cmd.length()) + cmd;
|
---|
68 | }
|
---|
69 |
|
---|
70 | private static final String left(Context context, int mod, int other) {
|
---|
71 | switch(context) {
|
---|
72 | case widget: return "Left click widget";
|
---|
73 | case background:
|
---|
74 | if((mod & (control | shift)) != 0) return "Go forward";
|
---|
75 | return "Go back";
|
---|
76 |
|
---|
77 | default:
|
---|
78 | if((other & action) != 0 && (mod & control) == 0) return "Run action";
|
---|
79 | if((other & link) != 0) return "Follow link";
|
---|
80 | return "Create link";
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | private static final String middle(Context context, int mod, int other) {
|
---|
85 | switch(context) {
|
---|
86 | case widget: return "Middle click widget";
|
---|
87 | case background:
|
---|
88 | if((other & cursor) != 0) return FreeItems.hasMultipleVisibleItems() ? "Put down items" : "Put down item";
|
---|
89 | return "Draw line/arrow";
|
---|
90 | case line:
|
---|
91 | if(FreeItems.isDrawingPolyLine()) return "Spot-weld polyline";
|
---|
92 | if((mod & shift) != 0) return "Extend shape";
|
---|
93 | case dot:
|
---|
94 | if((mod & shift) != 0) return "Pickup unconstrained";
|
---|
95 | case text:
|
---|
96 | if((other & cursor) != 0 && FreeItems.getInstance().size() == 1 && FreeItems.textOnlyAttachedToCursor()) return "Merge text";
|
---|
97 | default:
|
---|
98 | if((other & cursor) != 0) return FreeItems.hasMultipleVisibleItems() ? "Put down items" : "Put down item";
|
---|
99 | if((mod & shift) != 0) return "Draw line/arrow";
|
---|
100 | if(context == Context.polygon) return "Pickup enclo'd items";
|
---|
101 | return "Pickup item";
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | private static final String right(Context context, int mod, int other) {
|
---|
106 | switch(context) {
|
---|
107 | case widget: return "Right click widget";
|
---|
108 | case background:
|
---|
109 | if((other & cursor) != 0) {
|
---|
110 | if(FreeItems.isDrawingPolyLine()) return "Continue polyline";
|
---|
111 | return "Stamp copy";
|
---|
112 | }
|
---|
113 | return "Draw rectangle";
|
---|
114 | case line:
|
---|
115 | if(FreeItems.isDrawingPolyLine()) return "Spot-weld & continue";
|
---|
116 | if((mod & shift) != 0) return "Add line";
|
---|
117 | break;
|
---|
118 | case dot:
|
---|
119 | if((mod & shift) == 0)return "Extend line";
|
---|
120 | break;
|
---|
121 | default:
|
---|
122 | break;
|
---|
123 | }
|
---|
124 | if((other & cursor) != 0) return "Stamp copy";
|
---|
125 | if((mod & shift) != 0) return "Draw rectangle";
|
---|
126 | if(context == Context.polygon) return "Copy enclosed items";
|
---|
127 | return "Copy item";
|
---|
128 | }
|
---|
129 |
|
---|
130 | private static final String left_right(Context context, int mod, int other) {
|
---|
131 | switch(context) {
|
---|
132 | case widget: return null;
|
---|
133 | default:
|
---|
134 | if((other & cursor) == 0) return "Extract attributes";
|
---|
135 | return null;
|
---|
136 | case polygon:
|
---|
137 | case background:
|
---|
138 | if((mod & control) != 0) return "Horizontal format";
|
---|
139 | return "Vertical format";
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | private static final String middle_right(Context context, int mod, int other) {
|
---|
144 | switch(context) {
|
---|
145 | case widget: return null;
|
---|
146 | case text:
|
---|
147 | if((other & cursor) != 0 && FreeItems.getInstance().size() == 1 && FreeItems.textOnlyAttachedToCursor()) return "Swap text";
|
---|
148 | break;
|
---|
149 | case background:
|
---|
150 | if((other & cursor) == 0) {
|
---|
151 | if((mod & control) != 0) return "Redo";
|
---|
152 | return "Undo";
|
---|
153 | }
|
---|
154 | break;
|
---|
155 | default:
|
---|
156 | break;
|
---|
157 | }
|
---|
158 | return "Delete";
|
---|
159 | }
|
---|
160 |
|
---|
161 | private static final String drag_left(Context context, int mod, int other) {
|
---|
162 | switch(context) {
|
---|
163 | case widget: return null;
|
---|
164 | case background:
|
---|
165 | if((mod & shift) != 0 && (other & cursor) == 0 && (other & panning) != 0) return "Drag to pan";
|
---|
166 | break;
|
---|
167 | case text:
|
---|
168 | if((other & cursor) == 0) return "Select text region";
|
---|
169 | break;
|
---|
170 | default:
|
---|
171 | break;
|
---|
172 | }
|
---|
173 | return null;
|
---|
174 | }
|
---|
175 |
|
---|
176 | private static final String drag_middle(Context context, int mod, int other) {
|
---|
177 | switch(context) {
|
---|
178 | case widget: return null;
|
---|
179 | case text:
|
---|
180 | if((other & cursor) == 0) return "Cut text region";
|
---|
181 | default:
|
---|
182 | break;
|
---|
183 | }
|
---|
184 | return null;
|
---|
185 | }
|
---|
186 |
|
---|
187 | private static final String drag_right(Context context, int mod, int other) {
|
---|
188 | switch(context) {
|
---|
189 | case widget: return null;
|
---|
190 | case image:
|
---|
191 | return "Crop image";
|
---|
192 | case line:
|
---|
193 | return "Extrude shape";
|
---|
194 | case text:
|
---|
195 | if((other & cursor) == 0) return "Copy text region";
|
---|
196 | default:
|
---|
197 | break;
|
---|
198 | }
|
---|
199 | return null;
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | public static void updateStatus(boolean controlDown, boolean shiftDown)
|
---|
204 | {
|
---|
205 | Item current = FrameUtils.getCurrentItem();
|
---|
206 | Collection<Item> currents;
|
---|
207 | Context context;
|
---|
208 | Widget iw = null;
|
---|
209 | if(current != null) {
|
---|
210 | if(current instanceof Line) {
|
---|
211 | context = Context.line;
|
---|
212 | } else if(current instanceof Text) {
|
---|
213 | context = Context.text;
|
---|
214 | } else if(current instanceof Picture) {
|
---|
215 | context = Context.image;
|
---|
216 | } else if(current instanceof Dot ) {
|
---|
217 | context = Context.dot;
|
---|
218 | }else {
|
---|
219 | context = Context.item;
|
---|
220 | }
|
---|
221 | } else {
|
---|
222 | currents = FrameUtils.getCurrentItems();
|
---|
223 | if(currents != null) {
|
---|
224 | if(currents.size() >= 4) {
|
---|
225 | for(Item i : currents) {
|
---|
226 | if (i instanceof WidgetCorner) {
|
---|
227 | iw = ((WidgetCorner) i).getWidgetSource();
|
---|
228 | break;
|
---|
229 | } else if (i instanceof WidgetEdge) {
|
---|
230 | iw = ((WidgetEdge) i).getWidgetSource();
|
---|
231 | break;
|
---|
232 | }
|
---|
233 | }
|
---|
234 | }
|
---|
235 | if(iw != null) {
|
---|
236 | context = Context.widget;
|
---|
237 | } else {
|
---|
238 | context = Context.polygon;
|
---|
239 | }
|
---|
240 | } else {
|
---|
241 | context = Context.background;
|
---|
242 | }
|
---|
243 | }
|
---|
244 | int mod = (controlDown ? control : 0) | (shiftDown ? shift : 0);
|
---|
245 | int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) |
|
---|
246 | (current != null && current.hasAction() ? action : 0)|
|
---|
247 | (current != null && current.hasLink() ? link : 0) |
|
---|
248 | (FreeItems.hasItemsAttachedToCursor() ? cursor : 0);
|
---|
249 | String status = "";
|
---|
250 |
|
---|
251 |
|
---|
252 | String l = left(context, mod, other);
|
---|
253 | String m = middle(context, mod, other);
|
---|
254 | String r = right(context, mod, other);
|
---|
255 | String lr = left_right(context, mod, other);
|
---|
256 | String mr = middle_right(context, mod, other);
|
---|
257 | String dl = drag_left(context, mod, other);
|
---|
258 | String dm = drag_middle(context, mod, other);
|
---|
259 | String dr = drag_right(context, mod, other);
|
---|
260 |
|
---|
261 | if(l != null || m != null || r != null || lr != null || mr != null) status += " Click:";
|
---|
262 | status += (l != null ? command(mod, left) + l + padding.substring(l.length()) : emptyPadding);
|
---|
263 | status += (m != null ? command(mod, middle) + m + padding.substring(m.length()) : emptyPadding);
|
---|
264 | status += (r != null ? command(mod, right) + r + padding.substring(r.length()) : emptyPadding);
|
---|
265 | status += (lr != null ? command(mod, left | right) + lr + padding.substring(lr.length()) : emptyPadding);
|
---|
266 | status += (mr != null ? command(mod, middle | right) + mr + padding.substring(mr.length()) : emptyPadding);
|
---|
267 | if(iw != null) {
|
---|
268 | status += "\n Widget: " + iw.getClass().getSimpleName();
|
---|
269 | } else {
|
---|
270 | if(dl != null || dm != null || dr != null) status += "\n Drag: ";
|
---|
271 | status += (dl != null ? command(mod, left) + dl + padding.substring(dl.length()) : emptyPadding);
|
---|
272 | status += (dm != null ? command(mod, middle) + dm + padding.substring(dm.length()) : emptyPadding);
|
---|
273 | status += (dr != null ? command(mod, right) + dr + padding.substring(dr.length()) : emptyPadding);
|
---|
274 | }
|
---|
275 |
|
---|
276 | MessageBay.setStatus(status);
|
---|
277 | }
|
---|
278 |
|
---|
279 | }
|
---|