Changeset 50


Ignore:
Timestamp:
05/16/08 10:25:28 (16 years ago)
Author:
ra33
Message:

A whole day of big changes.
Adding the ability to have Text at the end of Lines.
Also a lot of refactoring to improve the quality of code relating to constraints and lines

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

Legend:

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

    r42 r50  
    99import java.util.LinkedList;
    1010import java.util.List;
     11import java.util.Random;
    1112
    1213import org.expeditee.agents.DisplayTree;
     
    2627import org.expeditee.items.Line;
    2728import org.expeditee.items.Text;
     29import org.expeditee.items.Item.SelectedMode;
    2830import org.expeditee.simple.BelowMinParametreCountException;
    2931import org.expeditee.simple.Context;
     
    206208                        }
    207209                }
    208 
     210                // The statement below assumes there are no other programs running at
     211                // the same time
     212                assert (_programsRunning == 0);
    209213                // Report the number of test passed and failed
    210214                FrameGraphics.DisplayMessage("Total tests: "
     
    239243
    240244        private static void FlagError(Item item) {
    241                 // item.setColor(Color.CYAN);
    242245                FrameUtils.DisplayFrame(item.getParent().getFrameName(), true);
     246                item.setSelectedMode(SelectedMode.Normal);
    243247                item.setSelectionColor(Color.CYAN);
    244248                FrameIO.SaveFrame(item.getParent());
     
    349353                                                                endOfToken + 1));
    350354                                        } else {
    351                                                 throw new Exception("Expected matching \" "
    352                                                                 + code.toString());
     355                                                throw new RuntimeException("Expected matching \" ");
    353356                                        }
    354357                                        break;
     
    745748                                        throw new UnitTestFailedException("false", "true");
    746749                                return Status.OK;
     750                        }
     751                        if (tokens[0].equals("assertfail")) {
     752                                assertExactParametreCount(tokens, 0);
     753                                throw new UnitTestFailedException("pass", "fail");
    747754                        } else if (tokens[0].equals("assertnull")) {
    748755                                assertExactParametreCount(tokens, 1);
     
    10421049
    10431050                                return Status.OK;
     1051                        } else if (tokens[0].equals("getrandominteger")) {
     1052                                assertExactParametreCount(tokens, 3);
     1053                                int lowerBound = (int) context.getPrimitives().getIntegerValue(
     1054                                                tokens[1]);
     1055                                int upperBound = (int) context.getPrimitives().getIntegerValue(
     1056                                                tokens[2]);
     1057                                Random random = new Random();
     1058                                long result = Math.abs(random.nextInt())
     1059                                                % (upperBound - lowerBound) + lowerBound;
     1060                                context.getPrimitives().setValue(tokens[3],
     1061                                                new SInteger(result));
     1062                                return Status.OK;
     1063                        } else if (tokens[0].equals("getrandomreal")) {
     1064                                assertExactParametreCount(tokens, 3);
     1065                                double lowerBound = context.getPrimitives().getDoubleValue(
     1066                                                tokens[1]);
     1067                                double upperBound = context.getPrimitives().getDoubleValue(
     1068                                                tokens[2]);
     1069                                Random random = new Random();
     1070                                double result = random.nextDouble() * (upperBound - lowerBound)
     1071                                                + lowerBound;
     1072                                context.getPrimitives().setValue(tokens[3], new SReal(result));
     1073                                return Status.OK;
     1074                        } else if (tokens[0].equals("getrandomtextitem")) {
     1075                                assertExactParametreCount(tokens, 2);
     1076                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     1077                                assertVariableType(tokens[2], 2, SPointer.itemPrefix);
     1078                                List<Text> items = ((Frame) context.getPointers().getVariable(
     1079                                                tokens[1]).getValue()).getBodyTextItems(false);
     1080                                Random random = new Random();
     1081                                int itemIndex = random.nextInt(items.size());
     1082                                context.getPointers()
     1083                                                .setObject(tokens[2], items.get(itemIndex));
     1084                                return Status.OK;
    10441085                        }
    10451086                } else if (tokens[0].equals("or")) {
     
    11361177                        String command = getMessage(tokens, context, code.toString(), " ",
    11371178                                        1);
    1138                         Process p = Runtime.getRuntime().exec(command);
    1139                         FrameGraphics.DisplayMessage(command, Color.darkGray);
    1140                        
    1141                         BufferedReader stdInput = new BufferedReader(new InputStreamReader(
    1142                                         p.getInputStream()));
    1143                         BufferedReader stdError = new BufferedReader(new InputStreamReader(
    1144                                         p.getErrorStream()));
    1145                         String message = "";
    1146                         while ((message = stdInput.readLine()) != null) {
    1147                                 FrameGraphics.DisplayMessage(message);
    1148                         }
    1149                         while ((message = stdError.readLine()) != null) {
    1150                                 FrameGraphics.ErrorMessage(message);
     1179                        try {
     1180                                Process p = Runtime.getRuntime().exec(command);
     1181                                FrameGraphics.DisplayMessage(command, Color.darkGray);
     1182
     1183                                BufferedReader stdInput = new BufferedReader(
     1184                                                new InputStreamReader(p.getInputStream()));
     1185                                BufferedReader stdError = new BufferedReader(
     1186                                                new InputStreamReader(p.getErrorStream()));
     1187                                String message = "";
     1188                                while ((message = stdInput.readLine()) != null) {
     1189                                        FrameGraphics.DisplayMessage(message);
     1190                                }
     1191                                while ((message = stdError.readLine()) != null) {
     1192                                        FrameGraphics.ErrorMessage(message);
     1193                                }
     1194                        } catch (Exception e) {
     1195                                throw new RuntimeException(e.getMessage());
    11511196                        }
    11521197                        return Status.OK;
     
    16661711                                        DisplayIO.setCurrentFrame(frame);
    16671712                                        pause(thisFramesPause);
    1668                                        
     1713
    16691714                                        long freeMemory = runtime.freeMemory();
    1670                                         if(freeMemory < DisplayTree.GARBAGE_COLLECTION_THRESHOLD){
     1715                                        if (freeMemory < DisplayTree.GARBAGE_COLLECTION_THRESHOLD) {
    16711716                                                runtime.gc();
    1672                                                 FrameGraphics.DisplayMessage("Force Garbage Collection!");
     1717                                                FrameGraphics
     1718                                                                .DisplayMessage("Force Garbage Collection!");
    16731719                                        }
    16741720                                }
     
    16931739                        String fileName = context.getPrimitives().getStringValue(tokens[3]);
    16941740                        WriteTree wt = new WriteTree(format, fileName);
    1695                         if (wt.initialise(source)){
     1741                        if (wt.initialise(source)) {
    16961742                                wt.setStartFrame(source);
    16971743                                wt.run();
  • trunk/src/org/expeditee/agents/ComputeTree.java

    r45 r50  
    33import org.expeditee.gui.AttributeUtils;
    44import org.expeditee.gui.Frame;
    5 import org.expeditee.gui.FrameGraphics;
    65import org.expeditee.gui.FrameIO;
    76import org.expeditee.items.Item;
  • trunk/src/org/expeditee/agents/DefaultAgent.java

    r45 r50  
    11package org.expeditee.agents;
    22
    3 import org.expeditee.gui.DisplayIO;
    43import org.expeditee.gui.Frame;
    54import org.expeditee.gui.FrameGraphics;
  • trunk/src/org/expeditee/agents/DisplayTree.java

    r45 r50  
    44import org.expeditee.gui.Frame;
    55import org.expeditee.gui.FrameGraphics;
    6 import org.expeditee.gui.FrameUtils;
    7 import org.expeditee.gui.TimeKeeper;
    86import org.expeditee.items.Item;
    97import org.expeditee.items.ItemUtils;
  • trunk/src/org/expeditee/agents/SwitchyardTree.java

    r45 r50  
    55
    66import org.expeditee.gui.Frame;
    7 import org.expeditee.gui.FrameGraphics;
    87import org.expeditee.gui.FrameIO;
    98import org.expeditee.items.Text;
  • trunk/src/org/expeditee/agents/TreeProcessor.java

    r45 r50  
    44import java.util.Stack;
    55
    6 import org.expeditee.gui.DisplayIO;
    76import org.expeditee.gui.Frame;
    87import org.expeditee.gui.FrameIO;
  • trunk/src/org/expeditee/agents/WriteTree.java

    r45 r50  
    66
    77import org.expeditee.actions.Actions;
    8 import org.expeditee.gui.DisplayIO;
    98import org.expeditee.gui.Frame;
    109import org.expeditee.gui.FrameGraphics;
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r48 r50  
    6666                        _GetMethods = new LinkedList<Method>();
    6767                        _GetMethods.add(Item.class.getMethod("getDateCreated", param));
    68                        
     68
    6969                        _GetMethods.add(Item.class.getMethod("getColor", param));
    7070                        _GetMethods.add(Item.class.getMethod("getBackgroundColor", param));
     
    7474                        _GetMethods.add(Item.class.getMethod("getFillPattern", param));
    7575                        _GetMethods.add(Item.class.getMethod("getThickness", param));
    76                        
     76
    7777                        _GetMethods.add(Item.class.getMethod("getOwner", param));
    7878                        _GetMethods.add(Item.class.getMethod("getLinkMark", param));
     
    9999                        _GetMethods.add(Text.class.getMethod("getJustification", param));
    100100                        _GetMethods.add(Text.class.getMethod("getWidth", param));
    101                         _GetMethods.add(Text.class.getMethod("getSize", param));
     101                        _GetMethods.add(Item.class.getMethod("getSize", param));
    102102
    103103                        _GetMethods.add(Frame.class.getMethod("getOwner", param));
     
    111111                        Class[] pString = { String.class };
    112112                        Class[] pInt = { int.class };
     113                        Class[] pFloat = { float.class };
    113114                        Class[] pColor = { Color.class };
    114115                        Class[] pBool = { boolean.class };
     
    119120                        _SetMethods = new HashMap<String, Method>();
    120121
    121                         _SetMethods.put("size", Item.class.getMethod("setSize", pInt));
    122                         _SetMethods.put("s", Item.class.getMethod("setSize", pInt));
     122                        _SetMethods.put("thickness", Item.class.getMethod("setThickness",
     123                                        pFloat));
     124                        _SetMethods.put("t", Item.class.getMethod("setThickness", pFloat));
    123125
    124126                        _SetMethods.put("color", Item.class.getMethod("setColor", pColor));
     
    173175                        _SetMethods.put("family", Text.class
    174176                                        .getMethod("setFamily", pString));
    175                         _SetMethods.put("face", Text.class.getMethod("setFontStyle", pString));
    176                         _SetMethods.put("fontstyle", Text.class.getMethod("setFontStyle", pString));
     177                        _SetMethods.put("face", Text.class.getMethod("setFontStyle",
     178                                        pString));
     179                        _SetMethods.put("fontstyle", Text.class.getMethod("setFontStyle",
     180                                        pString));
    177181                        _SetMethods.put("justification", Text.class.getMethod(
    178182                                        "setJustification", pInt));
    179183                        _SetMethods.put("width", Text.class.getMethod("setWidth", pInt));
     184                        _SetMethods.put("size", Item.class.getMethod("setSize", pInt));
     185                        _SetMethods.put("s", Item.class.getMethod("setSize", pInt));
    180186
    181187                        _SetMethods.put("foregroundcolor", Frame.class.getMethod(
     
    548554
    549555                        try {
    550                                 Object[] params = Conversion.Convert(possible, value,
    551                                                 current);
     556                                Object[] params = Conversion.Convert(possible, value, current);
    552557
    553558                                try {
     
    561566                                        e.printStackTrace();
    562567                                } catch (InvocationTargetException e) {
    563                                         // TODO Auto-generated catch block
    564                                         e.printStackTrace();
     568                                        FrameGraphics.DisplayMessage(toSet.getClass()
     569                                                        .getSimpleName()
     570                                                        + " type does not support that attribute.");
     571                                        // e.printStackTrace();
    565572                                }
    566573                        } catch (NumberFormatException e) {
     
    620627        public static void setSingleValue(Text text, String value) {
    621628                assert (value != null);
    622                
     629
    623630                String oldText = text.getTextNoList();
    624631                String attribute = stripAttribute(oldText);
  • trunk/src/org/expeditee/gui/Browser.java

    r25 r50  
    138138
    139139                DisplayIO.setCurrentFrame(firstFrame);
     140                DisplayIO.UpdateTitle();
    140141
    141142                FrameKeyboardActions keyboardListner = new FrameKeyboardActions();
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r34 r50  
    6060         * The title to display in the Title bar.
    6161         */
    62         public static final String TITLE = "Exp13May2008A";
     62        public static final String TITLE = "Exp15May2008A";
    6363
    6464        private DisplayIO() {
  • trunk/src/org/expeditee/gui/Frame.java

    r47 r50  
    231231        public List<Text> getBodyTextItems(boolean includeAnnotations) {
    232232                List<Text> bodyTextItems = new ArrayList<Text>();
    233                 Text frameTitle = getTitle();
    234 
    235233                for (Item i : getItems()) {
    236234                        // only add up normal body text items
     
    426424
    427425                for (Item i : _body)
    428                         if (i.isVisible() && i != _frameName && i.intersects(poly)) {
     426                        if (i.isVisible() /*&& i != _frameName*/ && i.intersects(poly)) {
    429427                                if (!results.contains(i))
    430428                                        results.add(i);
     
    730728                                        line.getStartItem().addLine(line);
    731729                                        line.getEndItem().addLine(line);
     730                                } else {
     731                                        i.setOffset(0, 0);
    732732                                }
    733733                        }
     
    11331133
    11341134        /**
    1135          * Creates a new Text Item with no text. The newly created Item is a copy
    1136          * the ItemTemplate if one is present, and inherits all the attributes of
    1137          * the Template
    1138          *
    1139          * @return The newly created Text Item
     1135         * Creates a new text item with the given text.
     1136         * @param text
     1137         * @return
    11401138         */
    11411139        public Text createNewText(String text) {
     
    11451143        }
    11461144
     1145        /**
     1146         * Creates a new Text Item with no text. The newly created Item is a copy
     1147         * the ItemTemplate if one is present, and inherits all the attributes of
     1148         * the Template
     1149         *
     1150         * @return The newly created Text Item
     1151         */
    11471152        public Text createBlankText(String templateType) {
    11481153                Text t;
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r24 r50  
    1616import org.expeditee.actions.Simple;
    1717import org.expeditee.io.Logger;
     18import org.expeditee.items.Constraint;
    1819import org.expeditee.items.Dot;
    1920import org.expeditee.items.Item;
     
    121122                // check for dot's being replaced with text
    122123                if (on != null && on instanceof Dot) {
     124                        if (ch == KeyEvent.VK_BACK_SPACE || ch == KeyEvent.VK_DELETE) {
     125                                return;
     126                        }
    123127                        replaceDot((Dot) on, ch);
     128                        ItemUtils.EnclosedCheck(DisplayIO.getCurrentFrame().getItems());
    124129                        return;
    125130                }
     
    183188        }
    184189
    185         private static void replaceDot(Dot dot, char ch) {
     190        public static Text replaceDot(Dot dot, char ch) {
    186191                SessionStats.CreatedItem();
    187192                Text text = createText(ch);
     193                text.setPosition(dot.getPosition());
     194                text.setThickness(dot.getThickness());
    188195                FrameUtils.LastEdited = text;
    189196
    190                 List<Line> lines = new LinkedList<Line>();
    191                 lines.addAll(dot.getLines());
     197                //Copy the lines list so it can be modified
     198                List<Line> lines = new LinkedList<Line>(dot.getLines());
    192199                for (Line line : lines)
    193200                        line.replaceEnd(dot, text);
    194 
    195                 dot.removeAllLines();
     201               
    196202                DisplayIO.getCurrentFrame().removeItem(dot);
    197203                DisplayIO.getCurrentFrame().addItem(text);
    198                 return;
     204                return text;
    199205        }
    200206
     
    206212                List<Line> lines = new LinkedList<Line>();
    207213                lines.addAll(text.getLines());
    208                 for (Line line : lines)
     214                if (lines.size() > 0)
     215                        dot.setColor(lines.get(0).getColor());
     216                for (Line line : lines){
    209217                        line.replaceEnd(text, dot);
    210                 text.removeAllLines();
    211 
    212                 DisplayIO.getCurrentFrame().removeItem(text);
     218                }
     219                text.delete();
    213220                DisplayIO.getCurrentFrame().addItem(dot);
    214221                DisplayIO.setCursor(Item.DEFAULT_CURSOR);
     
    576583                        if (enclosed != null && enclosed.size() > 0) {
    577584                                // ensure only one dot\line is present in the list
    578                                 List<Dot> dots = FrameUtils.getEnclosingDots();
     585                                List<Item> dots = FrameUtils.getEnclosingDots();
    579586                                List<Item> connected = dots.get(0).getAllConnected();
    580587
     
    621628
    622629                                if (key == COLOR_CHANGE && connected.size() > 0) {
    623                                         for (Dot d : dots) {
     630                                        for (Item d : dots) {
    624631                                                SetFillColor(d);
    625632                                                break;
     
    743750                dummyItem = createText();
    744751                if (Frame.textItemAttachedToCursor()) {
    745                         Text t = (Text)Frame.getItemAttachedToCursor();
     752                        Text t = (Text) Frame.getItemAttachedToCursor();
    746753                        dummyItem.setSize(t.getSize());
    747754                        for (int i = 0; i < t.getText().size(); i++) {
     
    987994         */
    988995        private static void SetSize(Item ip, int diff, boolean moveCursor) {
    989                 List<Item> toSize;
     996                List<Item> toSize = new ArrayList<Item>();
    990997                // the mouse is only moved when the Item is on the frame, not free
    991998                // boolean moveMouse = false;
     
    9951002                if (ip == null) {
    9961003                        if (Frame.itemAttachedToCursor())
    997                                 toSize = new ArrayList<Item>(Frame.FreeItems);
     1004                                toSize.addAll(Frame.FreeItems);
    9981005                        else {
    9991006                                FrameGraphics
     
    10091016                        }
    10101017                        toSet = ip;
    1011 
    1012                         toSize = toSet.getConnected();
    1013                         // moveMouse = true;
     1018                        Item currentItem = FrameUtils.getCurrentItem();
     1019
     1020                        if (currentItem != null && (currentItem instanceof Text)
     1021                                        && FrameUtils.getCurrentItems() == null) {
     1022                                toSize.add(currentItem);
     1023                        } else {
     1024                                toSize.addAll(toSet.getLines());
     1025                        }
    10141026                }
    10151027
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r47 r50  
    1313import java.util.List;
    1414
    15 import javax.swing.SwingUtilities;
    1615import javax.swing.Timer;
    1716
    1817import org.expeditee.actions.Actions;
    1918import org.expeditee.actions.NavigationActions;
    20 import org.expeditee.agents.Format;
    2119import org.expeditee.items.Constraint;
    2220import org.expeditee.items.Dot;
     
    223221
    224222                _lastClickedIn = FrameUtils.getCurrentItems();
     223                // if (_lastClickedIn != null){
     224                // System.out.println(_lastClickedIn.size());}
    225225
    226226                SessionStats.MouseClicked(e.getButton());
     
    632632                Item attachedToCursor = Frame.getItemAttachedToCursor();
    633633
    634                 if (clicked instanceof Text && !(attachedToCursor instanceof Text)) {
     634                if (clicked instanceof Text
     635                                && !(attachedToCursor instanceof Text || attachedToCursor
     636                                                .isLineEnd())) {
    635637                        return false;
    636638                }
     
    692694                                        if (toDisconnect != null) {
    693695                                                if (toDisconnect.getSelectedMode() == Item.SelectedMode.Normal) {
     696                                                        DisplayIO.setCursorPosition(toDisconnect
     697                                                                        .getPosition(), false);
    694698                                                        pickup(toDisconnect);
    695699                                                        return;
    696700                                                } else {
    697701                                                        List<Line> lines = toDisconnect.getLines();
     702                                                        // This is to remove constraints from single lines
     703                                                        // with constraints...
     704                                                        // ie. partially deleted rectangles
    698705                                                        if (lines.size() == 1) {
    699                                                                 // remove constraints
    700706                                                                toDisconnect.removeAllConstraints();
    701707
     
    706712                                                        }
    707713                                                        // If we are then detatch the line and pick up its
    708                                                         // end
    709                                                         // point...
     714                                                        // end point...
    710715                                                        Frame currentFrame = DisplayIO.getCurrentFrame();
    711                                                         Item newPoint = toDisconnect.copy();
    712                                                         newPoint.setID(currentFrame.getNextItemID());
     716                                                        Item newPoint = null;
     717
     718                                                        // If the point we are disconnecting is text...
     719                                                        // Then we want to leave the text behind
     720                                                        // And disconnect a point
     721                                                        if (toDisconnect instanceof Text) {
     722                                                                newPoint = new Dot(toDisconnect.getX(),
     723                                                                                toDisconnect.getY(), -1);
     724                                                                Item.DuplicateItem(toDisconnect, newPoint);
     725                                                        } else {
     726                                                                newPoint = toDisconnect.copy();
     727                                                        }
     728
    713729                                                        currentFrame.addItem(newPoint);
    714730                                                        // remove the current item from the connected
    715731                                                        // list for this item
    716                                                         for (Item i : lines) {
    717                                                                 if (i == l) {
    718                                                                         toDisconnect.removeLine(l);
    719                                                                         break;
    720                                                                 }
    721                                                         }
    722                                                         if (toDisconnect == l.getStartItem()) {
    723                                                                 l.setStartItem(newPoint);
    724                                                         } else {
    725                                                                 l.setEndItem(newPoint);
    726                                                         }
    727 
     732                                                        l.replaceEnd(toDisconnect, newPoint);
    728733                                                        // remove unneeded constrains
    729                                                         List<Constraint> constraints = toDisconnect
    730                                                                         .getConstraints();
    731                                                         if (constraints != null) {
    732                                                                 for (Constraint c : constraints) {
    733                                                                         Item oppositeEnd = l
    734                                                                                         .getOppositeEnd(newPoint);
    735                                                                         if (c.contains(oppositeEnd)) {
    736                                                                                 toDisconnect.removeConstraint(c);
    737                                                                                 oppositeEnd.removeConstraint(c);
    738                                                                                 break;
    739                                                                         }
    740                                                                 }
    741                                                         }
     734                                                        newPoint.removeAllConstraints();
    742735
    743736                                                        toDisconnect
     
    746739                                                                        .getPosition(), false);
    747740                                                        pickup(newPoint);
    748 
     741                                                        ItemUtils.EnclosedCheck(toDisconnect.getCurrentFrame().getItems());
    749742                                                        return;
    750743                                                }
    751744                                        }
    752745                                }
    753 
     746                                if (clicked.isLineEnd())
     747                                        DisplayIO.setCursorPosition(clicked.getPosition(), false);
    754748                                pickup(clicked);
    755749                                return;
     
    12281222                                if (Frame.FreeItems.size() == 2 && on instanceof Line) {
    12291223                                        Line line = (Line) on;
    1230                                         if (Frame.FreeItems.get(0) instanceof Dot)
    1231                                                 line.showVirtualSpot((Dot) Frame.FreeItems.get(0),
    1232                                                                 DisplayIO.getMouseX(), DisplayIO.getMouseY());
    1233                                         else if (Frame.FreeItems.get(1) instanceof Dot)
    1234                                                 line.showVirtualSpot((Dot) Frame.FreeItems.get(1),
    1235                                                                 DisplayIO.getMouseX(), DisplayIO.getMouseY());
     1224                                        if (Frame.FreeItems.get(0).isLineEnd())
     1225                                                line.showVirtualSpot(Frame.FreeItems.get(0), DisplayIO
     1226                                                                .getMouseX(), DisplayIO.getMouseY());
     1227                                        else if (Frame.FreeItems.get(1).isLineEnd())
     1228                                                line.showVirtualSpot(Frame.FreeItems.get(1), DisplayIO
     1229                                                                .getMouseX(), DisplayIO.getMouseY());
    12361230                                        else
    12371231                                                // The user is pointing at another point or text item
     
    12421236                                        // FrameGraphics.ChangeSelectionMode(on,
    12431237                                        // Item.SelectedMode.Connected);
     1238                                        // TODO: The method below is for the most part redundant
    12441239                                        FrameGraphics.Highlight(on);
    12451240                                }
     
    12561251                                // highlighting
    12571252                        } else if (on == null) {
    1258                                 List<Dot> enclosure = FrameUtils.getEnclosingDots();
     1253                                List<Item> enclosure = FrameUtils.getEnclosingDots();
    12591254                                if (enclosure != null && enclosure.size() > 1) {
    12601255                                        if (enclosure.get(0).getLines().size() > 1 &&
     
    12891284                if (Frame.itemAttachedToCursor()) {
    12901285                        move(Frame.FreeItems);
     1286                        // System.out.println(Frame.FreeItems.size());
    12911287                }
    12921288
     
    13001296        }
    13011297
    1302         private boolean ContainsOneOf(List<Dot> enclosure, List<Item> freeItems) {
     1298        private boolean ContainsOneOf(List<Item> enclosure, List<Item> freeItems) {
    13031299                if (freeItems == null)
    13041300                        return false;
     
    13111307
    13121308        /**
     1309         * Checks if lines are being rubber banded.
     1310         *
     1311         * @return true if the user is rubberBanding one or more lines
     1312         */
     1313        private static boolean rubberBanding() {
     1314                if (Frame.FreeItems.size() < 2) {
     1315                        return false;
     1316                }
     1317
     1318                // if rubber-banding, there will be 1 lineend and the rest will be lines
     1319                boolean foundLineEnd = false;
     1320                for (Item i : Frame.FreeItems) {
     1321                        if (i.isLineEnd()) {
     1322                                if (foundLineEnd) {
     1323                                        return false;
     1324                                }
     1325                                foundLineEnd = true;
     1326                        } else if (!(i instanceof Line)) {
     1327                                return false;
     1328                        }
     1329                }
     1330                return true;
     1331        }
     1332
     1333        /**
    13131334         * Updates the current mouse cursor to whatever it should be. i.e. Hidden
    13141335         * when rubber-banding lines, otherwise default (arrow)
    13151336         */
    13161337        private static void updateCursor() {
    1317                 // if rubber-banding, there will be exactly 2 items on the cursor
    1318                 if (Frame.FreeItems.size() != 2)
     1338                if (rubberBanding()) {
     1339                        DisplayIO.setCursor(Item.HIDDEN_CURSOR);
     1340                } else {
    13191341                        DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    1320                 else {
    1321                         Dot d = null;
    1322                         // check that it is indeed a line being rubber-banded
    1323                         if (Frame.FreeItems.get(0) instanceof Line
    1324                                         && Frame.FreeItems.get(1) instanceof Dot)
    1325                                 d = (Dot) Frame.FreeItems.get(1);
    1326                         else if (Frame.FreeItems.get(1) instanceof Line
    1327                                         && Frame.FreeItems.get(0) instanceof Dot)
    1328                                 d = (Dot) Frame.FreeItems.get(0);
    1329 
    1330                         if (d != null) {
    1331                                 DisplayIO.setCursor(Item.HIDDEN_CURSOR);
    1332                         } else
    1333                                 DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    1334                 }
    1335 
     1342                }
    13361343        }
    13371344
     
    15781585                        List<Item> toUndo = new LinkedList<Item>();
    15791586
    1580                         if (toDelete instanceof Dot) {
    1581                                 toUndo.addAll(deleteDot((Dot) toDelete));
     1587                        if (toDelete.isLineEnd()) {
     1588                                toUndo.addAll(deleteDot(toDelete));
    15821589                        } else
    15831590                                toUndo.addAll(copy(toDelete.getConnected()));
     
    16011608                List<Item> seen = new LinkedList<Item>();
    16021609
     1610                // Mike: Removed code that checked for rectangles and removed them
     1611                // completely!!
     1612
    16031613                // disconnect any connected items
    16041614                for (Item i : itemList) {
    16051615                        if (i.getLines().size() > 0) {
    1606 
    1607                                 // check for rectangle deletion
    1608                                 if (itemList.size() == 3) {
    1609                                         boolean rectangle = false;
    1610                                         // check that this is indeed a rectangle
    1611                                         for (Item check : itemList)
    1612                                                 if (check != i && !i.getLines().contains(check)) {
    1613                                                         rectangle = false;
    1614                                                         break;
    1615                                                 } else
    1616                                                         rectangle = true;
    1617 
    1618                                         // if this is a rectangle, remove the entire
    1619                                         // rectangle
    1620                                         if (rectangle) {
    1621                                                 List<Item> copy = copy(i.getAllConnected());
    1622                                                 current.addAllToUndo(copy);
    1623                                                 current.removeAllItems(i.getAllConnected());
    1624                                                 itemList.clear();
    1625                                                 // reset the mouse cursor
    1626                                                 updateCursor();
    1627                                                 FrameGraphics.Repaint();
    1628                                                 return;
    1629                                         }
    1630                                 }
    1631 
    1632                                 List<Item> copy = deleteDot((Dot) i);
     1616                                List<Item> copy = deleteDot(i);
    16331617                                // add the copied items to the undo stack
    16341618                                for (Item cop : copy)
     
    16661650        }
    16671651
    1668         private static List<Item> deleteDot(Dot dot) {
     1652        private static List<Item> deleteDot(Item dot) {
    16691653
    16701654                if (dot instanceof WidgetCorner) { // Brook
     
    17501734                        Dot dot = null;
    17511735                        // check that this is indeed a rectangle
     1736                        // This wont work now that corners can be Text items
    17521737                        for (Item check : merger) {
    1753                                 if (dot == null && check instanceof Dot)
     1738                                if (dot == null && check.isLineEnd())
    17541739                                        dot = (Dot) check;
    17551740                                else if (check != dot && !dot.getLines().contains(check)) {
     
    17861771                                        mergee.removeAllConstraints();
    17871772                                        mergee.removeAllLines();
     1773                                        mergee.setThickness(4 * mergee.getThickness());
    17881774                                        return mergee.getAllConnected();
    17891775                                } else {
     
    18191805                        } else {
    18201806                                // check for attribute merging
    1821                                 if (i instanceof Text) {
     1807                                if (i instanceof Text && !i.isLineEnd()) {
    18221808                                        Text txt = (Text) i;
    18231809
     
    18261812                                                // set mouse position for text merges
    18271813                                                if (mergee instanceof Text)
    1828                                                         // 18Feb Rob doesnt want cursor to jump when
    1829                                                         // inserting text
    18301814                                                        ((Text) mergee).insertText(txt.getTextNoList(),
    18311815                                                                        DisplayIO.getMouseX(), DisplayIO
     
    18331817
    18341818                                                else if (mergee instanceof Dot) {
    1835                                                         mergee.getParent().removeItem(mergee);
     1819                                                        txt.setPosition(mergee.getPosition());
     1820                                                        txt.setThickness(mergee.getThickness());
     1821                                                        Frame parent = mergee.getParent();
     1822                                                        parent.removeItem(mergee);
     1823                                                        anchor(txt);
     1824                                                        // change the end points of the lines to the text
     1825                                                        // item
     1826                                                        while (mergee.getLines().size() > 0) {
     1827                                                                Line l = mergee.getLines().get(0);
     1828                                                                l.replaceEnd(mergee, txt);
     1829                                                        }
    18361830                                                        break;
    18371831                                                }
     
    18981892                        Frame.FreeItems.add(i);
    18991893
    1900                         if (i instanceof Dot)
    1901                                 ((Dot) i).setFloating(true);
     1894                        i.setFloating(true);
    19021895                }
    19031896
     
    19681961
    19691962        public static void anchor(Item toAnchor) {
    1970                 // System.out.println("Anchor:" + toAnchor.getX() + "," +
    1971                 // toAnchor.getY());
    1972 
    1973                 Frame current = null;
    1974 
    1975                 // if the item is from an overlay the parent will NOT be null
    1976                 if (toAnchor.getParent() == null) {
    1977                         current = DisplayIO.getCurrentFrame();
    1978                 } else {
    1979                         current = toAnchor.getParent();
    1980                 }
    1981                 // update the items ID to prevent conflicts with the current frame
    1982                 //if (toAnchor.getID() < 0 || current.getItems().contains(toAnchor))
    1983                 //      ;
    1984                 toAnchor.setID(current.getNextItemID());
    1985                 toAnchor.setOffset(0, 0);
    1986                 toAnchor.setParent(current);
    1987 
    1988                 current.addItem(toAnchor);
    1989                 current.setResort(true);
    1990 
    1991                 toAnchor.setRelativeLink();
    1992 
    1993                 if (toAnchor instanceof Dot) {
    1994                         for (Line line : ((Dot) toAnchor).getLines()) {
    1995                                 if (line.getID() < 0 && !current.getItems().contains(line)) {
    1996                                         line.setID(current.getNextItemID());
    1997                                         line.setSelectionColor();
    1998                                         // Mike: Why was this line here?
    1999                                         // anchor(line);
    2000                                 }
    2001                         }
    2002                         ((Dot) toAnchor).setFloating(false);
    2003                 } else if (toAnchor instanceof Text) {
    2004                         // ensure all text items have their selection cleared
    2005                         ((Text) toAnchor).clearSelection();
    2006                         ((Text) toAnchor).setAlpha(0);
    2007                 } else if (toAnchor instanceof Line) {
    2008                         ((Line) toAnchor).fixArrowheadLength();
    2009                 }
     1963                toAnchor.anchor();
    20101964
    20111965                FrameGraphics.Repaint();
    2012                 ItemUtils.EnclosedCheck(current.getItems());
     1966                ItemUtils.EnclosedCheck(toAnchor.getCurrentFrame().getItems());
    20131967        }
    20141968
     
    20492003                                        else
    20502004                                                line.toggleArrowHeadLength(arg0.getWheelRotation());
    2051                                         line.getParent().change();
     2005                                        // line.getParent().change();
    20522006                                        FrameGraphics.Repaint();
    20532007                                }
     
    20612015
    20622016                        Item ip = FrameUtils.getCurrentItem();
    2063                         if (ip != null && clicks > 1)
     2017                        if (ip != null && clicks > 1) {
     2018                                float size = ip.getSize();
     2019                                if (ip instanceof Dot || ip instanceof Line)
     2020                                        size = ip.getThickness();
    20642021                                // base the number of clicks on the size of the object
    2065                                 clicks = (int) Math.ceil(ip.getSize() / 20.0 * clicks);
     2022                                clicks = (int) Math.ceil(size / 20.0 * clicks);
     2023                        }
    20662024
    20672025                        FrameKeyboardActions.functionKey(rotationType, clicks);
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r36 r50  
    10711071        public static List<Item> getCurrentItems() {
    10721072
    1073                 List<Dot> enclosure = getEnclosingDots();
     1073                List<Item> enclosure = getEnclosingDots();
    10741074                if (enclosure == null || enclosure.size() == 0)
    10751075                        return null;
     
    10851085        }
    10861086
    1087         public static List<Dot> getEnclosingDots() {
     1087        public static List<Item> getEnclosingDots() {
    10881088                // update enclosed shapes
    10891089                Frame current = DisplayIO.getCurrentFrame();
    10901090                List<Item> items = current.getItems();
    10911091
    1092                 ArrayList<Dot> used = new ArrayList<Dot>(0);
    1093                 ArrayList<Dot> seen = new ArrayList<Dot>(0);
     1092                ArrayList<Item> used = new ArrayList<Item>(0);
     1093                ArrayList<Item> seen = new ArrayList<Item>(0);
    10941094
    10951095                for (Item i : items)
    1096                         if (i instanceof Dot) {
    1097                                 Dot d = (Dot) i;
    1098                                 if (d.isEnclosed() && !seen.contains(d)) {
    1099                                         Polygon p = d.getEnclosedShape();
     1096                        if (i.isLineEnd()) {
     1097                                if (i.isEnclosed() && !seen.contains(i)) {
     1098                                        Polygon p = i.getEnclosedShape();
    11001099                                        if (p
    11011100                                                        .contains(DisplayIO.getMouseX(), DisplayIO
    11021101                                                                        .getMouseY())) {
    11031102
    1104                                                 used.add(d);
    1105                                                 seen.addAll(d.getEnclosingDots());
     1103                                                used.add(i);
     1104                                                seen.addAll(i.getEnclosingDots());
    11061105                                        }
    11071106                                }
     
    11161115                        // otherwise, determine which polygon is closest to the cursor
    11171116                } else {
    1118                         Collections.sort(used, new Comparator<Dot>() {
    1119                                 public int compare(Dot d1, Dot d2) {
     1117                        Collections.sort(used, new Comparator<Item>() {
     1118                                public int compare(Item d1, Item d2) {
    11201119                                        Polygon p1 = d1.getEnclosedShape();
    11211120                                        Polygon p2 = d2.getEnclosedShape();
  • trunk/src/org/expeditee/io/ExpReader.java

    r4 r50  
    3737
    3838        private String _frameName;
    39        
     39
    4040        /**
    4141         * Does nothing, location must be set before use
     
    4343        public ExpReader(String frameName) {
    4444                _frameName = frameName;
    45                
     45
    4646                if (_ItemTags != null && _FrameTags != null)
    4747                        return;
    48                
     48
    4949                _ItemTags = new LinkedHashMap<Character, Method>();
    5050                _FrameTags = new LinkedHashMap<Character, Method>();
     
    123123                        _ItemTags.put('k', Text.class.getMethod("setJustification", pInt));
    124124
    125                         _ItemTags.put('h', Dot.class.getMethod("setThickness", pFloat));
     125                        _ItemTags.put('h', Item.class.getMethod("setThickness", pFloat));
    126126                        _ItemTags.put('l', Item.class.getMethod("setLineIDs", pString));
    127                         _ItemTags
    128                                         .put('c', Dot.class.getMethod("setConstraintIDs", pString));
     127                        _ItemTags.put('c', Item.class
     128                                        .getMethod("setConstraintIDs", pString));
    129129
    130130                        // Lines and constraints are created differently
     
    164164
    165165                try {
    166                         //Framename must be set before setting the frame number
     166                        // Framename must be set before setting the frame number
    167167                        newFrame.setFrameName(_frameName);
    168                        
     168
    169169                        // First read all the header lines
    170170                        while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) {
     
    173173                                }
    174174                        }
    175                        
     175
    176176                        // Now read all the items
    177177                        Item currentItem = null;
    178178                        while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) {
    179179                                // if this is the start of a new item add a new item
    180                                 if (isValidLine(next) ) {
     180                                if (isValidLine(next)) {
    181181                                        if (getTag(next) == 'S') {
    182182                                                String value = getValue(next);
    183183                                                int id = Integer.parseInt(value.substring(2));
    184                                                
     184
    185185                                                switch (value.charAt(0)) {
    186                                                 case 'P': //check if its a point
     186                                                case 'P': // check if its a point
    187187                                                        currentItem = new Dot(id);
    188                                                         _linePoints.put(currentItem.getID(), currentItem);
    189188                                                        break;
    190189                                                default:
     
    192191                                                        break;
    193192                                                }
     193                                                _linePoints.put(currentItem.getID(), currentItem);
    194194                                                newFrame.addItem(currentItem);
    195195                                        } else if (currentItem != null) {
     
    232232                                        java.awt.Point startend = separateValues(next.substring(2));
    233233
    234                                         Dot a = (Dot) _linePoints.get(startend.x);
    235                                         Dot b = (Dot) _linePoints.get(startend.y);
     234                                        Item a = _linePoints.get(startend.x);
     235                                        Item b = _linePoints.get(startend.y);
    236236
    237237                                        new Constraint(a, b, idtype.x, idtype.y);
     
    276276                } catch (Exception e) {
    277277                        System.out.println("Error running tag method: " + tag);
    278                         //e.printStackTrace();
     278                        // e.printStackTrace();
    279279                }
    280280        }
     
    318318                        toRun.invoke(frame, vals);
    319319                } catch (Exception e) {
    320                         System.out.println("Error running method: " + toRun.toGenericString());
     320                        System.out.println("Error running method: "
     321                                        + toRun.toGenericString());
    321322                        e.printStackTrace();
    322323                }
  • trunk/src/org/expeditee/io/ExpWriter.java

    r10 r50  
    1212import org.expeditee.gui.Frame;
    1313import org.expeditee.items.Constraint;
    14 import org.expeditee.items.Dot;
    1514import org.expeditee.items.InteractiveWidget;
    1615import org.expeditee.items.Item;
     
    106105                        _ItemTags.put("k", Text.class.getMethod("getJustification", param));
    107106
    108                         _ItemTags.put("h", Dot.class.getMethod("getThickness", param));
    109                         _ItemTags.put("l", Dot.class.getMethod("getLineIDs", param));
    110                         _ItemTags.put("c", Dot.class.getMethod("getConstraintIDs", param));
     107                        _ItemTags.put("h", Item.class.getMethod("getThickness", param));
     108                        _ItemTags.put("l", Item.class.getMethod("getLineIDs", param));
     109                        _ItemTags.put("c", Item.class.getMethod("getConstraintIDs", param));
    111110
    112111                } catch (Exception e) {
     
    148147                // write out each Item in the Frame.
    149148                List<Item> items = frame.getItems();
    150                
     149
    151150                // iWidgets are handled specially since 8 items are written as one
    152151                List<InteractiveWidget> seenWidgets = new LinkedList<InteractiveWidget>();
     
    154153                // do not write items with ID -1, also skip any lines
    155154                for (Item i : items) {
    156                        
     155
    157156                        // Ensure only one of the WidgetCorners represent a single widget
    158157                        if (i instanceof WidgetCorner) {
    159                                 InteractiveWidget iw = ((WidgetCorner)i).getWidgetSource();
    160                                 if (seenWidgets.contains(iw)) continue;
     158                                InteractiveWidget iw = ((WidgetCorner) i).getWidgetSource();
     159                                if (seenWidgets.contains(iw))
     160                                        continue;
    161161                                seenWidgets.add(iw);
    162162                        }
    163        
     163
    164164                        if (i.getID() >= 0 && !(i instanceof Line)) {
    165165                                writeItem(i);
    166166                        }
    167167                }
    168                
     168
    169169                // write any lines or constraints
    170170                writeTerminator();
     
    172172                writeTerminator();
    173173                writeConstraintData();
    174                
     174
    175175                return;
    176176        }
     
    179179                Iterator<String> it = _FrameTags.keySet().iterator();
    180180                Object[] param = {};
    181                
     181
    182182                while (it.hasNext()) {
    183183                        String tag = it.next();
     
    217217
    218218        // writes the given Item out to the file
    219         //This method is not used to write out LINE items
     219        // This method is not used to write out LINE items
    220220        public void writeItem(Item item) throws IOException {
    221221                if (_writer == null)
     
    227227                else if (item instanceof WidgetCorner)
    228228                        item = ((WidgetCorner) item).getWidgetSource().getSource();
    229                
     229
    230230                if (item.getLines().size() > 0)
    231231                        writePoint(item);
     
    233233                        writeClass(item);
    234234                // lines are saved at the end of the file
    235                 //So dont worry about them in here
     235                // So dont worry about them in here
    236236                else
    237237                        System.out.println("Unknown Item: " + item.getID());
    238                
     238
    239239                writeLine("");
    240240        }
     
    259259                        if (lines != null && lines.size() > 0) {
    260260                                for (Line line : lines) {
    261                                        
     261
    262262                                        // Brook: widget edges are not saved
    263263                                        if (line instanceof WidgetEdge) {
     
    289289                        Item i = _points.get(0);
    290290
    291                         if (i instanceof Dot) {
    292                                 Dot p = (Dot) i;
    293 
    294                                 // if there are any constraints to write
    295                                 if (p.getConstraints() != null) {
    296                                         List<Constraint> constraints = p.getConstraints();
    297 
    298                                         // do not write constraints that have already been
    299                                         // written
    300                                         for (Constraint c : constraints) {
    301                                                 if (_points.contains(c.getStart())
    302                                                                 && _points.contains(c.getEnd())) {
    303                                                         writeLine("C", c.getID() + " "
    304                                                                         + c.getConstraintType());
    305                                                         writeLine("s", c.getLineEnds());
    306                                                         writeLine("");
    307                                                 }
    308 
     291                        // if there are any constraints to write
     292                        if (i.getConstraints() != null) {
     293                                List<Constraint> constraints = i.getConstraints();
     294
     295                                // do not write constraints that have already been
     296                                // written
     297                                for (Constraint c : constraints) {
     298                                        if (_points.contains(c.getStart())
     299                                                        && _points.contains(c.getEnd())) {
     300                                                writeLine("C", c.getID() + " " + c.getType());
     301                                                writeLine("s", c.getLineEnds());
     302                                                writeLine("");
    309303                                        }
     304
    310305                                }
    311306                        }
  • trunk/src/org/expeditee/io/KMSWriter.java

    r4 r50  
    339339                                                                && _points.contains(c.getEnd())) {
    340340                                                        writeLine("C", c.getID() + " "
    341                                                                         + c.getConstraintType());
     341                                                                        + c.getType());
    342342                                                        writeLine("s", c.getLineEnds());
    343343                                                }
  • trunk/src/org/expeditee/items/Constraint.java

    r4 r50  
    6060         *         constants defined in this class.
    6161         */
    62         public int getConstraintType() {
     62        public int getType() {
    6363                return _type;
    6464        }
     
    7272        }
    7373
    74         public boolean contains(Item d) {
    75                 if (_start == d || _end == d)
     74        public boolean contains(Item i) {
     75                if (_start == i || _end == i)
    7676                        return true;
    7777
     
    9797        }
    9898
    99         public void replacePoint(Dot toReplace, Dot with) {
    100                 if (_start == toReplace)
     99        public void replaceEnd(Item toReplace, Item with) {
     100                assert(_start != _end);
     101                if (_start == toReplace) {
    101102                        _start = with;
    102 
    103                 if (_end == toReplace)
     103                } else if (_end == toReplace) {
    104104                        _end = with;
     105                }
     106                toReplace.removeConstraint(this);
     107                with.addConstraint(this);
    105108        }
    106109
  • trunk/src/org/expeditee/items/Dot.java

    r24 r50  
    11package org.expeditee.items;
    22
     3import java.awt.Color;
    34import java.awt.Graphics2D;
    45import java.awt.Polygon;
     
    78import java.util.LinkedList;
    89import java.util.List;
     10
     11import org.expeditee.gui.Frame;
    912
    1013/**
     
    2225        private static final int _MINIMUM_DOT_SIZE = 6;
    2326
    24         // contains all dots (including this one) that form an enclosure
    25         // if this dot is part of an enclosing shape
    26         private List<Dot> _enclosure = null;
    27 
    2827        // the polygon surrounding this point, used for 'gravity'
    2928        private Polygon _poly = null;
    30 
    31         // The thickness (in pixels) of this Point
    32         private float _thickness = -1;
    3329
    3430        private int _pointType = Item.POINTTYPE_SQUARE;
     
    8278        @Override
    8379        public void setThickness(float thick) {
    84                 _thickness = thick;
     80                super.setThickness(thick);
    8581
    8682                updatePolygon();
    87 
    88                 // update the size of any lines
     83        }
     84       
     85        @Override
     86        public void setColor(Color c) {
     87                super.setColor(c);
     88
     89                // update the colour of any lines
    8990                for (Line line : getLines())
    90                         line.setThickness(thick);
    91         }
    92 
    93         /**
    94          * Returns the thickness (in pixels) of this Dot.
    95          *
    96          * @return The 'thickness' of this Dot. (returns -1 if the thickness is not
    97          *         set).
    98          */
    99         @Override
    100         public float getThickness() {
    101                 return _thickness;
     91                        line.setColor(c);
    10292        }
    10393
     
    134124                g.setColor(getPaintColor());
    135125
    136                 int thick = (int) _thickness;
     126                int thick = (int) getThickness();
    137127                if (thick < 2)
    138128                        thick = 2;
     
    216206
    217207        @Override
    218         public int getSize() {
    219                 return (int) getThickness();
    220         }
    221 
    222         @Override
    223         public void setSize(int size) {
    224         }
    225 
    226         @Override
    227208        public void setAnnotation(boolean val) {
    228209        }
     
    277258
    278259                if (merger instanceof Text) {
     260                        merger.setPosition(this.getPosition());
    279261                        List<Line> lines = new LinkedList<Line>();
    280262                        lines.addAll(getLines());
    281263                        for (Line line : lines)
    282264                                line.replaceEnd(this, merger);
    283 
    284                         removeAllLines();
     265                        this.delete();
    285266                        return merger;
    286267                }
     
    300281        }
    301282
    302         /**
    303          * Sets the list of Dots (including this one) that form a closed shape.
    304          * Passing null sets this dot back to its normal (non-enclosed) state.
    305          *
    306          * @param enclosed
    307          *            The List of Dots including this one that form a closed shape,
    308          *            or null.
    309          */
    310         public void setEnclosedList(List<Dot> enclosed) {
    311                 _enclosure = enclosed;
    312         }
    313 
    314         /**
    315          * Returns the polygon that represents the shape created by all the Dots in
    316          * this Dot's enclosed list. If the list is null, then null is returned.
    317          *
    318          * @return A Polygon the same shape and position as created by the Dots in
    319          *         the enclosed list.
    320          */
    321         public Polygon getEnclosedShape() {
    322                 if (_enclosure == null)
    323                         return null;
    324 
    325                 Polygon poly = new Polygon();
    326                 for (Dot d : _enclosure) {
    327                         poly.addPoint(d.getX(), d.getY());
    328                 }
    329 
    330                 return poly;
    331         }
    332 
    333         /**
    334          * Returns the list of Dots that, along with this Dot, form an enclosed
    335          * polygon. If this Dot is not part of an enclosure null may be returned.
    336          *
    337          * @return The List of Dots that form an enclosed shape with this Dot, or
    338          *         null if this Dot is not part of an enclosure.
    339          */
    340         public List<Dot> getEnclosingDots() {
    341                 return _enclosure;
    342         }
    343 
    344         /**
    345          * Returns whether this Dot has an assigned enclosure list of other Dots.
    346          * The result is the same as getEnclosedShape() != null.
    347          *
    348          * @return True if this Dot has an enclosure list of other Dots, false
    349          *         otherwise.
    350          */
    351         public boolean isEnclosed() {
    352                 return _enclosure != null;
    353         }
    354 
    355283        @Override
    356284        public String getTypeAndID() {
     
    370298                        l.delete();
    371299        }
     300       
     301        @Override
     302        public void anchor() {
     303                super.anchor();
     304                Frame current = getCurrentFrame();
     305                for (Line line : getLines()) {
     306                        if (line.getID() < 0 && !current.getItems().contains(line)) {
     307                                line.setID(current.getNextItemID());
     308                                line.setSelectionColor();
     309                                // Mike: Why was this line here?
     310                                // anchor(line);
     311                        }
     312                }
     313        }
     314       
     315        @Override
     316        public void addLine(Line line) {
     317                super.addLine(line);
     318                line.setColor(getColor());
     319                line.setThickness(getThickness());
     320                line.setLinePattern(getLinePattern());
     321        }
     322       
     323        @Override
     324        public void lineColorChanged(Color c) {
     325                if (getColor() != c) {
     326                        setColor(c);
     327                }
     328        }
    372329}
  • trunk/src/org/expeditee/items/Item.java

    r29 r50  
    3333 *
    3434 */
    35 public abstract class Item implements Comparable<Item>, Runnable {
     35public abstract class Item implements Comparable<Item>, Runnable {
     36
     37        // contains all dots (including this one) that form an enclosure
     38        // if this dot is part of an enclosing shape
     39        private List<Item> _enclosure = null;
    3640
    3741        public static int PERMISSION_NONE = 0;
     42
    3843        public static int PERMISSION_FOLLOW_LINKS = 1;
     44
    3945        public static int PERMISSION_COPY = 2;
     46
    4047        public static int PERMISSION_TDFC = 3;
     48
    4149        public static int PERMISSION_FULL = 4;
    42        
     50
    4351        public static final int NEAR_DISTANCE = 15;
    44        
     52
    4553        /**
    4654         * The default Color to draw highlighting in
     
    5159
    5260        public static final Color DEPRESSED_HIGHLIGHT = Color.GREEN;
    53        
     61
    5462        public static final Color DISCONNECT_HIGHLIGHT = Color.BLUE;
    5563
     
    7482
    7583        protected static final double DEFAULT_ARROWHEAD_RATIO = 0.5;
    76        
     84
    7785        public static final Color GREEN = Color.GREEN.darker();
    7886
     
    8189         * this Item.
    8290         */
    83         public static Color[] COLOR_WHEEL = { Color.BLACK, Color.RED,
    84                         Color.BLUE, Item.GREEN, Color.MAGENTA, Color.YELLOW.darker(),
     91        public static Color[] COLOR_WHEEL = { Color.BLACK, Color.RED, Color.BLUE,
     92                        Item.GREEN, Color.MAGENTA, Color.YELLOW.darker(),
    8593                        DisplayIO.DEFAULT_BACKGROUND };
    8694
    87         public static Color[] FILL_COLOR_WHEEL = { Color.BLACK, new Color(255,150,150),
    88                 new Color(150,150,255), new Color(150,255,150), new Color(255,150,255), new Color(255,255,100),
    89                 DisplayIO.DEFAULT_BACKGROUND };
     95        public static Color[] FILL_COLOR_WHEEL = { Color.BLACK,
     96                        new Color(255, 150, 150), new Color(150, 150, 255),
     97                        new Color(150, 255, 150), new Color(255, 150, 255),
     98                        new Color(255, 255, 100), DisplayIO.DEFAULT_BACKGROUND };
    9099
    91100        public static final int UNCHANGED_CURSOR = -100;
     
    144153                dest.setOffset(source.getOffset());
    145154                dest.setOwner(source.getOwner());
     155                dest.setThickness(source.getThickness());
    146156                dest.setSize(source.getSize());
    147157                dest.setTopShadowColor(source.getTopShadowColor());
     
    167177                return org.expeditee.gui.UserSettings.LineHighlight;
    168178        }
    169        
     179
    170180        public enum SelectedMode {
    171181                None, Enclosed, Connected, Disconnect, Normal
    172182        }
    173        
     183
    174184        public void setSelectedMode(SelectedMode mode) {
    175185                setSelectedMode(mode, DEFAULT_HIGHLIGHT);
    176186        }
    177        
     187
    178188        protected SelectedMode _mode = SelectedMode.None;
    179        
     189
    180190        private Point _offset = new Point(0, 0);
    181191
     
    213223
    214224        private Color _colorFill = null;
    215        
     225
    216226        private Color _color = null;
    217227
     
    249259
    250260        // list of points constrained with this point
    251         private List<Constraint> _constraints = null;
     261        private List<Constraint> _constraints = new ArrayList<Constraint>();
    252262
    253263        private LinkedList<String> _actions = null;
    254        
     264
    255265        private String _link_frameset = null;
    256266
     
    258268
    259269        private String _fillPattern = null;
    260        
     270
    261271        private boolean _visible = true;
    262        
     272
    263273        private SelectedMode _lastMode = SelectedMode.None;
     274
     275        private float _thickness = -1.0F;
    264276
    265277        protected Item() {
     
    300312         */
    301313        public void addConstraint(Constraint c) {
    302                 if (_constraints == null)
    303                         _constraints = new ArrayList<Constraint>();
    304 
    305314                // do not add duplicate constraint
    306315                if (_constraints.contains(c))
     
    320329                        return;
    321330                }
    322 
    323                 line.setColor(getColor());
    324                 line.setSize(getSize());
    325                 line.setLinePattern(getLinePattern());
    326331
    327332                _lines.add(line);
     
    381386        final public String getAbsoluteLink() {
    382387                String link = getLink();
    383                
     388
    384389                if (link == null)
    385390                        return null;
    386                 //assert (_parent!= null);
    387                 if (_parent == null){
    388                         //if parent is null it is an item on the message box
    389                         //so it must already be absolute
    390                         assert(!FrameIO.isPositiveInteger(link));
     391                // assert (_parent!= null);
     392                if (_parent == null) {
     393                        // if parent is null it is an item on the message box
     394                        // so it must already be absolute
     395                        assert (!FrameIO.isPositiveInteger(link));
    391396                        return link;
    392397                }
     
    394399                // if its a relative link then return absolute
    395400                if (FrameIO.isPositiveInteger(link)) {
    396                         return _parent.getFramesetName()
    397                                         + Conversion.getFrameNumber(link);
     401                        return _parent.getFramesetName() + Conversion.getFrameNumber(link);
    398402                }
    399403                return link;
     
    689693                return _owner;
    690694        }
    691        
     695
    692696        public Color getPaintBackgroundColor() {
    693697                if (_colorBackground == null) {
     
    752756         * @return The size of this Item.
    753757         */
    754         public abstract int getSize();
    755 
    756         public float getThickness() {
    757                 return 0;
     758        public int getSize() {
     759                return -1;
    758760        }
    759761
     
    809811                if (p == null)
    810812                        return false;
    811                
     813
    812814                // return p.getBounds().intersects(getArea().getBounds());
    813815                Area a = new Area(p);
    814                
     816
    815817                a.intersect(this.getArea());
    816818                return !a.isEmpty();
     
    830832
    831833        public boolean isFrameName() {
    832                 if (this.getParent() == null || this.getParent().getFrameNameItem() != this)
     834                if (this.getParent() == null
     835                                || this.getParent().getFrameNameItem() != this)
    833836                        return false;
    834837                return true;
     
    869872
    870873        public boolean isNear(int x, int y) {
    871                
    872                
     874
    873875                int xLeft = getPolygon().getBounds().x;
    874876                int yTop = getPolygon().getBounds().y;
    875                
    876                 return (x > xLeft - NEAR_DISTANCE && y > yTop - NEAR_DISTANCE 
    877                                 && x < xLeft + getBoundsWidth() + NEAR_DISTANCE
    878                                 && y < yTop + getBoundsHeight() + NEAR_DISTANCE);
     877
     878                return (x > xLeft - NEAR_DISTANCE && y > yTop - NEAR_DISTANCE
     879                                && x < xLeft + getBoundsWidth() + NEAR_DISTANCE && y < yTop
     880                                + getBoundsHeight() + NEAR_DISTANCE);
    879881        }
    880882
     
    945947        }
    946948
     949        /**
     950         * Removes all constraints that this item has.
     951         *
     952         */
    947953        public void removeAllConstraints() {
    948                 if (_constraints != null)
    949                         _constraints.clear();
     954                while (_constraints.size() > 0) {
     955                        Constraint c = _constraints.get(0);
     956                        c.getEnd().removeConstraint(c);
     957                        c.getStart().removeConstraint(c);
     958                }
    950959        }
    951960
     
    10151024
    10161025                if (_parent == null)
    1017                         framesetName = DisplayIO.getCurrentFrame()
    1018                                         .getFramesetName();
     1026                        framesetName = DisplayIO.getCurrentFrame().getFramesetName();
    10191027                else
    10201028                        framesetName = _parent.getFramesetName();
     
    11181126        public void setColor(Color c) {
    11191127                _color = c;
    1120 
    1121                 // update the colour of any lines
    1122                 for (Line line : getLines())
    1123                         line.setColor(c);
    11241128        }
    11251129
     
    12751279
    12761280                // update the position of any dots that are constrained by this one
    1277                 if (_constraints != null) {
    1278                         for (Constraint c : _constraints) {
    1279                                 Item other = c.getOppositeEnd(this);
    1280 
    1281                                 // only set the position if the other dot is still fixed to the
    1282                                 // frame
    1283                                 if (!other.isFloating()) {
    1284                                         if (c.getConstraintType() == Constraint.HORIZONTAL
    1285                                                         && other.getY() != getY())
    1286                                                 other.setY(getY());
    1287 
    1288                                         if (c.getConstraintType() == Constraint.VERTICAL
    1289                                                         && other.getX() != getX())
    1290                                                 other.setX(getX());
    1291                                 }
     1281                for (Constraint c : _constraints) {
     1282                        Item other = c.getOppositeEnd(this);
     1283
     1284                        // only set position if the other dot is still fixed to the
     1285                        // frame
     1286                        if (!other.isFloating()) {
     1287                                if (c.getType() == Constraint.HORIZONTAL
     1288                                                && other.getY() != getY())
     1289                                        other.setY(getY());
     1290
     1291                                if (c.getType() == Constraint.VERTICAL
     1292                                                && other.getX() != getX())
     1293                                        other.setX(getX());
    12921294                        }
    12931295                }
     
    13161318         * Dots this is the thickness.
    13171319         */
    1318         public abstract void setSize(int size);
    1319 
    1320         public void setThickness(float thick) throws UnsupportedOperationException {
    1321                 throw new UnsupportedOperationException(
    1322                                 "Item type does not support thickness attribute!");
     1320        public void setSize(int size) {
     1321        }
     1322
     1323        public void setThickness(float thick) {
     1324                _thickness = thick;
     1325                // update the size of any lines
     1326                for (Line line : getLines())
     1327                        line.setThickness(thick);
     1328        }
     1329
     1330        /**
     1331         * Returns the thickness (in pixels) of this Dot.
     1332         *
     1333         * @return The 'thickness' of this Dot. (returns -1 if the thickness is not
     1334         *         set).
     1335         */
     1336        public float getThickness() {
     1337                return _thickness;
    13231338        }
    13241339
     
    13861401                return Item.UNCHANGED_CURSOR;
    13871402        }
    1388        
     1403
    13891404        private void updateArrowPolygon() {
    13901405                if (getArrowheadLength() < 0 || getArrowheadRatio() < 0)
     
    14041419                }
    14051420        }
    1406        
     1421
    14071422        protected abstract void updatePolygon();
    14081423
     
    14141429                return _visible;
    14151430        }
    1416        
    1417        
    1418        
     1431
    14191432        // BROOK: Overrideable
    1420         public void onRemovedFromFrame() {}
    1421         public void onAddedToFrame(boolean isOverlayed, int overlayLevel) {}
    1422         public void onParentFameHidden() {} // because of caching
    1423         public void onParentFameShown(boolean isOverlayed, int overlayLevel) {} // because of caching
     1433        public void onRemovedFromFrame() {
     1434        }
     1435
     1436        public void onAddedToFrame(boolean isOverlayed, int overlayLevel) {
     1437        }
     1438
     1439        public void onParentFameHidden() {
     1440        } // because of caching
     1441
     1442        public void onParentFameShown(boolean isOverlayed, int overlayLevel) {
     1443        } // because of caching
    14241444
    14251445        public void setSelectedMode(SelectedMode mode, Color color) {
     
    14401460                return _mode;
    14411461        }
     1462
     1463        public void anchor() {
     1464                Frame current = getCurrentFrame();
     1465                setID(current.getNextItemID());
     1466                setOffset(0, 0);
     1467                setParent(current);
     1468
     1469                current.addItem(this);
     1470                current.setResort(true);
     1471                setRelativeLink();
     1472                setFloating(false);
     1473        }
     1474
     1475        /**
     1476         * Gets the parent frame if it is set or the current frame if this item does
     1477         * not have a parent set.
     1478         *
     1479         * @return
     1480         */
     1481        public Frame getCurrentFrame() {
     1482                // if the item is from an overlay the parent will NOT be null
     1483                if (getParent() == null) {
     1484                        return DisplayIO.getCurrentFrame();
     1485                }
     1486                return getParent();
     1487        }
     1488
     1489        /**
     1490         * Sets the list of Dots (including this one) that form a closed shape.
     1491         * Passing null sets this dot back to its normal (non-enclosed) state.
     1492         *
     1493         * @param enclosed
     1494         *            The List of Dots including this one that form a closed shape,
     1495         *            or null.
     1496         */
     1497        public void setEnclosedList(List<Item> enclosed) {
     1498                _enclosure = enclosed;
     1499        }
     1500
     1501        /**
     1502         * Returns the polygon that represents the shape created by all the Dots in
     1503         * this Dot's enclosed list. If the list is null, then null is returned.
     1504         *
     1505         * @return A Polygon the same shape and position as created by the Dots in
     1506         *         the enclosed list.
     1507         */
     1508        public Polygon getEnclosedShape() {
     1509                if (_enclosure == null)
     1510                        return null;
     1511
     1512                Polygon poly = new Polygon();
     1513                for (Item d : _enclosure) {
     1514                        poly.addPoint(d.getX(), d.getY());
     1515                }
     1516
     1517                return poly;
     1518        }
     1519
     1520        /**
     1521         * Returns the list of Dots that, along with this Dot, form an enclosed
     1522         * polygon. If this Dot is not part of an enclosure null may be returned.
     1523         *
     1524         * @return The List of Dots that form an enclosed shape with this Dot, or
     1525         *         null if this Dot is not part of an enclosure.
     1526         */
     1527        public List<Item> getEnclosingDots() {
     1528                return _enclosure;
     1529        }
     1530
     1531        /**
     1532         * Returns whether this Dot has an assigned enclosure list of other Dots.
     1533         * The result is the same as getEnclosedShape() != null.
     1534         *
     1535         * @return True if this Dot has an enclosure list of other Dots, false
     1536         *         otherwise.
     1537         */
     1538        public boolean isEnclosed() {
     1539                return _enclosure != null;
     1540        }
     1541
     1542        public boolean isLineEnd() {
     1543                return _lines.size() > 0;
     1544        }
     1545
     1546        /**
     1547         * Method that is called to notify an item that is on the end of a line that
     1548         * its line has changed color.
     1549         *
     1550         * @param c
     1551         *            the new color for the line
     1552         */
     1553        protected void lineColorChanged(Color c) {
     1554                for (Line l : getLines()) {
     1555                        if (l.getColor() != c)
     1556                                l.setColor(c);
     1557                }
     1558        }
    14421559}
  • trunk/src/org/expeditee/items/ItemUtils.java

    r26 r50  
    450450                                        for (Constraint c : consts) {
    451451                                                if (c.contains(line.getEndItem())) {
    452                                                         if (c.getConstraintType() == Constraint.VERTICAL) {
     452                                                        if (c.getType() == Constraint.VERTICAL) {
    453453                                                                vConst.add(line.getStartItem());
    454454                                                                vConst.add(line.getEndItem());
     
    659659                _seen.clear();
    660660
    661                 // get all dots on the Frame
    662                 List<Dot> dots = new ArrayList<Dot>(0);
     661                // get all lineEnds on the Frame
     662                List<Item> lineEnds = new ArrayList<Item>(0);
    663663                for (Item i : items) {
    664                         if (i instanceof Dot) {
    665                                 Dot d = (Dot) i;
    666                                 d.setEnclosedList(null);
    667 
    668                                 if (d.getLines().size() == 2)
    669                                         dots.add(d);
    670                         }
    671                 }
    672 
    673                 // if there are no dots on the Frame, then there can't be an enclosure
    674                 if (dots.size() == 0)
     664                        if (i.isLineEnd()) {
     665                                i.setEnclosedList(null);
     666
     667                                if (i.getLines().size() == 2)
     668                                        lineEnds.add(i);
     669                        }
     670                }
     671
     672                // if there are no line endpoints on the Frame, then there can't be an enclosure
     673                if (lineEnds.size() == 0)
    675674                        return;
    676675
    677676                //TODO optimise this code!!
    678                 // iterate through all the dots
    679                 for (Dot searchFor : dots) {
     677                // iterate through all the lineEnds
     678                for (Item searchFor : lineEnds) {
    680679                        _seen.clear();
    681680
     
    683682                                _seen.add(l);
    684683                                if (traverse(searchFor, l.getOppositeEnd(searchFor))) {
    685                                         _path.add((Dot) l.getOppositeEnd(searchFor));
    686 
    687                                         for (Dot d : _path)
    688                                                 d.setEnclosedList(_path);
    689 
    690                                         _path = new ArrayList<Dot>(0);
     684                                        _path.add(l.getOppositeEnd(searchFor));
     685
     686                                        for (Item i : _path)
     687                                                i.setEnclosedList(_path);
     688
     689                                        _path = new ArrayList<Item>(0);
    691690
    692691                                        break;
     
    699698        private static List<Line> _seen = new ArrayList<Line>();
    700699
    701         private static List<Dot> _path = new ArrayList<Dot>();
    702 
    703         private static boolean traverse(Dot toFind, Item searchFrom) {
     700        private static List<Item> _path = new ArrayList<Item>();
     701
     702        private static boolean traverse(Item toFind, Item searchFrom) {
    704703                if (toFind == null || searchFrom == null
    705                                 || !(searchFrom instanceof Dot))
     704                                || !searchFrom.isLineEnd())
    706705                        return false;
    707706
     
    716715                                _seen.add(l);
    717716                                if (traverse(toFind, l.getOppositeEnd(searchFrom))) {
    718                                         _path.add((Dot) l.getOppositeEnd(searchFrom));
     717                                        _path.add(l.getOppositeEnd(searchFrom));
    719718                                        return true;
    720719                                }
  • trunk/src/org/expeditee/items/Line.java

    r21 r50  
    8181
    8282                // initialise the line size
    83                 float thick;
    84 
    85                 if (_start instanceof Dot && _end instanceof Dot)
    86                         thick = (((Dot) _start).getThickness() + ((Dot) _end)
    87                                         .getThickness()) / 2.0f;
    88                 else if (_start instanceof Dot)
    89                         thick = ((Dot) _start).getThickness();
    90                 else if (_end instanceof Dot)
    91                         thick = ((Dot) _end).getThickness();
    92                 else
     83                float thick = (_start.getThickness() + _end.getThickness()) / 2.0f;
     84
     85                if (thick < 0)
    9386                        thick = 1;
     87                /*
     88                 * if (_start instanceof Dot && _end instanceof Dot) thick = (((Dot)
     89                 * _start).getThickness() + ((Dot) _end) .getThickness()) / 2.0f; else
     90                 * if (_start instanceof Dot) thick = ((Dot) _start).getThickness();
     91                 * else if (_end instanceof Dot) thick = ((Dot) _end).getThickness();
     92                 * else thick = 1;
     93                 */
    9494
    9595                setThickness(thick);
     
    134134
    135135        /**
    136          * Replaces either the start or end point of this Line with the given Dot.
    137          * This is used when merging two Dots.
     136         * Replaces either the start or end point of this Line with the given
     137         * LineEnd. This is used when merging LineEnds. It will also add and remove
     138         * the line from the LineEnds as well as adjust constraints.
    138139         *
    139140         * @param replace
     
    144145         */
    145146        public void replaceEnd(Item replace, Item with) {
    146                 if (_start == replace)
     147                Item otherEnd = null;
     148                if (_start == replace) {
    147149                        setStartItem(with);
    148                 else
     150                        otherEnd = _end;
     151                } else if (_end == replace) {
    149152                        setEndItem(with);
     153                        otherEnd = _start;
     154                }
     155                // if no end was replaced
     156                if (otherEnd == null)
     157                        return;
     158                // Copy the constraints list so the endPoints list can be modified
     159                List<Constraint> constraints = new ArrayList<Constraint>(replace
     160                                .getConstraints());
     161                // Now change all the constraints for this line only
     162                for (int i = 0; i < constraints.size(); i++) {
     163                        Constraint c = constraints.get(i);
     164                        if (c.contains(otherEnd)) {
     165                                c.replaceEnd(replace, with);
     166                        }
     167                }
    150168        }
    151169
     
    154172                        _start.removeLine(this);
    155173
    156                         if (!(start instanceof Dot)) {
    157                                 _startOffset.x = _start.getX() - start.getX();
    158                                 _startOffset.y = _start.getY() - start.getY();
    159                         } else {
     174                        /*
     175                         * if (!(start instanceof Dot)) { _startOffset.x = _start.getX() -
     176                         * start.getX(); _startOffset.y = _start.getY() - start.getY(); }
     177                         * else
     178                         */{
    160179                                _startOffset.x = 0;
    161180                                _startOffset.y = 0;
     
    172191                        _end.removeLine(this);
    173192
    174                         if (!(end instanceof Dot)) {
    175                                 _endOffset.x = _end.getX() - end.getX();
    176                                 _endOffset.y = _end.getY() - end.getY();
    177                         } else {
     193                        /*
     194                         * if (!(end instanceof Dot)) { _endOffset.x = _end.getX() -
     195                         * end.getX(); _endOffset.y = _end.getY() - end.getY(); } else
     196                         */{
    178197                                _endOffset.x = 0;
    179198                                _endOffset.y = 0;
     
    211230        }
    212231
     232        @Override
    213233        public void setX(int x) {
    214234        }
    215235
     236        @Override
    216237        public void setY(int y) {
    217238        }
     
    287308                g.setColor(getPaintColor());
    288309
    289                 //if (this._mode == Item.SelectedMode.Disconnect)
    290                 //      System.out.println("Disconnect mode!");
    291                
     310                // if (this._mode == Item.SelectedMode.Disconnect)
     311                // System.out.println("Disconnect mode!");
     312
    292313                if (_start instanceof Text && ((Text) _start).startsWith("@c")) {
    293314                        g.setStroke(_lineStroke);
     
    340361                        Point endOffset) {
    341362                // only draw an arrowhead if necessary
    342                 if (!(this._mode == Item.SelectedMode.Disconnect
    343                                 && withArrow._mode == Item.SelectedMode.Disconnect)
    344                                 && (!withArrow.hasVisibleArrow()
    345                                 || withArrow.getLines().size() > 1))
     363                if (!(this._mode == Item.SelectedMode.Disconnect && withArrow._mode == Item.SelectedMode.Disconnect)
     364                                && (!withArrow.hasVisibleArrow() || withArrow.getLines().size() > 1))
    346365                        return;
    347366
     
    356375                double arrowRatio = withArrow.getArrowheadRatio();
    357376
    358                 //set the size of the disconnect indicator arrowhead
    359                 if (this._mode == Item.SelectedMode.Disconnect){
    360                         //System.out.println("Disconnect mode!");
     377                // set the size of the disconnect indicator arrowhead
     378                if (this._mode == Item.SelectedMode.Disconnect) {
     379                        // System.out.println("Disconnect mode!");
    361380                        arrowLength = 15;
    362381                        arrowRatio = 0.3;
    363                         //Make sure the arrowhead positions get recalculated
     382                        // Make sure the arrowhead positions get recalculated
    364383                        withArrow.setArrowhead(null);
    365384                }
    366                
     385
    367386                // if the arrowhead is 'auto', then one and only one end must be
    368387                // floating
     
    489508                        return end;
    490509                } else if (distStart < DISCONNECT_THRESHHOLD) {
    491                         start._mode = Item.SelectedMode.Disconnect;
     510                        if (start.getLines().size() > 1
     511                                        || start.getConstraints().size() > 0)
     512                                start._mode = Item.SelectedMode.Disconnect;
     513                        else
     514                                start._mode = Item.SelectedMode.Normal;
    492515                        return start;
    493516                } else if (distEnd < DISCONNECT_THRESHHOLD) {
    494                         end._mode = Item.SelectedMode.Disconnect;
     517                        if (end.getLines().size() > 1 || end.getConstraints().size() > 0)
     518                                end._mode = Item.SelectedMode.Disconnect;
     519                        else
     520                                end._mode = Item.SelectedMode.Normal;
    495521                        return end;
    496522                }
     
    520546                super.setColor(c);
    521547
    522                 if (_start.getColor() != c)
    523                         _start.setColor(c);
    524 
    525                 if (_end.getColor() != c)
    526                         _end.setColor(c);
    527         }
    528 
    529         @Override
    530         public int getSize() {
    531                 return _start.getSize();
    532         }
    533 
    534         @Override
    535         public void setSize(int size) {
     548                _start.lineColorChanged(c);
     549                _end.lineColorChanged(c);
    536550        }
    537551
     
    543557                        thick = DEFAULT_THICKNESS;
    544558
    545                 if (_start instanceof Dot) {
    546                         Dot start = (Dot) _start;
    547                         if (start.getThickness() != thick)
    548                                 start.setThickness(thick);
    549                 }
    550 
    551                 if (_end instanceof Dot) {
    552                         Dot end = (Dot) _end;
    553                         if (end.getThickness() != thick)
    554                                 end.setThickness(thick);
    555                 }
     559                if (_start.getThickness() != thick)
     560                        _start.setThickness(thick);
     561
     562                if (_end.getThickness() != thick)
     563                        _end.setThickness(thick);
    556564
    557565                int[] pattern = _start.getLinePattern();
     
    734742        private Dot _virtualSpot = null;
    735743
    736         public void showVirtualSpot(Dot orig, int mouseX, int mouseY) {
     744        public void showVirtualSpot(Item orig, int mouseX, int mouseY) {
    737745                if (orig.getLines().size() != 1)
    738746                        return;
     
    742750                        return;
    743751
    744                 Dot spot = orig.copy();
     752                Dot spot = new Dot(-1, orig.getX(), orig.getY());
     753                Item.DuplicateItem(orig, spot);
    745754                spot.setThickness(Math.max(this.getThickness(), 5));
    746755                if (this.getColor() != Color.RED)
     
    817826        }
    818827
    819         public Item forceMerge(Item merger, int mouseX, int mouseY) {
    820                 Dot spot = (Dot) merger;
    821 
    822                 if (spot.getConstraints() != null)
    823                         spot.getConstraints().clear();
    824 
    825                 if (_end.getConstraints() != null)
    826                         _end.getConstraints().clear();
    827 
    828                 if (_start.getConstraints() != null)
    829                         _start.getConstraints().clear();
     828        public Item forceMerge(Item spot, int mouseX, int mouseY) {
     829
     830                spot.removeAllConstraints();
     831
     832                _end.removeAllConstraints();
     833
     834                _start.removeAllConstraints();
    830835
    831836                // calculate nearest point on line from spot
     
    840845                // if the line is horizontal
    841846                if (slope1 == 0) {
    842                         x = merger.getX();
     847                        x = spot.getX();
    843848                        y = _start.getY();
    844849                        // if the line is vertical
    845850                } else if (slope2 == 0) {
    846851                        x = _start.getX();
    847                         y = merger.getY();
     852                        y = spot.getY();
    848853                        // otherwise, the line is sloped
    849854                } else {
     
    875880        @Override
    876881        public Item merge(Item merger, int mouseX, int mouseY) {
    877                 if (!(merger instanceof Dot))
     882                if (!(merger.isLineEnd()))
    878883                        return merger;
    879884
    880                 Dot spot = (Dot) merger;
     885                Item spot = merger;
    881886
    882887                // dots with multiple lines cannot be attached, nor can dots with no
     
    10151020                        _end.delete();
    10161021        }
     1022
     1023        @Override
     1024        public void anchor() {
     1025                super.anchor();
     1026                fixArrowheadLength();
     1027        }
     1028
     1029        /**
     1030         * Removes constraints from the end points of this line.
     1031         */
     1032        @Override
     1033        public void removeAllConstraints() {
     1034                // Find all constraints that include both the start and end.
     1035                for (Constraint c : _start.getConstraints()) {
     1036                        if (c.contains(_end)) {
     1037                                _start.removeConstraint(c);
     1038                                _end.removeConstraint(c);
     1039                        }
     1040                }
     1041        }
    10171042}
  • trunk/src/org/expeditee/items/Text.java

    r41 r50  
    905905                                Rectangle textOutline = text.getLogicalHighlightShape(0,
    906906                                                text.getCharacterCount()).getBounds();
    907                                 textOutline.translate(getX(), textY);
     907                                textOutline.width += 2;
     908                                textOutline.height += 2;
     909                               
     910                                textOutline.translate(getX() -1, textY - 1);
    908911                                if (p.intersects(textOutline))
    909912                                        return true;
     
    14511454        @Override
    14521455        public Item merge(Item merger, int mouseX, int mouseY) {
    1453                 if (merger instanceof Dot) {
    1454                         Dot d = (Dot) merger;
     1456               
     1457                if (merger.isLineEnd()) {
     1458                        if (merger instanceof Text)
     1459                                insertText(((Text)merger).getTextNoList(), mouseX, mouseY);
     1460                       
     1461                        //this.setPosition(merger.getPosition());
    14551462                        List<Line> lines = new LinkedList<Line>();
    1456                         lines.addAll(d.getLines());
    1457                         for (Line line : lines)
    1458                                 line.replaceEnd(d, this);
    1459 
    1460                         d.removeAllLines();
     1463                        lines.addAll(merger.getLines());
     1464                        for (Line line : lines){
     1465                                line.replaceEnd(merger, this);
     1466                        }
     1467                        merger.delete();
     1468                        this.setOffset(0,0);
    14611469                        return null;
    14621470                }
     
    15691577                setVisible(false);
    15701578        }
     1579       
     1580        @Override
     1581        public void anchor() {
     1582                super.anchor();
     1583                // ensure all text items have their selection cleared
     1584                clearSelection();
     1585                setAlpha(0);
     1586        }
    15711587}
Note: See TracChangeset for help on using the changeset viewer.