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

Last change on this file since 685 was 685, checked in by jts21, 10 years ago

Fix incorrect case dropdown

File size: 5.7 KB
Line 
1package org.expeditee.gui;
2
3import org.expeditee.items.Item;
4import org.expeditee.items.Line;
5import org.expeditee.items.Text;
6import org.expeditee.settings.experimental.ExperimentalFeatures;
7
8
9public 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 break;
101 case background:
102 if((other & cursor) == 0) return "Undo";
103 break;
104 }
105 return "Delete";
106 }
107
108 private static final String drag_left(int context, int mod, int other) {
109 switch(context) {
110 case background:
111 if((mod & shift) != 0 && (other & cursor) == 0) return "Drag to pan";
112 break;
113 case text:
114 if((other & cursor) == 0) return "Select region";
115 break;
116 }
117 return null;
118 }
119
120 private static final String drag_middle(int context, int mod, int other) {
121 switch(context) {
122 case text:
123 if((other & cursor) == 0) return "Cut region";
124 }
125 return null;
126 }
127
128 private static final String drag_right(int context, int mod, int other) {
129 switch(context) {
130 case line:
131 return "Extrude shape";
132 case text:
133 if((other & cursor) == 0) return "Copy region";
134 }
135 return null;
136 }
137
138
139 public static void updateStatus() {
140 Item current = FrameUtils.getCurrentItem();
141 int context;
142 if(current != null) {
143 if(current instanceof Line) {
144 context = line;
145 } else if(current instanceof Text) {
146 context = text;
147 } else {
148 context = item;
149 }
150 } else if(FrameUtils.getCurrentItems() != null) {
151 context = item;
152 } else {
153 context = background;
154 }
155 int mod = (FrameMouseActions.isControlDown() ? control : 0) | (FrameMouseActions.isShiftDown() ? shift : 0);
156 int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) | (current != null && current.hasAction() ? action : 0) | (FreeItems.itemsAttachedToCursor() ? cursor : 0);
157 String status = "";
158
159 String l = left(context, mod, other);
160 String m = middle(context, mod, other);
161 String r = right(context, mod, other);
162 String lr = left_right(context, mod, other);
163 String lm = left_middle(context, mod, other);
164 String mr = middle_right(context, mod, other);
165 String dl = drag_left(context, mod, other);
166 String dm = drag_middle(context, mod, other);
167 String dr = drag_right(context, mod, other);
168
169 if(l != null) status += command(mod, left) + l + padding.substring(l.length());
170 if(m != null) status += command(mod, middle) + m + padding.substring(m.length());
171 if(r != null) status += command(mod, right) + r + padding.substring(r.length());
172 if(lm != null) status += command(mod, left | middle) + lm + padding.substring(lm.length());
173 if(lr != null) status += command(mod, left | right) + lr + padding.substring(lr.length());
174 if(mr != null) status += command(mod, middle | right) + mr + padding.substring(mr.length());
175 if(dl != null || dm != null || dr != null) status += "\n";
176 if(dl != null) status += command(mod, left, true) + dl + padding.substring(dl.length());
177 if(dm != null) status += command(mod, middle, true) + dm + padding.substring(dm.length());
178 if(dr != null) status += command(mod, right, true) + dr + padding.substring(dr.length());
179
180 MessageBay.setStatus(status);
181 }
182
183}
Note: See TracBrowser for help on using the repository browser.