Changeset 108


Ignore:
Timestamp:
06/27/08 16:44:21 (16 years ago)
Author:
ra33
Message:

Heaps of changes!!!!
Added circles...
Better drawing of lines etc etc

Location:
trunk/src/org/expeditee
Files:
1 added
1 deleted
42 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Actions.java

    r103 r108  
    11package org.expeditee.actions;
    22
     3import java.awt.GraphicsEnvironment;
    34import java.io.File;
    45import java.lang.reflect.Constructor;
     
    5455        private static HashMap<String, Method> _Actions = new HashMap<String, Method>();
    5556
     57        // map lower case fonts to capitalized fonts
     58        protected static HashMap<String, String> _Fonts = new HashMap<String, String>();
     59
    5660        // maps lower case JAG class names to capitalized JAG names
    5761        private static HashMap<String, String> _JAGs = new HashMap<String, String>();
     
    179183         */
    180184        public static Collection<String> Init() {
     185
    181186                Collection<String> warnings = new LinkedList<String>();
    182187                Class[] classes;
     
    489494        public static void stopAgent() {
    490495                if (_Agent != null && _Agent.isRunning()) {
    491                         FrameGraphics.DisplayMessage("Stopping Agent...");
     496                        FrameGraphics.ErrorMessage("Stopping Agent...");
    492497                        _Agent.stop();
    493498                }
     
    528533                        objects[0] = source;
    529534                        ind = 1;
    530                 } else if (paramTypes[0] == Item.class) {
     535                } else if (Item.class.isAssignableFrom(paramTypes[0])) {
    531536                        objects[0] = launcher;
    532537                        ind = 1;
     
    539544                                objects[1] = source;
    540545                                ind = 2;
    541                         } else if (paramTypes[1] == Item.class) {
     546                        } else if (Item.class.isAssignableFrom(paramTypes[1])) {
    542547                                objects[1] = launcher;
    543548                                ind = 2;
     
    653658                return command.substring(0, command.indexOf(" "));
    654659        }
     660
     661        /**
     662         * Gets an uncapitalized font name and returns the capitalized font name.
     663         * The capitalized form can be used with the Font.decoded method to get a
     664         * corresponding Font object.
     665         *
     666         * @param fontName
     667         *            a font name in mixed case
     668         * @return the correct capitalized form of the font name
     669         */
     670        public static String getCapitalizedFontName(String fontName) {
     671                //Initialize the fonts if they have not already been loaded
     672                if (_Fonts.size() == 0) {
     673                        String[] availableFonts = GraphicsEnvironment
     674                                        .getLocalGraphicsEnvironment()
     675                                        .getAvailableFontFamilyNames();
     676                        for (String s : availableFonts) {
     677                                _Fonts.put(s.toLowerCase(), s);
     678                        }
     679                }
     680                return _Fonts.get(fontName.toLowerCase());
     681        }
    655682}
  • trunk/src/org/expeditee/actions/Misc.java

    r107 r108  
    33import java.awt.Color;
    44import java.awt.Dimension;
    5 import java.awt.GraphicsEnvironment;
    65import java.awt.Image;
    76import java.awt.image.BufferedImage;
     
    1211import java.lang.reflect.Method;
    1312import java.util.ArrayList;
     13import java.util.Collection;
    1414import java.util.List;
    1515
     
    258258                Frame current = DisplayIO.getCurrentFrame();
    259259                Item text = current.getStatsTextItem(itemText);
    260                 text.setSelectedMode(Item.SelectedMode.Normal);
    261                 text.setSelectedMode(Item.SelectedMode.None);
    262260                FrameMouseActions.pickup(text);
    263261                FrameGraphics.Repaint();
     
    312310        public static void GetAvailableFontFamilyNames() {
    313311
    314                 String[] availableFonts = GraphicsEnvironment
    315                                 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
     312                Collection<String> availableFonts = Actions._Fonts.values();
    316313                StringBuilder fontsList = new StringBuilder();
    317314                for (String s : availableFonts) {
  • trunk/src/org/expeditee/actions/NavigationActions.java

    r105 r108  
    2525        }
    2626
    27         private static void Default() {
    28                 System.out.println("Not Implemented");
    29         }
    30 
    3127        /**
    3228         * Performs a back operation from the current Frame. If the back-stack is
     
    3531        public static void Back() {
    3632                DisplayIO.Back();
    37         }
    38 
    39         public static void ClearBack(Item i) {
    40                 Default();
    41         }
    42 
    43         public static void DeleteBack() {
    44                 Default();
    45         }
    46 
    47         public static void GetBack(String topFrame, int x, int y) {
    48                 Default();
    49         }
    50 
    51         public static void GetBackList() {
    52                 Default();
    5333        }
    5434
     
    223203        }
    224204
    225         public static void OtherWindow() {
    226                 Default();
    227         }
    228 
    229205        /**
    230206         * Turns TwinFrames on if it is off, otherwise does nothing
  • trunk/src/org/expeditee/actions/Simple.java

    r107 r108  
    44import java.awt.Point;
    55import java.awt.event.InputEvent;
     6import java.awt.geom.Point2D;
    67import java.io.BufferedReader;
    78import java.io.InputStreamReader;
     
    188189        private String _frameset;
    189190
    190         private boolean _verbose;
     191        private static boolean _verbose = false;
    191192
    192193        public Simple(String frameset, boolean verbose) {
     
    216217                        if (nextFrame == null)
    217218                                continue;
    218                         Item frameTitle = nextFrame.getTitleItem();
     219                        Text frameTitle = nextFrame.getTitleItem();
    219220                        if (frameTitle == null)
    220221                                continue;
    221222                        // Run the frames with the RunFrame action on the title
    222                         Item title = frameTitle.copy();
     223                        Text title = frameTitle.copy();
    223224                        List<String> actions = title.getAction();
    224225                        if (actions == null || title.isAnnotation())
     
    235236                                        _KeyStrokes.clear();
    236237                                        _programsRunning++;
    237                                         RunFrameAndReportError(title, new Context());
     238                                        Context context = new Context();
     239                                        RunFrameAndReportError(title, context);
    238240                                        _programsRunning--;
    239241                                        // if the throws exception annotation is on the frame then
     
    306308        }
    307309
    308         private static void RunFrame(Item current, boolean acceptKeyboardInput,
     310        private static void RunFrame(Text current, boolean acceptKeyboardInput,
    309311                        boolean step, int pause, Color color) {
    310312                try {
     
    321323                        // an item without a link signals to run the current frame
    322324                        if (current.getLink() == null) {
     325                                //Make a copy but hide it
    323326                                current = current.copy();
    324327                                current.setLink(DisplayIO.getCurrentFrame().getName());
     
    334337        }
    335338
    336         public static void RunFrame(Item current, boolean acceptKeyboardInput) {
     339        public static void RunFrame(Text current, boolean acceptKeyboardInput) {
    337340                RunFrame(current, acceptKeyboardInput, false, 0, null);
    338341        }
    339342
    340         public static void RunFrame(Item current) {
     343        public static void RunFrame(Text current) {
    341344                RunFrame(current, false);
    342345        }
     
    348351         * @param pause
    349352         */
    350         public static void DebugFrame(Item current, float pause, Color color) {
     353        public static void DebugFrame(Text current, float pause, Color color) {
     354                if(isProgramRunning()){
     355                        stop();
     356                }
    351357                RunFrame(current, false, true, Math.round(pause * 1000), color);
    352358        }
     
    359365         *            the time to pause between
    360366         */
    361         public static void DebugFrame(Item current, float pause) {
     367        public static void DebugFrame(Text current, float pause) {
    362368                DebugFrame(current, pause, null);
    363369        }
    364370
    365         public static void DebugFrame(Item current) {
     371        public static void DebugFrame(Text current) {
    366372                DebugFrame(current, -1.0F, null);
    367373        }
     
    391397                Frame child = FrameIO.LoadFrame(current.getAbsoluteLink());
    392398
     399                // Create frame variables for each linked annotation item on the frame
     400                // which has a single word of text corresponding to the variable name
     401                for (Text text : child.getAnnotationItems()) {
     402                        String link = text.getAbsoluteLink();
     403                        if (link == null)
     404                                continue;
     405                        Frame frame = FrameIO.LoadFrame(link);
     406                        if (frame == null)
     407                                continue;
     408                        // Now save the frame as a variable
     409                        String varName = text.getText().substring(1).trim();
     410                        if (varName.indexOf(' ') > 0)
     411                                continue;
     412                        context.getPointers().setObject(SPointer.framePrefix + varName,
     413                                        frame);
     414                        context.getPrimitives().add(SString.prefix + varName,
     415                                        new SString(frame.getName()));
     416                }
     417
    393418                if (_step) {
    394419                        if (child != DisplayIO.getCurrentFrame()) {
     
    419444                                Color oldColor = item.getBackgroundColor();
    420445                                if (_step) {
    421                                         if (item.getLink() != null) {
    422                                                 pause(item);
    423                                                 item.setSelectedMode(Item.SelectedMode.Normal,
    424                                                                 _stepColor);
    425                                         } else {
    426                                                 item.setBackgroundColor(_stepColor);
    427                                         }
    428                                         FrameGraphics.Repaint();
     446                                        pause(item);
    429447                                }
    430448                                lastItemStatus = RunItem(item, context, lastItemStatus);
     
    432450                                        if (item.getLink() == null) {
    433451                                                item.setBackgroundColor(oldColor);
    434                                                 pause(item);
    435452                                        } else {
    436453                                                item.setSelectedMode(Item.SelectedMode.None);
     
    464481                if (_step) {
    465482                        DisplayIO.removeFromBack();
    466                         DisplayIO.setCurrentFrame(current.getParent());
     483                        if(DisplayIO.getCurrentFrame() != current.getParent())
     484                                DisplayIO.setCurrentFrame(current.getParent());
    467485                }
    468486
     
    776794                                assertExactParametreCount(tokens, 3);
    777795
    778                                 Map map = (Map) context.getPointers().getVariable(tokens[1])
     796                                Map<String,String> map = (Map<String,String>) context.getPointers().getVariable(tokens[1])
    779797                                                .getValue();
    780798                                String attribute = context.getPrimitives().getStringValue(
     
    812830                                // attribute without the value in the same item
    813831                                if (!found && attributeItem != null) {
    814                                         Point endPoint = attributeItem.getEndParagraphPosition();
     832                                        Point2D.Float endPoint = attributeItem
     833                                                        .getEndParagraphPosition();
    815834
    816835                                        for (Text text : targetFrame.getBodyTextItems(true)) {
     
    10501069                                        // attribute without the value in the same item
    10511070                                        if (!found && attributeItem != null) {
    1052                                                 Point endPoint = attributeItem
     1071                                                Point2D.Float endPoint = attributeItem
    10531072                                                                .getEndParagraphPosition();
    10541073
     
    11121131                                                        .getValue();
    11131132                                        t.setText(log);
     1133                                } else if (tokens[0].equals("getframeitemcount")) {
     1134                                        String frameVar = DEFAULT_FRAME;
     1135                                        String countVar = DEFAULT_INTEGER;
     1136                                        if (tokens.length > 1) {
     1137                                                assertExactParametreCount(tokens, 2);
     1138                                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     1139                                                frameVar = tokens[1];
     1140                                                countVar = tokens[2];
     1141                                        }
     1142                                        Frame frame = (Frame) context.getPointers().getVariable(
     1143                                                        frameVar).getValue();
     1144                                        Integer count = frame.getItems(true).size();
     1145                                        context.getPrimitives().setValue(countVar,
     1146                                                        new SInteger(count));
    11141147                                }
    11151148                        } else if (tokens[0].equals("getassociation")) {
     
    11891222                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    11901223                                        // assertPrimitiveType(tokens[2], 2);
    1191                                         Integer size = ((Item) context.getPointers().getVariable(
    1192                                                         tokens[1]).getValue()).getSize();
     1224                                        Integer size = (int) ((Item) context.getPointers()
     1225                                                        .getVariable(tokens[1]).getValue()).getSize();
    11931226                                        context.getPrimitives().setValue(tokens[2],
    11941227                                                        new SInteger(size));
     
    14021435                        String codeText = getMessage(tokens, context, code.toString(), " ",
    14031436                                        1);
    1404                         Text dynamicCode = new Text(1, codeText);
     1437                        Text dynamicCode = new Text(codeText);
    14051438                        RunItem(dynamicCode, context, Status.OK);
    14061439                } else if (tokens[0].equals("runoscommand")) {
     
    16821715                        try {
    16831716                                success = FrameIO.DeleteFrame(frame);
    1684                                 if (!success)
     1717                                if (!success && _verbose)
    16851718                                        FrameGraphics.WarningMessage(errorMessage);
    16861719                        } catch (Exception e) {
    16871720                                // If an exception is thrown then success is false
    1688                                 FrameGraphics
    1689                                                 .WarningMessage(errorMessage
    1690                                                                 + (e.getMessage() != null ? ". "
    1691                                                                                 + e.getMessage() : ""));
     1721                                if (_verbose) {
     1722                                        FrameGraphics.WarningMessage(errorMessage
     1723                                                        + (e.getMessage() != null ? ". " + e.getMessage()
     1724                                                                        : ""));
     1725                                }
    16921726                        }
    16931727                        if (tokens.length > 2) {
     
    17001734                                        tokens[1]);
    17011735                        boolean success = FrameIO.DeleteFrameset(framesetName);
    1702                         if (!success)
     1736                        if (!success && _verbose) {
    17031737                                FrameGraphics.WarningMessage("Error deleting " + framesetName);
     1738                        }
    17041739                        if (tokens.length > 2) {
    17051740                                context.getPrimitives().setValue(tokens[2],
     
    17221757                        boolean success = FrameIO.CopyFrameset(framesetToCopy,
    17231758                                        copiedFrameset);
    1724                         if (!success)
     1759                        if (!success && _verbose)
    17251760                                FrameGraphics.WarningMessage("Error copying " + framesetToCopy);
    17261761                        if (tokens.length > 3) {
     
    17461781                        context.getPointers().setObject(tokens[2], freshCopy);
    17471782                        String fileContents = FrameIO.ForceSaveFrame(freshCopy);
     1783                        FrameIO.ResumeCache();
     1784                        // Need to add the new copy to the cache in case it is edited by
     1785                        // other simple statements
     1786                        FrameIO.addToCache(freshCopy);
    17481787                        boolean success = fileContents != null;
    1749                         if (!success)
     1788                        if (!success && _verbose)
    17501789                                FrameGraphics.WarningMessage("Error copying "
    17511790                                                + frameToCopy.getName());
    1752                         FrameIO.ResumeCache();
    17531791                        if (tokens.length > 4) {
    17541792                                context.getPrimitives().setValue(tokens[4],
     
    20142052                                count = countCharsInString(((Text) item).getText(), pattern);
    20152053                        context.getPrimitives().setValue(tokens[3], new SInteger(count));
     2054                } else if (tokens[0].equals("clearframe")) {
     2055                        String frameVar = DEFAULT_FRAME;
     2056                        if (tokens.length > 1) {
     2057                                assertMinParametreCount(tokens, 1);
     2058                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     2059                                frameVar = tokens[1];
     2060                        }
     2061                        boolean success = true;
     2062                        try {
     2063                                Frame frameToClear = (Frame) context.getPointers().getVariable(
     2064                                                frameVar).getValue();
     2065                                frameToClear.clear(false);
     2066                                assert (frameToClear.getItems().size() <= 1);
     2067                        } catch (Exception e) {
     2068                                success = false;
     2069                        }
     2070                        if (tokens.length > 2) {
     2071                                assertExactParametreCount(tokens, 2);
     2072                                context.getPrimitives().setValue(tokens[2],
     2073                                                new SBoolean(success));
     2074                        }
    20162075                } else if (tokens[0].equals("parseframename")) {
    20172076                        assertExactParametreCount(tokens, 4);
     
    20262085                        } catch (Exception e) {
    20272086                                success = false;
    2028                                 FrameGraphics.WarningMessage("Error parsing " + frameName);
     2087                                if (_verbose)
     2088                                        FrameGraphics.WarningMessage("Error parsing " + frameName);
    20292089                        }
    20302090                        // assertPrimitiveType(tokens[2], 2);
     
    24912551                FrameGraphics.DisplayMessage("Running SimpleProgram...", Color.BLUE);
    24922552        }
     2553
     2554        public static boolean isVerbose() {
     2555                return _verbose;
     2556        }
    24932557}
  • trunk/src/org/expeditee/agents/ComputeTree.java

    r97 r108  
    2020        protected Frame process(Frame frame) {
    2121                _format.setMinimumFractionDigits(0);
    22                 if (computeFrame(frame) == null) {
     22                if (computeFrame(frame) == null && !_stop) {
    2323                        message("Nothing to compute!");
    2424                }
     
    3838                String computeTag = null;
    3939                for (Item i : frame.getItems()) {
     40                        if(_stop)
     41                                return null;
    4042                        if (i.isAnnotation()) {
    4143                                String s = ((Text) i).getFirstLine().toLowerCase().trim();
     
    8587                // operation
    8688                for (Item i : frame.getBodyTextItems(false)) {
     89                        if(_stop)
     90                                return null;
    8791                        Double value = null;
    8892                        // Process the frame that each item is linked to
  • trunk/src/org/expeditee/agents/DefaultAgent.java

    r86 r108  
    9898
    9999                SessionStats.setEnabled(false);
    100 
     100                _start.change();
    101101                _end = process(_start);
    102102
  • trunk/src/org/expeditee/agents/DisplayTree.java

    r86 r108  
    8181                Item delay = ItemUtils.FindTag(toSearch.getItems(),
    8282                                "@DisplayTreePause:");
     83               
    8384                if (delay != null) {
    8485                        try {
  • trunk/src/org/expeditee/agents/SwitchyardTree.java

    r80 r108  
    22
    33import java.awt.Color;
    4 import java.awt.Point;
     4import java.awt.geom.Point2D;
    55
    66import org.expeditee.gui.Frame;
     
    1616                for (Text textItem : frame.getBodyTextItems(false)) {
    1717                        // Delete all non-annotations with more that one letter
    18                         if (textItem.getText().length() > 1)
     18                        if (textItem.getText().length() > 1){
    1919                                frame.removeItem(textItem);
    20                         else {
     20                                if(_stop)
     21                                        return null;
     22                        }else {
    2123                                // goto child frame of any linked 1 letter items
    2224                                String link = textItem.getAbsoluteLink();
     
    2426                                        Frame childFrame = FrameIO.LoadFrame(link);
    2527                                        if (childFrame != null) {
    26                                                 Point lastItemEnd = textItem.getEndParagraphPosition();
     28                                                Point2D.Float lastItemEnd = textItem.getEndParagraphPosition();
    2729                                                for (Text childItem : childFrame.getBodyTextItems(false)) {
    2830                                                        // look for red items
     
    3133                                                                Text itemCopy = childItem.copy();
    3234                                                                // add to the right of parent item
    33                                                                 lastItemEnd.translate(20, 0);
    34                                                                 itemCopy.setPosition(lastItemEnd);
     35                                                                lastItemEnd.setLocation(lastItemEnd.x + 20, lastItemEnd.y);
     36                                                                itemCopy.setPosition(lastItemEnd.x, lastItemEnd.y);
    3537                                                                lastItemEnd = itemCopy
    3638                                                                                .getEndParagraphPosition();
     
    3840                                                        }
    3941                                                        _itemCount++;
     42                                                        if(_stop)
     43                                                                return null;
    4044                                                }
    4145                                        }
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r102 r108  
    1313import org.expeditee.items.Item;
    1414import org.expeditee.items.Justification;
     15import org.expeditee.items.Permission;
    1516import org.expeditee.items.Text;
    1617
     
    127128
    128129                        _GetMethods.add(Frame.class.getMethod("getOwner", param));
    129                         _GetMethods.add(Frame.class.getMethod("getProtection", param));
     130                        _GetMethods.add(Frame.class.getMethod("getPermission", param));
    130131                        _GetMethods.add(Frame.class.getMethod("getDateCreated", param));
    131132                        _GetMethods.add(Frame.class.getMethod("getLastModifyUser", param));
     
    140141                        Class[] pColor = { Color.class };
    141142                        Class[] pBool = { boolean.class };
    142                         Class[] pArrow = { int.class, double.class };
     143                        Class[] pArrow = { float.class, double.class };
    143144                        Class[] pList = { List.class };
    144145                        Class[] pIntArray = { int[].class };
    145146                        Class[] pJustification = { Justification.class };
     147                        Class[] pPermission = { Permission.class };
    146148
    147149                        _SetMethods = new HashMap<String, Method>();
     
    228230                                        "setJustification", pJustification));
    229231                        _SetMethods.put("width", Text.class.getMethod("setWidth", pInt));
    230                         _SetMethods.put("size", Item.class.getMethod("setSize", pInt));
    231                         _SetMethods.put("s", Item.class.getMethod("setSize", pInt));
     232                        _SetMethods.put("size", Item.class.getMethod("setSize", pFloat));
     233                        _SetMethods.put("s", Item.class.getMethod("setSize", pFloat));
    232234
    233235                        _SetMethods.put("foregroundcolor", Frame.class.getMethod(
     
    239241                        _SetMethods.put("bgc0", Frame.class.getMethod("setBackgroundColor",
    240242                                        pColor));
    241                         _SetMethods.put("protection", Frame.class.getMethod(
    242                                         "setProtection", pString));
     243                        _SetMethods.put("permission", Frame.class.getMethod(
     244                                        "setPermission", pPermission));
    243245
    244246                } catch (SecurityException e) {
     
    626628         */
    627629        public static String getAttribute(String attributeValuePair) {
     630                if(attributeValuePair.length() <= 1)
     631                        return null;
     632               
    628633                attributeValuePair = attributeValuePair.trim();
    629634
  • trunk/src/org/expeditee/gui/Browser.java

    r102 r108  
    6565
    6666        public Browser() {
     67                FrameGraphics.SupressMessages(true);
    6768                // Use the default values initially so we can load the profile frame
    6869                setSizes(new Dimension(UserSettings.InitialWidth,
     
    9394                        }
    9495                }
     96                //DisplayIO.setCurrentFrame(profile);
    9597                FrameUtils.ParseProfile(profile);
    96 
    9798                // Now reset the size of the windows to the size specified in the users
    9899                // profile
     
    115116                pack();
    116117                try {
    117                         go();
     118                        Collection<String> warningMessages = Actions.Init();
     119
     120                        DisplayIO.Init(this);
     121                        // Set visible must be just after DisplayIO.Init for the message box to
     122                        // be the right size
     123                        setVisible(true);
     124                        setVisible(false);
     125
     126                        setupGraphics();
     127
     128                        // required to accept TAB key
     129                        setFocusTraversalKeysEnabled(false);
     130
     131                        FrameUtils.loadFirstFrame(profile);
     132                       
     133
     134                        DisplayIO.UpdateTitle();
     135
     136                        FrameGraphics.SupressMessages(false);
     137                        //I think this can be moved back up to the top of the Go method now...
     138                        //It used to crash the program trying to print error messages up the top
     139                        for (String message : warningMessages)
     140                                FrameGraphics.WarningMessage(message);
     141
     142                        FrameKeyboardActions keyboardListner = new FrameKeyboardActions();
     143                        this.getContentPane().addKeyListener(keyboardListner);
     144                        this.addKeyListener(keyboardListner);
     145                       
     146                        FrameKeyboardActions.Refresh();
     147                        setVisible(true);
    118148                } catch (Exception e) {
    119149                        e.printStackTrace();
    120150                        Logger.Log(e);
    121151                }
    122                 // FrameGraphics.ForceRepaint();
    123152        }
    124153
    125154        Graphics2D g;
    126 
    127         /**
    128          * Loads in the Menus and the first Frame.
    129          */
    130         public void go() {
    131                 Collection<String> warningMessages = Actions.Init();
    132 
    133                 DisplayIO.Init(this);
    134                 // Set visible must be just after DisplayIO.Init for the message box to
    135                 // be the right size
    136                 setVisible(true);
    137 
    138                 setupGraphics();
    139 
    140                 // required to accept TAB key
    141                 setFocusTraversalKeysEnabled(false);
    142 
    143                 assert (UserSettings.FirstFrame != null);
    144                 Frame firstFrame = FrameIO.LoadFrame(UserSettings.FirstFrame);
    145 
    146                 DisplayIO.setCurrentFrame(firstFrame);
    147                 DisplayIO.UpdateTitle();
    148 
    149                 //I think this can be moved back up to the top of the Go method now...
    150                 //It used to crash the program trying to print error messages up the top
    151                 for (String message : warningMessages)
    152                         FrameGraphics.WarningMessage(message);
    153 
    154                 FrameKeyboardActions keyboardListner = new FrameKeyboardActions();
    155                 this.getContentPane().addKeyListener(keyboardListner);
    156                 this.addKeyListener(keyboardListner);
    157         }
    158155
    159156        private void setupGraphics() {
  • trunk/src/org/expeditee/gui/ColorUtils.java

    r80 r108  
    55public class ColorUtils {
    66
    7         public static Color getNextColor(Color color, Color[] wheel) {
     7        /**
     8         * Gets the next color in the specified color wheel.
     9         *
     10         * @param color
     11         *            the current color
     12         * @param wheel
     13         *            the color wheel from which to find the next color
     14         * @param skip
     15         *            a color to ignore, for example the current background color when getting the next foreground color or
     16         *            null if no colors should be skipped
     17         * @return the next color on the color wheel
     18         */
     19        public static Color getNextColor(Color color, Color[] wheel, Color skip) {
     20                if (color == null)
     21                        return wheel[0];
    822                // search through the colour wheel to find the next colour
    923                int pos = -1;
    10                 for (int i = 0; i < wheel.length; i++){
    11                         if (color == null) {
    12                                 break;
    13                         } else if (color.equals(wheel[i])) {
     24                for (int i = 0; i < wheel.length; i++) {
     25                        if (color.equals(wheel[i])) {
    1426                                pos = i;
    1527                                break;
     
    2032                color = wheel[pos];
    2133
     34                if (skip != null && skip.equals(color))
     35                        return getNextColor(color, wheel, skip);
     36
    2237                return color;
    2338        }
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r106 r108  
    88import java.awt.Robot;
    99import java.awt.Toolkit;
     10import java.awt.geom.Point2D;
    1011import java.awt.image.MemoryImageSource;
    1112import java.util.LinkedList;
     
    1718import org.expeditee.items.Item;
    1819import org.expeditee.items.ItemParentStateChangedEvent;
     20import org.expeditee.items.Permission;
    1921import org.expeditee.items.Picture;
    2022import org.expeditee.items.Text;
     
    5860         * The title to display in the Title bar.
    5961         */
    60         public static final String TITLE = "Exp20Jun2008A";
     62        public static final String TITLE = "Exp26Jun2008B";
    6163
    6264        private DisplayIO() {
     
    8890                        boolean newSize) {
    8991
    90                 int size = text.getSize();
    91                 Point newMouse = text.moveCursor(cursorMovement, DisplayIO.getMouseX(),
    92                                 FrameMouseActions.getY());
     92                int size = Math.round(text.getSize());
     93                Point2D.Float newMouse = text.moveCursor(cursorMovement, DisplayIO.getFloatMouseX(),
     94                                FrameMouseActions.MouseY);
    9395
    9496                if (!newSize && cursorType == Item.TEXT_CURSOR) {
     
    230232         * @param pos
    231233         */
     234        public static void setCursorPosition(Point2D.Float pos) {
     235                setCursorPosition(pos.x, pos.y);
     236        }
     237       
    232238        public static void setCursorPosition(Point pos) {
    233239                setCursorPosition(pos.x, pos.y);
     
    235241
    236242        public static void setCursorPosition(Point pos, boolean forceArrow) {
     243                setCursorPosition(pos.x, pos.y, forceArrow);
     244        }
     245       
     246        public static void setCursorPosition(Point2D.Float pos, boolean forceArrow) {
    237247                setCursorPosition(pos.x, pos.y, forceArrow);
    238248        }
     
    351361                        if (_CurrentFrames[getOppositeSide()] == frame
    352362                                        || _CurrentFrames[getOppositeSide()].getOverlays()
    353                                                         .contains(new Overlay(frame, 1))) {
     363                                                        .contains(new Overlay(frame, Permission.followLinks))) {
    354364                                FrameIO.SuspendCache();
    355365                                frame = FrameIO.LoadFrame(frame.getName());
     
    713723         */
    714724        public static void MoveCursorToEndOfItem(Item i) {
    715                 setTextCursor((Text) i, Text.END);
     725                setTextCursor((Text) i, Text.END, true);
    716726        }
    717727}
  • trunk/src/org/expeditee/gui/Frame.java

    r105 r108  
    1212import java.util.Collections;
    1313import java.util.HashMap;
     14import java.util.LinkedHashSet;
    1415import java.util.LinkedList;
    1516import java.util.List;
     
    2627import org.expeditee.items.ItemUtils;
    2728import org.expeditee.items.Line;
     29import org.expeditee.items.Permission;
    2830import org.expeditee.items.Text;
    2931import org.expeditee.items.WidgetCorner;
     32import org.expeditee.items.XRayable;
    3033import org.expeditee.stats.SessionStats;
    3134
    3235/**
    33  * Represents a Expeditee Frame that is displayed on the screen. Also is a registered
    34  * MouseListener on the Browser, and processes any MouseEvents directly.
     36 * Represents a Expeditee Frame that is displayed on the screen. Also is a
     37 * registered MouseListener on the Browser, and processes any MouseEvents
     38 * directly.
    3539 *
    3640 * @author jdm18
     
    3943public class Frame implements ImageObserver {
    4044
    41         public static Color[] COLOR_WHEEL = {
    42                         new Color(235, 235, 235), new Color(225, 225, 255),
    43                         new Color(195, 255, 255), new Color(225, 255, 225),
    44                         new Color(255, 255, 195), new Color(255, 225, 225),
    45                         new Color(255, 195, 255), Color.WHITE,
    46                         Color.GRAY, Color.DARK_GRAY,Color.BLACK, null };
     45        private boolean _protectionChanged = false;
     46
     47        public boolean isReadOnly() {
     48                return !_frameName.hasPermission(Permission.full)
     49                                && !_protectionChanged;
     50        }
     51
     52        public static Color[] COLOR_WHEEL = { new Color(235, 235, 235),
     53                        new Color(225, 225, 255), new Color(195, 255, 255),
     54                        new Color(225, 255, 225), new Color(255, 255, 195),
     55                        new Color(255, 225, 225), new Color(255, 195, 255), Color.WHITE,
     56                        Color.GRAY, Color.DARK_GRAY, Color.BLACK, null };
    4757
    4858        // The various attributes of this Frame
     
    5363        private int _version = 0;
    5464
    55         private String _protection = "" + Item.PERMISSION_FULL;
     65        private Permission _permission = null;
    5666
    5767        private String _owner = null;
     
    184194         */
    185195        public void setChanged(boolean value) {
    186                 //System.out.println(getName() + " " + value);
     196                // System.out.println(getName() + " " + value);
    187197                _change = value;
    188198
     
    204214         * @return The list of Item objects that are on this Frame.
    205215         */
    206         public List<Item> getItems() {
     216        public List<Item> getItems(boolean visible) {
    207217
    208218                if (!_sorted) {
     
    211221                }
    212222
    213                 List<Item> visibleItems = new ArrayList<Item>();
     223                List<Item> items = new ArrayList<Item>();
    214224
    215225                for (Item i : _body) {
    216                         if (i.isVisible())
    217                                 visibleItems.add(i);
    218                 }
    219 
    220                 return visibleItems;
     226                        if (i == null)
     227                                continue;
     228                        if (i.isVisible() || (!visible && !i.isDeleted())) {
     229                                items.add(i);
     230                        }
     231                }
     232
     233                return items;
     234        }
     235
     236        public List<Item> getItems() {
     237                return getItems(false);
    221238        }
    222239
     
    233250
    234251        /**
     252         * Gets a list of all the non annotation text items on the frame, excluding
     253         * the title and frame name.
     254         *
     255         * @param includeAnnotations
     256         *            true if annotations should be included in the list
     257         * @return list of text items
     258         */
     259        public List<Text> getBodyTextItems(boolean includeAnnotations) {
     260                return getBodyTextItems(includeAnnotations, false);
     261        }
     262
     263        /**
    235264         * Returns a list of all the non annotation text items on the frame which
    236265         * are not the title or frame name.
    237266         *
     267         * @param includeLineEnds
     268         *            true if text on the end of lines should be included in the
     269         *            list
    238270         * @return the list of body text items.
    239271         */
    240         public List<Text> getBodyTextItems(boolean includeAnnotations) {
     272        public List<Text> getBodyTextItems(boolean includeAnnotations,
     273                        boolean includeLineEnds) {
    241274                List<Text> bodyTextItems = new ArrayList<Text>();
    242275                for (Item i : getItems()) {
    243276                        // only add up normal body text items
    244277                        if ((i instanceof Text)
    245                                         && (includeAnnotations || !i.isAnnotation())) {
     278                                        && (includeAnnotations || !i.isAnnotation())
     279                                        && (includeLineEnds || !i.isLineEnd())) {
    246280                                bodyTextItems.add((Text) i);
    247281                        }
     
    345379                for (Item i : items) {
    346380                        if (i instanceof Text && i.getX() < UserSettings.TitlePosition
    347                                         && i.getY() < UserSettings.TitlePosition /*
    348                                                                                                                                  * && i.getY() >
    349                                                                                                                                  * 0
    350                                                                                                                                  */)
     381                                        && i.getY() < UserSettings.TitlePosition)
    351382                                return (Text) i;
    352383                }
     
    399430                // We dont want the stats to wrap at all
    400431                t.setMaxSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
     432                t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
     433                // The next line is needed to make sure the item is removed from the
     434                // frame when picked up
     435                t.setParent(this);
    401436                t.setText(itemText);
    402                 t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
    403                
    404                 //The next line is needed to allow the link to be set properly when the item is picked up
    405                 _body.add(t);
    406                 //The next line is needed to make sure the item is removed from the frame when picked up
    407                 t.setParent(this);
    408437                return t;
    409438        }
    410 
    411439
    412440        public Text getCodeCommentTemplate() {
     
    430458         *         Item.intersects(shape) return true.
    431459         */
    432         public List<Item> getItemsWithin(Polygon poly) {
    433                 List<Item> results = new ArrayList<Item>();
    434 
    435                 for (Item i : _body)
    436                         if (i.isVisible() && i.intersects(poly)) {
    437                                 if (!results.contains(i))
     460        public Collection<Item> getItemsWithin(Polygon poly) {
     461                Collection<Item> results = new LinkedHashSet<Item>();
     462                for (Item i : getVisibleItems()) {
     463                        if (i.intersects(poly)) {
     464                                if (i instanceof XRayable) {
     465                                        results.addAll(i.getConnected());
     466                                } else {
    438467                                        results.add(i);
    439                         }
     468                                }
     469                        }
     470                }
    440471
    441472                for (Overlay o : _overlays)
     
    517548         *            The protection to use for this Frame.
    518549         */
    519         public void setProtection(String protection) {
    520                 _protection = protection;
     550        public void setPermission(Permission permission) {
     551                if (_permission != null && _permission.equals(permission))
     552                        _protectionChanged = true;
     553
     554                _permission = permission;
    521555
    522556                if (_body.size() > 0)
     
    593627         */
    594628        public void addItem(Item item) {
    595                 if (item != null) {
    596                         if (_body.contains(item)) {
    597                                 // System.out.println("Item (" + item.getClass().getSimpleName()
    598                                 // + ") with ID " + item.getID() + " already in body.");
    599                                 return;
    600                         }
    601 
    602                         if (item instanceof Line)
    603                                 _lineCount++;
    604 
    605                         _itemCount = Math.max(_itemCount, item.getID());
    606 
    607                         _body.add(item);
    608                         item.setParent(this);
    609 
    610                         // If the item is a line end and has constraints with items already
    611                         // on the frame then make sure the constraints hold
    612                         if (item.isLineEnd()) {
    613                                 item.setPosition(item.getPosition());
    614                         }
    615 
    616                         _sorted = false;
    617 
    618                         item.setMaxSize(FrameGraphics.getMaxFrameSize());
    619                         // add widget items to the list of widgets
    620                         if (item instanceof WidgetCorner) {
    621                                 InteractiveWidget iw = ((WidgetCorner) item).getWidgetSource();
    622                                 if (!this._iWidgets.contains(iw)) { // A set would have been
    623                                         // best
    624                                         _iWidgets.add(iw);
    625                                 }
    626                         }
    627 
    628                         item.onParentStateChanged(new ItemParentStateChangedEvent(this,
    629                                         ItemParentStateChangedEvent.EVENT_TYPE_ADDED));
    630 
    631                         change();
    632                 }
     629                if (item == null || item.equals(_frameName) || _body.contains(item))
     630                        return;
     631
     632                if (item instanceof Line)
     633                        _lineCount++;
     634
     635                _itemCount = Math.max(_itemCount, item.getID());
     636
     637                _body.add(item);
     638                item.setParent(this);
     639
     640                // If the item is a line end and has constraints with items already
     641                // on the frame then make sure the constraints hold
     642                if (item.isLineEnd()) {
     643                        item.setPosition(item.getPosition());
     644                }
     645
     646                _sorted = false;
     647
     648                item.setMaxSize(FrameGraphics.getMaxFrameSize());
     649                // add widget items to the list of widgets
     650                if (item instanceof WidgetCorner) {
     651                        InteractiveWidget iw = ((WidgetCorner) item).getWidgetSource();
     652                        if (!this._iWidgets.contains(iw)) { // A set would have been
     653                                // best
     654                                _iWidgets.add(iw);
     655                        }
     656                }
     657
     658                item.onParentStateChanged(new ItemParentStateChangedEvent(this,
     659                                ItemParentStateChangedEvent.EVENT_TYPE_ADDED));
     660
     661                change();
    633662        }
    634663
     
    637666                        return;
    638667
    639                 for (Item i : _body)
    640                         i.setMaxSize(max);
     668                for (Item i : _body) {
     669                        if (i != null)
     670                                i.setMaxSize(max);
     671                }
    641672
    642673                _frameName.resetFrameNamePosition();
     
    769800        }
    770801
    771         public String getProtection() {
    772                 return _protection;
     802        public Permission getPermission() {
     803                return getPermission(Permission.full);
     804        }
     805
     806        public Permission getPermission(Permission defaultPermission) {
     807                if (_permission == null)
     808                        return defaultPermission;
     809
     810                return _permission;
    773811        }
    774812
     
    847885                s += "Name: " + _frameset + _number + "\n";
    848886                s += "Version: " + _version + "\n";
    849                 s += "Protection: " + _protection + "\n";
     887                s += "Protection: " + _permission + "\n";
    850888                s += "Owner: " + _owner + "\n";
    851889                s += "Date Created: " + _creationDate + "\n";
     
    863901
    864902        public Item getItemAbove(Item current) {
     903                // Make sure the items are sorted
     904                Collections.sort(_body);
    865905                int ind = _body.indexOf(current);
    866906                if (ind == -1)
     
    12631303         * items are added to the backup-stack.
    12641304         */
    1265         public void clear() {
     1305        public void clear(boolean keepAnnotations) {
    12661306                List<Item> newBody = new ArrayList<Item>(0);
    1267                 for (Item i : _body)
    1268                         if (i.isAnnotation() || i == getNameItem() || i == getTitleItem())
    1269                                 newBody.add(i);
    1270 
     1307                Item title = getTitleItem();
     1308                if (title != null) {
     1309                        newBody.add(title);
     1310                        _body.remove(title);
     1311                }
     1312                if (keepAnnotations) {
     1313                        for (Item i : _body) {
     1314                                if (i.isAnnotation())
     1315                                        newBody.add(i);
     1316                        }
     1317                }
    12711318                _body.removeAll(newBody);
    12721319                addAllToUndo(_body);
    12731320                _body = newBody;
     1321                change();
    12741322        }
    12751323
     
    13071355                t.setText("");
    13081356                t.setParent(this);
     1357                addItem(t);
    13091358                return t;
    13101359        }
     
    13281377
    13291378        private Text getTemplate(Text defaultTemplate, int templateTag) {
    1330                 Text t = defaultTemplate;
     1379                Text t = null;
    13311380
    13321381                // check for an updated template...
     
    13381387                }
    13391388
    1340                 if (t == null)
    1341                         return null;
     1389                if (t == null) {
     1390                        if (defaultTemplate == null) {
     1391                                return null;
     1392                        }
     1393                        t = defaultTemplate;
     1394                }
    13421395
    13431396                // If the item is linked apply any attribute pairs on the child frame
     
    13781431                t.setPosition(x, y);
    13791432                t.addAction(action);
    1380 
    1381                 addItem(t);
    13821433                return t;
    13831434        }
     
    14001451
    14011452        public void setSaved() {
    1402                 //System.out.println(getName() + " saved");
     1453                // System.out.println(getName() + " saved");
    14031454                _saved = true;
    14041455                _change = false;
     
    15291580        public void toggleBackgroundColor() {
    15301581                setBackgroundColor(ColorUtils.getNextColor(_background,
    1531                                 Frame.COLOR_WHEEL));
     1582                                Frame.COLOR_WHEEL, null));
    15321583        }
    15331584
     
    15421593         */
    15431594        public void refreshItemPermissions() {
    1544                 int permission = FrameUtils.getPermissionLevel(_protection,
    1545                                 Item.PERMISSION_FULL);
    1546 
    1547                 _frameName.Permission = permission;
     1595                Permission permission = getPermission();
     1596                _frameName.setPermission(permission);
     1597
    15481598                switch (permission) {
    1549                 case Item.PERMISSION_NONE:
     1599                case none:
    15501600                        _frameName.setBackgroundColor(new Color(255, 220, 220));
    15511601                        break;
    1552                 case Item.PERMISSION_FOLLOW_LINKS:
     1602                case followLinks:
    15531603                        _frameName.setBackgroundColor(new Color(255, 230, 135));
    15541604                        break;
    1555                 case Item.PERMISSION_COPY:
     1605                case copy:
    15561606                        _frameName.setBackgroundColor(new Color(255, 255, 155));
    15571607                        break;
    1558                 case Item.PERMISSION_TDFC:
     1608                case createFrames:
    15591609                        _frameName.setBackgroundColor(new Color(220, 255, 220));
    15601610                        break;
    1561                 case Item.PERMISSION_FULL:
     1611                case full:
    15621612                        _frameName.setBackgroundColor(null);
    15631613                        break;
     
    15681618
    15691619                for (Item i : _body) {
    1570                         i.Permission = permission;
     1620                        i.setPermission(_permission);
    15711621                }
    15721622        }
     
    15921642                }
    15931643        }
    1594        
    1595         public void setActiveTime(Time activeTime){
     1644
     1645        public void setActiveTime(Time activeTime) {
    15961646                _activeTime = activeTime;
    15971647        }
    1598        
    1599         public void setDarkTime(Time darkTime){
     1648
     1649        public void setDarkTime(Time darkTime) {
    16001650                _darkTime = darkTime;
    16011651        }
     
    16401690                return _darkTime;
    16411691        }
    1642        
     1692
    16431693        public Time getActiveTime() {
    16441694                return _activeTime;
     
    17211771                _annotations.clear();
    17221772        }
     1773
     1774        public List<Item> getVisibleItems() {
     1775                return getItems(true);
     1776        }
     1777
     1778        public Collection<Text> getAnnotationItems() {
     1779                return _annotations.values();
     1780        }
     1781
     1782        /**
     1783         * Gets a list of items to be saved to file by text file writers.
     1784         *
     1785         * @return the list of items to be saved to a text file
     1786         */
     1787        public List<Item> getItemsToSave() {
     1788
     1789                if (!_sorted) {
     1790                        Collections.sort(_body);
     1791                        _sorted = true;
     1792                }
     1793
     1794                // iWidgets are handled specially since 8 items are written as one
     1795                Collection<InteractiveWidget> seenWidgets = new LinkedHashSet<InteractiveWidget>();
     1796
     1797                List<Item> toSave = new ArrayList<Item>();
     1798
     1799                for (Item i : _body) {
     1800                        // TODO Mike says: checkout if the ID check is still needed- When
     1801                        // will ID still
     1802                        // be -1 when saving a frame?
     1803                        if (i == null || i instanceof Line || !i.isVisible()
     1804                                        || i.getID() < 0 || i.offScreenTopOrLeft()) {
     1805                                continue;
     1806                        }
     1807
     1808                        // Ensure only one of the WidgetCorners represent a single widget
     1809                        if (i instanceof WidgetCorner) {
     1810                                InteractiveWidget iw = ((WidgetCorner) i).getWidgetSource();
     1811                                if (seenWidgets.contains(iw))
     1812                                        continue;
     1813                                seenWidgets.add(iw);
     1814                                toSave.add(iw.getSource());
     1815                        } else if(i instanceof XRayable){
     1816                                XRayable x = (XRayable)i;
     1817                                toSave.addAll(x.getItemsToSave());
     1818                        }//Circle centers are items with attached enclosures
     1819                        else if (i.hasEnclosures()){
     1820                                continue;
     1821                        }else{
     1822                                toSave.add(i);
     1823                        }
     1824                }
     1825
     1826                return toSave;
     1827        }
    17231828}
  • trunk/src/org/expeditee/gui/FrameCreator.java

    r97 r108  
    2222        private int _lastY = START_Y;
    2323
    24         private Item _Mnext = new Text(-1, "@Next");
     24        private Item _Mnext = new Text("@Next");
    2525
    26         private Item _Mprev = new Text(-1, "@Previous");
     26        private Item _Mprev = new Text("@Previous");
    2727
    2828        private Item _next;
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r106 r108  
    1212import java.awt.Point;
    1313import java.awt.RenderingHints;
    14 import java.awt.Stroke;
     14import java.awt.geom.Point2D;
    1515import java.awt.image.BufferedImage;
    1616import java.awt.image.VolatileImage;
     
    2727
    2828import org.expeditee.actions.Misc;
     29import org.expeditee.items.Circle;
    2930import org.expeditee.items.InteractiveWidget;
    3031import org.expeditee.items.Item;
     
    3435import org.expeditee.items.Text;
    3536import org.expeditee.items.WidgetEdge;
     37import org.expeditee.items.XRayable;
    3638
    3739public class FrameGraphics {
     
    114116        public static void ToggleXRayMode() {
    115117                if (_Mode == MODE_XRAY)
    116                         _Mode = MODE_NORMAL;
     118                        setMode(MODE_NORMAL, true);
    117119                else
    118                         _Mode = MODE_XRAY;
    119 
    120                 FrameUtils.Parse(DisplayIO.getCurrentFrame());
     120                        setMode(MODE_XRAY, true);
    121121                DisplayIO.UpdateTitle();
     122                FrameMouseActions.getInstance().refreshHighlights();
    122123                Repaint();
     124        }
     125
     126        public static void setMode(int mode, boolean parse) {
     127                if (_Mode == mode)
     128                        return;
     129                _Mode = mode;
     130                if (parse)
     131                        FrameUtils.Parse(DisplayIO.getCurrentFrame());
    123132        }
    124133
     
    222231                        AddAllOverlayItems(items, o.Frame, seenOverlays);
    223232
    224                 items.addAll(overlay.getItems());
     233                items.addAll(overlay.getVisibleItems());
    225234        }
    226235
     
    242251         */
    243252        public static void AddAllVectorItems(List<Item> items, Frame vector,
    244                         Collection<Frame> seenVectors, Point origin, Float scale,
     253                        Collection<Frame> seenVectors, Point2D.Float origin, Float scale,
    245254                        Color defaultForeground, Color defaultBackground) {
    246255
     
    250259                seenVectors.add(vector);
    251260
    252                 int originX = origin == null ? 0 : origin.x;
    253                 int originY = origin == null ? 0 : origin.y;
     261                float originX = origin == null ? 0 : origin.x;
     262                float originY = origin == null ? 0 : origin.y;
    254263
    255264                for (Vector o : vector.getVectors())
    256265                        AddAllVectorItems(items, o.Frame, new HashSet<Frame>(seenVectors),
    257                                         new Point(originX + Math.round(o.Origin.x * scale), originY
    258                                                         + Math.round(o.Origin.y * scale)), o.Scale * scale,
     266                                        new Point2D.Float(originX + o.Origin.x * scale, originY
     267                                                        + o.Origin.y * scale), o.Scale * scale,
    259268                                        o.Foreground, o.Background);
    260269                // if its the original frame then were done
     
    264273                }
    265274                // Put copies of the items shifted to the origin of the VectorTag
    266                 int dx = origin.x;
    267                 int dy = origin.y;
    268                 List<Item> copies = ItemUtils.CopyItems(vector.getItems());
     275                float dx = origin.x;
     276                float dy = origin.y;
     277                List<Item> copies = ItemUtils
     278                                .CopyItems(vector.getVisibleItems(), false);
    269279                // FrameMouseActions
    270                 Iterator<Item> iterator = copies.iterator();
    271                 while (iterator.hasNext()) {
    272                         Item i = iterator.next();
     280                while (!copies.isEmpty()) {
     281                        Iterator<Item> iterator = copies.iterator();
     282                        Item item = iterator.next();
    273283                        // Dont paint annotation items for @v
    274                         if (i.isAnnotation()) {
     284                        if (!item.isVisible() || item.isAnnotation()) {
    275285                                iterator.remove();
    276286                                continue;
    277287                        }
    278                         i.setLinkMark(false);
    279                         i.setActionMark(false);
    280                         if (!(i instanceof Line)) {
    281                                 i.setXY(Math.round(i.getX() * scale + dx), Math.round(i.getY()
    282                                                 * scale + dy));
    283                                 i.setThickness(Math.round(i.getThickness() * scale));
    284                                 i
    285                                                 .setArrowheadLength(Math.round(i.getArrowheadLength()
    286                                                                 * scale));
    287                                 if (i.getColor() == null) {
    288                                         i.setColor(defaultForeground);
     288                        item.setLinkMark(false);
     289                        item.setActionMark(false);
     290                        if (!(item instanceof Line)) {
     291                                item.setThickness(item.getThickness() * scale);
     292                                Collection<Item> connected = item.getAllConnected();
     293                                for (Item i : connected) {
     294                                        if (!(i instanceof Line)) {
     295                                                i.setXY(i.getX() * scale + dx, i.getY() * scale + dy);
     296                                                i.setArrowheadLength(i.getArrowheadLength() * scale);
     297                                                if (i.getColor() == null) {
     298                                                        i.setColor(defaultForeground);
     299                                                }
     300                                                if (i.getBackgroundColor() == null) {
     301                                                        i.setBackgroundColor(defaultBackground);
     302                                                }
     303                                                if (i.getFillColor() == null) {
     304                                                        i.setFillColor(defaultBackground);
     305                                                }
     306                                                if (i instanceof Text)
     307                                                        i.setSize(i.getSize() * scale);
     308                                                else if (i instanceof Picture) {
     309                                                        Picture p = (Picture) i;
     310                                                        p.setScale(p.getScale() * scale);
     311                                                }
     312                                        }
    289313                                }
    290                                 if (i.getBackgroundColor() == null) {
    291                                         i.setBackgroundColor(defaultBackground);
    292                                 }
    293                                 if (i.getFillColor() == null) {
    294                                         i.setFillColor(defaultBackground);
    295                                 }
    296                         }
    297                         if (i instanceof Text)
    298                                 i.setSize(Math.round(i.getSize() * scale));
    299                         items.add(i);
     314                                items.addAll(connected);
     315                                copies.removeAll(connected);
     316                        } else {
     317                                items.add(item);
     318                        }
    300319                }
    301320        }
     
    381400
    382401                        if (isActualFrame) {
     402                                // Add all the items for this frame and any other from other
     403                                // frames
    383404                                AddAllOverlayItems(paintItems, toPaint, new LinkedList<Frame>());
    384405
     
    388409
    389410                        } else {
    390                                 paintItems.addAll(toPaint.getItems());
     411                                paintItems.addAll(toPaint.getVisibleItems());
    391412                                paintWidgets = toPaint.getInteractiveWidgets();
    392413                        }
     
    399420
    400421                        PaintPictures(bg, paintItems);
    401 
    402                         if (toPaint == DisplayIO.getCurrentFrame())
     422                        PaintLines(bg, paintItems);
     423
     424                        if (isActualFrame /* && toPaint == DisplayIO.getCurrentFrame() */)
    403425                                PaintPictures(bg, Frame.FreeItems);
    404 
    405                         PaintLines(bg, paintItems);
     426                        // TODO if we can get transparency with FreeItems... then text can
     427                        // be done before freeItems
    406428                        PaintNonLinesNonPicture(bg, paintItems);
    407429
    408430                        // toPaint.setBufferValid(true);
     431
     432                        if (isActualFrame && !isAudienceMode()) {
     433                                PaintItem(bg, toPaint.getNameItem());
     434                        }
    409435
    410436                        if (DisplayIO.isTwinFramesOn()) {
     
    442468                                        }
    443469                                }
    444                                 PaintLines(bg, lines);
     470                                if (isActualFrame)
     471                                        PaintLines(bg, lines);
    445472                        } else {
    446                                 // PaintPictures(bg, Frame.FreeItems);
    447                                 // PaintNonLinesNonPicture(bg, Frame.FreeItems);
    448                                 PaintLines(bg, Frame.FreeItems);
    449                         }
    450 
    451                         if (toPaint == DisplayIO.getCurrentFrame())
     473                                // Dont paint the
     474                                if (isActualFrame)
     475                                        PaintLines(bg, Frame.FreeItems);
     476                        }
     477
     478                        if (isActualFrame /* && toPaint == DisplayIO.getCurrentFrame() */)
    452479                                PaintNonLinesNonPicture(bg, Frame.FreeItems);
    453 
    454                         if (isActualFrame && !isAudienceMode()) {
    455                                 PaintItem(bg, toPaint.getNameItem());
    456                         }
    457480
    458481                        // BROOK: Ensure popups are repainted
     
    613636        private static void PaintNonLinesNonPicture(Graphics2D g, List<Item> toPaint) {
    614637                for (Item i : toPaint)
    615                         if (!(i instanceof Line) && !(i instanceof Picture))
     638                        if (!(i instanceof Line) && !(i instanceof XRayable))
    616639                                PaintItem(g, i);
    617640        }
    618641
     642        /**
     643         * Paint the lines that are not part of an enclosure.
     644         *
     645         * @param g
     646         * @param toPaint
     647         */
    619648        private static void PaintLines(Graphics2D g, List<Item> toPaint) {
    620                 Stroke oldStroke = g.getStroke();
    621649                // Use this set to keep track of the items that have been painted
    622650                Collection<Item> done = new HashSet<Item>();
    623651                for (Item i : toPaint)
    624652                        if (i instanceof Line) {
    625                                 Line l = (Line)i;
     653                                Line l = (Line) i;
    626654                                if (done.contains(l)) {
    627655                                        l.paintArrows(g);
     
    633661                                }
    634662                        }
    635                 g.setStroke(oldStroke);
    636         }
    637 
     663        }
     664
     665        /**
     666         * Paint filled areas and their surrounding lines as well as pictures.
     667         *
     668         * @param g
     669         * @param toPaint
     670         */
    638671        private static void PaintPictures(Graphics2D g, List<Item> toPaint) {
    639672                // Use this set to keep track of the items that dont need to be
     
    643676                for (Item i : toPaint) {
    644677                        // Ignore items that have already been done!
     678                        // Also ignore invisible items..
     679                        // TODO possibly ignore invisible items before coming to this
     680                        // method?
    645681                        if (done.contains(i))
    646682                                continue;
    647                         if (i instanceof Picture) {
    648                                 PaintItem(g, i);
     683                        if (i instanceof XRayable) {
     684                                toFill.add(i);
     685                                done.addAll(i.getConnected());
     686                        } else if (i.hasEnclosures()) {
     687                                for (Item enclosure : i.getEnclosures()) {
     688                                        if (!toFill.contains(enclosure))
     689                                                toFill.add(enclosure);
     690                                }
     691                                done.addAll(i.getConnected());
    649692                        } else if (i.isLineEnd()
    650693                                        && (!isAudienceMode() || !i.isConnectedToAnnotation())) {
     
    653696                        }
    654697                }
    655                 //Sort the items to fill
     698                // Sort the items to fill
    656699                Collections.sort(toFill, new Comparator<Item>() {
    657700                        public int compare(Item a, Item b) {
    658                                 Integer aArea = a.getEnclosedArea();
    659                                 Integer bArea = b.getEnclosedArea();
     701                                Double aArea = a.getEnclosedArea();
     702                                Double bArea = b.getEnclosedArea();
    660703                                return aArea.compareTo(bArea) * -1;
    661704                        }
    662705                });
    663                 for(Item i: toFill){
    664                         i.paintFill(g);
    665                         PaintItem(g, i.getLines().get(0));
     706                for (Item i : toFill) {
     707                        if (i instanceof XRayable) {
     708                                PaintItem(g, i);
     709                        } else {
     710                                // Paint the fill and lines
     711                                i.paintFill(g);
     712                                PaintItem(g, i.getLines().get(0));
     713                        }
    666714                }
    667715        }
     
    705753                                }
    706754                        }
     755                } else if (i instanceof Circle) {
     756                        i.setSelectedMode(Item.SelectedMode.Connected);
    707757                } else {
    708                         //FrameGraphics.ChangeSelectionMode(i,
    709                         //              Item.SelectedMode.Normal);
    710                         //For polygons need to make sure all other endpoints are unHighlighted
    711                         for (Item conn : i.getAllConnected()) {
    712                                 conn.setSelectedMode(Item.SelectedMode.None);
    713                         }
    714                         i.setSelectedMode(Item.SelectedMode.Normal);
     758                        // FrameGraphics.ChangeSelectionMode(i,
     759                        // Item.SelectedMode.Normal);
     760                        // For polygons need to make sure all other endpoints are
     761                        // unHighlighted
     762                        ChangeSelectionMode(i, Item.SelectedMode.Normal,
     763                                        Item.SelectedMode.None);
    715764                }
    716765                Repaint();
     
    719768
    720769        public static void ChangeSelectionMode(Item item, Item.SelectedMode newMode) {
     770                ChangeSelectionMode(item, newMode, newMode);
     771        }
     772
     773        public static void ChangeSelectionMode(Item item,
     774                        Item.SelectedMode newMode, Item.SelectedMode connectedNewMode) {
    721775                if (item == null)
    722776                        return;
    723 
    724                 for (Item i : item.getAllConnected())
    725                         i.setSelectedMode(newMode);
     777                boolean freeItem = Frame.FreeItems.contains(item);
     778                for (Item i : item.getAllConnected()) {
     779                        // Mike: TODO comment on what the line below does!!
     780                        // I forgot already!!Opps
     781                        if (freeItem || !Frame.FreeItems.contains(i)) {
     782                                i.setSelectedMode(connectedNewMode);
     783                        }
     784                }
     785                if (newMode != connectedNewMode)
     786                        item.setSelectedMode(newMode);
    726787                Repaint();
    727788        }
     
    813874                        for (int i = 0; i < Messages.length; i++) {
    814875                                if (Messages[i] == null) {
    815                                         Messages[i] = new Text(-1, getMessagePrefix(true) + message);
     876                                        Messages[i] = new Text(getMessagePrefix(true) + message);
    816877                                        Messages[i].setPosition(20, pos);
    817878                                        Messages[i].setOffset(0, -_MaxSize.height);
     
    938999                for (Component c : parent.getComponents()) {
    9391000                        if (c instanceof JPopupMenu && ((JPopupMenu) c).isVisible()) {
    940 
    9411001                                Point p = SwingUtilities.convertPoint(c, c.getLocation(),
    9421002                                                Browser._theBrowser.getContentPane());
     
    9511011                }
    9521012        }
     1013
     1014        public static int getMode() {
     1015                return _Mode;
     1016        }
    9531017}
  • trunk/src/org/expeditee/gui/FrameIO.java

    r105 r108  
    2323import org.expeditee.items.Item;
    2424import org.expeditee.items.ItemUtils;
     25import org.expeditee.items.Permission;
    2526import org.expeditee.items.Text;
    2627import org.expeditee.stats.SessionStats;
     
    142143                        return null;
    143144
     145                String frameNameLower = frameName.toLowerCase();
    144146                // first try reading from cache
    145                 if (isCacheOn() && _Cache.containsKey(frameName.toLowerCase())) {
     147                if (isCacheOn() && _Cache.containsKey(frameNameLower)) {
    146148                        Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName
    147149                                        + " from cache.");
    148                         return _Cache.get(frameName.toLowerCase());
     150                        return _Cache.get(frameNameLower);
    149151                }
    150152
     
    289291                _UseCache = cache;
    290292                if (_Cache.containsKey(fresh.getName().toLowerCase()))
    291                         _Cache.put(fresh.getName().toLowerCase(), fresh);
     293                        addToCache(fresh);
    292294                DisplayIO.setCurrentFrame(fresh);
    293295        }
     
    672674                // Dont save if the frame is protected and it exists
    673675                if (checkBackup
    674                                 && toSave.getNameItem().Permission < Item.PERMISSION_TDFC) {
     676                                && toSave.isReadOnly()) {
    675677                        _Cache.remove(toSave.getName().toLowerCase());
    676678                        SessionStats.NewFrameSession();
     
    709711                                ResumeCache();
    710712                                // Put the modified version in the cache
    711                                 _Cache.put(toSave.getName().toLowerCase(), toSave);
     713                                addToCache(toSave);
    712714                                // Show the messages alerting the user
    713715                                Text originalMessage = new Text(-1);
     
    734736
    735737                                original.setFrameNumber(nextnum);
    736                                 original.setProtection("" + Item.PERMISSION_COPY);
     738                                original.setPermission(Permission.copy);
    737739                                original.change();
    738740                                SaveFrame(original, false, false);
     
    756758                        toSave.setActiveTime(activeTime);
    757759
     760                        //int oldMode = FrameGraphics.getMode();
     761                        //if (oldMode != FrameGraphics.MODE_XRAY)
     762                        //      FrameGraphics.setMode(FrameGraphics.MODE_XRAY, true);
    758763                        writer.writeFrame(toSave);
     764                        //FrameGraphics.setMode(oldMode, true);
    759765                        toSave.setSaved();
    760766                        if (inc) {
     
    764770                        // avoid out-of-sync frames (when in TwinFrames mode)
    765771                        if (_Cache.containsKey(toSave.getName().toLowerCase()))
    766                                 _Cache.put(toSave.getName().toLowerCase(), toSave);
     772                                addToCache(toSave);
    767773
    768774                        Logger.Log(Logger.SYSTEM, Logger.SAVE, "Saving " + toSave.getName()
     
    790796
    791797                return writer.getFileContents();
     798        }
     799
     800        /**
     801         * @param toAdd
     802         */
     803        public static void addToCache(Frame toAdd) {
     804                _Cache.put(toAdd.getName().toLowerCase(), toAdd);
    792805        }
    793806
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r105 r108  
    22
    33import java.awt.Color;
    4 import java.awt.Point;
    54import java.awt.Toolkit;
    65import java.awt.datatransfer.DataFlavor;
     
    87import java.awt.event.KeyEvent;
    98import java.awt.event.KeyListener;
     9import java.awt.geom.Point2D;
    1010import java.util.ArrayList;
    1111import java.util.Collection;
     12import java.util.HashSet;
    1213import java.util.LinkedList;
    1314import java.util.List;
     
    1819import org.expeditee.actions.Simple;
    1920import org.expeditee.io.Logger;
     21import org.expeditee.items.Circle;
    2022import org.expeditee.items.Dot;
    2123import org.expeditee.items.Item;
     
    2325import org.expeditee.items.Justification;
    2426import org.expeditee.items.Line;
     27import org.expeditee.items.Permission;
    2528import org.expeditee.items.Text;
     29import org.expeditee.items.XRayable;
    2630import org.expeditee.stats.SessionStats;
    2731
     
    3236        public synchronized void keyTyped(KeyEvent e) {
    3337                if (Simple.isProgramRunning()) {
    34                         if (e.getKeyChar() == KeyEvent.VK_ESCAPE
    35                                         || (e.isControlDown() && e.getKeyChar() == KeyEvent.VK_C)) {
     38                        if (e.isControlDown()
     39                                        && (e.getKeyChar() == KeyEvent.VK_ESCAPE || e.getKeyChar() == KeyEvent.VK_C)) {
    3640                                Simple.stop();
     41                                return;
    3742                        } else if (e.isControlDown() && e.getKeyChar() == KeyEvent.VK_SPACE) {
    3843                                Simple.nextStatement();
    39                         }
    40 
    41                         Simple.KeyStroke(e.getKeyChar());
    42 
     44                                return;
     45                        } else {
     46                                Simple.KeyStroke(e.getKeyChar());
     47                        }
    4348                        if (Simple.consumeKeyboardInput())
    4449                                return;
     
    4954                        return;
    5055                }
    51                 // ingnore auto TDFC key sequence
    52                 if (e.getKeyChar() == KeyEvent.VK_ENTER && e.isControlDown())
    53                         return;
    54 
    55                 if (FrameMouseActions.isWaitingForRobot()) {
    56                         // try{
    57                         // Thread.sleep(10000);
    58                         // }catch(Exception ex){
    59                         //                             
    60                         // }
    61                         // keyTyped(e);
    62                         // System.out.println("Waiting: " + e.getKeyChar());
    63                         return;
    64                 }
     56
     57                // Deal with splitting text items when typing too fast
     58                // Mike: thinks this problem may have been solved and was due to
     59                // rounding errors in the text class...
     60                // It may have been fixed by changing to the use of floats instead of
     61                // ints for text positioning etc
     62                // if (FrameMouseActions.isWaitingForRobot()) {
     63                // System.out.println("Waiting: " + e.getKeyChar());
     64                // return;
     65                // }
    6566                e.consume();
    6667                char ch = e.getKeyChar();
     
    8081
    8182                // permission check
    82                 if (on != null && on.Permission < Item.PERMISSION_FULL) {
     83                if (on != null && !on.hasPermission(Permission.full)) {
    8384                        FrameGraphics
    8485                                        .DisplayMessage("Insufficient permission to edit this item");
     
    9697
    9798                // ignore delete and backspace if in free space
    98                 if (on == null
     99                if ((on == null || !(on instanceof Text))
    99100                                && (ch == KeyEvent.VK_BACK_SPACE || ch == KeyEvent.VK_TAB || ch == KeyEvent.VK_DELETE))
    100101                        return;
     
    135136                        text = createText(ch);
    136137                        FrameUtils.LastEdited = text;
    137                         DisplayIO.getCurrentFrame().addItem(text);
    138138                        DisplayIO.setTextCursor(text, Text.NONE);
    139139                        return;
     
    141141
    142142                DisplayIO.setTextCursor(text, Text.NONE);
    143                 Point newMouse = null;
     143                Point2D.Float newMouse = null;
    144144                if (ch == '\t') {
    145145                        if (isShiftDown) {
    146                                 newMouse = text.removeTab(ch, DisplayIO.getMouseX(),
    147                                                 FrameMouseActions.getY());
     146                                newMouse = text.removeTab(ch, DisplayIO.getFloatMouseX(),
     147                                                FrameMouseActions.MouseY);
    148148                        } else {
    149                                 newMouse = text.insertTab(ch, DisplayIO.getMouseX(),
    150                                                 FrameMouseActions.getY());
     149                                newMouse = text.insertTab(ch, DisplayIO.getFloatMouseX(),
     150                                                FrameMouseActions.MouseY);
    151151                        }
    152152                } else {
    153                         newMouse = text.insertChar(ch, DisplayIO.getMouseX(),
    154                                         FrameMouseActions.getY());
     153                        newMouse = text.insertChar(ch, DisplayIO.getFloatMouseX(),
     154                                        FrameMouseActions.MouseY);
    155155                }
    156156                DisplayIO.setCursorPosition(newMouse.x, newMouse.y, false);
    157157
    158                 //This repaint is needed for WINDOWS only?!?!? Mike is not sure why!
    159                 if(ch == KeyEvent.VK_DELETE)
     158                // This repaint is needed for WINDOWS only?!?!? Mike is not sure why!
     159                if (ch == KeyEvent.VK_DELETE)
    160160                        FrameGraphics.Repaint();
    161                
     161
    162162                // a change has occured to the Frame
    163163                text.getParent().setChanged(true);
     
    183183        }
    184184
    185         public static Item replaceDot(Item dot, char ch) {
    186                 Item text = createText(ch);
     185        public static Text replaceDot(Item dot, char ch) {
     186                Text text = createText(ch);
    187187                Item.DuplicateItem(dot, text);
    188188                FrameUtils.LastEdited = text;
     
    194194                Frame current = dot.getParentOrCurrentFrame();
    195195                current.removeItem(dot);
    196                 current.addItem(text);
    197196                ItemUtils.EnclosedCheck(current.getItems());
    198197                return text;
     
    233232                Text t = DisplayIO.getCurrentFrame().createBlankText("" + start);
    234233
    235                 Point newMouse = t.insertChar(start, DisplayIO.getMouseX(),
     234                Point2D.Float newMouse = t.insertChar(start, DisplayIO.getMouseX(),
    236235                                FrameMouseActions.getY());
    237236                DisplayIO.setCursorPosition(newMouse.x, newMouse.y, false);
     
    266265                                return;
    267266                        } else {
    268                                 FrameUtils.LastEdited = on;
     267                                FrameUtils.LastEdited = (Text) on;
    269268                                DisplayIO.setTextCursor((Text) on, direction);
    270269                        }
     
    313312                }
    314313
    315                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
    316                         functionKey(FunctionKey.DropDown);
    317                         SessionStats.Escape();
    318                         return;
    319                 } else if (e.getKeyCode() >= KeyEvent.VK_F1
     314                if (e.getKeyCode() >= KeyEvent.VK_F1
    320315                                && e.getKeyCode() <= KeyEvent.VK_F12) {
    321316                        functionKey(FunctionKey.values()[e.getKeyCode() - KeyEvent.VK_F1
    322                                         + 1]);
    323                         return;
    324                 } else if (e.isControlDown() && e.getKeyCode() != KeyEvent.VK_CONTROL)
    325                         controlChar(e, e.getKeyCode());
     317                                        + 1], e.isShiftDown());
     318                        return;
     319                } else if (e.isControlDown() && e.getKeyCode() != KeyEvent.VK_CONTROL) {
     320                        controlChar(e.getKeyCode(), e.isShiftDown());
     321                        return;
     322                }
     323
     324                // Do escape last so Ctl+Escape does not perform DropDown
     325                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
     326                        functionKey(FunctionKey.DropDown, false);
     327                        SessionStats.Escape();
     328                        return;
     329                }
    326330
    327331                switch (e.getKeyCode()) {
    328332                case KeyEvent.VK_CONTROL:
    329                         FrameMouseActions.shift(e);
     333                        FrameMouseActions.control(e);
    330334                        break;
    331335                case KeyEvent.VK_LEFT:
     
    360364                case KeyEvent.VK_HOME:
    361365                        move(Text.HOME);
    362                         break;
    363                 case KeyEvent.VK_ENTER:
    364                         if (e.isControlDown()) {
    365                                 FrameMouseActions.leftButton(FrameUtils.getCurrentItem());
    366                                 FrameMouseActions.updateCursor();
    367                         }
    368366                        break;
    369367                }
     
    384382                List<Text> textItems = current.getBodyTextItems(false);
    385383                if (textItems.size() == 0) {
     384                        //If there are no text items on the frame its a NoOp
     385                        if(title == null)
     386                                return;
    386387                        DisplayIO.MoveCursorToEndOfItem(title);
    387388                        FrameGraphics.Repaint();
     
    420421                }
    421422                // If the user is on the title item
    422                 if (current.getTitleItem().equals(currentItem)) {
     423                if (current != null && title != null && title.equals(currentItem)) {
    423424                        if (down) {
    424425                                // Move to the first item
     
    428429                        return;
    429430                }
     431
    430432                // Find the current item... then move to the next item
    431433                for (int i = 0; i < textItems.size(); i++) {
     
    437439                                                                .get(nextIndex));
    438440                                        }
    439                                 } else {
     441                                } else if (title != null) {
    440442                                        DisplayIO.MoveCursorToEndOfItem(title);
    441443                                }
     
    452454        public void keyReleased(KeyEvent e) {
    453455                if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
    454                         FrameMouseActions.shift(e);
     456                        FrameMouseActions.control(e);
    455457                }
    456458        }
     
    473475        }
    474476
    475         private static void copyItemToClipboard(Item on){
     477        private static void copyItemToClipboard(Item on) {
    476478                if (on == null || !(on instanceof Text))
    477479                        return;
     
    487489                // add the text of the item to the clipboard
    488490                StringSelection selection = new StringSelection(text);
    489                 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
    490                                 selection, null);
    491         }
    492        
     491                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection,
     492                                null);
     493        }
     494
    493495        /**
    494496         * Processes all control character keystrokes. Currently Ctrl+C and Ctrl+V
     
    498500         *            The character being pressed along with the control key
    499501         */
    500         private static void controlChar(KeyEvent e, int key) {
     502        private static void controlChar(int key, boolean isShiftDown) {
    501503                Logger.Log(Logger.USER, Logger.CONTROL_CHAR, "User pressing: Ctrl+"
    502504                                + KeyEvent.getKeyText(key));
     
    570572                                if (clicked != null) {
    571573                                        // check permissions
    572                                         if (clicked.Permission < Item.PERMISSION_FULL
     574                                        if (!clicked.hasPermission(Permission.full)
    573575                                                        && clicked.getParent() != null
    574576                                                        && clicked.getParent().getNameItem() != clicked) {
     
    612614                        // if this is a copy command
    613615                } else if (key == KeyEvent.VK_C) {
    614                         Item on = FrameUtils.getCurrentItem();
    615                         if (on != null && on.Permission < Item.PERMISSION_COPY) {
     616                        if (current == null)
     617                                return;
     618
     619                        if (current instanceof Text) {
     620                                if (current != null && !current.hasPermission(Permission.copy)) {
     621                                        FrameGraphics
     622                                                        .DisplayMessage("Insufficient permission to copy that item");
     623                                        return;
     624                                }
     625                                copyItemToClipboard(current);
     626                                // FrameGraphics.DisplayMessage("Item copied to clipboard");
     627                                return;
     628                        }
     629                        if (current != null && !current.hasPermission(Permission.full)) {
    616630                                FrameGraphics
    617                                                 .DisplayMessage("Insufficient permission to copy that item" );
    618                                 return;
    619                         }
    620                         copyItemToClipboard(on);
    621                         //FrameGraphics.DisplayMessage("Item copied to clipboard");
     631                                                .DisplayMessage("Insufficient permission edit that item");
     632                                return;
     633                        }
     634                        Text item = null;
     635                        // Check if its a line to be turned into a circle
     636                        if (current instanceof Dot && current.getLines().size() == 1) {
     637                                item = replaceDot(current, '@');
     638                        } else if (current instanceof Line
     639                                        && current.getAllConnected().size() == 3) {
     640                                Item end = ((Line) current).getEndItem();
     641                                if (end instanceof Dot) {
     642                                        item = replaceDot(end, '@');
     643                                } else if (end instanceof Text) {
     644                                        item = (Text) end;
     645                                }
     646                        }
     647                        item.setText("@c");
     648                        DisplayIO.setCursorPosition(item.getX(), item.getY());
     649                        FrameUtils.setLastEdited(null);
     650                        Refresh();
    622651                        return;
    623652                } else if (key == KeyEvent.VK_X) {
    624                         Item on = FrameUtils.getCurrentItem();
    625                         if (on != null && on.Permission < Item.PERMISSION_FULL) {
     653                        if (current == null)
     654                                return;
     655                        if (current != null && !current.hasPermission(Permission.full)) {
    626656                                FrameGraphics
    627                                                 .DisplayMessage("Insufficient permission to cut that item" );
    628                                 return;
    629                         }
    630                         copyItemToClipboard(on);
     657                                                .DisplayMessage("Insufficient permission to cut that item");
     658                                return;
     659                        }
     660                        copyItemToClipboard(current);
    631661                        FrameMouseActions.delete(current);
    632662                        return;
    633                 }else if (key == KeyEvent.VK_D) {
     663                } else if (key == KeyEvent.VK_M) {
     664                        if (current == null)
     665                                return;
     666                        if (current != null && !current.hasPermission(Permission.full)) {
     667                                FrameGraphics
     668                                                .DisplayMessage("Insufficient permission toggle the items mark");
     669                                return;
     670                        }
     671                        boolean newValue = !(current.getLinkMark() || current
     672                                        .getActionMark());
     673                        current.setLinkMark(newValue);
     674                        current.setActionMark(newValue);
     675                } else if (key == KeyEvent.VK_Z) {
     676                        DisplayIO.getCurrentFrame().undo();
     677                        return;
     678                } else if (key == KeyEvent.VK_D) {
    634679                        // perform a delete operation
    635                         processChar((char) KeyEvent.VK_DELETE, e.isShiftDown());
     680                        processChar((char) KeyEvent.VK_DELETE, isShiftDown);
    636681                } else if (key == KeyEvent.VK_DELETE) {
    637682                        // perform a delete operation
     
    674719                                currentFrame.addItem(newText);
    675720                        }
     721                } else if (key == KeyEvent.VK_ENTER) {
     722                        Item currentItem = FrameUtils.getCurrentItem();
     723                        FrameMouseActions.leftButton(currentItem, FrameUtils
     724                                        .getCurrentItems(currentItem));
     725                        FrameMouseActions.updateCursor();
     726                } else if (key == KeyEvent.VK_BACK_SPACE) {
     727                        DisplayIO.Back();
    676728                }
    677729                FrameGraphics.Repaint();
     
    685737         */
    686738        private static Text getCurrentTextItem() {
    687                 Item ip = FrameUtils.getCurrentItem();
    688 
    689                 if (ip != null && ip.Permission < Item.PERMISSION_FULL) {
     739                Item item = FrameUtils.getCurrentItem();
     740
     741                if (item != null && !item.hasPermission(Permission.full)) {
    690742                        FrameGraphics
    691743                                        .DisplayMessage("Insufficient permission to copy that item");
     
    694746
    695747                Item on = null;
    696                 if (ip != null)
    697                         on = ip;
     748                if (item != null)
     749                        on = item;
    698750
    699751                if (on == null || !(on instanceof Text))
     
    703755        }
    704756
    705         public static void functionKey(FunctionKey key) {
    706                 functionKey(key, 1);
     757        public static void functionKey(FunctionKey key, boolean isShiftDown) {
     758                functionKey(key, 1, isShiftDown);
    707759        }
    708760
     
    711763         * action based on the key.
    712764         */
    713         public static void functionKey(FunctionKey key, int repeat) {
     765        public static void functionKey(FunctionKey key, int repeat,
     766                        boolean isShiftDown) {
    714767                // get whatever the user is pointing at
    715768                Item on = FrameUtils.getCurrentItem();
    716 
    717769                // check for enclosed mode
    718770                if (on == null && key.ordinal() < FunctionKey.AudienceMode.ordinal()) {
     
    721773                        if (enclosed != null && enclosed.size() > 0) {
    722774                                // ensure only one dot\line is present in the list
    723                                 Collection<Item> dots = FrameUtils.getEnclosingDots();
    724                                 Item firstConnected = dots.iterator().next();
     775                                Collection<Item> lineEnds = FrameUtils.getEnclosingLineEnds();
     776                                Item firstConnected = lineEnds.iterator().next();
    725777                                Collection<Item> connected = firstConnected.getAllConnected();
    726778
    727779                                // only resize lines if they are not surrounding some non line
    728780                                // items
    729                                 boolean resizeLines = true;
    730                                 for (Item ip : enclosed) {
    731                                         if (ip != null) {
    732                                                 if (!(ip instanceof Line) && !(ip.isLineEnd())) {
    733                                                         resizeLines = false;
    734                                                         break;
    735                                                 }
    736                                         }
    737                                 }
     781                                // boolean resizeLines = true;
     782                                // for (Item ip : enclosed) {
     783                                // if (ip != null) {
     784                                // if (!(ip instanceof Line) && !(ip.isLineEnd())) {
     785                                // resizeLines = false;
     786                                // break;
     787                                // }
     788                                // }
     789                                // }
    738790
    739791                                switch (key) {
    740792                                case SizeUp:
    741                                         if (resizeLines
    742                                                         || (!(firstConnected instanceof Line) && !(firstConnected instanceof Dot)))
    743                                                 SetSize(firstConnected, repeat, false);
     793                                        // if ((!(firstConnected instanceof Line) &&
     794                                        // !(firstConnected instanceof Dot)))
     795                                        SetSize(firstConnected, repeat, false, true);
    744796                                        break;
    745797                                case SizeDown:
    746                                         if (resizeLines
    747                                                         || (!(firstConnected instanceof Line) && !(firstConnected instanceof Dot)))
    748                                                 SetSize(firstConnected, -repeat, false);
     798                                        // if ((!(firstConnected instanceof Line) &&
     799                                        // !(firstConnected instanceof Dot)))
     800                                        SetSize(firstConnected, -repeat, false, true);
    749801                                        break;
    750802                                case ChangeColor:
    751803                                        if (connected.size() > 0) {
    752                                                 for (Item d : dots) {
    753                                                         SetFillColor(d);
     804                                                for (Item d : lineEnds) {
     805                                                        SetFillColor(d, isShiftDown);
    754806                                                        break;
    755807                                                }
     
    795847                        return;
    796848                case SizeUp:
    797                         SetSize(on, repeat, true);
     849                        SetSize(on, repeat, true, false);
    798850                        if (on instanceof Text) {
    799851                                DisplayIO.setTextCursor((Text) on, Text.NONE, true);
     
    801853                        break;
    802854                case SizeDown:
    803                         SetSize(on, -repeat, true);
     855                        SetSize(on, -repeat, true, false);
    804856                        if (on instanceof Text) {
    805857                                DisplayIO.setTextCursor((Text) on, Text.NONE, true);
     
    807859                        break;
    808860                case ChangeColor:
    809                         SetColor(on);
     861                        SetColor(on, isShiftDown);
    810862                        break;
    811863                case ToggleAnnotation:
     
    825877                        break;
    826878                case XRayMode:
    827                         ToggleXRayMode(on);
     879                        FrameGraphics.ToggleXRayMode();
    828880                        break;
    829881                case AudienceMode:
    830                         ToggleAudience(on);
     882                        FrameGraphics.ToggleAudienceMode();
    831883                        break;
    832884                case Refresh:
    833                         Refresh(on);
    834                         break;
    835                 }
    836                 if (on == null)
     885                        Refresh();
     886                        break;
     887                }
     888                on = FrameUtils.getCurrentItem();
     889                Collection<Item> enclosed = FrameUtils.getCurrentItems(on);
     890                if (on == null && (enclosed == null || enclosed.size() == 0))
    837891                        FrameGraphics.DisplayMessage(displayMessage);
    838892        }
     
    853907        private static void Drop(Item ip) {
    854908                try {
     909                        FrameUtils.setLastEdited(null);
     910
    855911                        String newItemText = DEFAULT_NEW_ITEM_TEXT;
    856912
     
    922978
    923979                        // If the only item on the frame is the title and the frame name
    924                         // just
    925                         // drop a specified distance below the title
     980                        // just drop a specified distance below the title
    926981                        if (column.size() == 0) {
    927982                                Item itemTemplate = DisplayIO.getCurrentFrame()
     
    9601015                                                if (!mouseMoved) {
    9611016                                                        Item moreTitle = moreFrame.getTitleItem();
    962                                                         moreTitle.Permission = Item.PERMISSION_FULL;
     1017                                                        moreTitle.setPermission(Permission.full);
    9631018                                                        Drop(moreTitle);
    9641019                                                }
     
    9911046                                        }
    9921047                                } else {
    993                                         DisplayIO.setCursorPosition(dummyItem
    994                                                         .getEndParagraphPosition().x, dummyItem.getY());
    995                                 }
    996                         }
    997 
     1048                                        DisplayIO.MoveCursorToEndOfItem(dummyItem);
     1049                                }
     1050                        }
     1051                        if(dummyItem.getText().length() == 0)
     1052                                dummyItem.getParentOrCurrentFrame().removeItem(dummyItem);
    9981053                        DisplayIO.resetCursorOffset();
    9991054                        FrameGraphics.Repaint();
    10001055                } catch (RuntimeException e) {
    1001                         FrameGraphics.ErrorMessage(e.getMessage());
     1056                        // FrameGraphics.ErrorMessage(e.getMessage());
    10021057                        e.printStackTrace();
    10031058                }
     
    10331088                String newItemText = DEFAULT_NEW_ITEM_TEXT;
    10341089
     1090                if (s == null)
     1091                        return newItemText;
    10351092                /*
    10361093                 * Item i = ItemUtils.FindTag(DisplayIO.getCurrentFrame().getItems(),
     
    11701227         *            with resizing
    11711228         */
    1172         private static void SetSize(Item item, int diff, boolean moveCursor) {
    1173                 List<Item> toSize = new ArrayList<Item>();
     1229        private static void SetSize(Item item, int diff, boolean moveCursor,
     1230                        boolean insideEnclosure) {
     1231                Collection<Item> toSize = new HashSet<Item>();
    11741232                // the mouse is only moved when the Item is on the frame, not free
    11751233                // boolean moveMouse = false;
     
    11911249                        }
    11921250                        // check permissions
    1193                         if (item.Permission < Item.PERMISSION_FULL) {
     1251                        if (!item.hasPermission(Permission.full)) {
    11941252                                FrameGraphics
    11951253                                                .DisplayMessage("Insufficient permission to change the size of that item");
     
    11971255                        }
    11981256                        toSet = item;
    1199 
    1200                         if (!(toSet instanceof Text) && toSet.isLineEnd()) {
     1257                        // For resizing enclosures pick up everything that is attached to
     1258                        // items partly in the enclosure
     1259                        //TODO make this only pick up stuff COMPLETELY enclosed... if we change copying to copy only the stuff completely enclosed
     1260                        if (insideEnclosure) {
     1261                                for (Item i : FrameUtils.getCurrentItems(toSet)) {
     1262                                        if (!toSize.contains(i))
     1263                                                toSize.addAll(i.getAllConnected());
     1264                                }
     1265                        } else if (!(toSet instanceof Text) && toSet.isLineEnd()) {
    12011266                                toSize.addAll(toSet.getLines());
    12021267                        } else if (toSet instanceof Line) {
     
    12121277                }
    12131278
    1214                 int old_width = 0;
    1215                 int old_height = 0;
    1216 
    1217                 if (toSet != null) {
    1218                         old_width = toSet.getBoundsWidth();
    1219                         old_height = toSet.getBoundsHeight();
     1279                Point2D origin = new Point2D.Float(FrameMouseActions.MouseX,
     1280                                FrameMouseActions.MouseY);
     1281                // Inside enclosures increase the size of the enclosure
     1282                if (insideEnclosure) {
     1283                        double ratio = (100.0 + diff * 2) / 100.0;
     1284                        Collection<Item> done = new HashSet<Item>();
     1285                        // adjust the size of all the items
     1286                        for (Item i : toSize) {
     1287                                if (done.contains(i))
     1288                                        continue;
     1289                                if (i.isLineEnd()) {
     1290                                        Collection<Item> allConnected = i.getAllConnected();
     1291                                        done.addAll(allConnected);
     1292                                        for (Item it : allConnected) {
     1293                                                it.translate(origin, ratio);
     1294                                                it
     1295                                                                .setArrowheadLength((float) (it
     1296                                                                                .getArrowheadLength() * ratio));
     1297                                        }
     1298                                        i.setThickness((float) (i.getThickness() * ratio));
     1299                                } else if (i instanceof XRayable) {
     1300                                        i.translate(origin, ratio);
     1301                                        i.setThickness((float) (i.getThickness() * ratio));
     1302                                        done.add(i);
     1303                                } else if (i instanceof Text) {
     1304                                        i.translate(origin, ratio);
     1305                                        i.setSize((float) (i.getSize() * ratio));
     1306                                        done.add(i);
     1307                                }
     1308                        }
     1309                        FrameGraphics.Repaint();
     1310                        return;
    12201311                }
    12211312
     
    12231314                for (Item i : toSize) {
    12241315                        // Lines and dots use thickness, not size
    1225                         if (i instanceof Line) {
    1226                                 Line line = (Line) i;
    1227                                 float current = Math.abs(line.getThickness());
     1316                        if (i instanceof Line || i instanceof Circle && !insideEnclosure) {
     1317                                float current = Math.abs(i.getThickness());
    12281318                                current = Math.max(current + diff, 1);
    1229                                 line.setThickness(current);
     1319                                i.setThickness(current);
    12301320                        } else if (i instanceof Dot) {
    12311321                                Item dot = (Item) i;
     
    12341324                                dot.setThickness(current);
    12351325                        } else {
    1236                                 int oldSize = Math.abs(i.getSize());
    1237                                 int newSize = Math.max(oldSize + diff, 1);
     1326                                float oldSize = Math.abs(i.getSize());
     1327                                float newSize = Math.max(oldSize + diff, 1);
     1328                                float resizeRatio = newSize / oldSize;
     1329                                // Set size for Picture also translates
    12381330                                i.setSize(newSize);
    1239                                 if (i instanceof Text) {
    1240                                         // Move the cursor as close as we can to where it should be
    1241                                         int itemX = i.getX();
    1242                                         int itemY = i.getY();
    1243                                         float resizeRatio = (float) newSize / oldSize;
    1244                                         float fromOriginX = DisplayIO.getFloatMouseX() - itemX;
    1245                                         float fromOriginY = FrameMouseActions.MouseY - itemY;
    1246                                         float newX = itemX + fromOriginX * resizeRatio;
    1247                                         float newY = itemY + fromOriginY * resizeRatio;
    1248                                         if (i instanceof Text)
    1249                                                 newY--;
    1250                                         DisplayIO.setCursorPosition(newX, newY, false);
    1251                                         toSet.getParent().setChanged(true);
    1252                                         return;
    1253                                 }
    1254                         }
    1255                 }
    1256 
    1257                 // center the mouse cursor on the item
    1258                 if (moveCursor && toSet != null) {
    1259                         if (!toSet
    1260                                         .contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) {
    1261                                 int x = DisplayIO.getMouseX();
    1262                                 int y = FrameMouseActions.getY();
    1263 
    1264                                 if (!toSet.contains(x, toSet.getY()))
    1265                                         x = x - (old_width - toSet.getBoundsWidth());
    1266 
    1267                                 // text grows 'up', pictures grow 'down'
    1268                                 int direction = -1;
    1269                                 if (toSet instanceof Text)
    1270                                         direction = 1;
    1271 
    1272                                 if (!toSet.contains(toSet.getX(), y))
    1273                                         y = y
    1274                                                         + (direction * (old_height - toSet
    1275                                                                         .getBoundsHeight()));
    1276 
    1277                                 DisplayIO.setCursorPosition(x, y, false);
    1278                         }
    1279 
    1280                         // int x = toSet.getX() + toSet.getBoundsWidth() / 2;
    1281                         // int y = toSet.getY() + toSet.getBoundsHeight() / 2;;
    1282                         // DisplayIO.setCursorPosition(x, y);
    1283 
     1331                                if (i instanceof Text && i.getSize() != oldSize) {
     1332                                        i.translate(origin, resizeRatio);
     1333                                }
     1334                        }
    12841335                }
    12851336
     
    12901341        }
    12911342
    1292         private static void SetFillColor(Item item) {
     1343        private static void SetFillColor(Item item, boolean setTransparent) {
    12931344                if (item == null)
    12941345                        return;
    12951346
    1296                 Item toSet = item;// ;
     1347                Item toSet = item;
    12971348                Color color = toSet.getFillColor();
    1298 
    1299                 color = ColorUtils.getNextColor(color, Item.FILL_COLOR_WHEEL);
    1300 
    1301                 if (color == null) {
    1302                         FrameGraphics.DisplayMessage("FillColor is now transparent");
    1303                 }
     1349                if (setTransparent)
     1350                        color = null;
     1351                else
     1352                        color = ColorUtils.getNextColor(color, Item.FILL_COLOR_WHEEL, null);
     1353
     1354                // if (color == null) {
     1355                // FrameGraphics.DisplayMessage("FillColor is now transparent");
     1356                // }
    13041357
    13051358                toSet.setFillColor(color);
     
    13161369         *            The Item whose colour is to be changed
    13171370         */
    1318         private static void SetColor(Item ip) {
     1371        private static void SetColor(Item ip, boolean setTransparent) {
    13191372                // first determine the next color
    13201373                Color color = null;
     
    13291382                        // frame name
    13301383                } else if (ip == currentFrame.getNameItem()) {
    1331                         currentFrame.toggleBackgroundColor();
     1384                        // check permissions
     1385                        if (!ip.hasPermission(Permission.full)) {
     1386                                FrameGraphics
     1387                                                .DisplayMessage("Insufficient permission to the frame's background color");
     1388                                return;
     1389                        }
     1390                        if (setTransparent)
     1391                                currentFrame.setBackgroundColor(null);
     1392                        else
     1393                                currentFrame.toggleBackgroundColor();
    13321394                        // Display a message if the color has changed to transparent
    1333                         if (currentFrame.getBackgroundColor() == null)
    1334                                 FrameGraphics
    1335                                                 .DisplayMessage("Background color is now transparent");
     1395                        // if (currentFrame.getBackgroundColor() == null)
     1396                        // FrameGraphics
     1397                        // .DisplayMessage("Background color is now transparent");
    13361398                        FrameGraphics.Repaint();
    13371399                        return;
    13381400                } else {
    13391401                        // check permissions
    1340                         if (ip.Permission < Item.PERMISSION_FULL) {
     1402                        if (!ip.hasPermission(Permission.full)) {
    13411403                                FrameGraphics
    13421404                                                .DisplayMessage("Insufficient permission to change that item's color");
    13431405                                return;
    13441406                        }
    1345                         color = ip.getColor();
    1346                 }
    1347 
    1348                 color = ColorUtils.getNextColor(color, Item.COLOR_WHEEL);
    1349 
    1350                 // if we didnt find the color on the wheel
    1351                 if (color == null) {
    1352                         FrameGraphics.DisplayMessage("Color is set to default");
    1353                 }
    1354 
    1355                 if (Frame.itemAttachedToCursor()) {
     1407                        color = ip.getPaintColor();
     1408                }
     1409                if (setTransparent)
     1410                        color = null;
     1411                else
     1412                        color = ColorUtils.getNextColor(color, Item.COLOR_WHEEL,
     1413                                        currentFrame.getPaintBackgroundColor());
     1414                // if (currentFrame.getPaintForegroundColor().equals(color))
     1415                // color = null;
     1416
     1417                // if color is being set to default display a message to indicate that
     1418                // if (color == null) {
     1419                // FrameGraphics.DisplayMessage("Color is set to default");
     1420                // }
     1421
     1422                if (ip == null && Frame.itemAttachedToCursor()) {
    13561423                        for (Item i : Frame.FreeItems)
    13571424                                i.setColor(color);
     
    13771444
    13781445                // check permissions
    1379                 if (toToggle.Permission < Item.PERMISSION_FULL) {
     1446                if (!toToggle.hasPermission(Permission.full)) {
    13801447                        FrameGraphics
    13811448                                        .DisplayMessage("Insufficient permission to toggle that item's annotation");
     
    14011468
    14021469                // check permissions
    1403                 if (toToggle.Permission < Item.PERMISSION_FULL) {
     1470                if (!toToggle.hasPermission(Permission.full)) {
    14041471                        FrameGraphics
    14051472                                        .DisplayMessage("Insufficient permission to toggle that item's annotation");
     
    14291496
    14301497                // check permissions
    1431                 if (toToggle.Permission < Item.PERMISSION_FULL) {
     1498                if (!toToggle.hasPermission(Permission.full)) {
    14321499                        FrameGraphics
    14331500                                        .DisplayMessage("Insufficient permission to toggle that item's annotation");
     
    14661533                        if (toAdd instanceof Text) {
    14671534                                // permission check
    1468                                 if (toAdd.Permission < Item.PERMISSION_FULL) {
     1535                                if (!toAdd.hasPermission(Permission.full)) {
    14691536                                        FrameGraphics
    14701537                                                        .DisplayMessage("Insufficicent permission to add the date to that item");
     
    15611628
    15621629                // check permissions
    1563                 if (item.Permission < Item.PERMISSION_FULL) {
     1630                if (!item.hasPermission(Permission.full)) {
    15641631                        FrameGraphics
    15651632                                        .DisplayMessage("Insufficient permission to create a frameset from this item");
     
    15851652
    15861653        /**
    1587          * Toggles Audience mode on\off
    1588          *
    1589          * @param ignored
    1590          *            This Item is currently ignored
    1591          */
    1592         private static void ToggleAudience(Item ignored) {
    1593                 FrameGraphics.ToggleAudienceMode();
    1594         }
    1595 
    1596         private static void ToggleXRayMode(Item ignored) {
    1597                 FrameGraphics.ToggleXRayMode();
    1598         }
    1599 
    1600         /**
    1601          * Runs the first Item on the first menu
    1602          *
    1603          * @param ignored
    1604          *            This Item is currently ignored
    1605          */
    1606         /*
    1607          * private static void RunFirstMenuItem(Item ignored) {
    1608          * DisplayIO.activateMenuItem(0, 0); }
    1609          */
    1610 
    1611         /**
    16121654         * Forces a re-parse and repaint of the current Frame.
    1613          *
    1614          * @param ignored
    1615          *            This Item is currently ignored
    1616          */
    1617         private static void Refresh(Item ignored) {
     1655         */
     1656        public static void Refresh() {
    16181657                Frame currentFrame = DisplayIO.getCurrentFrame();
    16191658                if (FrameIO.isProfileFrame(currentFrame)) {
     
    16321671                // etc and the text cursor is showing
    16331672                FrameMouseActions.updateCursor();
     1673                FrameMouseActions.getInstance().refreshHighlights();
    16341674                FrameGraphics.ForceRepaint();
    16351675        }
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r106 r108  
    2424import org.expeditee.actions.Actions;
    2525import org.expeditee.actions.NavigationActions;
     26import org.expeditee.items.Circle;
    2627import org.expeditee.items.Constraint;
    2728import org.expeditee.items.Dot;
     
    3132import org.expeditee.items.ItemUtils;
    3233import org.expeditee.items.Line;
     34import org.expeditee.items.Permission;
    3335import org.expeditee.items.Picture;
    3436import org.expeditee.items.Text;
    3537import org.expeditee.items.WidgetCorner;
    3638import org.expeditee.items.WidgetEdge;
     39import org.expeditee.items.XRayable;
     40import org.expeditee.items.Item.SelectedMode;
    3741import org.expeditee.stats.SessionStats;
    3842
     
    151155        private static Item _lastClickedOn = null;
    152156
    153         private static List<Item> _lastClickedIn = null;
     157        private static Collection<Item> _lastClickedIn = null;
    154158
    155159        private static boolean _pulseOn = false;
     
    315319                        _lastHighlightedItem = Frame.getItemAttachedToCursor();
    316320                        for (Item i : Frame.FreeItems) {
    317                                 i.restoreLastMode(Item.DEPRESSED_HIGHLIGHT);
     321                                i.setSelectionColor(Item.DEPRESSED_HIGHLIGHT);
    318322                        }
    319323                        FrameGraphics.Repaint();
     
    411415                // get whatever the user was pointing at
    412416                Item clickedOn = _lastClickedOn;
    413                 List<Item> clickedIn = _lastClickedIn;
     417                Collection<Item> clickedIn = _lastClickedIn;
    414418
    415419                MouseX = e.getX();
     
    417421
    418422                Item releasedOn = FrameUtils.getCurrentItem();
    419                 List<Item> releasedIn = FrameUtils.getCurrentItems(releasedOn);
     423                Collection<Item> releasedIn = FrameUtils.getCurrentItems(releasedOn);
    420424
    421425                // TODO Simplify the login below
     
    504508                                // Check if the user is trying to range an item for which they
    505509                                // do not have permission to do so... or it is the frame name
    506                                 if (lastRanged.Permission < Item.PERMISSION_FULL
     510                                if (!lastRanged.hasPermission(Permission.full)
    507511                                                || lastRanged.isFrameName()) {
    508512                                        FrameGraphics
    509                                                         .DisplayMessage("Insufficient permission to cut range");
     513                                                        .DisplayMessage("Insufficient permission to cut text");
    510514                                        lastRanged.clearSelection();
    511515                                        FrameGraphics.Repaint();
     
    525529                                // Check if the user is trying to range an item for which they
    526530                                // do not have permission to do so... or it is the frame name
    527                                 if (lastRanged.Permission < Item.PERMISSION_COPY) {
     531                                if (!lastRanged.hasPermission(Permission.copy)) {
    528532                                        FrameGraphics
    529                                                         .DisplayMessage("Insufficient permission to copy range");
     533                                                        .DisplayMessage("Insufficient permission to copy text");
    530534                                        lastRanged.clearSelection();
    531535                                        FrameGraphics.Repaint();
     
    558562                                // MIKE put the code below up here
    559563                                _lastCropped.clearCropping();
     564                                FrameGraphics.ChangeSelectionMode(_lastCropped,
     565                                                SelectedMode.None);
    560566                                _lastCropped = null;
    561567                                FrameGraphics.Repaint();
     
    577583                if (e.getButton() == MouseEvent.BUTTON1) {
    578584                        SessionStats.AddFrameEvent("Lu");
    579                         leftButton(clickedOn);
     585                        leftButton(clickedOn, clickedIn);
    580586                        return;
    581587                }
     
    601607         * This method handles all left-click actions
    602608         */
    603         public static void leftButton(Item clicked) {
     609        public static void leftButton(Item clicked, Collection<Item> clickedIn) {
    604610                // if the user is pointing at something then either follow the link or
    605611                // do TDFC
     
    627633                                && !(clicked instanceof Dot)) {
    628634                        // check item permissions
    629                         if (clicked.Permission < Item.PERMISSION_FOLLOW_LINKS) {
     635                        if (!clicked.hasPermission(Permission.followLinks)) {
    630636                                FrameGraphics
    631637                                                .DisplayMessage("Insufficient permissions to perform action on item");
     
    655661                        } else {
    656662                                // check for TDFC permission
    657                                 if (clicked.Permission < Item.PERMISSION_TDFC) {
     663                                if (!clicked.hasPermission(Permission.createFrames)) {
    658664                                        FrameGraphics
    659665                                                        .DisplayMessage("Insufficient permission to TDFC from that item");
     
    722728         * This method handles all middle-click actions
    723729         */
    724         private static void middleButton(Item clicked, List<Item> clickedIn) {
     730        private static void middleButton(Item clicked, Collection<Item> clickedIn) {
    725731                // if the cursor has Items attached
    726732                if (Frame.itemAttachedToCursor()) {
     
    729735                        if (doMerging(clicked)) {
    730736                                // check permissions
    731                                 if (clicked.Permission < Item.PERMISSION_FULL
     737                                if (!clicked.hasPermission(Permission.full)
    732738                                                && clicked.getParent() != null
    733739                                                && clicked.getParent().getNameItem() != clicked) {
     
    757763                } else if (clicked != null) {
    758764                        // check permissions
    759                         if (clicked.Permission < Item.PERMISSION_FULL) {
     765                        if (!clicked.hasPermission(Permission.full)) {
    760766                                FrameGraphics
    761767                                                .DisplayMessage("Insufficient permission to pick up item");
     
    841847                        ArrayList<Item> toPickup = new ArrayList<Item>(clickedIn.size());
    842848                        for (Item ip : clickedIn)
    843                                 if (ip.Permission >= Item.PERMISSION_FULL)
     849                                if (ip.hasPermission(Permission.full))
    844850                                        toPickup.add(ip);
    845851                        pickup(toPickup);
     
    850856                        // If we have permission to copy this item then pick it up
    851857                        if (on != null && on.isLineEnd()
    852                                         && on.Permission >= Item.PERMISSION_FULL) {
     858                                        && on.hasPermission(Permission.full)) {
    853859                                on.removeAllConstraints();
    854860                                pickup(on);
     
    858864                        // if its on a line then split the line and put a point on it and
    859865                        // pick that point up
    860                         if (on instanceof Line && on.Permission >= Item.PERMISSION_FULL) {
     866                        if (on instanceof Line && on.hasPermission(Permission.full)) {
    861867                                Frame current = DisplayIO.getCurrentFrame();
    862868                                // create the two endpoints
     
    932938         * This method handles all right-click action
    933939         */
    934         private static void rightButton(Item clicked, List<Item> clickedIn) {
     940        private static void rightButton(Item clicked, Collection<Item> clickedIn) {
    935941                // if the cursor has Items attached, then anchor a copy of them
     942
    936943                List<Item> copies = null;
    937944                if (Frame.itemAttachedToCursor()) {
     
    943950                                                        || clicked instanceof Dot || clicked.isLineEnd())) {
    944951                                // check permissions
    945                                 if (clicked.Permission < Item.PERMISSION_FULL
     952                                if (!clicked.hasPermission(Permission.full)
    946953                                                && clicked.getParent().getNameItem() != clicked) {
    947954                                        FrameGraphics
     
    949956                                        return;
    950957                                }
    951                                 if (clicked instanceof Text || clicked instanceof Dot) {
     958                                if (clicked instanceof Text || clicked instanceof Dot
     959                                                || clicked instanceof XRayable) {
    952960                                        if (isRubberBandingCorner()) {
    953961                                                // Move the cursor so that the copy is exactly the
     
    978986
    979987                                                for (Item ip : items) {
    980                                                         if (ip.Permission >= Item.PERMISSION_COPY)
     988                                                        if (ip.hasPermission(Permission.copy))
    981989                                                                toCopy.add(ip);
    982990                                                }
     
    990998                                                pickup(copies);
    991999                                                // line onto something
    992                                         } else if (Frame.FreeItems.size() == 2) {
     1000                                        } else if (Frame.FreeItems.size() == 2
     1001                                                        && clicked instanceof XRayable) {
    9931002                                                copies = ItemUtils.UnreelLine(Frame.FreeItems,
    994                                                                 _shiftDown);
     1003                                                                _controlDown);
    9951004                                                Collection<Item> leftOver = merge(Frame.FreeItems,
    9961005                                                                clicked);
     
    10161025                                        }
    10171026                                } else {
    1018                                         copies = ItemUtils.UnreelLine(Frame.FreeItems, _shiftDown);
     1027                                        copies = ItemUtils
     1028                                                        .UnreelLine(Frame.FreeItems, _controlDown);
    10191029                                        if (copies == null)
    10201030                                                copies = copy(Frame.FreeItems);
     
    10361046                                        updateCursor();
    10371047                                        // pick up a copy of all enclosed items
    1038                                         List<Item> enclosedItems = FrameUtils.getItemsEnclosedBy(
    1039                                                         DisplayIO.getCurrentFrame(), d.getEnclosedShape());
     1048                                        Collection<Item> enclosedItems = FrameUtils
     1049                                                        .getItemsEnclosedBy(DisplayIO.getCurrentFrame(), d
     1050                                                                        .getEnclosedShape());
    10401051                                        if (enclosedItems != null) {
    10411052                                                enclosedItems.removeAll(d.getAllConnected());
    1042                                                 List<Item> toCopy = getFullyEnclosedItems(enclosedItems);
     1053                                                Collection<Item> toCopy = getFullyEnclosedItems(enclosedItems);
    10431054
    10441055                                                if (toCopy.size() > 0) {
     
    10481059                                                        Item closest = null;
    10491060                                                        double shortestDistance = Double.MAX_VALUE;
    1050                                                         for (int i = 0; i < toCopy.size(); i++) {
    1051                                                                 Item next = toCopy.get(i);
     1061                                                        for (Item next : toCopy) {
    10521062                                                                if (next instanceof Line)
    10531063                                                                        continue;
     
    10741084                                        }
    10751085                                } else {
    1076                                         if (Frame.FreeItems.size() == 2) {
     1086                                        if (rubberBanding()) {
    10771087                                                if (clicked != null) {
    10781088                                                        Collection<Item> leftOver = merge(Frame.FreeItems,
     
    10831093                                                // endpoint and unreeling. ie. Normal unreeling
    10841094                                                copies = ItemUtils.UnreelLine(Frame.FreeItems,
    1085                                                                 _shiftDown);
     1095                                                                _controlDown);
    10861096
    10871097                                                if (copies == null)
     
    11191129                        if (clicked != null) {
    11201130                                // check permissions
    1121                                 if (clicked.Permission < Item.PERMISSION_COPY) {
     1131                                if (!clicked.hasPermission(Permission.copy)) {
    11221132                                        FrameGraphics
    11231133                                                        .DisplayMessage("Insufficient permission to copy item");
     
    11251135                                }
    11261136
    1127                                 copies = ItemUtils.UnreelLine(clicked, _shiftDown);
     1137                                copies = ItemUtils.UnreelLine(clicked, _controlDown);
    11281138                                // Copies will NOT be null if the user right clicked on a point
    11291139                                if (copies == null) {
     
    11431153                                        }
    11441154
     1155                                        FrameGraphics.ChangeSelectionMode(clicked,
     1156                                                        SelectedMode.None);
     1157
    11451158                                        if (!_extrude)
    11461159                                                clearParent(copies);
     
    11521165                                if (clickedIn != null) {
    11531166                                        // Set the selection mode for the items that were clicked in
    1154                                         List<Item> enclosed = getFullyEnclosedItems(clickedIn);
     1167                                        Collection<Item> enclosed = getFullyEnclosedItems(clickedIn);
    11551168                                        if (enclosed.size() == 0) {
    11561169                                                FrameGraphics
     
    11581171                                        } else {
    11591172                                                copies = copy(enclosed);
    1160                                                 // TODO figure out how to get copies to be SELECTED when
    1161                                                 // they are anchored
    1162                                                 // for (Item i : copies) {
    1163                                                 // if (i.isEnclosed()) {
    1164                                                 // i.setSelectedMode(Item.SelectedMode.Enclosed);
    1165                                                 // i.setSelectedMode(Item.SelectedMode.None);
    1166                                                 // }
    1167                                                 // }
    11681173                                                clearParent(copies);
    11691174                                                pickup(copies);
     1175                                                for (Item i : clickedIn) {
     1176                                                        i.setSelectedMode(SelectedMode.None);
     1177                                                }
    11701178                                        }
    11711179                                        // otherwise, create a rectangle
     
    11741182                                                        MouseX, MouseY);
    11751183                                        // if its on a line then create a line from that line
    1176                                         if (on instanceof Line
    1177                                                         && on.Permission >= Item.PERMISSION_FULL) {
     1184                                        if (on instanceof Line && on.hasPermission(Permission.full)) {
    11781185
    11791186                                                Line onLine = (Line) on;
     
    12311238                                        anchor(new ArrayList<Item>(copies));
    12321239                                        pickup(d[3]);
     1240                                        d[3].setSelectedMode(SelectedMode.Normal);
     1241                                        d[3].setSelectedMode(SelectedMode.None);
     1242
    12331243                                        SessionStats.CreatedItems(copies);
    12341244                                        copies.clear();
     
    12361246                        }
    12371247                }
     1248                getInstance().refreshHighlights();
    12381249                SessionStats.CopiedItems(copies);
    12391250                updateCursor();
     
    12521263                // and dragging
    12531264                move(Frame.FreeItems);
     1265                for (Item i : copies) {
     1266                        i.setSelectedMode(SelectedMode.None);
     1267                }
    12541268                anchor(copies);
    12551269        }
     
    12591273         * @return
    12601274         */
    1261         private static List<Item> getFullyEnclosedItems(List<Item> enclosure) {
     1275        private static Collection<Item> getFullyEnclosedItems(
     1276                        Collection<Item> enclosure) {
    12621277                // copy the enclosedItems because the list will be modified
    1263                 List<Item> enclosedItems = new ArrayList<Item>(enclosure);
    1264                 List<Item> toCopy = new ArrayList<Item>(enclosedItems.size());
     1278                Collection<Item> enclosedItems = new LinkedHashSet<Item>(enclosure);
     1279                Collection<Item> toCopy = new LinkedHashSet<Item>(enclosedItems.size());
     1280
    12651281                while (enclosedItems.size() > 0) {
    1266                         Item i = enclosedItems.get(0);
    1267                         if (i.Permission >= Item.PERMISSION_COPY) {
     1282                        Item i = enclosedItems.iterator().next();
     1283                        if (i.hasPermission(Permission.copy)) {
    12681284                                Collection<Item> items = i.getAllConnected();
    12691285                                // Only copy if the entire shape is enclosed
     
    12921308         */
    12931309        private static void clearParent(List<Item> items) {
    1294                 for (Item i : items)
     1310                for (Item i : items) {
     1311                        // The next line is only necessary for circles...
     1312                        // Need to clean up/refactory some of this stuff
     1313                        i.getParentOrCurrentFrame().removeItem(i);
    12951314                        i.setParent(null);
     1315                }
    12961316        }
    12971317
     
    14091429        });
    14101430
    1411         private static boolean _shiftDown;
     1431        private static boolean _controlDown;
    14121432
    14131433        public static void setLastRobotMove(float x, float y) {
     
    14531473                MouseY = e.getY();
    14541474
     1475                //Moving the mouse a certain distance removes the last edited text if it is empty
     1476                Text lastEdited = FrameUtils.LastEdited;
     1477                if(lastEdited != null && lastEdited.getPosition().distance(e.getPoint()) > 20){
     1478                        FrameUtils.setLastEdited(null);
     1479                }
     1480
    14551481                // If shift is down then the movement is constrained
    1456                 if (_shiftDown && Frame.FreeItems.size() > 0) {
     1482                if (_controlDown && Frame.FreeItems.size() > 0) {
    14571483                        // Check if we are rubber banding a line
    14581484                        if (shiftStateChanged && rubberBanding()) {
     
    15211547                                        Integer c2 = line2.getPossibleConstraint();
    15221548
    1523                                         if (c1 != null) {
     1549                                        if (c1 != null && c2 != null) {
    15241550                                                // This is the case of a constrained rectangle
    15251551                                                if ((c2 == Constraint.VERTICAL || c2 == Constraint.HORIZONTAL)
     
    15481574                                                        }
    15491575                                                }
    1550                                         } else if (c2 != null) {
    1551 
    1552                                         } // Other wise it is a not constrained shape so constrain
    1553                                         // the two lines lengths to be equal
    1554                                         else {
     1576                                                // } else if (c2 != null) {
     1577                                                //
     1578                                                // } // Other wise it is a not constrained shape so
     1579                                                // constrain
     1580                                                // the two lines lengths to be equal
     1581                                        } else {
    15551582                                                Item lineEnd1 = line1.getOppositeEnd(thisEnd);
    15561583                                                Item lineEnd2 = line2.getOppositeEnd(thisEnd);
     
    15881615                                }
    15891616                        }
    1590                 } else if (shiftStateChanged && !_shiftDown && rubberBanding()) {
     1617                } else if (shiftStateChanged && !_controlDown && rubberBanding()) {
    15911618                        // Get the line end that is being rubber banded
    15921619                        Item thisEnd = Frame.FreeItems.get(0).isLineEnd() ? Frame.FreeItems
     
    15981625                        _lastMouseMoved = e;
    15991626
    1600                 /*
    1601                  * int distance = (int) Math.sqrt(Math.pow(Math
    1602                  * .abs(_lastMouseEvent.getX() - e.getX()), 2) +
    1603                  * Math.pow(Math.abs(_lastMouseEvent.getY() - e.getY()), 2));
    1604                  */
    1605 
    1606                 // Just do the sum of the distance moved in x and y direction for
    1607                 // speed!!
    1608                 /*
    1609                  * int distance = Math.abs(_lastMouseEvent.getX() - e.getX()) +
    1610                  * Math.abs(_lastMouseEvent.getY() - e.getY());
    1611                  */
    1612 
    1613                 boolean checkHighlight = true;
    1614 
    1615                 // Mike: This code checks if the mouse is moving above a
    1616                 // threshold speed. If so it doesnt execute the code that checks if
    1617                 // items underneath the cursor need to be highlighted.
    1618                 /*
    1619                  * if (Frame.itemAttachedToCursor()) { long time = e.getWhen() -
    1620                  * _lastMouseEvent.getWhen(); // System.out.println(time + " D:" +
    1621                  * distance); if (time > 0 && distance * 3 > time) { checkHighlight =
    1622                  * false; // System.out.println("Dont check highlight!"); if
    1623                  * (_lastHighlightedItem != null && !_lastHoldsHighlight) {
    1624                  * if(_lastHighlightedItem instanceof Text) {
    1625                  * FrameGraphics.ChangeSelectionMode(_lastHighlightedItem,
    1626                  * Item.SelectedMode.None); } } } }
    1627                  */
    1628 
    16291627                _lastMouseMoved = e;
    16301628
    1631                 if (checkHighlight) {
    1632                         // ByMike: Get the item the mouse is hovering over
    1633                         Item click = FrameUtils.getCurrentItem();
    1634                         Item on = null;
    1635                         // System.out.println(click);
    1636                         if (click != null) {
    1637                                 on = click;
    1638                                 // set the context
    1639                                 if (on instanceof Line)
    1640                                         _context = CONTEXT_AT_LINE;
    1641                                 else if (on instanceof Dot)
    1642                                         _context = CONTEXT_AT_DOT;
    1643                                 else if (on instanceof Text) {
    1644                                         // Checks that we are actually pointing on a character
    1645                                         // not just space in the text box's bounding box
    1646                                         if (((Item) on).contains(DisplayIO.getMouseX(),
    1647                                                         FrameMouseActions.getY())) {
    1648                                                 _context = CONTEXT_AT_TEXT;
    1649                                         } else {
    1650                                                 // if we are pointing in space in the text box... it is
    1651                                                 // the same as pointing in freespace
    1652                                                 on = null;
    1653                                                 _context = CONTEXT_FREESPACE;
    1654                                         }
    1655                                 }
    1656 
    1657                                 _alpha = 60;
    1658                         } else {
    1659                                 _context = CONTEXT_FREESPACE;
    1660                                 _alpha = -1;
    1661                         }
    1662 
    1663                         // if the user is pointing at an item, highlight it
    1664                         if (on != null && !Frame.FreeItems.contains(on)) {
    1665                                 // if the user can spot-weld, show the virtual spot
    1666                                 if (Frame.FreeItems.size() == 2 && on instanceof Line) {
    1667                                         Line line = (Line) on;
    1668                                         Item freeItem0 = Frame.FreeItems.get(0);
    1669                                         Item freeItem1 = Frame.FreeItems.get(1);
    1670                                         Item lineEnd = freeItem0.isLineEnd() ? freeItem0
    1671                                                         : (freeItem1.isLineEnd() ? freeItem1 : null);
    1672                                         if (lineEnd != null) {
    1673                                                 line.showVirtualSpot(lineEnd, DisplayIO.getMouseX(),
    1674                                                                 FrameMouseActions.getY());
    1675                                         } else
    1676                                                 // The user is pointing at another point or text item
    1677                                                 // etc
    1678                                                 FrameGraphics.ChangeSelectionMode(on,
    1679                                                                 Item.SelectedMode.Normal);
    1680                                 } else {
    1681                                         // FrameGraphics.ChangeSelectionMode(on,
    1682                                         // Item.SelectedMode.Connected);
    1683                                         // TODO: The method below is for the most part redundant
    1684                                         on = FrameGraphics.Highlight(on);
    1685                                 }
    1686                                 // if the last item highlighted is still highlighted, clear it
    1687                                 if (_lastHoldsHighlight) {
    1688                                         _lastHoldsHighlight = false;
    1689                                         for (Item i : DisplayIO.getCurrentFrame().getItems())
    1690                                                 if (i.isHighlighted() && i != on)
    1691                                                         FrameGraphics.ChangeSelectionMode(i,
    1692                                                                         Item.SelectedMode.None);
    1693                                 }
    1694 
    1695                                 // if the user is not pointing at an item, check for enclosure
    1696                                 // highlighting
    1697                         } else if (on == null) {
    1698                                 Collection<Item> enclosure = FrameUtils.getEnclosingDots();
    1699                                 if (enclosure != null && enclosure.size() > 1) {
    1700                                         Item firstLineEnd = enclosure.iterator().next();
    1701                                         if (firstLineEnd.getLines().size() > 1 &&
    1702                                         // check that the enclosure is not part of a point being
    1703                                                         // dragged in space
    1704                                                         !ContainsOneOf(enclosure, Frame.FreeItems)) {
    1705                                                 on = firstLineEnd.getLines().get(0);
    1706                                                 // System.out.println(on == null ? "Null" :
    1707                                                 // on.toString());
    1708                                                 FrameGraphics.ChangeSelectionMode(on,
    1709                                                                 Item.SelectedMode.Enclosed);
    1710                                         }
    1711                                 } else if (_lastHighlightedItem != null) {
    1712                                         // System.out.println("LastHighlightedItem");
    1713                                         _lastHoldsHighlight = false;
    1714                                 }
    1715                         }
    1716 
    1717                         // disable cursor changes when the cursor has items attached
    1718                         if (Frame.itemAttachedToCursor()
    1719                                         && DisplayIO.getCursor() != Item.TEXT_CURSOR)
    1720                                 _forceArrowCursor = false;
    1721 
    1722                         if (_lastHighlightedItem != null && _lastHighlightedItem != on
    1723                                         && !_lastHoldsHighlight) {
    1724                                 // Only want to turn off the highlighting only if
    1725                                 // the last highlighted item is not connected to the currentItem
    1726                                 // Otherwise we get flickering in transition from connected to
    1727                                 // normal mode while moving the cursor along a line.
    1728                                 if (on == null
    1729                                                 || !_lastHighlightedItem.getAllConnected().contains(on))
    1730                                         FrameGraphics.ChangeSelectionMode(_lastHighlightedItem,
    1731                                                         Item.SelectedMode.None);
    1732                         }
    1733 
    1734                         _lastHighlightedItem = on;
    1735 
    1736                 }
     1629                refreshHighlights();
    17371630
    17381631                if (Frame.itemAttachedToCursor()) {
     
    17441637                        updateCursor();
    17451638
    1746                 // if (_lastItem == null)
    1747                 // DisplayIO.UpdateTitle();
    1748 
    17491639                _forceArrowCursor = true;
     1640        }
     1641
     1642        public void refreshHighlights() {
     1643                // ByMike: Get the item the mouse is hovering over
     1644                Item click = FrameUtils.getCurrentItem();
     1645                Item on = null;
     1646                // System.out.println(click);
     1647                if (click != null) {
     1648                        on = click;
     1649                        // set the context
     1650                        if (on instanceof Line)
     1651                                _context = CONTEXT_AT_LINE;
     1652                        else if (on instanceof Dot)
     1653                                _context = CONTEXT_AT_DOT;
     1654                        else if (on instanceof Text) {
     1655                                // Checks that we are actually pointing on a character
     1656                                // not just space in the text box's bounding box
     1657                                if (((Item) on).contains(DisplayIO.getMouseX(),
     1658                                                FrameMouseActions.getY())) {
     1659                                        _context = CONTEXT_AT_TEXT;
     1660                                } else {
     1661                                        // if we are pointing in space in the text box... it is
     1662                                        // the same as pointing in freespace
     1663                                        on = null;
     1664                                        _context = CONTEXT_FREESPACE;
     1665                                }
     1666                        }
     1667                        if (Frame.FreeItems.size() > 0)
     1668                                _alpha = 60;
     1669                        else
     1670                                _alpha = -1;
     1671                } else {
     1672                        _context = CONTEXT_FREESPACE;
     1673                        _alpha = -1;
     1674                }
     1675
     1676                // if the user is pointing at an item, highlight it
     1677                if (on != null && !Frame.FreeItems.contains(on)) {
     1678                        // if the user can spot-weld, show the virtual spot
     1679                        if (Frame.FreeItems.size() == 2 && on instanceof Line) {
     1680                                Line line = (Line) on;
     1681                                Item freeItem0 = Frame.FreeItems.get(0);
     1682                                Item freeItem1 = Frame.FreeItems.get(1);
     1683                                Item lineEnd = freeItem0.isLineEnd() ? freeItem0 : (freeItem1
     1684                                                .isLineEnd() ? freeItem1 : null);
     1685                                if (lineEnd != null) {
     1686                                        line.showVirtualSpot(lineEnd, DisplayIO.getMouseX(),
     1687                                                        FrameMouseActions.getY());
     1688                                } else
     1689                                        // The user is pointing at another point or text item
     1690                                        // etc
     1691                                        FrameGraphics.ChangeSelectionMode(on,
     1692                                                        Item.SelectedMode.Normal);
     1693                        } else {
     1694                                // FrameGraphics.ChangeSelectionMode(on,
     1695                                // Item.SelectedMode.Connected);
     1696                                // TODO: The method below is for the most part redundant
     1697                                on = FrameGraphics.Highlight(on);
     1698                        }
     1699                        // if the last item highlighted is still highlighted, clear it
     1700                        if (_lastHoldsHighlight) {
     1701                                _lastHoldsHighlight = false;
     1702                                for (Item i : DisplayIO.getCurrentFrame().getItems())
     1703                                        if (i.isHighlighted() && i != on)
     1704                                                FrameGraphics.ChangeSelectionMode(i,
     1705                                                                Item.SelectedMode.None);
     1706                        }
     1707
     1708                        // if the user is not pointing at an item, check for enclosure
     1709                        // highlighting
     1710                } else if (on == null) {
     1711                        Collection<Item> enclosure = FrameUtils.getEnclosingLineEnds();
     1712                        if (enclosure != null && enclosure.size() > 0) {
     1713                                Item firstLineEnd = enclosure.iterator().next();
     1714                                if (firstLineEnd.getLines().size() > 1 &&
     1715                                // check that the enclosure is not part of a point being
     1716                                                // dragged in space
     1717                                                !ContainsOneOf(enclosure, Frame.FreeItems)) {
     1718                                        on = firstLineEnd.getLines().get(0);
     1719                                        // System.out.println(on == null ? "Null" :
     1720                                        // on.toString());
     1721                                        FrameGraphics.ChangeSelectionMode(on,
     1722                                                        Item.SelectedMode.Enclosed);
     1723                                } else if (firstLineEnd instanceof XRayable) {
     1724                                        on = firstLineEnd;
     1725                                        FrameGraphics.ChangeSelectionMode(firstLineEnd,
     1726                                                        Item.SelectedMode.Enclosed);
     1727                                }
     1728                        } else if (_lastHighlightedItem != null) {
     1729                                // System.out.println("LastHighlightedItem");
     1730                                _lastHoldsHighlight = false;
     1731                        }
     1732                }
     1733
     1734                // disable cursor changes when the cursor has items attached
     1735                if (Frame.itemAttachedToCursor()
     1736                                && DisplayIO.getCursor() != Item.TEXT_CURSOR)
     1737                        _forceArrowCursor = false;
     1738
     1739                // setLastHighlightedItem(on);
     1740
     1741                if (_lastHighlightedItem != null && _lastHighlightedItem != on
     1742                                && !_lastHoldsHighlight) {
     1743                        // Turn off the highlighting only if
     1744                        // the last highlighted item is not connected to the currentItem
     1745                        // Otherwise we get flickering in transition from connected to
     1746                        // normal mode while moving the cursor along a line.
     1747                        if (on == null
     1748                                        || (!on.getAllConnected().contains(_lastHighlightedItem))) {
     1749                                FrameGraphics.ChangeSelectionMode(_lastHighlightedItem,
     1750                                                Item.SelectedMode.None);
     1751                        }
     1752                }
     1753
     1754                _lastHighlightedItem = on;
     1755
    17501756        }
    17511757
     
    17791785                                }
    17801786                                foundLineEnd = true;
    1781                         } else if (!(i instanceof Line)) {
     1787                        } else if (!(i instanceof Line) || !i.isVisible()) {
    17821788                                return false;
    17831789                        }
     
    17911797         */
    17921798        public static void updateCursor() {
    1793                 if (rubberBanding()/* && !_shiftDown */) {
     1799                if (rubberBanding()) {
    17941800                        DisplayIO.setCursor(Item.HIDDEN_CURSOR);
    17951801                        return;
     
    18281834
    18291835                for (Item move : toMove) {
    1830                         if (!(move instanceof Line))
    1831                                 move.setPosition(move.getX() - deltax, move.getY() - deltay);
     1836                        move.setPosition(move.getX() - deltax, move.getY() - deltay);
    18321837
    18331838                        if (move instanceof Text) {
     
    19211926                Item item = toExtract;
    19221927                // Extract the frames attributes when the user clicks on the frame name
     1928                FrameGraphics.ChangeSelectionMode(item, SelectedMode.None);
    19231929                if (item.isFrameName())
    19241930                        attribs = AttributeUtils.extractAttributes(item.getParent());
    1925                 else
     1931                else {
    19261932                        attribs = AttributeUtils.extractAttributes(item);
     1933                }
    19271934
    19281935                if (attribs == null)
     
    19441951                if (toDelete != null
    19451952                                && toDelete == DisplayIO.getCurrentFrame().getNameItem()) {
    1946                         DisplayIO.getCurrentFrame().clear();
     1953                        DisplayIO.getCurrentFrame().clear(false);
    19471954                        FrameGraphics.Repaint();
    19481955                        return;
     
    19571964
    19581965                                // check permissions
    1959                                 if (toDelete.Permission < Item.PERMISSION_FULL) {
     1966                                if (!toDelete.hasPermission(Permission.full)) {
    19601967                                        FrameGraphics
    19611968                                                        .DisplayMessage("Insufficient permission to swap Item text");
     
    19891996                        // if the user is pointing inside a closed shape, delete all
    19901997                        // items inside it
    1991                         List<Item> items = FrameUtils.getCurrentItems(null);
     1998                        Collection<Item> items = FrameUtils.getCurrentItems(null);
    19921999
    19932000                        if (items != null) {
     
    19952002                                                .size());
    19962003                                for (Item ip : items) {
    1997                                         if (ip.Permission >= Item.PERMISSION_FULL) {
     2004                                        if (ip.hasPermission(Permission.full)) {
    19982005                                                // Only include lines if one of their enpoints are also
    19992006                                                // being removed
    20002007                                                if (ip instanceof Line) {
    20012008                                                        Line l = (Line) ip;
    2002                                                         if (!items.contains(l.getEndItem())
    2003                                                                         && !items.contains(l.getStartItem()))
     2009                                                        Item end = l.getEndItem();
     2010                                                        Item start = l.getStartItem();
     2011
     2012                                                        // If one end of a line is being delted, remove the
     2013                                                        // other end if all its connecting lines are being
     2014                                                        // delted
     2015                                                        if (items.contains(end)) {
     2016                                                                if (!items.contains(start)
     2017                                                                                && items.containsAll(start.getLines())) {
     2018                                                                        toRemove.add(start);
     2019                                                                }
     2020                                                        } else if (items.contains(start)) {
     2021                                                                if (items.containsAll(end.getLines())) {
     2022                                                                        toRemove.add(end);
     2023                                                                }
     2024                                                        } else {
    20042025                                                                continue;
     2026                                                        }
    20052027                                                }
    20062028                                                toRemove.add(ip);
     
    20222044                } else {
    20232045                        // check permissions
    2024                         if (toDelete.Permission < Item.PERMISSION_FULL) {
     2046                        if (!toDelete.hasPermission(Permission.full)) {
    20252047                                FrameGraphics
    20262048                                                .DisplayMessage("Insufficient permission to delete item");
     
    20852107                // disconnect any connected items
    20862108                for (Item i : itemList) {
     2109                        // Make sure text items attached to cursor are reset back to the
     2110                        // transparency they should have.
     2111                        if (i instanceof Text) {
     2112                                ((Text) i).setAlpha(-1);
     2113                        }
     2114
    20872115                        if (i.getLines().size() > 0) {
    20882116                                Collection<Item> toDelete = deleteLineEnd(i);
     
    21942222                }
    21952223
     2224                // if(mergee instanceof XRayable)
     2225                // return merger;
     2226
    21962227                // check for rectangle merging
    21972228                if (merger.size() == 3 && mergee.getLines().size() == 2) {
     
    22462277
    22472278                for (Item i : merger) {
     2279                        if (!i.isVisible())
     2280                                continue;
    22482281                        // check for link merging
    22492282                        if (i instanceof Text
     
    23052338                mergee.getParent().setChanged(true);
    23062339                ItemUtils.EnclosedCheck(mergee.getParent().getItems());
     2340                //Mike: Why does parse frame have to be called?!?
    23072341                FrameUtils.Parse(mergee.getParent());
    23082342
     
    23222356                        return;
    23232357
    2324                 if (toGrab.Permission < Item.PERMISSION_FULL) {
     2358                if (!toGrab.hasPermission(Permission.full)) {
    23252359                        FrameGraphics
    23262360                                        .DisplayMessage("Insufficient permission pickup the item");
    23272361                        return;
    23282362                }
     2363
     2364                if (toGrab instanceof Circle)
     2365                        toGrab.setSelectedMode(SelectedMode.Connected);
     2366                else
     2367                        toGrab.setSelectedMode(SelectedMode.Normal);
     2368
    23292369                // Brook: If the widget corner is being picked up. Instead refer to
    23302370                // picking up the edge for fixed-sized widgets so it is not so confusing
     
    23492389                while (iter.hasNext()) {
    23502390                        Item i = iter.next();
    2351                         if (i.Permission < Item.PERMISSION_FULL) {
     2391                        if (!i.hasPermission(Permission.full)) {
    23522392                                iter.remove();
    23532393                                continue;
    23542394                        }
    2355 
     2395                        if (i.equals(_lastHighlightedItem))
     2396                                _lastHighlightedItem = null;
     2397                        // i.setSelectedMode(SelectedMode.None);
    23562398                        // Check if it has a relative link if so make it absolute
    23572399                        i.setAbsoluteLink();
     
    23652407                        i.setFloating(true);
    23662408                }
    2367 
     2409                _lastHighlightedItem = null;
    23682410                updateCursor();
    23692411
     
    23722414                if (toGrab.size() > 1) {
    23732415                        for (Item i : toGrab) {
    2374                                 // MIKE: Why cant we use a line for the offset calculations?!?
    2375                                 if (!(i instanceof Line)) {
     2416                                // MIKE: Movement goes haywire if these are removed because Line
     2417                                // class returns 0 for getX
     2418                                if (!(i instanceof Line) && !(i instanceof XRayable)) {
    23762419                                        _offX = DisplayIO.getMouseX() - i.getX() + i.getOffset().x;
    23772420                                        _offY = getY() - i.getY() + i.getOffset().y;
     
    24192462                // attach the line to the cursor
    24202463                pickup(end);
     2464                _lastHighlightedItem = null;
     2465
     2466                // TODO figure out how to get the end to highlight
     2467                // end.setSelectedMode(SelectedMode.Normal);
     2468                // end.setSelectedMode(SelectedMode.None);
    24212469
    24222470                return line;
     
    24742522                int clicks = arg0.getClickCount();
    24752523
    2476                 // if a line is being rubber-banded, check for auto straightening
    24772524                if (Frame.FreeItems.size() == 2) {
    2478                         if ((Frame.FreeItems.get(0) instanceof Dot && Frame.FreeItems
    2479                                         .get(1) instanceof Line)
    2480                                         || (Frame.FreeItems.get(1) instanceof Dot && Frame.FreeItems
     2525                        if ((Frame.FreeItems.get(0).isLineEnd() && Frame.FreeItems.get(1) instanceof Line)
     2526                                        || (Frame.FreeItems.get(1).isLineEnd() && Frame.FreeItems
    24812527                                                        .get(0) instanceof Line)) {
    24822528
     
    25072553                        if (ip != null && clicks > 1) {
    25082554                                float size = ip.getSize();
    2509                                 if (ip instanceof Dot || ip instanceof Line)
     2555                                if (ip instanceof Dot || ip instanceof Line
     2556                                                || ip instanceof Circle) {
    25102557                                        size = ip.getThickness();
     2558                                }
    25112559                                // base the number of clicks on the size of the object
    25122560                                clicks = (int) Math.ceil(size / 20.0 * clicks);
    25132561                        }
    2514                         FrameKeyboardActions.functionKey(rotationType, clicks);
     2562                        FrameKeyboardActions.functionKey(rotationType, clicks, arg0
     2563                                        .isShiftDown());
    25152564
    25162565                } else if (clicks == MOUSE_WHEEL_THRESHOLD) {
     
    25242573                        }
    25252574
    2526                         if (item instanceof Line) {
     2575                        if (item instanceof Line || item instanceof Circle) {
    25272576                                // check permissions
    2528                                 if (item.Permission < Item.PERMISSION_FULL) {
     2577                                if (!item.hasPermission(Permission.full)) {
    25292578                                        FrameGraphics
    25302579                                                        .DisplayMessage("Insufficient permission to edit the Line");
    25312580                                        return;
    25322581                                }
    2533                                 Line line = (Line) item;
    2534                                 line.toggleDashed(arg0.getWheelRotation());
    2535                                 line.getParent().change();
     2582                                item.toggleDashed(arg0.getWheelRotation());
     2583                                item.getParent().change();
    25362584                                FrameGraphics.Repaint();
    25372585                                return;
     
    25792627        }
    25802628
    2581         public static void shift(KeyEvent ke) {
    2582                 _shiftDown = ke.isControlDown();
    2583 
    2584                 if (_shiftDown) {
     2629        public static void control(KeyEvent ke) {
     2630                _controlDown = ke.isControlDown();
     2631
     2632                if (_controlDown) {
    25852633                        _offX = 0;
    25862634                        _offY = 0;
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r107 r108  
    88import java.util.Collections;
    99import java.util.Comparator;
     10import java.util.LinkedHashSet;
    1011import java.util.LinkedList;
    1112import java.util.List;
    1213
    1314import org.expeditee.io.Logger;
     15import org.expeditee.items.Circle;
    1416import org.expeditee.items.Dot;
     17import org.expeditee.items.FrameBitmap;
     18import org.expeditee.items.FrameImage;
    1519import org.expeditee.items.InteractiveWidget;
    1620import org.expeditee.items.InteractiveWidgetInitialisationFailedException;
     
    1923import org.expeditee.items.ItemUtils;
    2024import org.expeditee.items.Line;
     25import org.expeditee.items.Permission;
    2126import org.expeditee.items.Picture;
    2227import org.expeditee.items.Text;
    2328import org.expeditee.items.WidgetCorner;
    2429import org.expeditee.items.WidgetEdge;
     30import org.expeditee.items.XRayable;
    2531import org.expeditee.stats.SessionStats;
    2632
     
    3945        private static float _LastResponse = 0;
    4046
    41         public static Item LastEdited = null;
     47        public static Text LastEdited = null;
    4248
    4349        public static int MINIMUM_INTERITEM_SPACING = -6;
     
    281287                                } else
    282288                                        return false;
    283                         } else if (opposite.getOverlays().contains(new Overlay(toSave, 1))) {
     289                        } else if (opposite.getOverlays().contains(
     290                                        new Overlay(toSave, Permission.followLinks))) {
    284291                                if (opposite.getOverlays().get(
    285                                                 opposite.getOverlays().indexOf(new Overlay(toSave, 1))).Frame
     292                                                opposite.getOverlays().indexOf(
     293                                                                new Overlay(toSave, Permission.followLinks))).Frame
    286294                                                .hasChanged())
    287295                                        if (DisplayIO.DisplayConfirmDialog(
     
    384392                DisplayIO.setCurrentFrame(toDisplay);
    385393                FrameMouseActions.updateCursor();
     394                // FrameMouseActions.getInstance().refreshHighlights();
    386395                // update response timer
    387396                _LastResponse = ResponseTimer.getElapsedSeconds();
     
    464473                        return false;
    465474                }
    466 
    467                 // replace the Text source with the new Picture
    468                 frame.removeItem(txt);
    469                 frame.addItem(pic);
    470 
    471                 return true;
    472         }
    473 
    474         private static boolean createFramePicture(Frame frame, Text txt) {
    475                 if (txt.getLink() == null)
    476                         return false;
    477 
    478                 // attempt to create the picture
    479                 Picture pic = ItemUtils.CreateFrameImage(txt, frame);
    480 
    481                 // if the picture could not be created successfully
    482                 if (pic == null) {
    483                         FrameGraphics.ErrorMessage("Error loading frame image");
    484                         return false;
    485                 }
    486 
    487                 // replace the Text source with the new Picture
    488                 frame.removeItem(txt);
    489                 frame.addItem(pic);
    490 
    491                 return true;
    492         }
    493 
    494         private static boolean createFrameBitmap(Frame frame, Text txt) {
    495                 if (txt.getLink() == null)
    496                         return false;
    497 
    498                 // attempt to create the picture
    499                 Picture pic = ItemUtils.CreateFrameBitmap(txt, frame);
    500 
    501                 // if the picture could not be created successfully
    502                 if (pic == null) {
    503                         FrameGraphics.ErrorMessage("Error loading frame image");
    504                         return false;
    505                 }
    506 
    507                 // replace the Text source with the new Picture
    508                 frame.removeItem(txt);
    509475                frame.addItem(pic);
    510476
     
    573539                UserSettings.TitleTemplate = profile.getTitleItem();
    574540
    575                 List<Text> items = profile.getBodyTextItems(true);
     541                List<Text> items = profile.getBodyTextItems(true, true);
    576542
    577543                // check for all tags setting user values
     
    670636                        }
    671637                }
    672 
     638        }
     639       
     640        public static void loadFirstFrame(Frame profile) {
    673641                if (UserSettings.FirstFrame == null)
    674642                        UserSettings.FirstFrame = profile.getName();
    675643                else {
    676                         if (FrameIO.LoadFrame(UserSettings.FirstFrame) == null) {
     644                        Frame firstFrame = FrameIO.LoadFrame(UserSettings.FirstFrame);
     645                        if ( firstFrame == null) {
    677646                                FrameGraphics.WarningMessage("Home frame not found: "
    678647                                                + UserSettings.FirstFrame);
    679648                                UserSettings.FirstFrame = profile.getName();
    680                         }
    681                 }
    682 
     649                                DisplayIO.setCurrentFrame(profile);
     650                        }else{
     651                                DisplayIO.setCurrentFrame(firstFrame);
     652                        }
     653                }
    683654        }
    684655
     
    821792         */
    822793        public static void Parse(Frame toParse, boolean firstParse) {
     794                // TODO check why we are getting toParse == null... when profile frame
     795                // is being created and change the lines below
     796                if (toParse == null)
     797                        return;
    823798                // System.out.println(firstParse);
    824799                if (firstParse)
     
    833808
    834809                        for (Item i : items) {
    835                                 if (i instanceof Picture) {
     810                                if (i instanceof XRayable) {
    836811                                        toParse.removeItem(i);
    837                                         toParse.addItem(((Picture) i).getText());
     812                                        // Show the items
     813                                        for (Item item : ((XRayable) i).getConnected()) {
     814                                                item.setHidden(false);
     815                                                item.removeEnclosure(i);
     816                                        }
    838817                                } else if (i instanceof WidgetCorner) {
    839818                                        toParse.removeItem(i);
     
    861840                boolean filledPoints = true;
    862841
    863                 int permissionLevel = getPermissionLevel(toParse.getProtection(),
    864                                 Item.PERMISSION_FULL);
     842                Permission permission = toParse.getPermission();
    865843                toParse.clearAnnotations();
    866844
     
    868846                for (Item i : toParse.getItems()) {
    869847                        try {
    870                                 i.Permission = permissionLevel;
     848                                i.setPermission(permission);
    871849                                if (i instanceof Text && i.isAnnotation()) {
    872850                                        if (ItemUtils.startsWithTag(i, ItemUtils.TAG_POINTTYPE)) {
     
    898876                                                // frame contains an @ao which leads to a frame with an
    899877                                                // @v which points back to the frame with the @ao
    900 
    901878                                                Frame vector = FrameIO.LoadFrame(i.getAbsoluteLink());
    902879                                                if (vector != null) {
     
    908885                                                        } catch (Exception e) {
    909886                                                        }
    910                                                         vectors.add(new Vector(vector, i.getPosition(),
    911                                                                         scale, i.getColor(), i.getBackgroundColor()));
     887                                                        vectors
     888                                                                        .add(new Vector(vector, i.getPosition(),
     889                                                                                        scale, i.getColor(), i
     890                                                                                                        .getBackgroundColor()));
    912891                                                }
    913892                                        }
     
    928907                                                // Parse(overlay);
    929908                                                if (overlay != null && !overlays.contains(overlay))
    930                                                         overlays.add(new Overlay(overlay,
    931                                                                         Item.PERMISSION_NONE));
     909                                                        overlays.add(new Overlay(overlay, Permission.none));
    932910                                        }
    933911                                        // check for ACTIVE_OVERLAY items
     
    949927                                                                .getFirstLine());
    950928                                                // default permission (if none is specified)
    951                                                 int permission = getPermissionLevel(level,
    952                                                                 Item.PERMISSION_FOLLOW_LINKS);
     929                                                Permission permissionLevel = Permission.getPermission(
     930                                                                level, Permission.followLinks);
    953931
    954932                                                if (overlay != null) {
     
    959937                                                        for (Overlay o : overlays) {
    960938                                                                if (o.Frame.equals(overlay)) {
    961                                                                         o.Level = permission;
     939                                                                        o.Frame.setPermission(permissionLevel);
    962940                                                                        found = true;
    963941                                                                        break;
     
    966944                                                        // If it wasnt in the list create it and add it.
    967945                                                        if (!found) {
    968                                                                 overlays.add(new Overlay(overlay, permission));
     946                                                                overlays.add(new Overlay(overlay,
     947                                                                                permissionLevel));
    969948                                                        }
    970949                                                }
     
    974953                                                if (!FrameGraphics.isXRayMode()) {
    975954                                                        if (ItemUtils.startsWithTag(i, ItemUtils.TAG_IMAGE,
    976                                                                         true))
     955                                                                        true)) {
    977956                                                                createPicture(toParse, (Text) i);
    978                                                         // check for frame images
    979                                                         else if (i.getLink() != null
     957                                                                // check for frame images
     958                                                        } else if (ItemUtils.startsWithTag(i,
     959                                                                        ItemUtils.TAG_FRAME_IMAGE)
     960                                                                        && i.getLink() != null
    980961                                                                        && !i.getAbsoluteLink().equalsIgnoreCase(
    981962                                                                                        toParse.getName())) {
    982                                                                 if (ItemUtils.startsWithTag(i,
    983                                                                                 ItemUtils.TAG_FRAME_IMAGE)) {
    984                                                                         createFramePicture(toParse, (Text) i);
    985                                                                 } else if (ItemUtils.startsWithTag(i,
    986                                                                                 ItemUtils.TAG_BITMAP_IMAGE)) {
    987                                                                         createFrameBitmap(toParse, (Text) i);
     963                                                                XRayable image = null;
     964                                                                if (i.getEnclosures().size() > 0) {
     965                                                                        i.setHidden(true);
     966                                                                        image = i.getEnclosures().iterator().next();
     967                                                                        image.refresh();
     968                                                                } else {
     969                                                                        image = new FrameImage((Text) i, toParse, null);
    988970                                                                }
    989                                                         }
    990                                                         // Check for interactive widgets
    991                                                         else if (ItemUtils.startsWithTag(i,
     971                                                                //TODO Add the image when creating new FrameImage
     972                                                                toParse.addItem(image);
     973                                                        } else if (ItemUtils.startsWithTag(i,
     974                                                                        ItemUtils.TAG_BITMAP_IMAGE)
     975                                                                        && i.getLink() != null
     976                                                                        && !i.getAbsoluteLink().equalsIgnoreCase(
     977                                                                                        toParse.getName())) {
     978                                                                XRayable image = null;
     979                                                                if (i.getEnclosures().size() > 0) {
     980                                                                        image = i.getEnclosures().iterator().next();
     981                                                                        image.refresh();
     982                                                                        i.setHidden(true);
     983                                                                } else {
     984                                                                        // If a new bitmap is created for a
     985                                                                        // frame which already has a bitmap dont
     986                                                                        // recreate the bitmap
     987                                                                        image = new FrameBitmap((Text) i, toParse, null);
     988                                                                }
     989                                                                toParse.addItem(image);
     990                                                        } else if (ItemUtils.startsWithTag(i, "@c")) {
     991                                                                // Can only have a @c
     992                                                                if (i.getLines().size() == 1) {
     993                                                                        toParse.addItem(new Circle((Text) i));
     994                                                                }
     995                                                                // Check for interactive widgets
     996                                                        } else if (ItemUtils.startsWithTag(i,
    992997                                                                        ItemUtils.TAG_IWIDGET)) {
    993998                                                                createWidget(toParse, (Text) i);
     
    10011006                                // only remove items on first parse
    10021007                                if (firstParse) {
     1008                                        // TODO refactor so thta this code is not needed
     1009                                        // Remove when the file is being saved
    10031010                                        // remove dots of size 1
    10041011                                        if (i instanceof Dot) {
     
    10571064
    10581065        /**
    1059          * Converts a string containing the permission level into its integer
    1060          * equivalent.
    1061          *
    1062          * @param level
    1063          * @param defaultPermission
    1064          * @return
    1065          */
    1066         public static int getPermissionLevel(String level, int defaultPermission) {
    1067                 level = level.trim().toLowerCase();
    1068                 if (level.length() == 0)
    1069                         return defaultPermission;
    1070 
    1071                 try {
    1072                         return Integer.parseInt(level);
    1073                 } catch (Exception e) {
    1074                         // if this is a text permission level, parse it
    1075 
    1076                         if (level.equals("none"))
    1077                                 return Item.PERMISSION_NONE;
    1078                         else if (level.equals("links") || level.equals("link"))
    1079                                 return Item.PERMISSION_FOLLOW_LINKS;
    1080                         else if (level.equals("copy"))
    1081                                 return Item.PERMISSION_COPY;
    1082                         else if (level.equals("tdfc"))
    1083                                 return Item.PERMISSION_TDFC;
    1084                         else if (level.equals("full") || level.equals("all"))
    1085                                 return Item.PERMISSION_FULL;
    1086                 }
    1087                 return defaultPermission;
    1088         }
    1089 
    1090         /**
    10911066         * Searches through the list of items on this frame to find one at the given
    10921067         * x,y coordinates.
     
    10991074         */
    11001075        public static Item onItem(Frame toCheck, float floatX, float floatY) {
    1101                 //System.out.println("MouseX: " + floatX + " MouseY: " + floatY);
    1102                
     1076                // System.out.println("MouseX: " + floatX + " MouseY: " + floatY);
     1077
    11031078                int x = Math.round(floatX);
    11041079                int y = Math.round(floatY);
     
    11141089                                if (message != null) {
    11151090                                        if (message.contains(x, y)) {
    1116                                                 message.Permission = Item.PERMISSION_COPY;
     1091                                                message.setPermission(Permission.copy);
    11171092                                                possibles.add(message);
    1118                                         } else
     1093                                        } else{
    11191094                                                // Not sure why but if the line below is removed then
    11201095                                                // several items can be highlighted at once
    11211096                                                message.setSelectedMode(Item.SelectedMode.None);
     1097                                        }
    11221098                                }
    11231099                        }
     
    11261102                        if (FrameGraphics.MessageLink != null) {
    11271103                                if (FrameGraphics.MessageLink.contains(x, y)) {
    1128                                         FrameGraphics.MessageLink.Permission = Item.PERMISSION_COPY;
     1104                                        FrameGraphics.MessageLink.setPermission(Permission.copy);
    11291105                                        possibles.add(FrameGraphics.MessageLink);
    11301106                                }
     
    11351111                        // otherwise, the mouse is on the frame
    11361112                } else {
    1137 
    1138                         if (LastEdited != null && LastEdited.contains(x, y)
     1113                        if (LastEdited != null && /*LastEdited.isVisible()
     1114                                        &&*/ LastEdited.contains(x, y)
    11391115                                        && !Frame.FreeItems.contains(LastEdited)
    11401116                                        && LastEdited.getParent() == DisplayIO.getCurrentFrame()
    11411117                                        && LastEdited.getParent().getItems().contains(LastEdited)) {
    1142                                 LastEdited.Permission = Item.PERMISSION_FULL;
     1118                                LastEdited.setPermission(Permission.full);
    11431119                                return LastEdited;
    11441120                        } else
     
    11461122
    11471123                        ArrayList<Item> checkList = new ArrayList<Item>();
    1148                         checkList.addAll(toCheck.getItems());
     1124                        checkList.addAll(toCheck.getVisibleItems());
    11491125                        checkList.add(toCheck.getNameItem());
    11501126                        for (Item i : checkList) {
     
    11561132                                }
    11571133                        }
    1158                         int framePermission = getPermissionLevel(toCheck.getProtection(),
    1159                                         Item.PERMISSION_FULL);
     1134                        Permission framePermission = toCheck.getPermission();
    11601135                        for (Overlay o : toCheck.getOverlays()) {
    1161                                 if (o.Level > Item.PERMISSION_NONE) {
     1136                                if (o.Level.ordinal() > Permission.none.ordinal()) {
    11621137                                        Item i = onItem(o.Frame, x, y);
    11631138
     
    11651140                                        // it should be ignored here
    11661141                                        if (i != null && i.getID() > 0) {
    1167                                                 i.Permission = Math.min(o.Level, framePermission);
     1142                                                i.setPermission(Permission
     1143                                                                .min(o.Level, framePermission));
    11681144                                                possibles.add(i);
    11691145                                        }
     
    12141190        }
    12151191
    1216         public static List<Item> getCurrentItems(Item currentItem) {
    1217 
    1218                 Collection<Item> enclosure = getEnclosingDots();
     1192        public static Collection<Item> getCurrentItems(Item currentItem) {
     1193
     1194                Collection<Item> enclosure = getEnclosingLineEnds();
    12191195                if (enclosure == null || enclosure.size() == 0)
    12201196                        return null;
     
    12221198                Item firstItem = enclosure.iterator().next();
    12231199
    1224                 List<Item> enclosed = getItemsEnclosedBy(DisplayIO.getCurrentFrame(),
    1225                                 firstItem.getEnclosedShape());
     1200                Collection<Item> enclosed = getItemsEnclosedBy(DisplayIO
     1201                                .getCurrentFrame(), firstItem.getEnclosedShape());
    12261202
    12271203                // Brook: enclosed widgets are to be fully enclosed, never partially
     
    12491225        }
    12501226
    1251         public static Collection<Item> getEnclosingDots() {
     1227        public static Collection<Item> getEnclosingLineEnds() {
    12521228                // update enclosed shapes
    12531229                Frame current = DisplayIO.getCurrentFrame();
     
    12681244                        Item i = items.get(0);
    12691245                        items.remove(i);
    1270                         if (i.isLineEnd() && i.isEnclosed()) {
     1246                        if (i.isEnclosed()) {
    12711247                                Polygon p = i.getEnclosedShape();
    12721248                                if (p.contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) {
     
    13361312        }
    13371313
    1338         public static List<Item> getItemsEnclosedBy(Frame frame, Polygon poly) {
    1339                 List<Item> contained = frame.getItemsWithin(poly);
    1340 
    1341                 ArrayList<Item> results = new ArrayList<Item>(contained.size());
     1314        //TODO Remove this method!!
     1315        //We should be able to get by with just getItemsWithin
     1316        public static Collection<Item> getItemsEnclosedBy(Frame frame, Polygon poly) {
     1317                Collection<Item> contained = frame.getItemsWithin(poly);
     1318
     1319                Collection<Item> results = new LinkedHashSet<Item>(contained.size());
    13421320
    13431321                // check for correct permissions
     
    13451323                        // if the item is on the frame
    13461324                        if (item.getParent() == frame || item.getParent() == null) {
    1347                                 // item.Permission = Item.PERMISSION_FULL;
     1325                                // item.Permission = Permission.full;
    13481326                                results.add(item);
    13491327                                // otherwise, it must be on an overlay frame
     
    13511329                                for (Overlay overlay : frame.getOverlays())
    13521330                                        if (overlay.Frame == item.getParent()) {
    1353                                                 item.Permission = overlay.Level;
     1331                                                item.setPermission(overlay.Level);
    13541332                                                results.add(item);
    13551333                                                break;
     
    13971375
    13981376                Text t = profile.addText(xPos, yPos, "@ItemTemplate", null);
    1399                 t.setColor(Color.black);
     1377                t.setColor(null);
    14001378
    14011379                yPos += spacing;
     
    14831461
    14841462        private static Item _tdfcItem = null;
     1463
     1464        public static void setLastEdited(Text lastEdited) {
     1465                if(LastEdited != null && LastEdited.getText().length() == 0){
     1466                        LastEdited.getParentOrCurrentFrame().removeItem(LastEdited);
     1467                }
     1468                LastEdited = lastEdited;
     1469        }
    14851470}
  • trunk/src/org/expeditee/gui/Overlay.java

    r4 r108  
    11package org.expeditee.gui;
     2
     3import org.expeditee.items.Permission;
    24
    35public class Overlay {
    46        public Frame Frame;
    57
    6         public int Level;
     8        public Permission Level;
    79
    8         public Overlay(Frame overlay, int level) {
     10        public Overlay(Frame overlay, Permission level) {
    911                Frame = overlay;
    1012                Level = level;
  • trunk/src/org/expeditee/gui/UserSettings.java

    r80 r108  
    4949        public static boolean Threading = true;
    5050
    51         public static Text ItemTemplate = new Text(-1, "@ItemTemplate");
     51        public static Text ItemTemplate = new Text("@ItemTemplate");
    5252       
    53         public static Text LineTemplate = new Text(-1, "@LineTemplate");
     53        public static Text LineTemplate = new Text("@LineTemplate");
    5454
    5555        public static Text AnnotationTemplate = null;
  • trunk/src/org/expeditee/io/Conversion.java

    r97 r108  
    1010import java.util.StringTokenizer;
    1111
     12import org.expeditee.actions.Actions;
    1213import org.expeditee.items.Item;
    1314import org.expeditee.items.Justification;
     15import org.expeditee.items.Permission;
    1416import org.expeditee.items.Text;
    1517
     
    7375
    7476                float color[] = { 0, 0, 0 };
    75                 //Assert.assertTrue(color.length == 3);
     77                // Assert.assertTrue(color.length == 3);
    7678
    7779                if (colorCode.startsWith("red"))
     
    8991        private static Color getRGBColor(String colorCode, Color current) {
    9092                int color[] = new int[3];
    91                 //Assert.assertTrue(color.length == 3);
     93                // Assert.assertTrue(color.length == 3);
    9294
    9395                try {
     
    171173         */
    172174        public static String getExpediteeFontCode(Font font) {
    173                 String code = "t";
    174                 String fontName = font.getFamily().toLowerCase();
     175                String fontName = font.getFamily();
     176                String code = font.getFamily() + '_';
    175177
    176178                for (int i = 0; i < Text.FONT_WHEEL.length; i++) {
    177                         if (Text.FONT_WHEEL[i].equals(fontName)) {
     179                        if (Text.FONT_WHEEL[i].equalsIgnoreCase(fontName)) {
    178180                                code = "" + Text.FONT_CHARS[i];
    179181                                break;
     
    212214                assert (fontCode != null);
    213215
     216                int separator = fontCode.indexOf('_');
    214217                String code = Text.FONT_WHEEL[0];
    215 
    216                 char c = fontCode.charAt(0);
    217                 for (int i = 0; i < Text.FONT_CHARS.length; i++) {
    218                         if (c == Text.FONT_CHARS[i]) {
    219                                 code = Text.FONT_WHEEL[i] + '-';
    220                                 break;
     218                if (separator > 0) {
     219                        code = Actions.getCapitalizedFontName(fontCode.substring(0,separator)) + '-';
     220                        fontCode = fontCode.substring(separator);
     221                } else {
     222                        char c = fontCode.charAt(0);
     223                        for (int i = 0; i < Text.FONT_CHARS.length; i++) {
     224                                if (c == Text.FONT_CHARS[i]) {
     225                                        code = Text.FONT_WHEEL[i] + '-';
     226                                        break;
     227                                }
    221228                        }
    222229                }
     
    293300        }
    294301
    295         public static String getFramesetName(String framename, boolean convertToLower) {
     302        public static String getFramesetName(String framename,
     303                        boolean convertToLower) {
    296304                String set = null;
    297305                assert (Character.isDigit(framename.charAt(framename.length() - 1)));
     
    337345                        try {
    338346                                // Find the field and value of colorName
    339                                 Field[] fields = Class.forName("java.awt.Color").getFields();
     347                                Field[] fields = java.awt.Color.class.getFields();
    340348                                Field field = null;
    341349                                for (int i = 0; i < fields.length; i++) {
     
    458466                String name = method.getName();
    459467                Class[] types = method.getParameterTypes();
    460                
     468
    461469                String fullValue = value;
    462470                value = value.trim();
     
    466474                        just[0] = Justification.getJustification(value);
    467475                        return just;
     476                }else if (name.endsWith("Permission")) {
     477                        Permission[] permission = new Permission[1];
     478                        permission[0] = Permission.getPermission(value);
     479                        return permission;
    468480                }
    469481
     
    472484                                return null;
    473485
    474                         Integer length = null;
     486                        Float length = null;
    475487                        Double ratio = null;
    476488
     
    480492                        } else {
    481493                                assert (current instanceof String);
    482                                 int oldLength = getArrowLength(current.toString());
     494                                float oldLength = getArrowLength(current.toString());
    483495                                double oldRatio = getArrowRatio(current.toString());
    484                                 length = (Integer) Convert(int.class, value.substring(0, value
     496                                length = (Float) Convert(float.class, value.substring(0, value
    485497                                                .indexOf(" ")), oldLength);
    486498                                ratio = (Double) Convert(double.class, value.substring(
     
    512524        }
    513525
    514         private static int getArrowLength(String s) {
    515                 return Integer.parseInt(s.substring(0, s.indexOf(" ")));
     526        private static float getArrowLength(String s) {
     527                return Float.parseFloat(s.substring(0, s.indexOf(" ")));
    516528        }
    517529
     
    532544
    533545                if (name.endsWith("Justification"))
    534                         return ((Justification)output).getCode();
     546                        return ((Justification) output).getCode();
     547               
     548                if (name.endsWith("Permission"))
     549                        return ((Permission) output).getCode();
    535550
    536551                // strings can be returned immediately
  • trunk/src/org/expeditee/io/DefaultFrameWriter.java

    r86 r108  
    4444                try {
    4545                        _FrameTags.put("V", Frame.class.getMethod("getVersion", param));
    46                         _FrameTags.put("p", Frame.class.getMethod("getProtection", param));
     46                        _FrameTags.put("p", Frame.class.getMethod("getPermission", param));
    4747                        _FrameTags.put("U", Frame.class.getMethod("getOwner", param));
    4848                        _FrameTags.put("D", Frame.class.getMethod("getDateCreated", param));
  • trunk/src/org/expeditee/io/ExpWriter.java

    r105 r108  
    1212import org.expeditee.gui.Frame;
    1313import org.expeditee.items.Constraint;
    14 import org.expeditee.items.InteractiveWidget;
    1514import org.expeditee.items.Item;
    1615import org.expeditee.items.Line;
    17 import org.expeditee.items.Picture;
    18 import org.expeditee.items.WidgetCorner;
    1916import org.expeditee.items.WidgetEdge;
    2017import org.expeditee.stats.SessionStats;
     
    7673                writeHeader(frame);
    7774
    78                 // write out each Item in the Frame.
    79                 List<Item> items = frame.getItems();
    80 
    81                 // iWidgets are handled specially since 8 items are written as one
    82                 List<InteractiveWidget> seenWidgets = new LinkedList<InteractiveWidget>();
    83 
    84                 // do not write items with ID -1, also skip any lines
    85                 for (Item i : items) {
    86 
    87                         // Ensure only one of the WidgetCorners represent a single widget
    88                         if (i instanceof WidgetCorner) {
    89                                 InteractiveWidget iw = ((WidgetCorner) i).getWidgetSource();
    90                                 if (seenWidgets.contains(iw))
    91                                         continue;
    92                                 seenWidgets.add(iw);
    93                         }
    94 
    95                         if (i.getID() >= 0 && !(i instanceof Line)) {
    96                                 writeItem(i);
    97                         }
     75
     76                // write each item in the frame
     77                for (Item i : frame.getItemsToSave()) {
     78                        assert(!(i instanceof Line));
     79                        writeItem(i);
    9880                }
    9981
     
    119101                                o = Conversion.ConvertToExpeditee(_FrameTags.get(tag), o);
    120102                                if (o != null) {
    121                                         writeLine(tag, (String) o);
     103                                        writeLine(tag, o.toString());
    122104                                }
    123105                        } catch (Exception e) {
     
    155137                        return;
    156138
    157                 // Dont save the item if it is off the screen
    158                 if (item.offScreenTopOrLeft()) {
    159                         //System.out.println("item offscreen!");
    160                         return;
    161                 }
    162 
    163                 // Pictures are saved as the corresponding text items that created them
    164                 if (item instanceof Picture)
    165                         item = ((Picture) item).getText();
    166                 else if (item instanceof WidgetCorner)
    167                         item = ((WidgetCorner) item).getWidgetSource().getSource();
    168 
    169139                if (item.isLineEnd())
    170                         writePoint(item);
     140                        writeLineEnd(item);
    171141                else if (!(item instanceof Line))
    172142                        writeClass(item);
     
    179149        }
    180150
    181         private List<Item> _points = new LinkedList<Item>();
    182 
    183         // Writes out a Dot to the file
    184         protected void writePoint(Item point) throws IOException {
    185                 _points.add(point);
     151        private List<Item> _lineEnds = new LinkedList<Item>();
     152
     153        // Writes out a LineEnd to the file
     154        protected void writeLineEnd(Item point) throws IOException {
     155                _lineEnds.add(point);
    186156                writeClass(point);
    187157        }
     
    192162
    193163                // loop through all points stored
    194                 for (int i = 0; i < _points.size(); i++) {
    195                         List<Line> lines = _points.get(i).getLines();
     164                for (int i = 0; i < _lineEnds.size(); i++) {
     165                        List<Line> lines = _lineEnds.get(i).getLines();
    196166
    197167                        // if this point is part of one or more lines
     
    225195
    226196                // loop through all the points
    227                 while (_points.size() > 0) {
    228                         Item i = _points.get(0);
     197                while (_lineEnds.size() > 0) {
     198                        Item i = _lineEnds.get(0);
    229199
    230200                        // if there are any constraints to write
     
    235205                                // written
    236206                                for (Constraint c : constraints) {
    237                                         if (_points.contains(c.getStart())
    238                                                         && _points.contains(c.getEnd())) {
     207                                        if (_lineEnds.contains(c.getStart())
     208                                                        && _lineEnds.contains(c.getEnd())) {
    239209                                                writeLine("C", c.getID() + " " + c.getType());
    240210                                                writeLine("s", c.getLineEnds());
     
    245215                        }
    246216                        // remove the point from the list
    247                         _points.remove(0);
     217                        _lineEnds.remove(0);
    248218                }
    249219        }
     
    265235                        String tag = it.next();
    266236                        Method toRun = _ItemTags.get(tag);
    267                         Class declarer = toRun.getDeclaringClass();
     237                        Class<?> declarer = toRun.getDeclaringClass();
    268238                        if (declarer.isAssignableFrom(toWrite.getClass())) {
    269239                                try {
  • trunk/src/org/expeditee/io/FrameReader.java

    r97 r108  
    1414import org.expeditee.items.Justification;
    1515import org.expeditee.items.Line;
     16import org.expeditee.items.Permission;
    1617import org.expeditee.items.Text;
    1718
     
    2829        protected static Class[] pFont = { Font.class };
    2930        protected static Class[] pPoint = { Point.class };
    30         protected static Class[] pArrow = { int.class, double.class };
     31        protected static Class[] pArrow = { float.class, double.class };
    3132        protected static Class[] pList = { List.class };
    3233        protected static Class[] pIntArray = { int[].class };
    3334        protected static Class[] pItem = { Item.class };
    3435        protected static Class[] pJustification = { Justification.class };
     36        protected static Class[] pPermission = { Permission.class };
    3537       
    3638        public FrameReader(){
     
    4547                        _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt));
    4648                        _FrameTags
    47                                         .put('p', Frame.class.getMethod("setProtection", pString));
     49                                        .put('p', Frame.class.getMethod("setPermission", pPermission));
    4850                        _FrameTags.put('U', Frame.class.getMethod("setOwner", pString));
    4951                        _FrameTags.put('D', Frame.class
  • trunk/src/org/expeditee/io/HTMLBWriter.java

    r80 r108  
    4747                                        + filesFolder, fileName);
    4848                } else {//It is a normal Image stored somewhere
    49                         Text source = pic.getText();
     49                        Text source = pic.getSource();
    5050
    5151                        fileName = source.getFirstLine();
  • trunk/src/org/expeditee/io/HTMLWriter.java

    r80 r108  
    108108        @Override
    109109        protected void writePicture(Picture pic) throws IOException {
    110                 Text source = pic.getText();
     110                Text source = pic.getSource();
    111111
    112112                String line = source.getFirstLine();
  • trunk/src/org/expeditee/io/KMSReader.java

    r97 r108  
    4949                        _FrameTags.put("V", Frame.class.getMethod("setVersion", pInt));
    5050                        _FrameTags
    51                                         .put("p", Frame.class.getMethod("setProtection", pString));
     51                                        .put("p", Frame.class.getMethod("setPermission", pPermission));
    5252                        _FrameTags.put("U", Frame.class.getMethod("setOwner", pString));
    5353                        _FrameTags.put("D", Frame.class
  • trunk/src/org/expeditee/io/KMSWriter.java

    r97 r108  
    1616import org.expeditee.items.Item;
    1717import org.expeditee.items.Line;
    18 import org.expeditee.items.Picture;
    1918import org.expeditee.stats.SessionStats;
    2019
     
    8079
    8180                // write out each Item in the Frame.
    82                 List<Item> items = frame.getItems();
     81                List<Item> items = frame.getItemsToSave();
    8382
    8483                // do not write items with ID -1, also skip any lines
    8584                for (Item i : items) {
    86                         if (i.getID() >= 0 && !(i instanceof Line))
    87                                 writeItem(i);
     85                        writeItem(i);
    8886                }
    8987
     
    108106                                o = Conversion.ConvertToExpeditee(_FrameTags.get(tag), o);
    109107                                if (o != null) {
    110                                         writeLine(tag, (String) o);
     108                                        writeLine(tag, o.toString());
    111109                                }
    112110                        } catch (IllegalArgumentException e) {
     
    147145                if (_writer == null)
    148146                        return;
    149                
    150                 if (item.offScreenTopOrLeft()) {
    151                         //System.out.println("item offscreen!");
    152                         return;
    153                 }
    154147
    155148                writeLine("");
    156                 // Pictures are saved as the corresponding text items that created them
    157                 if (item instanceof Picture)
    158                         item = ((Picture) item).getText();
    159 
    160149                if (item.getLines().size() > 0)
    161150                        writePoint(item);
    162                 else if (!(item instanceof Line))
     151                else
    163152                        writeClass(item);
    164                 else
    165                         System.out.println("Unknown Item: " + item.getID());
    166153        }
    167154
     
    253240                        String tag = it.next();
    254241                        Method toRun = _ItemTags.get(tag);
    255                         Class declarer = toRun.getDeclaringClass();
     242                        Class<?> declarer = toRun.getDeclaringClass();
    256243                        if (declarer.isAssignableFrom(toWrite.getClass())) {
    257244                                try {
  • trunk/src/org/expeditee/items/Dot.java

    r97 r108  
    2626
    2727        private static final int _MINIMUM_DOT_SIZE = 6;
    28 
    29         // the polygon surrounding this point, used for 'gravity'
    30         private Polygon _poly = null;
    3128
    3229        private int _pointType = Item.POINTTYPE_SQUARE;
     
    9289        public void paint(Graphics2D g) {
    9390                if (isHighlighted() /* && !Frame.FreeItems.contains(this) */) {
    94                         g.setColor(getHighlightColor());
     91                        Color backgroundColor = g.getBackground();
     92                        Color highlightColor = getHighlightColor();
     93                        if (highlightColor.equals(backgroundColor)){
     94                                highlightColor = ALTERNATE_HIGHLIGHT;
     95                        }
     96                        g.setColor(highlightColor);
     97                        g.setStroke(HIGHLIGHT_STROKE);
     98                        //g.setStroke()
    9599                        // Draw the highlighting rectangle surrounding the dot
    96100                        // this is drawn even if its part of a rectangle
     
    150154         */
    151155        protected void updatePolygon() {
    152                 int thick = (int) Math.ceil(getThickness());
     156                int thick = Math.round(getThickness());
    153157                // Sets a minimum size for the dot
    154158                thick = Math.max(thick, _MINIMUM_DOT_SIZE);
     
    165169
    166170        @Override
    167         public Polygon getPolygon() {
    168                 if (_poly == null)
    169                         updatePolygon();
    170 
    171                 Polygon external = new Polygon(_poly.xpoints, _poly.ypoints,
    172                                 _poly.npoints);
    173 
    174                 return external;
    175         }
    176 
    177         @Override
    178171        public Item copy() {
    179172                Dot copy = new Dot(getX(), getY(), getID());
     
    205198                // if the item being merged with is another Dot
    206199                if (merger instanceof Dot) {
     200                        if(merger.hasEnclosures() || hasEnclosures())
     201                                return merger;
     202                       
    207203                        Item dot = (Item) merger;
    208204                        merger.setPosition(this.getPosition());
  • trunk/src/org/expeditee/items/FrameBitmap.java

    r106 r108  
    22
    33import java.awt.Color;
     4import java.awt.Image;
    45import java.awt.image.BufferedImage;
    56import java.awt.image.ImageObserver;
     
    910import org.expeditee.gui.FrameIO;
    1011
     12//TODO tidy up the mess I caused with refresh during the period where I was going into XRay mode before saving
     13
    1114public class FrameBitmap extends FramePicture {
    12         public FrameBitmap(Text source, String size, ImageObserver observer)
    13                         throws IllegalArgumentException {
    14                 super();
    15                 _source = source;
    16                 _imageObserver = observer;
    17 
    18                 refresh();
    19 
    20                 if (_image == null)
    21                         throw new IllegalArgumentException();
    22 
    23                 parseSize(size);
     15        public FrameBitmap(Text source, ImageObserver observer, Image image){
     16                super(source, observer, image);
    2417        }
    2518
     
    7770        @Override
    7871        protected Picture createPicture() {
    79                 return ItemUtils.CreateFrameBitmap((Text) _source.copy(),
    80                                 _imageObserver);
     72                return new FrameBitmap((Text) _source.copy(),
     73                                _imageObserver, _image);
    8174        }
    8275
  • trunk/src/org/expeditee/items/FrameImage.java

    r80 r108  
    11package org.expeditee.items;
    22
     3import java.awt.Image;
    34import java.awt.image.ImageObserver;
    45
     
    2223         *            screen.
    2324         */
    24         public FrameImage(Text source, String size, ImageObserver observer)
    25                         throws IllegalArgumentException {
    26                 super();
    27                 _source = source;
    28                 _imageObserver = observer;
    29 
    30                 refresh();
    31 
    32                 if (_image == null)
    33                         throw new IllegalArgumentException();
    34 
    35                 parseSize(size);
    36 
     25        public FrameImage(Text source, ImageObserver observer, Image image) {
     26                super(source, observer, image);
    3727        }
    3828
    3929        @Override
    4030        protected Picture createPicture() {
    41                 return ItemUtils
    42                                 .CreateFrameImage((Text) _source.copy(), _imageObserver);
     31                return new FrameImage(_source.copy(), _imageObserver, _image);
    4332        }
    4433
    4534        @Override
    4635        public boolean refresh() {
     36                // Need to parse the first time the frame is being displayed
     37                // parseSize();
    4738                assert (_source.getLink() != null);
    4839                Frame frame = FrameIO.LoadFrame(_source.getAbsoluteLink());
     
    5445                _image = frame.getBuffer();
    5546
     47                // TODO tidy this up, need to call parse size only when the frame has
     48                // been created to begin with
     49                parseSize();
     50                updatePolygon();
    5651                return true;
    5752        }
    58        
     53
    5954        @Override
    6055        protected String getTagText() {
  • trunk/src/org/expeditee/items/FramePicture.java

    r80 r108  
    11package org.expeditee.items;
     2
     3import java.awt.Color;
     4import java.awt.Image;
     5import java.awt.image.ImageObserver;
    26
    37import org.expeditee.gui.Frame;
    48
    59public class FramePicture extends Picture {
    6         protected FramePicture() {
    7                 super();
     10        protected FramePicture(Text source, ImageObserver observer, Image image) {
     11                super(source, observer, image);
    812        }
    913
     14        @Override
     15        public void setColor(Color c) {
     16                super.setColor(c);
     17                refresh();
     18        }
     19       
    1020        @Override
    1121        public void setLink(String frameName) {
     
    1424                else {
    1525                        _source.setLink(frameName);
    16 
     26                        //remove the picture if the link is being removed
    1727                        if (_source.getLink() == null) {
    1828                                Frame parent = getParent();
    1929                                if (parent != null) {
    2030                                        parent.removeItem(this);
    21                                         parent.addItem(_source);
     31                                        _source.setHidden(false);
     32                                        _source.removeEnclosure(this);
    2233                                }
    2334                        } else {
  • trunk/src/org/expeditee/items/InteractiveWidget.java

    r85 r108  
    748748                if ((e.getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY || e
    749749                                .getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY)
    750                                 && e.getOverlayLevel() == Item.PERMISSION_NONE) {
     750                                && e.getOverlayLevel().equals(Permission.none)) {
    751751                        return; // item belongs to a non-active overlay
    752752                }
  • trunk/src/org/expeditee/items/Item.java

    r107 r108  
    99import java.awt.Polygon;
    1010import java.awt.Rectangle;
     11import java.awt.Stroke;
    1112import java.awt.geom.AffineTransform;
    1213import java.awt.geom.Area;
     14import java.awt.geom.Point2D;
     15import java.awt.geom.Rectangle2D;
    1316import java.util.ArrayList;
    1417import java.util.Collection;
    1518import java.util.ConcurrentModificationException;
     19import java.util.HashSet;
    1620import java.util.LinkedHashSet;
    1721import java.util.LinkedList;
     
    3943public abstract class Item implements Comparable<Item>, Runnable {
    4044
     45        public static final Float DEFAULT_THICKNESS = 2f;
     46
     47        public static final Float MINIMUM_THICKNESS = 1f;
     48
    4149        protected final int JOIN = BasicStroke.JOIN_ROUND;
    4250
    4351        protected final int CAP = BasicStroke.CAP_BUTT;
    44        
     52
     53        protected final Stroke HIGHLIGHT_STROKE = new BasicStroke(
     54                        MINIMUM_THICKNESS, CAP, JOIN, 4.0F);
     55
    4556        // contains all dots (including this one) that form an enclosure
    4657        // if this dot is part of an enclosing shape
     
    4960        public static final int LEFT_MARGIN = 13;
    5061
     62        // indicates which end the arrowhead should be drawn at
     63        protected Polygon _poly = null;
     64
    5165        protected boolean _connectedToAnnotation = false;
    52 
    53         public static final int PERMISSION_NONE = 0;
    54 
    55         public static final int PERMISSION_FOLLOW_LINKS = 1;
    56 
    57         public static final int PERMISSION_COPY = 2;
    58 
    59         public static final int PERMISSION_TDFC = 3;
    60 
    61         public static final int PERMISSION_FULL = 4;
    6266
    6367        public static final int NEAR_DISTANCE = 15;
     
    103107         * this Item.
    104108         */
    105         public static Color[] COLOR_WHEEL = { Color.RED, Color.BLUE, Item.GREEN,
    106                         Color.MAGENTA, Color.YELLOW.darker(), Color.BLACK, Color.DARK_GRAY,
    107                         Color.GRAY, Color.WHITE, null };
    108 
     109        public static Color[] COLOR_WHEEL = { Color.BLACK, Color.RED, Color.BLUE,
     110                        Item.GREEN, Color.MAGENTA, Color.YELLOW.darker(), Color.WHITE };
     111
     112        // TODO Have shift toggle through a black and white color wheel?
    109113        public static Color[] FILL_COLOR_WHEEL = { new Color(255, 150, 150),
    110114                        new Color(150, 150, 255), new Color(150, 255, 150),
    111115                        new Color(255, 150, 255), new Color(255, 255, 100), Color.WHITE,
    112                         Color.GRAY, Color.DARK_GRAY, Color.BLACK, null };
     116                         Color.BLACK};
     117                                                                                                                                 /* Color.GRAY,
     118                                                                                                                                 * Color.DARK_GRAY,
     119                                                                                                                                 */
    113120
    114121        public static final int UNCHANGED_CURSOR = -100;
     
    167174
    168175                dest.setParent(source.getParent());
    169                 dest._mode = SelectedMode.None;
    170                 dest._lastMode = source._mode;
    171 
     176                dest._mode = source._mode;// SelectedMode.None;
     177                dest._visible = source._visible;
    172178                Frame parent = source.getParentOrCurrentFrame();
    173179                // TODO MIKE says maybe we could tighten up and only give items ID's if
     
    199205        private Point _offset = new Point(0, 0);
    200206
    201         private float _x;
    202 
    203         private float _y;
     207        protected float _x;
     208
     209        protected float _y;
    204210
    205211        private int _id;
     
    229235        private List<String> _actionLeaveFrame = null;
    230236
    231         public int Permission = PERMISSION_FULL;
     237        public Permission _permission = Permission.full;
     238       
     239        public void setPermission(Permission permission){
     240                _permission = permission;
     241        }
     242       
     243        public boolean hasPermission(Permission permission){
     244                return _permission.ordinal() >= permission.ordinal();
     245        }
    232246
    233247        // A fill color of null represents transparent
     
    256270
    257271        // arrowhead parameters
    258         private int _arrowheadLength = 0;
     272        private float _arrowheadLength = 0;
    259273
    260274        private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO;
     
    283297
    284298        private boolean _visible = true;
    285 
    286         private SelectedMode _lastMode = SelectedMode.None;
    287299
    288300        private float _thickness = -1.0F;
     
    303315                }
    304316
    305                 if (_actions == null)
     317                if (_actions == null){
     318                        _poly = null;
    306319                        _actions = new LinkedList<String>();
     320                }
    307321                _actions.add(action);
    308322        }
     
    312326                        connected.add(this);
    313327
    314                 for (Line line : getLines()) {
    315                         if (!connected.contains(line))
    316                                 line.addAllConnected(connected);
     328                for (Item item : getConnected()) {
     329                        if (!connected.contains(item))
     330                                item.addAllConnected(connected);
    317331                }
    318332        }
     
    383397
    384398        public void delete() {
    385                 setVisible(false);
    386         }
    387 
     399                _deleted = true;
     400        }
     401
     402        @Override
    388403        public boolean equals(Object o) {
    389                 if (o instanceof Item) {
     404                if (o == null)
     405                        return false;
     406                if (getClass().equals(o.getClass())) {
    390407                        Item i = (Item) o;
    391408                        return i.getID() == getID()
    392409                                        && ((i.getParent() == _parent) || (i.getParent() != null && i
    393410                                                        .getParent().equals(_parent)));
    394 
    395411                } else
    396412                        return false;
     
    463479        }
    464480
    465         public int getArrowheadLength() {
     481        public float getArrowheadLength() {
    466482                return _arrowheadLength;
    467483        }
     
    559575                List<Item> conn = new LinkedList<Item>();
    560576                conn.add(this);
    561 
     577                conn.addAll(getEnclosures());
    562578                conn.addAll(getLines());
    563579                return conn;
     
    698714
    699715        public Color getPaintBackgroundColor() {
    700                 if (_colorBackground == null) {
     716                Color colorBackground = getBackgroundColor();
     717                if (colorBackground == null) {
    701718                        if (getParent() != null && getParent().getBackgroundColor() != null)
    702719                                return getParent().getBackgroundColor();
     
    705722                }
    706723
    707                 return _colorBackground;
     724                return colorBackground;
    708725        }
    709726
     
    713730         * @return The Color of this item (foreground)
    714731         */
    715         public Color getPaintColor() {
     732        public final Color getPaintColor() {
    716733                // If color is null then get the paint foregroundColor for the frame the
    717734                // item is on which is a color adjusted to suit the background
    718                 if (_color == null) {
     735                Color color = getColor();
     736
     737                if (color == null) {
    719738                        if (getParent() != null)
    720739                                return getParent().getPaintForegroundColor();
     
    727746                }
    728747
    729                 return _color;
     748                return color;
    730749        }
    731750
     
    739758        }
    740759
    741         public Frame getParent() {
     760        public final Frame getParent() {
    742761                return _parent;
    743762        }
    744763
    745         /**
    746          * Returns the Shape that surrounds this Item representing this Item's
    747          * 'gravity'.
    748          *
    749          * @return The Shape (rectangle) surrounding this Item, which represents
    750          *         this Items 'gravity'.
    751          */
    752         public abstract Polygon getPolygon();
    753 
    754         public Point getPosition() {
     764        public final Point getPosition() {
    755765                return new Point(getX(), getY());
    756766        }
     
    762772         * @return The size of this Item.
    763773         */
    764         public int getSize() {
    765                 return -1;
     774        public float getSize() {
     775                return -1.0F;
    766776        }
    767777
     
    809819        /**
    810820         * Checks if the given Shape intersects with the Shape around this Item.
    811          * Note: Both Shape objects should be rectangles for this to work properly.
    812821         *
    813822         * @param s
     
    819828                        return false;
    820829
    821                 // return p.getBounds().intersects(getArea().getBounds());
    822830                Area a = new Area(p);
    823 
    824831                a.intersect(this.getArea());
     832
    825833                return !a.isEmpty();
    826834        }
     
    859867         */
    860868        public boolean isHighlighted() {
     869                if (isFloating())
     870                        return false;
    861871                return _mode != SelectedMode.None;
    862872        }
     
    917927
    918928        public void paintFill(Graphics2D g) {
    919                 if (getFillColor() != null && getEnclosingDots() != null) {
    920                         g.setColor(getFillColor());
     929                Color fillColor = getFillColor();
     930                if (fillColor != null && getEnclosingDots() != null) {
     931                        if(isFloating()){
     932                                //TODO experiment with adding alpha when picking up filled items...
     933                                //Slows things down quite alot!!
     934                                fillColor = new Color(fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue());
     935                        }                       
     936                        g.setColor(fillColor);
    921937                        // The painting is not efficient enough for gradients...
    922938                        // Shape s = getEnclosedShape();
     
    10211037                // Check if all the characters are digits and hence it is a relative
    10221038                // link
    1023                 for (int i = 0; i < link.length(); i++) {
    1024                         if (!Character.isDigit(link.charAt(i)))
    1025                                 return;
    1026                 }
     1039                if(!FrameIO.isPositiveInteger(link))
     1040                        return;
    10271041
    10281042                // Make it an absolute link
     
    10381052
    10391053        /**
    1040          * Sets any action code (KMS action language) that should be associated with
     1054         * Sets any action code that should be associated with
    10411055         * this Item Each entry in the list is one line of code
    10421056         *
     
    10451059         */
    10461060        public void setActions(List<String> actions) {
     1061                //Want to resize the highlight box for text items if actions have been added
     1062                _poly = null;
    10471063                if (actions == null || actions.size() == 0)
    10481064                        _actions = null;
     
    10751091
    10761092        public void setActionMark(boolean val) {
     1093                _poly = null;
    10771094                _actionMark = val;
    10781095        }
     
    10961113         *            The ratio of the arrow's length to its width.
    10971114         */
    1098         public void setArrow(int length, double ratio) {
     1115        public void setArrow(float length, double ratio) {
    10991116                _arrowheadLength = length;
    11001117                _arrowheadRatio = ratio;
     
    11061123        }
    11071124
    1108         public void setArrowheadLength(int length) {
     1125        public void setArrowheadLength(float length) {
    11091126                _arrowheadLength = length;
    11101127                updateArrowPolygon();
     
    12501267
    12511268        public void setLinkMark(boolean val) {
     1269                _poly = null;
    12521270                _linkMark = val;
    12531271        }
     
    13071325                _y = y;
    13081326
     1327                for (Item i : getEnclosures()) {
     1328                        i.updatePolygon();
     1329                }
    13091330                updatePolygon();
    13101331
     
    14001421                        return;
    14011422                assert (_parent != null);
     1423               
     1424                if(FrameIO.isPositiveInteger(link))
     1425                        return;
     1426               
    14021427                // Check if the link is for the current frameset
    14031428                if (_parent.getFramesetName().equalsIgnoreCase(
     
    14111436         * Dots this is the thickness.
    14121437         */
    1413         public void setSize(int size) {
     1438        public void setSize(float size) {
    14141439        }
    14151440
     
    15001525                else {
    15011526                        _arrowhead = new Polygon();
    1502                         _arrowhead.addPoint((int) getX(), (int) getY());
     1527                        _arrowhead.addPoint(Math.round(getX()), Math.round(getY()));
     1528                        _arrowhead.addPoint((Math.round(getX() - getArrowheadLength())),
     1529                                        ((int) Math.round(getY()
     1530                                                        - (getArrowheadLength() * getArrowheadRatio()))));
     1531                        _arrowhead.addPoint(Math.round(getX()), (int) getY());
    15031532                        _arrowhead
    15041533                                        .addPoint(
    1505                                                         (int) getX() - getArrowheadLength(),
    1506                                                         (int) (getY() - (getArrowheadLength() * getArrowheadRatio())));
    1507                         _arrowhead.addPoint((int) getX(), (int) getY());
    1508                         _arrowhead
    1509                                         .addPoint(
    1510                                                         (int) getX() - getArrowheadLength(),
    1511                                                         (int) (getY() + (getArrowheadLength() * getArrowheadRatio())));
     1534                                                        (int) Math.round(getX() - getArrowheadLength()),
     1535                                                        (int) Math
     1536                                                                        .round((getY() + (getArrowheadLength() * getArrowheadRatio()))));
    15121537                }
    15131538        }
    15141539
    15151540        protected abstract void updatePolygon();
     1541
     1542        public void setHidden(boolean state) {
     1543                this._visible = !state;
     1544        }
     1545       
    15161546
    15171547        public void setVisible(boolean state) {
     
    15201550
    15211551        public boolean isVisible() {
    1522                 return _visible;
     1552                return _visible && !_deleted;
    15231553        }
    15241554
     
    15401570                }
    15411571                setSelectionColor(color);
    1542                 _lastMode = _mode;
    15431572                _mode = mode;
    1544         }
    1545 
    1546         public void restoreLastMode(Color selectionColor) {
    1547                 setSelectionColor(selectionColor);
    1548                 if (_mode != SelectedMode.None)
    1549                         return;
    1550                 _mode = _lastMode;
    1551                 _lastMode = SelectedMode.None;
    15521573        }
    15531574
     
    16591680        }
    16601681
     1682        /**
     1683         * True if this item is the end of a line.
     1684         *
     1685         * @return
     1686         */
    16611687        public boolean isLineEnd() {
     1688                // TODO this will need to be redone when enclosure class is added...
     1689                // At the moment enclosures are only circles...we dont want circle
     1690                // centers to be lineEnds
    16621691                return _lines.size() > 0;
     1692        }
     1693       
     1694        public boolean hasEnclosures(){
     1695                return _enclosures.size() > 0;
    16631696        }
    16641697
     
    17171750
    17181751        public void setAction(String string) {
     1752                //Want to resize the highlight box for text items if actions are been added
     1753                if(_actions == null || _actions.size() == 0){
     1754                        _poly = null;
     1755                }
    17191756                _actions = new LinkedList<String>();
    17201757                _actions.add(string);
     
    17321769        protected void paintLink(Graphics2D g) {
    17331770                if (getLink() != null || getAction() != null) {
     1771                        g.setStroke(HIGHLIGHT_STROKE);
    17341772                        if (getLink() != null && getAction() != null) {
    17351773                                g.setColor(LINK_ACTION_COLOR);
     
    18061844                        return null;
    18071845                // assert (_parent!= null);
     1846                Frame parent = getParentOrCurrentFrame();
    18081847                if (_parent == null) {
    18091848                        // if parent is null it is an item on the message box
    18101849                        // so it must already be absolute
    1811                         assert (!FrameIO.isPositiveInteger(link));
    1812                         return link;
     1850                        //assert (!FrameIO.isPositiveInteger(link));
     1851                        //return link;
     1852                       
    18131853                }
    18141854
    18151855                // if its a relative link then return absolute
    18161856                if (FrameIO.isPositiveInteger(link)) {
    1817                         return _parent.getFramesetName() + link;
     1857                        return parent.getFramesetName() + link;
    18181858                }
    18191859                return link;
     
    18281868         *            new y position
    18291869         */
    1830         public void setXY(int x, int y) {
     1870        public void setXY(float x, float y) {
    18311871                _x = x;
    18321872                _y = y;
     
    18771917
    18781918        /**
    1879          * Gets the size of the enclosure that this item is part of.
    1880          * @return the area of the box surrounding the enclosed shape that this item is part of
    1881          */
    1882         public Integer getEnclosedArea() {
     1919         * Gets the size of the enclosure that this item is part of. Used to
     1920         * determine the paint order of items, with smaller items being painted
     1921         * first.
     1922         *
     1923         * @return the area of the box surrounding the enclosed shape that this item
     1924         *         is part of
     1925         */
     1926        public double getEnclosedArea() {
    18831927                if (_enclosure == null)
    1884                         return 0;
    1885                 Rectangle box = getEnclosedShape().getBounds();
    1886                 Integer area = box.width * box.height;
    1887                
    1888                 if (getFillColor() == null)
    1889                         return -area;
    1890                
    1891                 return area;
     1928                        return 0.0;
     1929                Rectangle2D box = getEnclosedShape().getBounds2D();
     1930                return box.getWidth() * box.getHeight();
     1931        }
     1932
     1933        /**
     1934         * Returns the Shape that surrounds this Item representing this Item's
     1935         * 'gravity'.
     1936         *
     1937         * @return The Shape (rectangle) surrounding this Item, which represents
     1938         *         this Items 'gravity'.
     1939         */
     1940        public final Polygon getPolygon() {
     1941                if (_poly == null)
     1942                        updatePolygon();
     1943
     1944                return new Polygon(_poly.xpoints, _poly.ypoints, _poly.npoints);
     1945        }
     1946
     1947        /**
     1948         * Shifts the position of the item along the line between this items
     1949         * location and a specified point.
     1950         *
     1951         * @param origin
     1952         * @param ratio
     1953         */
     1954        public void translate(Point2D origin, double ratio) {           
     1955                _x = (float) (origin.getX() + ratio * (_x - origin.getX()));
     1956                _y = (float) (origin.getY() + ratio * (_y - origin.getY()));
     1957                updatePolygon();
     1958                for (Line line : getLines())
     1959                        line.updatePolygon();
     1960        }
     1961
     1962        private static int[] LinePatterns = new int[] { 0, 10, 20 };
     1963
     1964        /**
     1965         * The rotates through a wheel of dashed lines.
     1966         *
     1967         * @param amount
     1968         *            number of rotations around the wheel to toggle by.
     1969         */
     1970        public void toggleDashed(int amount) {
     1971                // find the index of the current line pattern
     1972                int[] currentPattern = getLinePattern();
     1973
     1974                // Find the current pattern and move to the next pattern in the wheel
     1975                for (int i = 0; i < LinePatterns.length; i++) {
     1976                        if (currentPattern == null || currentPattern[0] == LinePatterns[i]) {
     1977                                i += LinePatterns.length + amount;
     1978                                i %= LinePatterns.length;
     1979
     1980                                // if we are at the start of the wheel make it 'null' (solid
     1981                                // line)
     1982                                if (i == 0) {
     1983                                        setLinePattern(null);
     1984                                } else {
     1985                                        setLinePattern(new int[] { LinePatterns[i], LinePatterns[i] });
     1986                                }
     1987                                return;
     1988                        }
     1989                }
     1990        }
     1991
     1992        Collection<XRayable> _enclosures = new HashSet<XRayable>();
     1993
     1994        private boolean _deleted = false;
     1995
     1996        /**
     1997         * For now there can only be one enclosure per item
     1998         * @param enclosure
     1999         */
     2000        public void addEnclosure(XRayable enclosure) {
     2001                _enclosures.clear();
     2002                _enclosures.add(enclosure);
     2003        }
     2004
     2005        public Collection<? extends XRayable> getEnclosures() {
     2006                return _enclosures;
     2007        }
     2008
     2009        public void removeEnclosure(Item i) {
     2010                _enclosures.remove(i);
     2011
     2012        }
     2013
     2014        public boolean isDeleted() {
     2015                return _deleted;
    18922016        }
    18932017}
  • trunk/src/org/expeditee/items/ItemParentStateChangedEvent.java

    r55 r108  
    1212       
    1313        private Frame _src;
    14         private int _overlayLevel;
     14        private Permission _overlayLevel;
    1515        private int _eventType;
    1616       
     
    2424       
    2525        public ItemParentStateChangedEvent(Frame src, int eventType) {
    26                 this(src, eventType, 0);
     26                this(src, eventType, Permission.none);
    2727        }
    2828       
    29         public ItemParentStateChangedEvent(Frame src, int eventType, int overlayLevel) {
     29        public ItemParentStateChangedEvent(Frame src, int eventType, Permission overlayLevel) {
    3030                _src = src;
    3131                _overlayLevel = overlayLevel;
     
    3737         * @return
    3838         */
    39         public int getOverlayLevel() {
     39        public Permission getOverlayLevel() {
    4040                return _overlayLevel;
    4141        }
  • trunk/src/org/expeditee/items/ItemUtils.java

    r97 r108  
    1414import java.util.Map;
    1515
    16 import org.expeditee.gui.AttributeUtils;
    1716import org.expeditee.gui.DisplayIO;
    1817import org.expeditee.gui.Frame;
     18import org.expeditee.items.Item.SelectedMode;
    1919
    2020//Static methods that provide functions for the objects\
     
    132132                                        return (Text) i;
    133133                }
    134 
    135134                return null;
    136135        }
     
    406405        }
    407406
    408         public static Picture CreateFrameImage(Text source, ImageObserver observer) {
    409                 String size = source.getFirstLine();
    410 
    411                 // remove @f tag
    412                 size = AttributeUtils.getValue(size);
    413 
    414                 try {
    415                         Picture pic = new FrameImage(source, size, observer);
    416                         return pic;
    417                 } catch (Exception e) {
    418                         // e.printStackTrace();
    419                         return null;
    420                 }
    421         }
    422 
    423         public static Picture CreateFrameBitmap(Text source, ImageObserver observer) {
    424                 String size = source.getFirstLine();
    425 
    426                 // remove @b tag
    427                 size = AttributeUtils.getValue(size);
    428 
    429                 try {
    430                         Picture pic = new FrameBitmap(source, size, observer);
    431                         return pic;
    432                 } catch (Exception e) {
    433                         // e.printStackTrace();
    434                         return null;
    435                 }
    436         }
    437 
    438407        /**
    439408         * Creates a deep copy of the given List of Items.
     
    454423                Collection<Item> lineEnds = new LinkedHashSet<Item>();
    455424                Collection<Line> lines = new LinkedHashSet<Line>();
     425                Collection<XRayable> xrayables = new LinkedHashSet<XRayable>();
    456426                Collection<Constraint> constraints = new LinkedHashSet<Constraint>();
    457427
     
    467437                        // BROOK
    468438                        if (i instanceof WidgetCorner) { // dont add these
    469 
    470439                                if (!widgets.contains(((WidgetCorner) i).getWidgetSource()))
    471440                                        widgets.add(((WidgetCorner) i).getWidgetSource());
    472 
    473441                                // BROOK
    474442                        } else if (i instanceof WidgetEdge) { // dont add these
    475 
    476443                                // lines are recreated later
    477444                        } else if (i instanceof Line) {
    478445                                lines.add((Line) i);
     446                        } else if (i instanceof XRayable) {
     447                                xrayables.add((XRayable)i);
    479448                        } else {
    480449                                if (i.isLineEnd()) {
     
    486455                        }
    487456                }
    488 
     457               
     458                //Dont copy the other items that are part of the circle
     459                for(XRayable x : xrayables){
     460                        Collection<Item> connected = x.getConnected();
     461                        singles.removeAll(connected);
     462                        lineEnds.removeAll(connected);
     463                        lines.removeAll(connected);
     464                        copies.addAll(x.copy().getConnected());
     465                }
     466               
    489467                // copy all single items
    490468                for (Item i : singles) {
     
    608586                for (Item item : toUnreel) {
    609587                        // we dont want to unreel anything other than lines
    610                         if (!(item.isLineEnd() || item instanceof Line)) {
     588                        if (item.hasEnclosures() || !(item.isLineEnd() || item instanceof Line)) {
    611589                                return null;
    612590                        }
     
    623601                // copy the original endpoint
    624602                Item copy = origEnd.copy();
     603                origEnd.setSelectedMode(SelectedMode.None);
    625604                copy.removeAllLines();
    626605                copy.removeAllConstraints();
     
    631610                // if the previous line was constrained then make the new line
    632611                // constrained if it was a single line
    633                 //TODO add later a diagonal constraint if getLines() == 3 or 4
     612                // TODO add later a diagonal constraint if getLines() == 3 or 4
    634613                Collection<Constraint> constraints = origEnd.getConstraints();
    635                 if (constrain && constraints.size() > 0 && origEnd.getLines().size() == 2) {
     614                if (constrain && constraints.size() > 0
     615                                && origEnd.getLines().size() == 2) {
    636616                        Integer type = null;
    637617                        for (Constraint c : constraints) {
     
    640620                                } else if (c.getType() == Constraint.VERTICAL) {
    641621                                        type = Constraint.HORIZONTAL;
    642                                 } if (c.getType() == Constraint.DIAGONAL_NEG) {
     622                                }
     623                                if (c.getType() == Constraint.DIAGONAL_NEG) {
    643624                                        type = Constraint.DIAGONAL_POS;
    644625                                } else if (c.getType() == Constraint.DIAGONAL_POS) {
  • trunk/src/org/expeditee/items/Line.java

    r107 r108  
    3838        private static final int MAXIMUM_ARROW_HEAD_LENGTH = 60;
    3939
    40         public static final Float DEFAULT_THICKNESS = 2f;
    41 
    42         public static final Float MINIMUM_THICKNESS = 1f;
    43 
    4440        private Item _start;
    4541
     
    5147        private Point _endOffset = new Point(0, 0);
    5248
    53         // indicates which end the arrowhead should be drawn at
    54         private Polygon _poly = null;
    55 
    5649        private float _thickness = -1;
    57 
    58         private boolean _isCircle = false;
    59 
     50       
    6051        // brush strokes used for painting this line and highlighting
    6152        private Stroke _lineStroke = new BasicStroke(DEFAULT_THICKNESS, CAP, JOIN,
    6253                        4.0F);
     54       
     55        Stroke getStroke() {
     56                return _lineStroke;
     57        }
    6358
    6459        // private Stroke _highlightStroke = new BasicStroke (1f + /*GRAVITY +
     
    9186                if (thick < 0)
    9287                        thick = 1;
    93                 /*
    94                  * if (_start instanceof Dot && _end instanceof Dot) thick = (((Dot)
    95                  * _start).getThickness() + ((Dot) _end) .getThickness()) / 2.0f; else
    96                  * if (_start instanceof Dot) thick = ((Dot) _start).getThickness();
    97                  * else if (_end instanceof Dot) thick = ((Dot) _end).getThickness();
    98                  * else thick = 1;
    99                  */
    100 
     88       
    10189                setThickness(thick);
    10290        }
     
    253241        }
    254242
    255         private void paintCircle(Graphics2D g, Item end) {
    256                 int distance = (int) Math.sqrt(Math.pow(Math.abs(_start.getX()
    257                                 - _end.getX()), 2)
    258                                 + Math.pow(Math.abs(_start.getY() - _end.getY()), 2));
    259 
    260                 // Approximation of circle for mouse interaction
    261                 int points = 20;
    262 
    263                 double radians = 0.0;
    264                 int xPoints[] = new int[points];
    265                 int yPoints[] = new int[xPoints.length];
    266 
    267                 for (int i = 0; i < xPoints.length; i++) {
    268                         xPoints[i] = (int) (distance * Math.cos(radians));
    269                         yPoints[i] = (int) (distance * Math.sin(radians));
    270                         radians += (2.0 * Math.PI) / xPoints.length;
    271                 }
    272 
    273                 _poly = new Polygon(xPoints, yPoints, xPoints.length);
    274                 _poly.translate(end.getX(), end.getY());
    275 
    276                 distance *= 2;
    277 
    278                 g.drawOval(end.getX() - (distance / 2), end.getY() - (distance / 2),
    279                                 distance, distance);
    280                 // Arc version, same result but allows for portions of the circle to be
    281                 // drawn
    282                 // g.drawArc(end.getX() - (distance / 2), end.getY() - (distance / 2),
    283                 // distance, distance, 0, 360);
    284         }
    285 
     243        @Override
    286244        public void setLinePattern(int[] pattern) {
    287245                super.setLinePattern(pattern);
     
    311269        @Override
    312270        public void paint(Graphics2D g) {
     271                if(!isVisible())
     272                        return;
    313273                g.setColor(getPaintColor());
    314274
    315275                // if (this._mode == Item.SelectedMode.Disconnect)
    316276                // System.out.println("Disconnect mode!");
    317 
    318                 if (_start instanceof Text && ((Text) _start).startsWith("@c")) {
    319                         g.setStroke(_lineStroke);
    320                         paintCircle(g, _end);
    321                         _isCircle = true;
    322                 } else if (_end instanceof Text && ((Text) _end).startsWith("@c")) {
    323                         g.setStroke(_lineStroke);
    324                         paintCircle(g, _start);
    325                         _isCircle = true;
    326                 } else {
    327                         // Get a path of points
    328                         int[][][] paths = getPaths();
    329                         g.setStroke(_lineStroke);
    330                         for (int i = 0; i < paths.length; i++) {
    331                                 int[][] path = paths[i];
    332                                 int last = path[0].length - 1;
    333                                 if (path[0][0] == path[0][last] && path[1][0] == path[1][last]) {
    334                                         g.drawPolygon(path[0], path[1], last);
    335                                 } else {
    336                                         g.drawPolyline(path[0], path[1], last + 1);
    337                                 }
    338                         }
    339                         // paint the arrowhead (if necessary)
    340                         paintArrows(g);
    341                         // g.drawLine(_start.getX() + _startOffset.x, _start.getY()
    342                         // + _startOffset.y, _end.getX() + _endOffset.x, _end.getY()
    343                         // + _endOffset.y);
    344                         // TODO deal with the offset
    345                         _isCircle = false;
    346                 }
    347 
    348                 // update the highlight shape
    349                 // java.awt.geom.Line2D.Float shape = new
    350                 // java.awt.geom.Line2D.Float(_startx, _starty, _endx, _endy);
    351                 // _shape = _highlightStroke.createStrokedShape(shape);
    352 
    353                 // g.setStroke(norm);
     277                g.setStroke(_lineStroke);
     278                // Get a path of points
     279                int[][][] paths = getPaths();
     280                for (int i = 0; i < paths.length; i++) {
     281                        int[][] path = paths[i];
     282                        int last = path[0].length - 1;
     283                        if (path[0][0] == path[0][last] && path[1][0] == path[1][last]) {
     284                                g.drawPolygon(path[0], path[1], last);
     285                        } else {
     286                                g.drawPolyline(path[0], path[1], last + 1);
     287                        }
     288                }
     289                // paint the arrowhead (if necessary)
     290                paintArrows(g);
    354291
    355292                if (showLineHighlight() && isHighlighted()) {
    356293                        g.setColor(getHighlightColor());
    357                         g.setStroke(new BasicStroke(MINIMUM_THICKNESS, CAP, JOIN));
     294                        g.setStroke(HIGHLIGHT_STROKE);
    358295                        ((Graphics2D) g).draw(this.getArea());
    359296                }
     
    398335                visited.add(this);
    399336
    400                 start.appendPath(visited, points,
    401                                                 true, toExplore);
    402                 end.appendPath(visited, points, false,
    403                                                 toExplore);
     337                start.appendPath(visited, points, true, toExplore);
     338                end.appendPath(visited, points, false, toExplore);
    404339                return points;
    405340        }
     
    437372                y0 = getOppositeEnd(withArrow).getY() + endOffset.y;
    438373
    439                 int arrowLength = withArrow.getArrowheadLength();
     374                float arrowLength = withArrow.getArrowheadLength();
    440375                double arrowRatio = withArrow.getArrowheadRatio();
    441376
     
    474409                        arrowhead = new Polygon();
    475410                        arrowhead.addPoint((int) x0, (int) y0);
    476                         arrowhead.addPoint((int) x0 - arrowLength,
    477                                         (int) (y0 - (arrowLength * arrowRatio)));
     411                        arrowhead.addPoint((int)Math.round(x0 - arrowLength),
     412                                        (int)Math.round((y0 - (arrowLength * arrowRatio))));
    478413                        arrowhead.addPoint((int) x0, (int) y0);
    479                         arrowhead.addPoint((int) x0 - arrowLength,
    480                                         (int) (y0 + (arrowLength * arrowRatio)));
     414                        arrowhead.addPoint((int)Math.round( x0 - arrowLength),
     415                                        (int)Math.round( (y0 + (arrowLength * arrowRatio))));
    481416                        if (!disconnectMode)
    482417                                withArrow.setArrowhead(arrowhead);
     
    523458
    524459                return rad;
    525         }
    526 
    527         @Override
    528         public Polygon getPolygon() {
    529                 if (_poly == null)
    530                         updatePolygon();
    531 
    532                 return _poly;
    533460        }
    534461
     
    696623                int length = (int) Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
    697624                length /= ARROW_HEAD_TO_LENGTH_RATIO;
    698                 arrow.setArrowheadLength(Math.min(MAXIMUM_ARROW_HEAD_LENGTH,Math.max(MINIMUM_ARROW_HEAD_LENGTH, length)));
     625                arrow.setArrowheadLength(Math.min(MAXIMUM_ARROW_HEAD_LENGTH, Math.max(
     626                                MINIMUM_ARROW_HEAD_LENGTH, length)));
    699627        }
    700628
     
    723651        }
    724652
    725         private static int[] LinePatterns = new int[] { 0, 10, 20 };
    726 
    727         /**
    728          * The rotates through a wheel of dashed lines.
    729          *
    730          * @param amount
    731          *            number of rotations around the wheel to toggle by.
    732          */
    733         public void toggleDashed(int amount) {
    734                 // find the index of the current line pattern
    735                 int[] currentPattern = getLinePattern();
    736 
    737                 // Find the current pattern and move to the next pattern in the wheel
    738                 for (int i = 0; i < LinePatterns.length; i++) {
    739                         if (currentPattern == null || currentPattern[0] == LinePatterns[i]) {
    740                                 i += LinePatterns.length + amount;
    741                                 i %= LinePatterns.length;
    742 
    743                                 // if we are at the start of the wheel make it 'null' (solid
    744                                 // line)
    745                                 if (i == 0) {
    746                                         setLinePattern(null);
    747                                 } else {
    748                                         setLinePattern(new int[] { LinePatterns[i], LinePatterns[i] });
    749                                 }
    750                                 return;
    751                         }
    752                 }
    753         }
    754 
    755653        private static double[] ArrowHeadRatios = new double[] { 0.25, 0.5, 1.0 };
    756654
     
    803701
    804702                // find the index of the current line pattern
    805                 int currentLength = arrow.getArrowheadLength();
     703                float currentLength = arrow.getArrowheadLength();
    806704
    807705                // Find the current pattern and move to the next pattern in the wheel
     
    1036934        @Override
    1037935        protected void updatePolygon() {
    1038                 if (_isCircle) {
    1039 
    1040                 }
    1041 
    1042936                _poly = new Polygon();
    1043937
  • trunk/src/org/expeditee/items/Picture.java

    r106 r108  
    22
    33import java.awt.AlphaComposite;
    4 import java.awt.Color;
    54import java.awt.Dimension;
    65import java.awt.Graphics2D;
     
    109import java.awt.Rectangle;
    1110import java.awt.Shape;
     11import java.awt.geom.Point2D;
    1212import java.awt.image.ImageObserver;
    1313import java.io.File;
    1414import java.io.IOException;
    1515import java.text.DecimalFormat;
    16 import java.util.List;
    1716
    1817import javax.imageio.ImageIO;
    1918import javax.swing.ImageIcon;
    2019
     20import org.expeditee.gui.AttributeUtils;
    2121import org.expeditee.gui.FrameGraphics;
     22import org.expeditee.gui.FrameMouseActions;
    2223import org.expeditee.io.Logger;
    2324
     
    3940 *
    4041 */
    41 public class Picture extends Item {
    42 
    43         private static final int MINIMUM_WIDTH = 10;
     42public class Picture extends XRayable {
     43
     44        private static final int MINIMUM_WIDTH = 20;
    4445
    4546        public static final int WIDTH = 0;
     
    4849
    4950        protected Image _image = null;
    50 
    51         private Polygon _poly = null;
    52 
    53         // private Polygon _circle = null;
    54         protected Text _source = null;
    5551
    5652        private int _scaleType = RATIO;
     
    7773        protected ImageObserver _imageObserver = null;
    7874
    79         protected Picture() {
    80                 super();
     75        protected Picture(Text source, ImageObserver observer, Image image) {
     76                super(source);
     77
     78                _imageObserver = observer;
     79                _image = image;
     80
     81                refresh();
     82
     83                if (_image != null)
     84                        parseSize();
    8185        }
    8286
     
    99103         */
    100104        public Picture(Text source, String fileName, String path, String size,
    101                         ImageObserver observer) throws IllegalArgumentException {
    102                 super();
     105                        ImageObserver observer) {
     106                this(source, observer, null);
    103107                _fileName = fileName;
    104108                _path = path;
    105                 _source = source;
    106                 _imageObserver = observer;
    107 
    108                 refresh();
    109 
     109        }
     110
     111        protected void parseSize() {
     112                String size = _source.getFirstLine();
     113                size = AttributeUtils.getValue(size);
     114               
     115                if(_end.x != 0 || _end.y != 0)
     116                        return;
     117               
     118                // set the default values for start and end
     119                _start.setLocation(0, 0);
    110120                if (_image == null)
    111                         throw new IllegalArgumentException();
    112 
    113                 parseSize(size);
    114         }
    115 
    116         protected void parseSize(String size) {
    117                 // set the default values for start and end
    118                 _start = new Point(0, 0);
    119                 _end = new Point(_image.getWidth(null), _image.getHeight(null));
     121                        _end.setLocation(0, 0);
     122                else
     123                        _end.setLocation(_image.getWidth(null), _image.getHeight(null));
    120124                size = size.trim();
    121125                String[] values = size.split("\\s+");
     
    197201
    198202        protected void updatePolygon() {
    199                 if (_image == null)
    200                         return;
    201 
     203                if (_image == null) {
     204                        refresh();
     205                        parseSize();
     206                }
    202207                _poly = new Polygon();
    203208
     
    206211                        int height = getHeight();
    207212
    208                         int xdiff = -getLeftMargin();
     213                        int xdiff = -MARGIN_RIGHT; // -getLeftMargin();
    209214
    210215                        // extra pixel around the image so the highlighting is visible
     
    227232        }
    228233
    229         /**
    230          * Returns the Text Item that was used to create this Picture object. This
    231          * is required when saving the Frame.
    232          *
    233          * @return The Text Item used to create this Picture.
    234          */
    235         public Text getText() {
    236                 return _source;
    237         }
    238 
    239         @Override
    240         public int getID() {
    241                 return _source.getID();
    242         }
    243 
    244         @Override
    245         public void setID(int newID) {
    246                 _source.setID(newID);
    247         }
    248 
    249         @Override
    250         public int getY() {
    251                 return _source.getY();
    252         }
    253 
    254         @Override
    255         public int getX() {
    256                 return _source.getX();
    257         }
    258 
    259         @Override
    260         public void setPosition(float x, float y) {
    261                 _source.setPosition(x, y);
    262 
    263                 updatePolygon();
    264         }
    265 
    266         @Override
    267         public String getLink() {
    268                 if (_source == null)
    269                         return null;
    270                 else
    271                         return _source.getLink();
    272         }
    273 
    274         @Override
    275         public void setLink(String frameName) {
    276                 if (_source == null) {
    277                         return;
    278                 } else {
    279                         _source.setLink(frameName);
    280                 }
    281 
    282                 updatePolygon();
    283         }
    284 
    285         @Override
    286         public void setActions(List<String> action) {
    287                 if (_source == null)
    288                         return;
    289                 else
    290                         _source.setActions(action);
    291 
    292                 updatePolygon();
    293         }
    294 
    295         @Override
    296         public List<String> getAction() {
    297                 if (_source == null)
    298                         return null;
    299                 else
    300                         return _source.getAction();
     234        @Override
     235        public double getEnclosedArea() {
     236                return getWidth() * getHeight();
    301237        }
    302238
     
    325261         */
    326262        @Override
    327         protected void paintLink(Graphics2D g){
     263        protected void paintLink(Graphics2D g) {
    328264                if (FrameGraphics.isAudienceMode())
    329265                        return;
    330266                super.paintLink(g);
    331267        }
    332        
     268
    333269        @Override
    334270        public void paint(Graphics2D g) {
     
    383319
    384320        @Override
    385         public Polygon getPolygon() {
    386                 if (_poly == null)
    387                         updatePolygon();
    388 
    389                 Polygon external = new Polygon(_poly.xpoints, _poly.ypoints,
    390                                 _poly.npoints);
    391                 return external;
    392         }
    393 
    394         @Override
    395321        public int setSelectionColor() {
    396322                super.setSelectionColor();
     
    407333                Picture p = createPicture();
    408334                p._image = _image;
    409                 p._imageObserver = _imageObserver;
    410                 p._source = _source.copy();
    411                 Item.DuplicateItem(this, p);
     335                p._mode = _mode;
     336                // Doing Duplicate item duplicates link mark which we dont want to do
     337                // when in audience mode because the linkMark will be copied incorrectly
     338                // Get all properties from the source
    412339
    413340                if (!isCropTooSmall() && _cropStart != null && _cropEnd != null) {
     
    439366                        p._start = new Point(startX, startY);
    440367                        p._end = new Point(endX, endY);
    441                         p.setPosition(topLeft.x + _source.getX(), topLeft.y + _source.getY());
     368                        p._source.setPosition(topLeft.x + _source.getX(), topLeft.y
     369                                        + _source.getY());
    442370                } else {
    443371                        p._start = _start;
     
    460388        }
    461389
    462         @Override
    463         public Color getColor() {
    464                 return _source.getColor();
    465         }
    466 
    467         @Override
    468         public void setColor(Color c) {
    469                 _source.setColor(c);
    470         }
    471 
    472         @Override
    473         public int getSize() {
     390        public float getScale() {
     391                return _scale;
     392        }
     393       
     394        public void setScale(float scale){
     395                _scale = scale;
     396        }
     397       
     398        @Override
     399        public float getSize() {
    474400                return _source.getSize();
    475401        }
    476402
    477403        @Override
    478         public void setSize(int size) {
    479                 int diff = size - _source.getSize();
     404        public void setSize(float size) {
     405                float diff = size - _source.getSize();
    480406                float oldScale = _scale;
    481407
    482                 int multiplier = 1000 + (diff) * 40;
    483                 _scale = (Math.round(_scale * multiplier)) / 1000F;
    484 
    485                 //If the above formula didnt change stuff due to rounding
    486                 //change it manually
    487                 if (_scale == oldScale){
    488                         _scale += 0.01 * diff;
    489                 }
    490                        
     408                float multiplier = (1000F + diff * 40F) / 1000F;
     409                _scale = _scale * multiplier;
     410
    491411                // picture must still be at least XX pixels wide
    492                 if (getWidth() < MINIMUM_WIDTH) {                       
     412                if (getWidth() < MINIMUM_WIDTH) {
    493413                        _scale = oldScale;
    494                 }
    495 
     414                } else {
     415                        _source.translate(new Point2D.Float(FrameMouseActions.MouseX,
     416                                        FrameMouseActions.MouseY), multiplier);
     417                }
    496418                updateSource();
    497419                updatePolygon();
     
    513435
    514436        @Override
    515         public Item merge(Item merger, int mouseX, int mouseY) {
    516                 return merger;
    517         }
    518 
    519437        public boolean refresh() {
    520438                // ImageIcon is faster, but cannot handle some formats
     
    556474        @Override
    557475        public boolean getLinkMark() {
    558                 return _source.getLinkMark();
     476                return !FrameGraphics.isAudienceMode() && _source.getLinkMark();
    559477        }
    560478
     
    601519                _source.setText(newText.toString());
    602520        }
     521       
     522        @Override
     523        public void translate(Point2D origin, double ratio){
     524                _scale *= ratio;
     525                updateSource();
     526                super.translate(origin, ratio);
     527        }
    603528}
  • trunk/src/org/expeditee/items/Text.java

    r107 r108  
    1717import java.awt.font.TextLayout;
    1818import java.awt.geom.AffineTransform;
     19import java.awt.geom.Point2D;
    1920import java.awt.geom.Rectangle2D;
    2021import java.text.AttributedString;
     
    9192
    9293        private int _selectionEnd = -1;
    93 
     94       
    9495        // text is broken up into lines
    9596        private StringBuffer _text = new StringBuffer();
     
    103104        // The font to display this text in
    104105        private Font _font;
    105 
    106         // the rectangle surrounding this text item
    107         private Polygon _poly = null;
    108106
    109107        /**
     
    121119
    122120                setID(id);
     121        }
     122       
     123        /**
     124         * Creates a text item which is not added to the frame.
     125         * @param text
     126         */
     127        public Text(String text) {
     128                super();
     129                _text.append(text);
     130                rebuild(false);
     131                setID(-1);
    123132        }
    124133
     
    323332         *            The Y position to insert the Strings at.
    324333         */
    325         public Point insertChar(char ch, int mouseX, int mouseY) {
     334        public Point2D.Float insertChar(char ch, float mouseX, float mouseY) {
    326335                if (ch != '\t')
    327336                        return insertText("" + ch, mouseX, mouseY);
     
    362371        }
    363372
    364         public Point getEndPosition(int mouseY) {
     373        public Point2D.Float getEndPosition(int mouseY) {
    365374                return getEdgePosition(getLinePosition(mouseY), false);
    366375        }
    367376
    368         public Point getStartPosition(int mouseY) {
     377        public Point2D.Float getStartPosition(int mouseY) {
    369378                return getEdgePosition(getLinePosition(mouseY), true);
    370379        }
    371380
    372         public Point getEndParagraphPosition() {
     381        public Point2D.Float getEndParagraphPosition() {
    373382                return getEdgePosition(_textLayouts.size() - 1, false);
    374383        }
    375384
    376         public Point getStartParagraphPosition() {
     385        public Point2D.Float getStartParagraphPosition() {
    377386                return getEdgePosition(0, true);
    378387        }
    379388
    380         private Point getEdgePosition(int line, boolean start) {
     389        private Point2D.Float getEdgePosition(int line, boolean start) {
    381390                // if there is no text yet, or the line is invalid
    382391                if (_text == null || _text.length() == 0 || line < 0
    383392                                || line > _textLayouts.size() - 1)
    384                         return new Point(getX(), getY());
     393                        return new Point2D.Float(getX(), getY());
    385394
    386395                TextLayout last = _textLayouts.get(line);
     
    400409                                                x,
    401410                                                (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
    402                 return new Point(Math.round(x), Math.round(getY() + y + caret[1]));
     411                return new Point2D.Float(x, getY() + y + caret[1]);
    403412        }
    404413
     
    483492         * @return The new location that the mouse cursor should be moved to
    484493         */
    485         public java.awt.Point insertText(String text, int mouseX, int mouseY) {
     494        public Point2D.Float insertText(String text, float mouseX, float mouseY) {
     495                return insertText(text, mouseX, mouseY, -1);
     496        }
     497
     498        public Point2D.Float insertText(String text, float mouseX, float mouseY,
     499                        int insertPos) {
    486500                TextHitInfo hit;
    487501                TextLayout current = null;
     
    490504                // check for empty string
    491505                if (text == null || text.length() == 0)
    492                         return new Point(mouseX, mouseY);
     506                        return new Point2D.Float(mouseX, mouseY);
    493507
    494508                // if there is no text yet
     
    516530                                pos++;
    517531
     532                        if (insertPos < 0)
     533                                insertPos = pos;
     534
    518535                        // if this is a backspace key
    519536                        if (text.charAt(0) == KeyEvent.VK_BACK_SPACE) {
    520                                 if (pos > 0) {
    521                                         deleteChar(pos - 1, false);
    522 
    523                                         pos--;
     537                                if (insertPos > 0) {
     538                                        deleteChar(insertPos - 1);
     539                                        if (pos > 0)
     540                                                pos--;
    524541                                }
    525542                                // if this is a delete key
    526543                        } else if (text.charAt(0) == KeyEvent.VK_DELETE) {
    527                                 if (pos < _text.length()) {
    528                                         deleteChar(pos, false);
     544                                if (insertPos < _text.length()) {
     545                                        deleteChar(insertPos);
    529546                                }
    530547                                // this is a tab
     
    549566                                                if (_text.length() > 0
    550567                                                                && Character.isSpaceChar(_text.charAt(0))) {
    551                                                         deleteChar(0, false);
     568                                                        deleteChar(0);
    552569                                                        pos--;
    553570                                                } else
     
    575592                                // this is a normal insert
    576593                        } else {
    577                                 insertString(text, pos);
     594                                insertString(text, insertPos);
    578595                                pos += text.length();
     596                        }
     597
     598                        if (_text.length() == 0){
     599                                rebuild(false);
     600                                return new Point2D.Float(this._x, this._y);
    579601                        }
    580602
     
    621643                                                x,
    622644                                                (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
    623                 return new Point(Math.round(x), Math.round(getY() + y + caret[1]));
    624         }
    625 
    626         public Point moveCursor(int direction, int mouseX, int mouseY) {
     645                return new Point2D.Float(Math.round(x), Math.round(getY() + y
     646                                + caret[1]));
     647        }
     648
     649        public Point2D.Float moveCursor(int direction, float mouseX, float mouseY) {
    627650                // check for home or end keys
    628651                if (direction == HOME)
     
    638661                // if there is no text yet
    639662                if (_text == null || _text.length() == 0) {
    640                         return new Point(mouseX, mouseY);
     663                        return new Point2D.Float(mouseX, mouseY);
    641664                        // otherwise, move the cursor
    642665                } else {
     
    700723                float y = getLineDrop(current) * line;
    701724
    702                 return new Point(
    703                                 Math.round(getX() + caret[0]) + getJustOffset(current), Math
    704                                                 .round(getY() + y + caret[1]));
     725                return new Point2D.Float(getX() + caret[0] + getJustOffset(current),
     726                                getY() + y + caret[1]);
    705727        }
    706728
     
    715737         * @return The position in the string of the character being pointed at.
    716738         */
    717         public TextHitInfo getCharPosition(int line, int mouseX) {
     739        public TextHitInfo getCharPosition(int line, float mouseX) {
    718740                if (line < 0 || line >= _textLayouts.size())
    719741                        return null;
     
    726748        }
    727749
    728         public int getLinePosition(int mouseY) {
     750        public int getLinePosition(float mouseY) {
    729751                mouseY += getOffset().y;
    730752
     
    737759
    738760                        if (bounds.getWidth() < 1)
    739                                 bounds.setRect(bounds.getMinX(), bounds
    740                                                 .getMinY(), 10, bounds.getHeight());
     761                                bounds.setRect(bounds.getMinX(), bounds.getMinY(), 10, bounds
     762                                                .getHeight());
    741763
    742764                        double x = bounds.getCenterX();
     
    791813
    792814        public void setFamily(String newFamily) {
    793                 String toDecode = newFamily + "-" + getFontStyle() + "-" + getSize();
     815                String toDecode = newFamily + "-" + getFontStyle() + "-"
     816                                + Math.round(getSize());
    794817                setFont(Font.decode(toDecode));
    795818        }
     
    10751098                _poly.addPoint(maxX + getGravity(), maxY + getGravity());
    10761099                _poly.addPoint(minX - getGravity(), maxY + getGravity());
     1100
     1101                _poly.translate(getX(), getY());
    10771102        }
    10781103
     
    10821107        private void rebuild(boolean limitWidth) {
    10831108                // if there is no text, there is nothing to do
    1084                 if (_text == null || _text.length() == 0)
     1109                if (_text == null || _text.length() == 0){
     1110//                      Frame parent = getParent();
     1111//                      if(parent != null)
     1112//                              parent.removeItem(this);
    10851113                        return;
     1114                }
    10861115
    10871116                AttributedString paragraphText = new AttributedString(_text.toString());
     
    12461275        @Override
    12471276        public void paint(Graphics2D g) {
     1277                if (!isVisible())
     1278                        return;
     1279
    12481280                // if there is no text to paint, do nothing.
    12491281                if (_text == null || _text.length() == 0 || getMaxSize() == null)// ||
    1250                         // _textLayouts.size()
    1251                         // < 1)
    12521282                        return;
    12531283
     
    12571287                        return;
    12581288                }
    1259 
     1289               
    12601290                // the background is only cleared if required
    12611291                if (getBackgroundColor() != null) {
     
    12661296                        g.setColor(bgc);
    12671297                        g.fill(getPolygon());
     1298                }
     1299
     1300                if (isHighlighted()) {
     1301                        g.setColor(getPaintHighlightColor());
     1302                        Stroke _highlightStroke = new BasicStroke(
     1303                                        (float) _highlightThickness, CAP, JOIN);
     1304                        g.setStroke(_highlightStroke);
     1305                        if (SelectedMode.Enclosed.equals(getSelectedMode()))
     1306                                g.fillPolygon(getPolygon());
     1307                        else
     1308                                g.drawPolygon(getPolygon());
    12681309                }
    12691310
     
    13491390
    13501391                paintLink(g);
    1351 
    1352                 if (isHighlighted()) {
    1353                         g.setColor(getPaintHighlightColor());
    1354                         Stroke _highlightStroke = new BasicStroke(
    1355                                         (float) _highlightThickness, CAP, JOIN);
    1356                         g.setStroke(_highlightStroke);
    1357                         g.drawPolygon(getPolygon());
    1358                 }
    13591392        }
    13601393
     
    13721405
    13731406        @Override
    1374         public Polygon getPolygon() {
    1375                 updatePolygon();
    1376 
    1377                 Polygon external = new Polygon(_poly.xpoints, _poly.ypoints,
    1378                                 _poly.npoints);
    1379                 external.translate(getX(), getY());
    1380 
    1381                 return external;
    1382         }
    1383 
    1384         @Override
    13851407        public Text copy() {
    13861408                Text copy = new Text(getID());
    1387 
    13881409                // copy standard item values
    13891410                Item.DuplicateItem(this, copy);
     
    13981419                copy.setFont(getFont());
    13991420                copy.setText(_text.toString());
     1421                copy.setHidden(!isVisible());
    14001422                // copy._poly = new Polygon(_poly.xpoints,_poly.ypoints, _poly.npoints);
    14011423
     
    14041426
    14051427        @Override
    1406         public int getSize() {
    1407                 return getPaintFont().getSize();
     1428        public float getSize() {
     1429                return getPaintFont().getSize2D();
    14081430        }
    14091431
     
    14181440
    14191441        @Override
    1420         public void setSize(int size) {
     1442        public void setSize(float size) {
    14211443                // Dont want to have size set when duplicating a point which has size 0
    14221444                if (size < 0)
     
    14251447                if (size < MINIMUM_FONT_SIZE)
    14261448                        size = MINIMUM_FONT_SIZE;
    1427                 setFont(getPaintFont().deriveFont((float) size));
     1449                setFont(getPaintFont().deriveFont(size));
    14281450        }
    14291451
    14301452        @Override
    14311453        public void setAnnotation(boolean val) {
     1454                float mouseX = DisplayIO.getFloatMouseX();
     1455                float mouseY = FrameMouseActions.MouseY;
     1456                Point2D.Float newPoint = new Point2D.Float();
    14321457                if (val) {
    14331458                        // if this is already an annotation, do nothing
    14341459                        if (isAnnotation())
    14351460                                return;
    1436                         if (_text.charAt(0) == '*') {
    1437                                 deleteChar(0, true);
     1461                        if (!isLineEnd() && _text.length() > 0 && _text.charAt(0) == '*') {
     1462                                newPoint.setLocation(insertText(""
     1463                                                + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1));
    14381464                                if (_text.length() > 0 && _text.charAt(0) == ' ')
    1439                                         deleteChar(0, true);
     1465                                        newPoint.setLocation(insertText(""
     1466                                                        + (char) KeyEvent.VK_BACK_SPACE, newPoint.x,
     1467                                                        newPoint.y, 1));
    14401468                        } else {
    1441                                 insertString("@", 0);
     1469                                newPoint.setLocation(insertText("@", mouseX, mouseY, 0));
    14421470                        }
    14431471                } else {
     
    14451473                        if (!isAnnotation())
    14461474                                return;
    1447 
    1448                         if (_text.charAt(0) == '@') {
    1449                                 _text.setCharAt(0, ' ');
    1450                                 insertString("*", 0);
     1475                        if (!isLineEnd() && _text.charAt(0) == '@') {
     1476                                newPoint.setLocation(insertText(""
     1477                                                + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1));
     1478                                newPoint
     1479                                                .setLocation(insertText("* ", newPoint.x, newPoint.y, 0));
    14511480                        } else {
    1452                                 deleteChar(0, true);
     1481                                newPoint.setLocation(insertText(""
     1482                                                + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1));
    14531483                        }
    14541484                }
    14551485                rebuild(false);
     1486                DisplayIO.setCursorPosition(newPoint.x, newPoint.y, false);
    14561487        }
    14571488
     
    14751506        }
    14761507
    1477         private void deleteChar(int pos, boolean replaceWithDot) {
     1508        private void deleteChar(int pos) {
    14781509                _text.deleteCharAt(pos);
    14791510
    14801511                if (_text.length() == 0) {
    1481                         if (replaceWithDot) {
     1512                        if (this.isLineEnd()) {
    14821513                                // Remove and replace with a dot
    14831514                                FrameKeyboardActions.replaceText(this);
    1484                                 DisplayIO.setCursorPosition(this.getPosition());
     1515                                DisplayIO.setCursorPosition(this._x, this._y);
    14851516                        }
    14861517                        return;
     
    16421673
    16431674        @Override
    1644         public void delete() {
    1645                 setVisible(false);
    1646         }
    1647 
    1648         @Override
    16491675        public void anchor() {
    16501676                super.anchor();
     
    16741700        public static final String TAB_STRING = "      ";
    16751701
    1676         public Point insertTab(char ch, int mouseX, int mouseY) {
     1702        public Point2D.Float insertTab(char ch, float mouseX, float mouseY) {
    16771703                return insertText("" + ch, mouseX, mouseY);
    16781704        }
    16791705
    1680         public Point removeTab(char ch, int mouseX, int mouseY) {
     1706        public Point2D.Float removeTab(char ch, float mouseX, float mouseY) {
    16811707                // Insert a space as a flag that it is a backwards tab
    16821708                return insertText(ch + " ", mouseX, mouseY);
    16831709        }
     1710
     1711        @Override
     1712        public void setLink(String frame) {
     1713                // If a link is being removed or set then need to reset poly so the
     1714                // highlighting is drawn with the correct width
     1715                if (frame == null || getLink() == null)
     1716                        _poly = null;
     1717                super.setLink(frame);
     1718        }
    16841719}
  • trunk/src/org/expeditee/simple/Context.java

    r97 r108  
    77import java.io.FileWriter;
    88
     9import org.expeditee.actions.Simple;
    910import org.expeditee.gui.Frame;
    1011import org.expeditee.gui.FrameGraphics;
     
    236237                        success = false;
    237238                }
    238                 if (!success)
     239                if (!success && Simple.isVerbose())
    239240                        FrameGraphics.WarningMessage("Error creating " + framesetName);
    240241                if (successVar != null) {
  • trunk/src/org/expeditee/simple/Primitives.java

    r87 r108  
    180180        }
    181181
     182        /**
     183         * Adds two variables to gether returning the value in the first.
     184         * @param toSet
     185         * @param amount
     186         * @throws Exception
     187         */
    182188        public void add(String toSet, String amount) throws Exception {
    183189                setValue(toSet, new SReal(getVariable(toSet).doubleValue()
Note: See TracChangeset for help on using the changeset viewer.