Changeset 680


Ignore:
Timestamp:
01/10/14 16:04:39 (10 years ago)
Author:
jts21
Message:

Switch to a bitwise comparison solution for populating status array, (tidier and easier to use)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/Help.java

    r678 r680  
    1717       
    1818        // modifiers
    19         public static final int none = 0, control = 1, shift = 2, drag = 4; // TODO: add mod for click+hold ???
     19        public static final int none = 0, control = 1, shift = 2, drag = 4, hold = 8;
    2020        private static final String[] modifiers = { "", "^", "+", "^+", "d", "d^", "d+", "d^+" };
    2121       
     
    2727       
    2828        /**
    29          *
    30          * @param array
    31          * @param max
    32          * @return int[] containing all positive values NOT in array, below max
     29         * Set each index of $array to reference $value
    3330         */
    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                         }
     31        private static final void fill(String[] array, String value) {
     32                for(int i = 0; i < array.length; i++) {
     33                        array[i] = value;
    4134                }
    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;
    5935        }
    6036       
    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        
     37        /**
     38         * Set each index of $array to reference an array filled with $value
     39         */
    6740        private static final void fill(String[][] array, String value) {
    68                 array[0] = Arrays.copyOf(array[0], array[0].length);
     41                array[0] = new String[array[0].length];
    6942                fill(array[0], value);
    7043                for(int i = 1; i < array.length; i++) {
     
    7346        }
    7447       
    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;
     48        /**
     49         * Set the indices of $array that have $indexBit set (or not set if $invert) to reference $value
     50         */
     51        private static final void fill(String[] array, int indexBit, String value, boolean invert, boolean lazy) {
     52                for(int i = 0; i < array.length; i++) {
     53                        if((!lazy && ((i & indexBit) == indexBit && !invert) || ((i & indexBit) == 0 && invert)) ||
     54                                (lazy && ((i & indexBit) != 0 && !invert)        || ((i & indexBit) != indexBit && invert))){
     55                                array[i] = value;
     56                        }
    8157                }
    8258        }
    8359       
    84         private static final void fill(String[] array, int indexBit, String value, boolean invert) {
     60        /**
     61         * Calls fill(array, indexBit, value, false, false)
     62         */
     63        private static final void fill(String[] array, int indexBit, String value) {
     64                fill(array, indexBit, value, false, false);
     65        }
     66       
     67        /**
     68         * Set the indices of $array that have $indexBit set (or not set if $invert) to reference an array filled with $value
     69         */
     70        private static final void fill(String[][] array, int indexBit, String value, boolean invert, boolean lazy) {
    8571                for(int i = 0; i < array.length; i++) {
    86                        
     72                        if((!lazy && ((i & indexBit) == indexBit && !invert) || ((i & indexBit) == 0 && invert)) ||
     73                                (lazy && ((i & indexBit) != 0 && !invert)        || ((i & indexBit) != indexBit && invert))){
     74                                fill(array[i] = Arrays.copyOf(array[i], array[i].length), value);
     75                        }
    8776                }
    8877        }
    8978       
    90         private static final void fill(String[][] array, int[] indices, String value, boolean invert) {
    91                 if(invert) {
    92                         indices = invert(indices, array.length);
    93                 }
    94                 array[indices[0]] = Arrays.copyOf(array[indices[0]], array[indices[0]].length);
    95                 fill(array[indices[0]], value);
    96                 for(int i = 1; i < indices.length; i++) {
    97                         array[indices[i]] = array[indices[0]];
     79        /**
     80         * Calls fill(array, indexBit, value, false, false)
     81         */
     82        private static final void fill(String[][] array, int indexBit, String value) {
     83                fill(array, indexBit, value, false, false);
     84        }
     85       
     86        /**
     87         * For each array at the indices of $array that have $indexBit set (or not set if $invert),
     88         * set each index that has $indexBit2 set (or not set if $invert) to reference $value
     89         */
     90        private static final void fill(String[][] array, int indexBit, int indexBit2, String value, boolean invert, boolean invert2, boolean lazy, boolean lazy2) {
     91                for(int i = 0; i < array.length; i++) {
     92                        if((!lazy && ((i & indexBit) == indexBit && !invert) || ((i & indexBit) == 0 && invert)) ||
     93                                (lazy && ((i & indexBit) != 0 && !invert)        || ((i & indexBit) != indexBit && invert))) {
     94                                fill(array[i] = Arrays.copyOf(array[i], array[i].length), indexBit2, value, invert2, lazy2);
     95                        }
    9896                }
    9997        }
    10098       
    101         private static final void fill(String[][] array, int[] indices, int[] indices2, String value, boolean invert, boolean invert2) {
    102                 if(indices != null) {
    103                         if(invert) {
    104                         indices = invert(indices, array.length);
    105                 }
    106                         // fill the correct indices
    107                         array[indices[0]] = Arrays.copyOf(array[indices[0]], array[indices[0]].length);
    108                         fill(array[indices[0]], indices2, value, invert2);
    109                 for(int i = 1; i < indices.length; i++) {
    110                         array[indices[i]] = array[indices[0]];
    111                 }
    112                 } else {
    113                         // fill all indices
    114                         array[0] = Arrays.copyOf(array[0], array[0].length);
    115                         fill(array[0], indices2, value, invert2);
    116                         for(int i = 1; i < array.length; i++) {
    117                                 array[i] = array[0];
    118                         }
    119                 }
     99        /**
     100         * Calls fill(array, indexBit, indexBit2, value, false, false, false, false)
     101         */
     102        private static final void fill(String[][] array, int indexBit, int indexBit2, String value) {
     103                fill(array, indexBit, indexBit2, value, false, false, false, false);
    120104        }
    121105       
     
    124108        static {
    125109                fill(statusText[background][left], "Go back");
    126                 fill(statusText[background][left], new int[] { control, control | shift, shift }, "Go forward", false);
    127                 fill(statusText[background][left], new int[] { drag, control | drag, shift | drag, control | shift | drag }, null, false); // no action for dragging unless shift down
    128                 fill(statusText[background][left], new int[] { control | shift | drag, shift | drag }, new int[] { panning, panning | action }, "Drag to pan", false, false);
     110                fill(statusText[background][left], control | shift, "Go forward", false, true);
     111                fill(statusText[background][left], drag, null); // no action for dragging unless shift down
     112                fill(statusText[background][left], shift | drag, panning, "Drag to pan");
    129113                fill(statusText[background][middle], "Create arrow");
    130                 fill(statusText[background][middle], new int[] { drag, control | drag, shift | drag, control | shift | drag }, null, false); // no action for dragging
     114                fill(statusText[background][middle], drag, null); // no action for dragging
    131115                fill(statusText[background][right], "Create rectangle");
    132                 fill(statusText[background][right], new int[] { drag, control | drag, shift | drag, control | shift | drag }, null, false); // no action for dragging
    133                 fill(statusText[background][left | middle], null);
     116                fill(statusText[background][right], drag, null); // no action for dragging
     117                fill(statusText[background][left | middle], null); // no action for left + middle
    134118                fill(statusText[background][left | right], "Auto format");
    135119                fill(statusText[background][middle | right], "Undo");
    136120       
    137121        fill(statusText[item][left], "Follow link");
    138         fill(statusText[item][left], new int[] { control, control | shift }, new int[] { action, panning | action }, "Run action", true, false);
    139         fill(statusText[item][left], new int[] { drag, control | drag, shift | drag, control | shift | drag }, null, false); // no action for dragging
     122        fill(statusText[item][left], control, action, "Run action", true, false, false, false);
     123        fill(statusText[item][left], drag, null); // no action for dragging
    140124        fill(statusText[item][middle], "Pickup");
    141         fill(statusText[item][middle], new int[] { drag, control | drag, shift | drag, control | shift | drag }, null, false); // no action for dragging
     125        fill(statusText[item][middle], drag, null); // no action for dragging
    142126        fill(statusText[item][right], "Copy");
    143         fill(statusText[item][right], new int[] { drag, control | drag, shift | drag, control | shift | drag }, null, false); // no action for dragging
     127        fill(statusText[item][right], drag, null); // no action for dragging
    144128        fill(statusText[item][left | middle], null); // no action for left + middle
    145129                fill(statusText[item][left | right], "Extract attributes");
Note: See TracChangeset for help on using the changeset viewer.