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

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

Switch to using some simple methods instead of a massive array for determining status text

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