- Timestamp:
- 01/13/14 10:28:53 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/Help.java
r681 r683 11 11 12 12 // contexts 13 p ublic static final int background = 0, item = 1;13 private static final int background = 0, item = 1, line = 2, text = 3; 14 14 15 15 // mouse buttons 16 p ublicstatic final int left = 1, middle = 2, right = 4;16 private static final int left = 1, middle = 2, right = 4; 17 17 private static final String[] buttons = { "", "L", "M", "LM", "R", "LR", "MR" }; 18 18 19 19 // modifiers 20 p ublic static final int none = 0, control = 1, shift = 2, drag = 4;21 private static final String[] modifiers = { "", "^", "+", "^+" , "d", "d^", "d+", "d^+"};20 private static final int control = 1, shift = 2; 21 private static final String[] modifiers = { "", "^", "+", "^+" }; 22 22 23 23 // other 24 p ublic static final int panning = 1, action = 2, line = 4, cursor = 8;24 private static final int panning = 1, action = 2, cursor = 4; 25 25 26 26 // separator between command and description 27 private static final String separator = ": "; 28 29 /** 30 * Set each index of $array to reference $value 31 */ 32 private static final void fill(String[] array, String value) { 33 for(int i = 0; i < array.length; i++) { 34 array[i] = value; 35 } 36 } 37 38 /** 39 * Set each index of $array to reference an array filled with $value 40 */ 41 private static final void fill(String[][] array, String value) { 42 array[0] = new String[array[0].length]; 43 fill(array[0], value); 44 for(int i = 1; i < array.length; i++) { 45 array[i] = array[0]; 46 } 47 } 48 49 /** 50 * Set the indices of $array that have $indexBit set (or not set if $invert) to reference $value 51 */ 52 private static final void fill(String[] array, int indexBit, String value, boolean invert, boolean lazy) { 53 for(int i = 0; i < array.length; i++) { 54 if((!lazy && ((i & indexBit) == indexBit && !invert) || ((i & indexBit) == 0 && invert)) || 55 (lazy && ((i & indexBit) != 0 && !invert) || ((i & indexBit) != indexBit && invert))){ 56 array[i] = value; 57 } 58 } 59 } 60 61 /** 62 * Calls fill(array, indexBit, value, false, false) 63 */ 64 private static final void fill(String[] array, int indexBit, String value) { 65 fill(array, indexBit, value, false, false); 66 } 67 68 /** 69 * Set the indices of $array that have $indexBit set (or not set if $invert) to reference an array filled with $value 70 */ 71 private static final void fill(String[][] array, int indexBit, String value, boolean invert, boolean lazy) { 72 for(int i = 0; i < array.length; i++) { 73 if((!lazy && ((i & indexBit) == indexBit && !invert) || ((i & indexBit) == 0 && invert)) || 74 (lazy && ((i & indexBit) != 0 && !invert) || ((i & indexBit) != indexBit && invert))){ 75 fill(array[i] = Arrays.copyOf(array[i], array[i].length), value); 76 } 77 } 78 } 79 80 /** 81 * Calls fill(array, indexBit, value, false, false) 82 */ 83 private static final void fill(String[][] array, int indexBit, String value) { 84 fill(array, indexBit, value, false, false); 85 } 86 87 /** 88 * For each array at the indices of $array that have $indexBit set (or not set if $invert), 89 * set each index that has $indexBit2 set (or not set if $invert) to reference $value 90 */ 91 private static final void fill(String[][] array, int indexBit, int indexBit2, String value, boolean invert, boolean invert2, boolean lazy, boolean lazy2) { 92 for(int i = 0; i < array.length; i++) { 93 if((!lazy && ((i & indexBit) == indexBit && !invert) || ((i & indexBit) == 0 && invert)) || 94 (lazy && ((i & indexBit) != 0 && !invert) || ((i & indexBit) != indexBit && invert))) { 95 fill(array[i] = Arrays.copyOf(array[i], array[i].length), indexBit2, value, invert2, lazy2); 96 } 97 } 98 } 99 100 /** 101 * Calls fill(array, indexBit, indexBit2, value, false, false, false, false) 102 */ 103 private static final void fill(String[][] array, int indexBit, int indexBit2, String value) { 104 fill(array, indexBit, indexBit2, value, false, false, false, false); 105 } 106 107 // help text 108 private static final String[/* contexts */][/* buttons */][/* modifiers */][/* other */] statusText = new String[2][8][8][16]; 109 static { 110 fill(statusText[background][left], "Go back"); 111 fill(statusText[background][left], control | shift, "Go forward", false, true); 112 fill(statusText[background][left], drag, null); // no action for dragging unless shift down 113 fill(statusText[background][left], shift | drag, panning, "Drag to pan"); 114 fill(statusText[background][left], drag, cursor, null); 115 116 fill(statusText[background][middle], "Create arrow"); 117 fill(statusText[background][middle], 0, cursor, "Place item(s)", true, false, true, false); 118 fill(statusText[background][middle], drag, null); // no action for dragging 119 120 fill(statusText[background][right], "Create rectangle"); 121 fill(statusText[background][right], 0, cursor, "Stamp item(s)", true, false, true, false); 122 fill(statusText[background][right], drag, null); // no action for dragging 123 124 fill(statusText[background][left | middle], null); // no action for left + middle 125 126 fill(statusText[background][left | right], "Auto format"); 127 128 fill(statusText[background][middle | right], "Undo"); 129 fill(statusText[background][middle | right], 0, cursor, "Delete", true, false, true, false); 130 131 132 fill(statusText[item][left], "Follow link"); 133 fill(statusText[item][left], control, action, "Run action", true, false, false, false); 134 fill(statusText[item][left], drag, null); // no action for dragging 135 136 fill(statusText[item][middle], "Pickup"); 137 fill(statusText[item][middle], shift, "Create arrow"); 138 fill(statusText[item][middle], 0, cursor, "Place item(s)", true, false, true, false); 139 fill(statusText[item][middle], drag, null); // no action for dragging 140 141 fill(statusText[item][right], "Copy"); 142 fill(statusText[item][right], shift, "Create rectangle"); 143 fill(statusText[item][right], 0, cursor, "Stamp item(s)", true, false, true, false); 144 fill(statusText[item][right], drag, null); // no action for dragging unless currentItem is a line 145 fill(statusText[item][right], drag, line, "Extrude shape"); 146 147 fill(statusText[item][left | middle], null); // no action for left + middle 148 149 fill(statusText[item][left | right], "Extract attributes"); 150 fill(statusText[item][left | right], 0, cursor, null, true, false, true, false); 151 152 fill(statusText[item][middle | right], "Delete"); 153 } 27 private static final String separatorString = ": "; 28 // flag for dragging 29 private static final String dragString = "d"; 154 30 155 31 private static final String commandPadding = " "; 156 32 private static final String padding = " "; 157 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 158 39 private static final String command(int mod, int button) { 159 String cmd = modifiers[mod] + buttons[button]; 160 return commandPadding.substring(cmd.length()) + cmd + separator; 40 return command(mod, button, false); 161 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 162 132 163 133 public static void updateStatus() { 164 134 Item current = FrameUtils.getCurrentItem(); 165 int context = current != null || FrameUtils.getCurrentItems() != null ? item : background; 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 } 166 147 int mod = (FrameMouseActions.isControlDown() ? control : 0) | (FrameMouseActions.isShiftDown() ? shift : 0); 167 int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) | (current != null && current.hasAction() ? action : 0) | ( current instanceof Line ? line : 0) | (FreeItems.itemsAttachedToCursor() ? cursor : 0);148 int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) | (current != null && current.hasAction() ? action : 0) | (FreeItems.itemsAttachedToCursor() ? cursor : 0); 168 149 String status = ""; 169 150 170 String l = statusText[context][left][mod][other];171 String m = statusText[context][middle][mod][other];172 String r = statusText[context][right][mod][other];173 String lr = statusText[context][left | right][mod][other];174 String lm = statusText[context][left | middle][mod][other];175 String mr = statusText[context][middle | right][mod][other];176 String dl = statusText[context][left][mod | drag][other];177 String dm = statusText[context][middle][mod | drag][other];178 String dr = statusText[context][right][mod | drag][other];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); 179 160 180 161 if(l != null) status += command(mod, left) + l + padding.substring(l.length()); … … 185 166 if(mr != null) status += command(mod, middle | right) + mr + padding.substring(mr.length()); 186 167 if(dl != null || dm != null || dr != null) status += "\n"; 187 if(dl != null) status += command(mod | drag, left) + dl + padding.substring(dl.length());188 if(dm != null) status += command(mod | drag, middle) + dm + padding.substring(dm.length());189 if(dr != null) status += command(mod | drag, right) + dr + padding.substring(dr.length());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()); 190 171 191 172 MessageBay.setStatus(status);
Note:
See TracChangeset
for help on using the changeset viewer.