Changeset 737


Ignore:
Timestamp:
01/22/14 13:58:17 (10 years ago)
Author:
jts21
Message:

Enable per-item permission values, and tidy up DefaultFrameWriter a little

Location:
trunk/src/org/expeditee
Files:
13 edited

Legend:

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

    r720 r737  
    271271                        _Attrib.put("Tooltip",              Item.class.getMethod("getTooltip"),
    272272                                                            Item.class.getMethod("setTooltips", pList));
     273                        _Attrib.put("Permission",           Item.class.getMethod("getPermission"),
     274                                                            Item.class.getMethod("setPermission", pPermission));
    273275                       
    274276                        // Text Items
  • trunk/src/org/expeditee/gui/Frame.java

    r731 r737  
    18641864        /**
    18651865         * Sets the item permissions to match the protection for the frame.
     1866         * No longer sets item permissions, since items can have their own permissions now (but still default to frame permissions)
    18661867         *
    18671868         */
     
    18711872               
    18721873                UserAppliedPermission permission = UserAppliedPermission.min(maxPermission, getUserAppliedPermission());
    1873                 _frameName.setPermission(permission);
    18741874
    18751875                switch (permission) {
     
    18941894                }
    18951895
    1896                 for (Overlay o : getOverlays())
     1896                for (Overlay o : getOverlays()) {
     1897                        for(Item i : o.Frame._body) {
     1898                                i.setOverlayPermission(o.permission);
     1899                        }
    18971900                        o.Frame.refreshItemPermissions(o.permission);
    1898 
    1899                 // Only update the permissions if we have to
    1900                 if (_body.size() > 0 && permission.equals(_body.get(0).getPermission()))
    1901                         return;
    1902 
    1903                 for (Item i : _body) {
    1904                         i.setPermission(permission);
    1905                 }
    1906 
     1901                }
    19071902        }
    19081903
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r729 r737  
    13011301                                                if (!mouseMoved) {
    13021302                                                        Item moreTitle = moreFrame.getTitleItem();
    1303                                                         moreTitle.setPermission(UserAppliedPermission.full);
     1303                                                        moreTitle.setOverlayPermission(UserAppliedPermission.full);
    13041304                                                        Drop(moreTitle, bPasting);
    13051305                                                }
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r729 r737  
    796796                for (Item i : toParse.getItems()) {
    797797                        try {
    798                                 i.setPermission(permission);
     798                                // reset overlay permission
     799                                i.setOverlayPermission(null);
     800                                // i.setPermission(permission);
    799801                                if (i instanceof WidgetCorner) {
    800802                                        // TODO improve efficiency so it only updates once... using
     
    10681070                                if (message != null) {
    10691071                                        if (message.contains(x, y)) {
    1070                                                 message.setPermission(UserAppliedPermission.copy);
     1072                                                message.setOverlayPermission(UserAppliedPermission.copy);
    10711073                                                possibles.add(message);
    10721074                                        } else {
     
    10811083                        if (MessageBay.getMessageLink() != null) {
    10821084                                if (MessageBay.getMessageLink().contains(x, y)) {
    1083                                         MessageBay.getMessageLink().setPermission(UserAppliedPermission.copy);
     1085                                        MessageBay.getMessageLink().setOverlayPermission(UserAppliedPermission.copy);
    10841086                                        possibles.add(MessageBay.getMessageLink());
    10851087                                }
     
    10971099                                                && LastEdited.getParent().getItems().contains(
    10981100                                                                LastEdited)) {
    1099                                         LastEdited.setPermission(UserAppliedPermission.full);
     1101                                        LastEdited.setOverlayPermission(UserAppliedPermission.full);
    11001102                                        return LastEdited;
    11011103                                } else if (bResetLastEdited) {
     
    13351337                                for (Overlay overlay : frame.getOverlays()) {
    13361338                                        if (overlay.Frame == item.getParent()) {
    1337                                                 item.setPermission(overlay.permission);
     1339                                                item.setOverlayPermission(overlay.permission);
    13381340                                                results.add(item);
    13391341                                                break;
  • trunk/src/org/expeditee/io/DefaultFrameReader.java

    r720 r737  
    110110                        _ItemTags
    111111                                        .put('y', Item.class.getMethod("setLinkTemplate", pString));
    112                         _ItemTags.put('g', Item.class
    113                                         .getMethod("setLinePattern", pIntArray));
     112                        _ItemTags.put('g', Item.class.getMethod("setLinePattern", pIntArray));
    114113
    115114                        _ItemTags.put('j', Item.class.getMethod("setArrow", pArrow));
     
    135134                        _ItemTags.put('B', Item.class.getMethod("setLinkHistory", pBool));
    136135                       
     136                        _ItemTags.put('p', Item.class.getMethod("setPermission", pPermission));
     137                       
    137138                        // Lines and constraints are created differently
    138139                        _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem));
  • trunk/src/org/expeditee/io/DefaultFrameWriter.java

    r720 r737  
    3838
    3939        // keep track of methods that are put on the same line
    40         protected static LinkedHashMap<String, Method> _ItemTags = null;
    41 
    42         protected static LinkedHashMap<String, Method> _FrameTags = null;
     40        protected static LinkedHashMap<Character, Method> _ItemTags = null;
     41
     42        protected static LinkedHashMap<Character, Method> _FrameTags = null;
    4343
    4444        public DefaultFrameWriter() {
     45               
    4546                if (_ItemTags != null && _FrameTags != null)
    4647                        return;
    4748
    48                 _ItemTags = new LinkedHashMap<String, Method>();
    49                 _FrameTags = new LinkedHashMap<String, Method>();
    50 
    51                 Class[] param = {};
    52 
    53                 try {
    54                         _FrameTags.put("V", Frame.class.getMethod("getVersion", param));
    55                         _FrameTags.put("p", Frame.class.getMethod("getPermission", param));
    56                         _FrameTags.put("U", Frame.class.getMethod("getOwner", param));
    57                         _FrameTags.put("D", Frame.class.getMethod("getDateCreated", param));
    58                         _FrameTags.put("M", Frame.class.getMethod("getLastModifyUser",
    59                                         param));
    60                         _FrameTags.put("d", Frame.class.getMethod("getLastModifyDate",
    61                                         param));
    62                         _FrameTags.put("F", Frame.class.getMethod("getFrozenDate", param));
    63 
    64                         _FrameTags.put("O", Frame.class.getMethod("getForegroundColor",
    65                                         param));
    66                         _FrameTags.put("B", Frame.class.getMethod("getBackgroundColor",
    67                                         param));
    68                         _ItemTags.put("S", Item.class.getMethod("getTypeAndID", param));
    69                         _ItemTags.put("s", Item.class.getMethod("getDateCreated", param));
    70                         _ItemTags.put("d", Item.class.getMethod("getColor", param));
    71                         _ItemTags.put("G", Item.class.getMethod("getBackgroundColor", param));
    72                         _ItemTags.put("K", Item.class.getMethod("getBorderColor", param));
    73 
    74                         _ItemTags.put("R", Item.class.getMethod("getAnchorLeft", param));
    75                         _ItemTags.put("H", Item.class.getMethod("getAnchorRight", param));
    76                         _ItemTags.put("N", Item.class.getMethod("getAnchorTop", param));
    77                         _ItemTags.put("I", Item.class.getMethod("getAnchorBottom", param));
    78 
    79                         _ItemTags.put("P", Item.class.getMethod("getPosition", param));
    80                         _ItemTags.put("T", Text.class.getMethod("getText", param));
    81                         _ItemTags.put("F", Item.class.getMethod("getLink", param));
    82                         _ItemTags.put("X", Item.class.getMethod("getAction", param));
    83                         _ItemTags.put("x", Item.class.getMethod("getActionMark", param));
    84                         _ItemTags.put("U", Item.class.getMethod("getActionCursorEnter",
    85                                         param));
    86                         _ItemTags.put("V", Item.class.getMethod("getActionCursorLeave",
    87                                         param));
    88                         _ItemTags.put("W", Item.class.getMethod("getActionEnterFrame",
    89                                         param));
    90                         _ItemTags.put("Y", Item.class.getMethod("getActionLeaveFrame",
    91                                         param));
    92                         _ItemTags.put("D", Item.class.getMethod("getData", param));
    93                         _ItemTags.put("u", Item.class.getMethod("getHighlight", param));
    94                         _ItemTags.put("e", Item.class.getMethod("getFillColor", param));
    95                         _ItemTags.put("E", Item.class.getMethod("getGradientColor", param));
    96                         _ItemTags.put("Q", Item.class.getMethod("getGradientAngle", param));
    97 
    98                         _ItemTags.put("i", Item.class.getMethod("getFillPattern", param));
    99                         _ItemTags.put("o", Item.class.getMethod("getOwner", param));
    100                         _ItemTags.put("n", Item.class.getMethod("getLinkMark", param));
    101                         _ItemTags.put("q", Item.class.getMethod("getLinkFrameset", param));
    102                         _ItemTags.put("y", Item.class.getMethod("getLinkTemplate", param));
    103                         _ItemTags.put("g", Item.class.getMethod("getLinePattern", param));
    104 
    105                         _ItemTags.put("j", Item.class.getMethod("getArrow", param));
    106                        
    107                         _ItemTags.put("v", Item.class.getMethod("getDotType", param));
    108                         _ItemTags.put("z", Item.class.getMethod("getFilled", param));
    109 
    110                         _ItemTags.put("f", Text.class.getMethod("getFont", param));
    111                         _ItemTags.put("t", Text.class.getMethod("getSpacing", param));
     49                _ItemTags = new LinkedHashMap<Character, Method>();
     50                _FrameTags = new LinkedHashMap<Character, Method>();
     51
     52                try {
     53                        _FrameTags.put('V', Frame.class.getMethod("getVersion"));
     54                        _FrameTags.put('p', Frame.class.getMethod("getPermission"));
     55                        _FrameTags.put('U', Frame.class.getMethod("getOwner"));
     56                        _FrameTags.put('D', Frame.class.getMethod("getDateCreated"));
     57                        _FrameTags.put('M', Frame.class.getMethod("getLastModifyUser"));
     58                        _FrameTags.put('d', Frame.class.getMethod("getLastModifyDate"));
     59                        _FrameTags.put('F', Frame.class.getMethod("getFrozenDate"));
     60
     61                        _FrameTags.put('O', Frame.class.getMethod("getForegroundColor"));
     62                        _FrameTags.put('B', Frame.class.getMethod("getBackgroundColor"));
     63                       
     64                        _ItemTags.put('S', Item.class.getMethod("getTypeAndID"));
     65                        _ItemTags.put('s', Item.class.getMethod("getDateCreated"));
     66                        _ItemTags.put('d', Item.class.getMethod("getColor"));
     67                        _ItemTags.put('G', Item.class.getMethod("getBackgroundColor"));
     68                        _ItemTags.put('K', Item.class.getMethod("getBorderColor"));
     69
     70                        _ItemTags.put('R', Item.class.getMethod("getAnchorLeft"));
     71                        _ItemTags.put('H', Item.class.getMethod("getAnchorRight"));
     72                        _ItemTags.put('N', Item.class.getMethod("getAnchorTop"));
     73                        _ItemTags.put('I', Item.class.getMethod("getAnchorBottom"));
     74
     75                        _ItemTags.put('P', Item.class.getMethod("getPosition"));
     76                        _ItemTags.put('T', Text.class.getMethod("getText"));
     77                        _ItemTags.put('F', Item.class.getMethod("getLink"));
     78                        _ItemTags.put('X', Item.class.getMethod("getAction"));
     79                        _ItemTags.put('x', Item.class.getMethod("getActionMark"));
     80                        _ItemTags.put('U', Item.class.getMethod("getActionCursorEnter"));
     81                        _ItemTags.put('V', Item.class.getMethod("getActionCursorLeave"));
     82                        _ItemTags.put('W', Item.class.getMethod("getActionEnterFrame"));
     83                        _ItemTags.put('Y', Item.class.getMethod("getActionLeaveFrame"));
     84                        _ItemTags.put('D', Item.class.getMethod("getData"));
     85                        _ItemTags.put('u', Item.class.getMethod("getHighlight"));
     86                        _ItemTags.put('e', Item.class.getMethod("getFillColor"));
     87                        _ItemTags.put('E', Item.class.getMethod("getGradientColor"));
     88                        _ItemTags.put('Q', Item.class.getMethod("getGradientAngle"));
     89
     90                        _ItemTags.put('i', Item.class.getMethod("getFillPattern"));
     91                        _ItemTags.put('o', Item.class.getMethod("getOwner"));
     92                        _ItemTags.put('n', Item.class.getMethod("getLinkMark"));
     93                        _ItemTags.put('q', Item.class.getMethod("getLinkFrameset"));
     94                        _ItemTags.put('y', Item.class.getMethod("getLinkTemplate"));
     95                        _ItemTags.put('g', Item.class.getMethod("getLinePattern"));
     96
     97                        _ItemTags.put('j', Item.class.getMethod("getArrow"));
     98                       
     99                        _ItemTags.put('v', Item.class.getMethod("getDotType"));
     100                        _ItemTags.put('z', Item.class.getMethod("getFilled"));
     101
     102                        _ItemTags.put('f', Text.class.getMethod("getFont"));
     103                        _ItemTags.put('t', Text.class.getMethod("getSpacing"));
    112104
    113105                        // TODO set a boolean flag to indicate that the text is a formula
    114106                        // Store the formula in the text property NOT the answer
    115                         _ItemTags.put("J", Item.class.getMethod("getFormula", param));
    116 
    117                         _ItemTags.put("a", Text.class.getMethod("getWordSpacing", param));
    118                         _ItemTags.put("b", Text.class.getMethod("getLetterSpacing", param));
    119                         _ItemTags.put("m", Text.class.getMethod("getInitialSpacing", param));
    120                         _ItemTags.put("w", Text.class.getMethod("getWidthToSave", param));
    121                         _ItemTags.put("k", Text.class.getMethod("getJustification", param));
    122                         _ItemTags.put("r", Text.class.getMethod("getAutoWrapToSave", param));
    123 
    124                         _ItemTags.put("h", Item.class.getMethod("getThickness", param));
    125                         _ItemTags.put("l", Item.class.getMethod("getLineIDs", param));
    126                         _ItemTags.put("c", Item.class.getMethod("getConstraintIDs", param));
    127                        
    128                         _ItemTags.put("A", Item.class.getMethod("getTooltip", param));
    129                         _ItemTags.put("B", Item.class.getMethod("getLinkHistory", param));
     107                        _ItemTags.put('J', Item.class.getMethod("getFormula"));
     108
     109                        _ItemTags.put('a', Text.class.getMethod("getWordSpacing"));
     110                        _ItemTags.put('b', Text.class.getMethod("getLetterSpacing"));
     111                        _ItemTags.put('m', Text.class.getMethod("getInitialSpacing"));
     112                        _ItemTags.put('w', Text.class.getMethod("getWidthToSave"));
     113                        _ItemTags.put('k', Text.class.getMethod("getJustification"));
     114                        _ItemTags.put('r', Text.class.getMethod("getAutoWrapToSave"));
     115
     116                        _ItemTags.put('h', Item.class.getMethod("getThickness"));
     117                        _ItemTags.put('l', Item.class.getMethod("getLineIDs"));
     118                        _ItemTags.put('c', Item.class.getMethod("getConstraintIDs"));
     119                       
     120                        _ItemTags.put('A', Item.class.getMethod("getTooltip"));
     121                        _ItemTags.put('B', Item.class.getMethod("getLinkHistory"));
     122                       
     123                        _ItemTags.put('p', Item.class.getMethod("getPermission"));
    130124
    131125                } catch (Exception e) {
  • trunk/src/org/expeditee/io/ExpWriter.java

    r603 r737  
    6565
    6666                try {
    67                         _FrameTags.remove("A");
    68                         _ItemTags.put("S", Item.class.getMethod("getTypeAndID",
     67                        _FrameTags.remove('A');
     68                        _ItemTags.put('S', Item.class.getMethod("getTypeAndID",
    6969                                        new Class[] {}));
    7070                } catch (Exception e) {
     
    107107
    108108        private void writeHeader(Frame toWrite) throws IOException {
    109                 Iterator<String> it = _FrameTags.keySet().iterator();
     109                Iterator<Character> it = _FrameTags.keySet().iterator();
    110110                Object[] param = {};
    111111
    112112                while (it.hasNext()) {
    113                         String tag = it.next();
     113                        Character tag = it.next();
    114114                        try {
    115115                                Object o = _FrameTags.get(tag).invoke(toWrite, param);
    116116                                o = Conversion.ConvertToExpeditee(_FrameTags.get(tag), o);
    117117                                if (o != null) {
    118                                         writeLine(tag, o.toString());
     118                                        writeLine(tag.toString(), o.toString());
    119119                                }
    120120                        } catch (Exception e) {
     
    162162                // lines are saved at the end of the file
    163163                // So dont worry about them in here
    164                 else
    165                         System.out.println("Unknown Item: " + item.getID());
     164//              else
     165//                      System.out.println("Unknown Item: " + item.getID() + " (" + item.getClass().getName() + ")");
    166166
    167167                writeLine("");
     
    248248
    249249        private void writeClass(Object toWrite) throws IOException {
    250                 Iterator<String> it = _ItemTags.keySet().iterator();
     250                Iterator<Character> it = _ItemTags.keySet().iterator();
    251251                Object[] param = {};
    252252
    253253                while (it.hasNext()) {
    254                         String tag = it.next();
     254                        Character tag = it.next();
    255255                        Method toRun = _ItemTags.get(tag);
    256256                        Class<?> declarer = toRun.getDeclaringClass();
     
    262262                                                if (o instanceof List) {
    263263                                                        for (Object line : (List) o)
    264                                                                 writeLine(tag, line.toString());
     264                                                                writeLine(tag.toString(), line.toString());
    265265                                                } else
    266                                                         writeLine(tag, o.toString());
     266                                                        writeLine(tag.toString(), o.toString());
    267267                                        }
    268268                                } catch (Exception e) {
  • trunk/src/org/expeditee/io/KMSWriter.java

    r362 r737  
    6262               
    6363                try {
    64                         _FrameTags.put("A", Frame.class.getMethod("getName", new Class[] {}));
    65                         _ItemTags.put("S", Item.class.getMethod("getID", new Class[] {}));
     64                        _FrameTags.put('A', Frame.class.getMethod("getName", new Class[] {}));
     65                        _ItemTags.put('S', Item.class.getMethod("getID", new Class[] {}));
    6666                } catch (Exception e) {
    6767
     
    100100
    101101        private void writeHeader(Frame toWrite) throws IOException {
    102                 Iterator<String> it = _FrameTags.keySet().iterator();
     102                Iterator<Character> it = _FrameTags.keySet().iterator();
    103103                Object[] param = {};
    104104
     
    107107
    108108                while (it.hasNext()) {
    109                         String tag = it.next();
     109                        Character tag = it.next();
    110110                        try {
    111111                                Object o = _FrameTags.get(tag).invoke(toWrite, param);
    112112                                o = Conversion.ConvertToExpeditee(_FrameTags.get(tag), o);
    113113                                if (o != null) {
    114                                         writeLine(tag, o.toString());
     114                                        writeLine(tag.toString(), o.toString());
    115115                                }
    116116                        } catch (IllegalArgumentException e) {
     
    240240
    241241        private void writeClass(Object toWrite) throws IOException {
    242                 Iterator<String> it = _ItemTags.keySet().iterator();
     242                Iterator<Character> it = _ItemTags.keySet().iterator();
    243243                Object[] param = {};
    244244
    245245                while (it.hasNext()) {
    246                         String tag = it.next();
     246                        Character tag = it.next();
    247247                        Method toRun = _ItemTags.get(tag);
    248248                        Class<?> declarer = toRun.getDeclaringClass();
     
    254254                                                if (o instanceof List) {
    255255                                                        for (Object line : (List) o)
    256                                                                 writeLine(tag, line.toString());
     256                                                                writeLine(tag.toString(), line.toString());
    257257                                                } else
    258                                                         writeLine(tag, o.toString());
     258                                                        writeLine(tag.toString(), o.toString());
    259259                                        }
    260260                                } catch (IllegalArgumentException e) {
  • trunk/src/org/expeditee/items/Circle.java

    r450 r737  
    320320
    321321        @Override
    322         public void setPermission(UserAppliedPermission p) {
    323                 super.setPermission(p);
    324                 _center.setPermission(p);
    325                 _line.setPermission(p);
     322        public void setPermission(PermissionPair permissionPair) {
     323                super.setPermission(permissionPair);
     324                _center.setPermission(permissionPair);
     325                _line.setPermission(permissionPair);
    326326        }
    327327       
  • trunk/src/org/expeditee/items/Item.java

    r729 r737  
    312312        private List<String> _actionLeaveFrame = null;
    313313
    314         private UserAppliedPermission _permission = UserAppliedPermission.full;
    315 
    316         public void setPermission(UserAppliedPermission permission) {
    317                 _permission = permission;
    318         }
    319 
    320         public UserAppliedPermission getPermission() {
    321                 return _permission;
     314        private PermissionPair _permissionPair = null;
     315       
     316        private UserAppliedPermission _overlayPermission = null;
     317       
     318        public void setOverlayPermission(UserAppliedPermission overlayPermission) {
     319                _overlayPermission = overlayPermission;
     320        }
     321
     322        public void setPermission(PermissionPair permissionPair) {
     323                _permissionPair = permissionPair;
     324        }
     325       
     326        public PermissionPair getPermission() {
     327                return _permissionPair;
     328        }
     329
     330        public UserAppliedPermission getUserAppliedPermission() {
     331                String owner = _owner != null ? _owner : _parent != null ? _parent.getOwner() : null;
     332                if(_permissionPair != null) return _permissionPair.getPermission(owner);
     333                if(_overlayPermission != null) return _overlayPermission;
     334                if(_parent != null) return _parent.getUserAppliedPermission();
     335                return UserAppliedPermission.full;
    322336        }
    323337       
    324338        public boolean hasPermission(UserAppliedPermission permission) {
    325                 return _permission.ordinal() >= permission.ordinal();
     339                return getUserAppliedPermission().ordinal() >= permission.ordinal();
    326340        }
    327341
  • trunk/src/org/expeditee/items/ItemUtils.java

    r655 r737  
    946946                Color defaultBackground = v.Background;
    947947                UserAppliedPermission permission = v.permission;
    948                 item.setPermission(permission);
     948                // TODO should this be checking if the frame has the
     949                // same permissions as the vector
     950                // and if so don't set the item's permissions?
     951                item.setOverlayPermission(permission);
    949952
    950953                // TODO encapsulate this somewhere inside of circle class!
  • trunk/src/org/expeditee/items/Line.java

    r559 r737  
    12301230
    12311231        @Override
    1232         public void setPermission(UserAppliedPermission p) {
    1233                 _start.setPermission(p);
    1234                 _end.setPermission(p);
     1232        public void setPermission(PermissionPair permissionPair) {
     1233                _start.setPermission(permissionPair);
     1234                _end.setPermission(permissionPair);
    12351235        }
    12361236
  • trunk/src/org/expeditee/items/XRayable.java

    r720 r737  
    285285       
    286286        @Override
    287         public void setPermission(UserAppliedPermission p) {
    288                 _source.setPermission(p);
     287        public void setPermission(PermissionPair permissionPair) {
     288                _source.setPermission(permissionPair);
    289289        }
    290290}
Note: See TracChangeset for help on using the changeset viewer.