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