1 | package org.expeditee.gui;
|
---|
2 |
|
---|
3 | import org.expeditee.items.Item;
|
---|
4 | import org.expeditee.items.Line;
|
---|
5 | import org.expeditee.items.Text;
|
---|
6 | import org.expeditee.settings.experimental.ExperimentalFeatures;
|
---|
7 |
|
---|
8 |
|
---|
9 | public class Help {
|
---|
10 |
|
---|
11 | // contexts
|
---|
12 | private static final int background = 0, item = 1, line = 2, text = 3;
|
---|
13 |
|
---|
14 | // mouse buttons
|
---|
15 | private static final int left = 1, middle = 2, right = 4;
|
---|
16 | private static final String[] buttons = { "", "L", "M", "LM", "R", "LR", "MR" };
|
---|
17 |
|
---|
18 | // modifiers
|
---|
19 | private static final int control = 1, shift = 2;
|
---|
20 | private static final String[] modifiers = { "", "^", "+", "^+" };
|
---|
21 |
|
---|
22 | // other
|
---|
23 | private static final int panning = 1, action = 2, cursor = 4;
|
---|
24 |
|
---|
25 | // separator between command and description
|
---|
26 | private static final String separatorString = ": ";
|
---|
27 | // flag for dragging
|
---|
28 | private static final String dragString = "d";
|
---|
29 |
|
---|
30 | private static final String commandPadding = " ";
|
---|
31 | private static final String padding = " ";
|
---|
32 |
|
---|
33 | private static final String command(int mod, int button, boolean drag) {
|
---|
34 | String cmd = (drag ? dragString : "") + modifiers[mod] + buttons[button];
|
---|
35 | return commandPadding.substring(cmd.length()) + cmd + separatorString;
|
---|
36 | }
|
---|
37 |
|
---|
38 | private static final String command(int mod, int button) {
|
---|
39 | return command(mod, button, false);
|
---|
40 | }
|
---|
41 |
|
---|
42 | private static final String left(int context, int mod, int other) {
|
---|
43 | switch(context) {
|
---|
44 | case background:
|
---|
45 | if((mod & (control | shift)) != 0) return "Go forward";
|
---|
46 | return "Go back";
|
---|
47 | default:
|
---|
48 | if((other & action) != 0 && (mod & control) == 0) return "Run action";
|
---|
49 | return "Follow link";
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | private static final String middle(int context, int mod, int other) {
|
---|
54 | switch(context) {
|
---|
55 | case background:
|
---|
56 | if((other & cursor) != 0) return "Place item(s)";
|
---|
57 | return "Create arrow";
|
---|
58 | case line:
|
---|
59 | if((mod & shift) != 0) return "Extend shape";
|
---|
60 | case text:
|
---|
61 | if((other & cursor) != 0 && FrameUtils.getCurrentItem() instanceof Text) return "Merge text";
|
---|
62 | default:
|
---|
63 | if((other & cursor) != 0) return "Place item(s)";
|
---|
64 | if((mod & shift) != 0) return "Create arrow";
|
---|
65 | return "Pickup";
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | private static final String right(int context, int mod, int other) {
|
---|
70 | switch(context) {
|
---|
71 | case background:
|
---|
72 | if((other & cursor) != 0) return "Stamp item(s)";
|
---|
73 | return "Create rectangle";
|
---|
74 | case line:
|
---|
75 | if((mod & shift) != 0) return "Add line";
|
---|
76 | default:
|
---|
77 | if((other & cursor) != 0) return "Stamp item(s)";
|
---|
78 | if((mod & shift) != 0) return "Create rectangle";
|
---|
79 | return "Copy";
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | private static final String left_middle(int context, int mod, int other) {
|
---|
84 | return null;
|
---|
85 | }
|
---|
86 |
|
---|
87 | private static final String left_right(int context, int mod, int other) {
|
---|
88 | switch(context) {
|
---|
89 | default:
|
---|
90 | if((other & cursor) == 0) return "Extract attributes";
|
---|
91 | case background:
|
---|
92 | return "Auto format";
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | private static final String middle_right(int context, int mod, int other) {
|
---|
97 | switch(context) {
|
---|
98 | case text:
|
---|
99 | if((other & cursor) != 0 && FrameUtils.getCurrentItem() instanceof Text) return "Swap text";
|
---|
100 | case background:
|
---|
101 | if((other & cursor) == 0) return "Undo";
|
---|
102 | default:
|
---|
103 | return "Delete";
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | private static final String drag_left(int context, int mod, int other) {
|
---|
108 | switch(context) {
|
---|
109 | case background:
|
---|
110 | if((mod & shift) != 0 && (other & cursor) == 0) return "Drag to pan";
|
---|
111 | case text:
|
---|
112 | if((other & cursor) == 0) return "Select region";
|
---|
113 | }
|
---|
114 | return null;
|
---|
115 | }
|
---|
116 |
|
---|
117 | private static final String drag_middle(int context, int mod, int other) {
|
---|
118 | switch(context) {
|
---|
119 | case text:
|
---|
120 | if((other & cursor) == 0) return "Cut region";
|
---|
121 | }
|
---|
122 | return null;
|
---|
123 | }
|
---|
124 |
|
---|
125 | private static final String drag_right(int context, int mod, int other) {
|
---|
126 | switch(context) {
|
---|
127 | case line:
|
---|
128 | return "Extrude shape";
|
---|
129 | case text:
|
---|
130 | if((other & cursor) == 0) return "Copy region";
|
---|
131 | }
|
---|
132 | return null;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | public static void updateStatus() {
|
---|
137 | Item current = FrameUtils.getCurrentItem();
|
---|
138 | int context;
|
---|
139 | if(current != null) {
|
---|
140 | if(current instanceof Line) {
|
---|
141 | context = line;
|
---|
142 | } else if(current instanceof Text) {
|
---|
143 | context = text;
|
---|
144 | } else {
|
---|
145 | context = item;
|
---|
146 | }
|
---|
147 | } else if(FrameUtils.getCurrentItems() != null) {
|
---|
148 | context = item;
|
---|
149 | } else {
|
---|
150 | context = background;
|
---|
151 | }
|
---|
152 | int mod = (FrameMouseActions.isControlDown() ? control : 0) | (FrameMouseActions.isShiftDown() ? shift : 0);
|
---|
153 | int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) | (current != null && current.hasAction() ? action : 0) | (FreeItems.itemsAttachedToCursor() ? cursor : 0);
|
---|
154 | String status = "";
|
---|
155 |
|
---|
156 | String l = left(context, mod, other);
|
---|
157 | String m = middle(context, mod, other);
|
---|
158 | String r = right(context, mod, other);
|
---|
159 | String lr = left_right(context, mod, other);
|
---|
160 | String lm = left_middle(context, mod, other);
|
---|
161 | String mr = middle_right(context, mod, other);
|
---|
162 | String dl = drag_left(context, mod, other);
|
---|
163 | String dm = drag_middle(context, mod, other);
|
---|
164 | String dr = drag_right(context, mod, other);
|
---|
165 |
|
---|
166 | if(l != null) status += command(mod, left) + l + padding.substring(l.length());
|
---|
167 | if(m != null) status += command(mod, middle) + m + padding.substring(m.length());
|
---|
168 | if(r != null) status += command(mod, right) + r + padding.substring(r.length());
|
---|
169 | if(lm != null) status += command(mod, left | middle) + lm + padding.substring(lm.length());
|
---|
170 | if(lr != null) status += command(mod, left | right) + lr + padding.substring(lr.length());
|
---|
171 | if(mr != null) status += command(mod, middle | right) + mr + padding.substring(mr.length());
|
---|
172 | if(dl != null || dm != null || dr != null) status += "\n";
|
---|
173 | if(dl != null) status += command(mod, left, true) + dl + padding.substring(dl.length());
|
---|
174 | if(dm != null) status += command(mod, middle, true) + dm + padding.substring(dm.length());
|
---|
175 | if(dr != null) status += command(mod, right, true) + dr + padding.substring(dr.length());
|
---|
176 |
|
---|
177 | MessageBay.setStatus(status);
|
---|
178 | }
|
---|
179 |
|
---|
180 | }
|
---|