Changeset 674
- Timestamp:
- 01/10/14 13:21:49 (10 years ago)
- Location:
- trunk/src/org/expeditee/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/Help.java
r673 r674 3 3 import java.util.Arrays; 4 4 5 import org.expeditee.items.Item; 5 6 import org.expeditee.settings.experimental.ExperimentalFeatures; 6 7 7 8 8 public class Help { 9 public class Help { 9 10 10 11 // contexts 11 public static final int background = 0, item = 1 , action = 2;12 public static final int background = 0, item = 1; 12 13 13 14 // mouse buttons 14 public static final int left = 0, middle = 1, right = 2;15 private static final char[] buttons = { 'L', 'M', 'R'};15 public static final int left = 1, middle = 2, right = 4; 16 private static final String[] buttons = { "", "L", "M", "LM", "R", "LR", "MR" }; 16 17 17 // keyboardmodifiers18 public static final int none = 0, control = 1, shift = 2 ;19 private static final String[] modifiers = { " ", " ^", " +", "^+" };18 // modifiers 19 public static final int none = 0, control = 1, shift = 2, drag = 4; 20 private static final String[] modifiers = { "", "^", "+", "^+", "d", "d^", "d+", "d^+" }; 20 21 21 // settings22 public static final int panning = 1 ;22 // other 23 public static final int panning = 1, action = 2; 23 24 24 25 // separator between command and description 25 26 private static final String separator = ": "; 26 27 27 private static final void setButtonText(String[][] button, String text) { 28 for(String[] s : button) { 29 Arrays.fill(s, text); 28 /** 29 * 30 * @param array 31 * @param max 32 * @return int[] containing all positive values NOT in array, below max 33 */ 34 private static final int[] invert(int[] array, int max) { 35 int c = 0; 36 // count the values within the range from the array 37 for(int i : array) { 38 if(i < max && i >= 0) { 39 c++; 40 } 41 } 42 // make a new array of the correct size 43 int[] ret = new int[max - c]; 44 int p = 0; 45 // populate the array 46 for(int i = 0; i < max; i++) { 47 boolean add = true; 48 for(int j = 0; j < array.length; j++) { 49 if(i == array[j]) { 50 add = false; 51 break; 52 } 53 } 54 if(add) { 55 ret[p++] = i; 56 } 57 } 58 return ret; 59 } 60 61 private static final void fill(String[] array, String value) { 62 for(int i = 0; i < array.length; i++) { 63 array[i] = value; 64 } 65 } 66 67 private static final void fill(String[][] array, String value) { 68 array[0] = Arrays.copyOf(array[0], array[0].length); 69 fill(array[0], value); 70 for(int i = 1; i < array.length; i++) { 71 array[i] = array[0]; 72 } 73 } 74 75 private static final void fill(String[] array, int[] indices, String value, boolean invert) { 76 if(invert) { 77 indices = invert(indices, array.length); 78 } 79 for(int i = 0; i < indices.length; i++) { 80 array[indices[i]] = value; 81 } 82 } 83 84 private static final void fill(String[][] array, int[] indices, String value, boolean invert) { 85 if(invert) { 86 indices = invert(indices, array.length); 87 } 88 array[indices[0]] = Arrays.copyOf(array[indices[0]], array[indices[0]].length); 89 fill(array[indices[0]], value); 90 for(int i = 1; i < indices.length; i++) { 91 array[indices[i]] = array[indices[0]]; 92 } 93 } 94 95 private static final void fill(String[][] array, int[] indices, int[] indices2, String value, boolean invert, boolean invert2) { 96 if(indices != null) { 97 if(invert) { 98 indices = invert(indices, array.length); 99 } 100 // fill the correct indices 101 array[indices[0]] = Arrays.copyOf(array[indices[0]], array[indices[0]].length); 102 fill(array[indices[0]], indices2, value, invert2); 103 for(int i = 1; i < indices.length; i++) { 104 array[indices[i]] = array[indices[0]]; 105 } 106 } else { 107 // fill all indices 108 array[0] = Arrays.copyOf(array[0], array[0].length); 109 fill(array[0], indices2, value, invert2); 110 for(int i = 1; i < array.length; i++) { 111 array[i] = array[0]; 112 } 30 113 } 31 114 } 32 115 33 116 // help text 34 private static final String[ ][][][] helpText = new String[3][3][4][2];117 private static final String[/* contexts */][/* buttons */][/* modifiers */][/* other */] statusText = new String[2][8][8][4]; 35 118 static { 36 setButtonText(helpText[background][left], "Go back"); 37 helpText[background][left][control | shift][panning] = helpText[background][left][shift][panning] = "Drag to pan"; 38 helpText[background][left][control | shift][none] = helpText[background][left][control][none] = helpText[background][left][shift][none] = "Go forward"; 39 setButtonText(helpText[background][middle], "Create arrow"); 40 setButtonText(helpText[background][right], "Create rectangle"); 119 fill(statusText[background][left], "Go back"); 120 fill(statusText[background][left], new int[] { control, control | shift, shift }, "Go forward", false); 121 fill(statusText[background][left], new int[] { control | shift | drag, shift | drag }, new int[] { panning, panning | action }, "Drag to pan", false, false); 122 fill(statusText[background][middle], "Create arrow"); 123 fill(statusText[background][right], "Create rectangle"); 124 fill(statusText[background][left | middle], ""); 125 fill(statusText[background][left | right], "Auto format"); 126 fill(statusText[background][middle | right], "Undo"); 41 127 42 setButtonText(helpText[item][left], "Follow link");43 setButtonText(helpText[item][middle], "Pickup");44 setButtonText(helpText[item][right], "Copy");45 46 setButtonText(helpText[action][left], "Run action");47 setButtonText(helpText[action][middle], "Pickup");48 setButtonText(helpText[action][right], "Copy");128 fill(statusText[item][left], "Follow link"); 129 fill(statusText[item][left], new int[] { control, control | shift }, new int[] { action, panning | action }, "Run action", true, false); 130 fill(statusText[item][middle], "Pickup"); 131 fill(statusText[item][right], "Copy"); 132 fill(statusText[item][left | middle], ""); 133 fill(statusText[item][left | right], "Extract attributes"); 134 fill(statusText[item][middle | right], "Delete"); 49 135 } 50 136 51 public static final String padding = " "; 137 private static final String commandPadding = " "; 138 private static final String padding = " "; 139 140 private static final String command(int mod, int button) { 141 String cmd = modifiers[mod] + buttons[button]; 142 return commandPadding.substring(cmd.length()) + cmd + separator; 143 } 52 144 53 145 public static void updateStatus() { 54 int context = FrameUtils.getCurrentItem() == null ? 0 : FrameUtils.getCurrentItem().hasAction() ? 2 : 1; 55 int mod = (FrameMouseActions.isControlDown() ? 1 : 0) | (FrameMouseActions.isShiftDown() ? 2 : 0); 56 int settings = (ExperimentalFeatures.MousePan.get() ? 1 : 0); 57 String l = modifiers[mod] + buttons[left] + separator + helpText[context][left][mod][settings]; 58 String m = modifiers[mod] + buttons[middle] + separator + helpText[context][middle][mod][settings]; 59 String r = modifiers[mod] + buttons[right] + separator + helpText[context][right][mod][settings]; 60 MessageBay.setStatus(l + padding.substring(l.length()) + m + padding.substring(m.length()) + r + padding.substring(r.length())); 146 Item current = FrameUtils.getCurrentItem(); 147 int context = current != null ? item : 0; 148 int mod = (FrameMouseActions.isControlDown() ? control : 0) | (FrameMouseActions.isShiftDown() ? shift : 0); 149 int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) | (current != null ? current.hasAction() ? action : 0 : 0); 150 String l = command(mod, left) + statusText[context][left][mod][other]; 151 String m = command(mod, middle) + statusText[context][middle][mod][other]; 152 String r = command(mod, right) + statusText[context][right][mod][other]; 153 // String lm = command(mod, left | middle) + helpText[context][left | middle][mod][other]; 154 String lr = command(mod, left | right) + statusText[context][left | right][mod][other]; 155 String mr = command(mod, middle | right) + statusText[context][middle | right][mod][other]; 156 MessageBay.setStatus(l + padding.substring(l.length()) + 157 m + padding.substring(m.length()) + 158 r + padding.substring(r.length()) + 159 // lm + padding.substring(lm.length()) + 160 lr + padding.substring(lr.length()) + 161 mr + padding.substring(mr.length())); 61 162 } 62 163 -
trunk/src/org/expeditee/gui/MessageBay.java
r673 r674 453 453 if (_status == null) { 454 454 _status = new Text(status); 455 _status.setPosition( 20, 90);455 _status.setPosition(0, 90); 456 456 _status.setOffset(0, FrameGraphics.getMaxFrameSize().height); 457 457 _status.setLink(null); // maybe link to a help frame?
Note:
See TracChangeset
for help on using the changeset viewer.