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

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

Add help text for Text items

File size: 5.7 KB
RevLine 
[673]1package org.expeditee.gui;
2
[674]3import org.expeditee.items.Item;
[681]4import org.expeditee.items.Line;
[684]5import org.expeditee.items.Text;
[673]6import org.expeditee.settings.experimental.ExperimentalFeatures;
7
8
[674]9public class Help {
[673]10
11 // contexts
[683]12 private static final int background = 0, item = 1, line = 2, text = 3;
[673]13
14 // mouse buttons
[683]15 private static final int left = 1, middle = 2, right = 4;
[674]16 private static final String[] buttons = { "", "L", "M", "LM", "R", "LR", "MR" };
[673]17
[674]18 // modifiers
[683]19 private static final int control = 1, shift = 2;
20 private static final String[] modifiers = { "", "^", "+", "^+" };
[673]21
[674]22 // other
[683]23 private static final int panning = 1, action = 2, cursor = 4;
[673]24
25 // separator between command and description
[683]26 private static final String separatorString = ": ";
27 // flag for dragging
28 private static final String dragString = "d";
[673]29
[683]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;
[673]36 }
37
[683]38 private static final String command(int mod, int button) {
39 return command(mod, button, false);
[674]40 }
41
[683]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";
[684]47 default:
[683]48 if((other & action) != 0 && (mod & control) == 0) return "Run action";
49 return "Follow link";
[674]50 }
51 }
52
[683]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";
[684]60 case text:
61 if((other & cursor) != 0 && FrameUtils.getCurrentItem() instanceof Text) return "Merge text";
62 default:
[683]63 if((other & cursor) != 0) return "Place item(s)";
64 if((mod & shift) != 0) return "Create arrow";
65 return "Pickup";
66 }
[680]67 }
68
[683]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";
[684]76 default:
[683]77 if((other & cursor) != 0) return "Stamp item(s)";
78 if((mod & shift) != 0) return "Create rectangle";
79 return "Copy";
[678]80 }
81 }
82
[683]83 private static final String left_middle(int context, int mod, int other) {
84 return null;
[674]85 }
86
[683]87 private static final String left_right(int context, int mod, int other) {
88 switch(context) {
[684]89 default:
[683]90 if((other & cursor) == 0) return "Extract attributes";
91 case background:
92 return "Auto format";
[674]93 }
94 }
95
[683]96 private static final String middle_right(int context, int mod, int other) {
97 switch(context) {
[684]98 case text:
99 if((other & cursor) != 0 && FrameUtils.getCurrentItem() instanceof Text) return "Swap text";
[683]100 case background:
101 if((other & cursor) == 0) return "Undo";
[684]102 default:
[683]103 return "Delete";
104 }
[680]105 }
106
[683]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";
[684]111 case text:
112 if((other & cursor) == 0) return "Select region";
[683]113 }
114 return null;
[673]115 }
116
[683]117 private static final String drag_middle(int context, int mod, int other) {
[684]118 switch(context) {
119 case text:
120 if((other & cursor) == 0) return "Cut region";
121 }
[683]122 return null;
123 }
[673]124
[683]125 private static final String drag_right(int context, int mod, int other) {
126 switch(context) {
127 case line:
128 return "Extrude shape";
[684]129 case text:
130 if((other & cursor) == 0) return "Copy region";
[683]131 }
132 return null;
[674]133 }
134
[683]135
[673]136 public static void updateStatus() {
[674]137 Item current = FrameUtils.getCurrentItem();
[683]138 int context;
139 if(current != null) {
140 if(current instanceof Line) {
141 context = line;
[684]142 } else if(current instanceof Text) {
143 context = text;
[683]144 } else {
145 context = item;
146 }
147 } else if(FrameUtils.getCurrentItems() != null) {
148 context = item;
149 } else {
150 context = background;
151 }
[674]152 int mod = (FrameMouseActions.isControlDown() ? control : 0) | (FrameMouseActions.isShiftDown() ? shift : 0);
[683]153 int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) | (current != null && current.hasAction() ? action : 0) | (FreeItems.itemsAttachedToCursor() ? cursor : 0);
[678]154 String status = "";
155
[683]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);
[678]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";
[683]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());
[678]176
177 MessageBay.setStatus(status);
[673]178 }
179
180}
Note: See TracBrowser for help on using the repository browser.