Changeset 72


Ignore:
Timestamp:
05/23/08 09:02:59 (16 years ago)
Author:
ra33
Message:

Added lots of stuff

Location:
trunk
Files:
29 edited

Legend:

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

    r41 r72  
    4545
    4646        public static final String ROOT_PACKAGE = "org.expeditee.";
    47        
     47
    4848        // Package and class file locations
    4949        private static final String ACTIONS_PACKAGE = ROOT_PACKAGE + "actions.";
    5050
    5151        private static final String AGENTS_PACKAGE = ROOT_PACKAGE + "agents.";
    52        
    53         private static final String NAVIGATIONS_CLASS = ROOT_PACKAGE + "actions.NavigationActions";
    54        
     52
     53        private static final String NAVIGATIONS_CLASS = ROOT_PACKAGE
     54                        + "actions.NavigationActions";
     55
    5556        public static Class[] getClasses(String pckgname)
    5657                        throws ClassNotFoundException {
     
    232233
    233234        /**
    234          * Performs the given KMS action command. The source Frame and Item are
    235          * given because they are required by some actions. Note that the source
    236          * frame does not have to be the Item's parent Frame.
     235         * Performs the given action command. The source Frame and Item are given
     236         * because they are required by some actions. Note that the source frame
     237         * does not have to be the Item's parent Frame.
    237238         *
    238239         * @param source
     
    246247                if (!command.equalsIgnoreCase("Restore"))
    247248                        FrameIO.SaveFrame(source, false);
    248                
     249
    249250                // separate method name and parameter names
    250251                String mname = getName(command);
     
    278279                // Need to save the frame if we are navigating away from it so we dont
    279280                // loose changes
    280                 if (toRun.getDeclaringClass().getName().equals(
    281                                  NAVIGATIONS_CLASS)) {
     281                if (toRun.getDeclaringClass().getName().equals(NAVIGATIONS_CLASS)) {
    282282                        FrameIO.SaveFrame(DisplayIO.getCurrentFrame());
    283283                }
     
    363363                        if (con == null) {
    364364                                FrameGraphics.DisplayMessage("Invalid parametres for agent.");
    365                                 //System.out.println("Constructor not found...");
     365                                // System.out.println("Constructor not found...");
    366366                                return;
    367367                        }
     
    482482                }
    483483
    484                 String param;
     484                String param = values;
    485485                // convert the rest of the objects
    486486                for (; ind < objects.length; ind++) {
    487                         // strip off the next value
    488                         param = ParseValue(values);
    489                         values = RemainingParams(values);
    490 
    491487                        // check if its the last param and combine
    492                         if (values.length() > 0 && ind == objects.length - 1)
    493                                 param = param.trim() + ' ' + values.trim();
    494 
     488                        if (values.length() > 0 && ind == objects.length - 1) {
     489                                param = values.trim();
     490                                // check if its a string
     491                                if (param.length() > 0 && param.charAt(0) == '"'){
     492                                        int endOfString = param.indexOf('"', 1);
     493                                        if (endOfString > 0){
     494                                                param = param.substring(0,endOfString);
     495                                        }
     496                                }
     497                        } else {// strip off the next value
     498                                param = ParseValue(values);
     499                                values = RemainingParams(values);
     500                        }
    495501                        // convert the value to an object
    496502                        Object o = Conversion.Convert(paramTypes[ind], param);
     
    509515         * @return the remaining N - 1 parameters
    510516         */
    511         private static String RemainingParams(String params) {
     517        public static String RemainingParams(String params) {
    512518                if (params.length() == 0)
    513519                        return null;
     
    523529                // Check if we have a string parameter
    524530                if (params.charAt(0) == '"') {
    525                         return params.substring(params.indexOf('"', 1) + 1);
    526                 }
    527 
    528                 return params.substring(params.indexOf(" "));
     531                        int endOfString = params.indexOf('"', 1);
     532                        if (endOfString > 0){
     533                                if (endOfString > params.length())
     534                                        return "";
     535                                return params.substring(endOfString + 1).trim();
     536                        }
     537                }
     538
     539                return params.substring(params.indexOf(" ")).trim();
    529540        }
    530541
     
    537548         * @return The first value in the String
    538549         */
    539         private static String ParseValue(String params) {
     550        public static String ParseValue(String params) {
    540551                if (params.length() == 0)
    541552                        return null;
     
    543554                // remove leading and trailing spaces
    544555                String param = params.trim();
     556
     557                // Check if we have a string parameter
     558                if (param.charAt(0) == '"') {
     559                        int endOfString = param.indexOf('"', 1);
     560                        if (endOfString > 0)
     561                                return param.substring(1, endOfString);
     562                }
    545563
    546564                // if there are no more parameters, we are done
     
    549567                }
    550568
    551                 // Check if we have a string parameter
    552                 if (param.charAt(0) == '"') {
    553                         return param.substring(1, param.indexOf('"', 1));
    554                 }
    555 
    556569                return param.substring(0, param.indexOf(" "));
    557570        }
  • trunk/src/org/expeditee/actions/Debug.java

    r4 r72  
    55import org.expeditee.gui.DisplayIO;
    66import org.expeditee.items.Constraint;
    7 import org.expeditee.items.Dot;
    87import org.expeditee.items.Item;
    98
     
    2423
    2524                for (Item i : items)
    26                         if (i instanceof Dot) {
     25                        if (i.isLineEnd()) {
    2726                                System.out.println(i.getID());
    2827
    29                                 for (Constraint c : ((Dot) i).getConstraints())
    30                                         if (c.getOppositeEnd((Dot) i) != null)
     28                                for (Constraint c : i.getConstraints())
     29                                        if (c.getOppositeEnd(i) != null)
    3130                                                System.out.println("\t"
    32                                                                 + c.getOppositeEnd((Dot) i).getID());
     31                                                                + c.getOppositeEnd(i).getID());
    3332                                        else
    3433                                                System.out.println("\tNULL");
  • trunk/src/org/expeditee/actions/Misc.java

    r70 r72  
    88import java.io.FileNotFoundException;
    99import java.io.IOException;
     10import java.lang.reflect.Method;
    1011import java.util.ArrayList;
    1112import java.util.List;
     
    1819import org.expeditee.gui.FrameIO;
    1920import org.expeditee.gui.FrameMouseActions;
     21import org.expeditee.gui.TimeKeeper;
    2022import org.expeditee.items.Item;
    2123import org.expeditee.items.Text;
     
    2830 */
    2931public class Misc {
    30         private static final int STATS_FONT_SIZE = 18;
    31 
    3232        private static final int FRAME_FILE_FONT_SIZE = 10;
    3333
     
    152152                getFromChildFrame(current, false);
    153153        }
    154        
    155         /**
    156          * Loads the Frame linked to by the given Item. The first Text Item on the Frame
    157          * that is not the title or name is then placed on the cursor. If the given
    158          * Item has no link, or no item is found then this is a no-op.
     154
     155        /**
     156         * Loads the Frame linked to by the given Item. The first Text Item on the
     157         * Frame that is not the title or name is then placed on the cursor. If the
     158         * given Item has no link, or no item is found then this is a no-op.
    159159         *
    160160         * @param current
     
    165165                getFromChildFrame(current, true);
    166166        }
    167        
    168         private static void getFromChildFrame(Item current, boolean textOnly){
     167
     168        private static void getFromChildFrame(Item current, boolean textOnly) {
    169169                Item item = getFirstBodyItemOnChildFrame(current, textOnly);
    170170                // if no item was found
     
    226226
    227227        public static void CreateTextItem(String itemText) {
    228                 Text text = DisplayIO.getCurrentFrame().createNewText();
    229                 // We dont want the stats to wrap at all
    230                 text.setMaxSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    231 
    232                 text.setText(itemText);
    233 
    234                 text.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());
    235                 text.setSize(STATS_FONT_SIZE);
    236 
     228                SessionStats.CreatedText();
     229                Frame current = DisplayIO.getCurrentFrame();
     230                Text text = current.getStatsTextItem(itemText);
    237231                FrameMouseActions.pickup(text);
    238 
    239232                FrameGraphics.Repaint();
    240233        }
     
    419412
    420413        /**
     414         * Runs two methods alternatively a specified number of times and reports on
     415         * the time spent running each method.
     416         *
     417         * @param fullMethodNameA
     418         * @param fullMethodNameB
     419         * @param repsPerTest
     420         *            the number of time each method is run per test
     421         * @param tests
     422         *            the number of tests to conduct
     423         *
     424         */
     425        public static void CompareMethods(String fullMethodNameA,
     426                        String fullMethodNameB, int repsPerTest, int tests) {
     427                try {
     428                        String classNameA = getClassName(fullMethodNameA);
     429                        String classNameB = getClassName(fullMethodNameB);
     430                        String methodNameA = getMethodName(fullMethodNameA);
     431                        String methodNameB = getMethodName(fullMethodNameB);
     432
     433                        Class classA = Class.forName(classNameA);
     434                        Class classB = Class.forName(classNameB);
     435                        Method methodA = classA.getDeclaredMethod(methodNameA,
     436                                        new Class[] {});
     437                        Method methodB = classB.getDeclaredMethod(methodNameB,
     438                                        new Class[] {});
     439                        TimeKeeper timeKeeper = new TimeKeeper();
     440                        long timeA = 0;
     441                        long timeB = 0;
     442                        // Run the tests
     443                        for (int i = 0; i < tests; i++) {
     444                                // Test methodA
     445                                timeKeeper.restart();
     446                                for (int j = 0; j < repsPerTest; j++) {
     447                                        methodA.invoke((Object) null, new Object[]{});
     448                                }
     449                                timeA += timeKeeper.getElapsedMillis();
     450                                timeKeeper.restart();
     451                                // Test methodB
     452                                for (int j = 0; j < repsPerTest; j++) {
     453                                        methodB.invoke((Object) null, new Object[]{});
     454                                }
     455                                timeB += timeKeeper.getElapsedMillis();
     456                        }
     457
     458                        float aveTimeA = timeA * 1000F / repsPerTest / tests;
     459                        float aveTimeB = timeB * 1000F / repsPerTest / tests;
     460                        // Display Results
     461                        FrameGraphics.DisplayMessage("Average Execution Time");
     462                        FrameGraphics.DisplayMessage(methodNameA + ": "
     463                                        + TimeKeeper.Formatter.format(aveTimeA) + "us");
     464                        FrameGraphics.DisplayMessage(methodNameB + ": "
     465                                        + TimeKeeper.Formatter.format(aveTimeB) + "us");
     466                } catch (Exception e) {
     467                        FrameGraphics.ErrorMessage(e.getClass().getSimpleName() + ": "
     468                                        + e.getMessage());
     469                }
     470        }
     471
     472        public static String getClassName(String fullMethodName) {
     473                assert (fullMethodName != null);
     474                assert (fullMethodName.length() > 0);
     475                int lastPeriod = fullMethodName.lastIndexOf('.');
     476                if (lastPeriod > 0 && lastPeriod < fullMethodName.length() - 1)
     477                        return fullMethodName.substring(0, lastPeriod);
     478                throw new RuntimeException("Invalid method name: " + fullMethodName);
     479        }
     480
     481        public static String getMethodName(String methodName) {
     482                assert (methodName != null);
     483                assert (methodName.length() > 0);
     484                int lastPeriod = methodName.lastIndexOf('.');
     485                if (lastPeriod > 0 && lastPeriod < methodName.length() - 1)
     486                        return methodName.substring(1 + lastPeriod);
     487                throw new RuntimeException("Invalid method name: " + methodName);
     488        }
     489
     490        /**
    421491         * Loads the Frame linked to by the given Item. The first Item on the Frame
    422492         * that is not the title or name is then placed on the current frame. The
     
    458528        }
    459529
    460         private static Item getFirstBodyItemOnChildFrame(Item current, boolean textOnly) {
     530        private static Item getFirstBodyItemOnChildFrame(Item current,
     531                        boolean textOnly) {
    461532                // the item must link to a frame
    462533                if (current.getLink() == null) {
     
    476547                // find the first non-title and non-name item
    477548                List<Item> body = new ArrayList<Item>();
    478                 if(textOnly)
     549                if (textOnly)
    479550                        body.addAll(child.getBodyTextItems(false));
    480551                else
  • trunk/src/org/expeditee/actions/Simple.java

    r70 r72  
    14021402                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    14031403                        assertVariableType(tokens[2], 2, SPointer.itemPrefix);
    1404                         Dot dot1 = null;
    1405                         Dot dot2 = null;
     1404                        Item dot1 = null;
     1405                        Item dot2 = null;
    14061406                        try {
    1407                                 dot1 = (Dot) context.getPointers().getVariable(tokens[1])
     1407                                dot1 = (Item) context.getPointers().getVariable(tokens[1])
    14081408                                                .getValue();
    14091409                        } catch (Exception e) {
     
    14111411                        }
    14121412                        try {
    1413                                 dot2 = (Dot) context.getPointers().getVariable(tokens[2])
     1413                                dot2 = (Item) context.getPointers().getVariable(tokens[2])
    14141414                                                .getValue();
    14151415                        } catch (Exception e) {
  • trunk/src/org/expeditee/agents/DefaultAgent.java

    r70 r72  
    4242                super();
    4343                try {
    44                         _delay = (int)(Double.parseDouble(delay) * 1000);
     44                        _delay = (int) (Double.parseDouble(delay) * 1000);
    4545                } catch (Exception e) {
    4646                }
     
    6565                                / (_timer.getElapsedMillis() / 1000.0));
    6666                String stats = (_itemCount > 0 ? ("Items: " + _itemCount + ", ") : "")
    67                                 + "Frames: " + _frameCount + ", Time: "
    68                                 + _timer.getElapsedStringSeconds()
     67                                + (_frameCount > 1 ? ("Frames: " + _frameCount + ", ") : "")
     68                                + "Time: " + _timer.getElapsedStringSeconds()
    6969                                + (framesPerSecond > 1 ? (", FPS: " + framesPerSecond) : "");
    7070                String msg = this.getClass().getSimpleName() + " stats- ";
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r71 r72  
    7575                        _AllowNull = new LinkedList<Method>();
    7676                        _AllowNull.add(Item.class.getMethod("getColor", param));
    77                         _AllowNull.add(Item.class.getMethod("getBackgroundColor", param));
    78 
    79                         _AllowNull.add(Frame.class.getMethod("getBackgroundColor", param));
     77                        //_AllowNull.add(Item.class.getMethod("getBackgroundColor", param));
     78
     79                        //_AllowNull.add(Frame.class.getMethod("getBackgroundColor", param));
    8080                        _AllowNull.add(Frame.class.getMethod("getForegroundColor", param));
    8181
     
    175175                        _SetMethods.put("linkmark", Item.class.getMethod("setLinkMark",
    176176                                        pBool));
     177                        _SetMethods.put("lm", Item.class.getMethod("setLinkMark",
     178                                        pBool));
    177179                        _SetMethods.put("actionmark", Item.class.getMethod("setActionMark",
     180                                        pBool));
     181                        _SetMethods.put("am", Item.class.getMethod("setActionMark",
    178182                                        pBool));
    179183
     
    197201                        _SetMethods.put("lp", Item.class.getMethod("setLinePattern",
    198202                                        pIntArray));
     203                       
    199204                        _SetMethods.put("linkframeset", Item.class.getMethod(
    200205                                        "setLinkFrameset", pString));
     206                        _SetMethods.put("lf", Item.class.getMethod(
     207                                        "setLinkFrameset", pString));
    201208                        _SetMethods.put("linktemplate", Item.class.getMethod(
     209                                        "setLinkTemplate", pString));
     210                        _SetMethods.put("lt", Item.class.getMethod(
    202211                                        "setLinkTemplate", pString));
    203212
     
    222231                        _SetMethods.put("bgc0", Frame.class.getMethod("setBackgroundColor",
    223232                                        pColor));
    224 
    225                         /*
    226                          * _Abbreviations = new HashMap<String, String>();
    227                          * _Abbreviations.put("a", "Action"); _Abbreviations.put("l",
    228                          * "Link"); _Abbreviations.put("c", "Color");
    229                          * _Abbreviations.put("bgc", "BackgroundColor");
    230                          * _Abbreviations.put("fgc", "ForegroundColor");
    231                          * _Abbreviations.put("fc", "FillColor"); _Abbreviations.put("s",
    232                          * "Size");
    233                          */
     233                        _SetMethods.put("protection", Frame.class.getMethod("setProtection",
     234                                        pString));
    234235
    235236                } catch (SecurityException e) {
     
    413414
    414415                // create the text Item
    415                 Text attribs = DisplayIO.getCurrentFrame().createNewText();
    416                 attribs.setText(attributes.toString());
    417                 attribs.setColor(null);
     416                Frame current = DisplayIO.getCurrentFrame();
     417                Text attribs = current.getStatsTextItem(attributes.toString());
    418418                return attribs;
    419419        }
  • trunk/src/org/expeditee/gui/Browser.java

    r71 r72  
    4747         */
    4848        public static void main(String[] args) {
     49                FrameGraphics.SupressMessages(true);
    4950                _theBrowser = new Browser();
     51                FrameGraphics.SupressMessages(false);
    5052                // Why do we want to ignore repaint?
    5153                //_theBrowser.setIgnoreRepaint(true);
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r70 r72  
    1515import javax.swing.JOptionPane;
    1616
    17 import org.expeditee.actions.NavigationActions;
    1817import org.expeditee.items.Item;
    1918import org.expeditee.items.ItemParentStateChangedEvent;
     
    6059         * The title to display in the Title bar.
    6160         */
    62         public static final String TITLE = "Exp21May2008A";
     61        public static final String TITLE = "Exp22May2008A";
    6362
    6463        private DisplayIO() {
     
    170169                setCursorPosition(x, y, true);
    171170        }
    172 
     171       
    173172        public static void setCursorPosition(int x, int y, boolean forceArrow) {
    174173                int deltax = x - FrameMouseActions.MouseX;
     
    180179                }
    181180
    182                 // ensures the cursor doesn't fall behind while waiting for robot
    183                 FrameMouseActions.MouseX = x;
    184                 FrameMouseActions.MouseY = y;
    185 
     181                //When the Robot moves the cursor... a short time later a mouseMoved event is generated...
     182                //We want to ignore this event by remembering the location the robot was shifted to.
     183                FrameMouseActions.setLastRobotMove(x, y);
     184               
    186185                if (Frame.itemAttachedToCursor()) {
    187186                        List<Item> toMove = Frame.FreeItems;
     
    193192                // cheat
    194193                FrameMouseActions.setForceArrow(forceArrow);
    195                 _Robot.mouseMove((int) _Browser.getContentPane().getLocationOnScreen()
     194                int mouseX = (int) _Browser.getContentPane().getLocationOnScreen()
    196195                                .getX()
    197                                 + x, (int) _Browser.getContentPane().getLocationOnScreen()
     196                                + x;
     197                int mouseY = (int) _Browser.getContentPane().getLocationOnScreen()
    198198                                .getY()
    199                                 + y);
     199                                + y;
     200                _Robot.mouseMove(mouseX, mouseY);
     201                //System.out.println("MouseMoved: " + x + "," + y);
    200202        }
    201203
     
    327329                                for (Item i : _CurrentFrames[getCurrentSide()].getItems()) {
    328330                                        i.onParentStateChanged(new ItemParentStateChangedEvent(
    329                                                         _CurrentFrames[getCurrentSide()], 
     331                                                        _CurrentFrames[getCurrentSide()],
    330332                                                        ItemParentStateChangedEvent.EVENT_TYPE_HIDDEN));
    331333                                }
     
    336338                        for (Item i : _CurrentFrames[getCurrentSide()].getItems()) {
    337339                                i.onParentStateChanged(new ItemParentStateChangedEvent(
    338                                                 _CurrentFrames[getCurrentSide()], 
     340                                                _CurrentFrames[getCurrentSide()],
    339341                                                ItemParentStateChangedEvent.EVENT_TYPE_SHOWN));
    340342                        }
     
    378380                                List<Frame> seen = new LinkedList<Frame>();
    379381                                seen.addAll(sharedOverlays); // Signify that seen all shared
    380                                                                                                 // overlays
     382                                // overlays
    381383                                seen.remove(_CurrentFrames[getCurrentSide()]); // must ensure
    382                                                                                                                                 // excluded
     384                                // excluded
    383385
    384386                                // Get all items seen from the current frame - including all
     
    390392                                for (Item i : items) {
    391393                                        i.onParentStateChanged(new ItemParentStateChangedEvent(
    392                                                         _CurrentFrames[getCurrentSide()], 
     394                                                        _CurrentFrames[getCurrentSide()],
    393395                                                        ItemParentStateChangedEvent.EVENT_TYPE_HIDDEN));
    394396                                }
     
    420422                                // else ...
    421423                                assert (owner != null);
    422                                 i.onParentStateChanged(new ItemParentStateChangedEvent(
    423                                                 _CurrentFrames[getCurrentSide()],
    424                                                 ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY,
    425                                                 owner.Level));
     424                                i
     425                                                .onParentStateChanged(new ItemParentStateChangedEvent(
     426                                                                _CurrentFrames[getCurrentSide()],
     427                                                                ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY,
     428                                                                owner.Level));
    426429                        }
    427430
     
    429432                        for (Item i : nonOverlayItems) {
    430433                                i.onParentStateChanged(new ItemParentStateChangedEvent(
    431                                                 _CurrentFrames[getCurrentSide()], 
     434                                                _CurrentFrames[getCurrentSide()],
    432435                                                ItemParentStateChangedEvent.EVENT_TYPE_SHOWN));
    433436                        }
     
    438441
    439442        public static void UpdateTitle() {
    440                 StringBuffer title = new StringBuffer(TITLE + " [");
     443                StringBuffer title = new StringBuffer(TITLE);
    441444
    442445                if (FrameGraphics.isAudienceMode())
    443446                        title.append(" - Audience Mode");
    444447                else
    445                         title.append(SessionStats.getShortStats()).append(']');
     448                        title.append(" [").append(SessionStats.getShortStats()).append(']');
    446449
    447450                _Browser.setTitle(title.toString());
     
    537540        }
    538541
    539         public static void Back() {     
     542        public static void Back() {
    540543                int side = getCurrentSide();
    541544
     
    557560                        FrameIO.SuspendCache();
    558561                Frame frame = null;
    559                 do{
     562                do {
    560563                        frame = FrameIO.LoadFrame(_VisitedFrames[side].pop());
    561                 }while(frame == getCurrentFrame());
     564                } while (frame == getCurrentFrame());
     565
    562566                if (isTwinFramesOn())
    563567                        FrameIO.ResumeCache();
  • trunk/src/org/expeditee/gui/Frame.java

    r71 r72  
    2424import org.expeditee.items.Text;
    2525import org.expeditee.items.WidgetCorner;
     26import org.expeditee.stats.SessionStats;
    2627
    2728/**
     
    4950        private int _version = 0;
    5051
    51         private String _protection = null;
     52        private String _protection = "" + Item.PERMISSION_FULL;
    5253
    5354        private String _owner = null;
     
    7071
    7172        // The items contained in this Frame
    72 
    7373        // records whether a change has been made to this Frame (for saving
    7474        // purposes).
     
    354354        }
    355355
     356        public Text getStatTemplate() {
     357                SessionStats.CreatedText();
     358                Text t = getTemplate(UserSettings.StatTemplate,
     359                                ItemUtils.TAG_STAT_TEMPLATE);
     360
     361                if (t == null) {
     362                        t = getItemTemplate();
     363                }
     364
     365                return t;
     366        }
     367
     368        public Text getStatsTextItem(String itemText) {
     369                Text t = getStatTemplate();
     370                // We dont want the stats to wrap at all
     371                t.setMaxSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
     372                t.setText(itemText);
     373                t.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());
     374                addItem(t);
     375                return t;
     376        }
     377
    356378        public Text getCodeCommentTemplate() {
    357379                Text t = getTemplate(UserSettings.CodeCommentTemplate,
     
    378400
    379401                for (Item i : _body)
    380                         if (i.isVisible() /* && i != _frameName */&& i.intersects(poly)) {
     402                        if (i.isVisible() && i.intersects(poly)) {
    381403                                if (!results.contains(i))
    382404                                        results.add(i);
     
    404426                String frameset = Conversion.getFrameset(framename, false);
    405427
    406                 setFrameset(frameset);
    407                 setFrameNumber(num);
     428                setFrameName(frameset, num);
    408429        }
    409430
     
    464485        public void setProtection(String protection) {
    465486                _protection = protection;
     487               
     488                if (_body.size() > 0)
     489                        refreshItemPermissions();
    466490        }
    467491
     
    11251149         */
    11261150        public Text createBlankText(String templateType) {
     1151                SessionStats.CreatedText();
    11271152                Text t;
    11281153                if (templateType.length() == 0)
     
    11401165        }
    11411166
    1142         public Dot createDot() {
    1143                 Dot dot = new Dot(DisplayIO.getRealMouseX(), DisplayIO.getMouseY(),
     1167        public Item createDot() {
     1168                Item dot = new Dot(DisplayIO.getRealMouseX(), DisplayIO.getMouseY(),
    11441169                                getNextItemID());
    11451170
     
    11671192                        }
    11681193                }
     1194
     1195                if (t == null)
     1196                        return null;
    11691197
    11701198                // If the item is linked apply any attribute pairs on the child frame
     
    12161244        }
    12171245
    1218         public Dot addDot(int x, int y) {
    1219                 Dot d = new Dot(x, y, getNextItemID());
     1246        public Item addDot(int x, int y) {
     1247                Item d = new Dot(x, y, getNextItemID());
    12201248                addItem(d);
    12211249                return d;
     
    13571385                                Frame.COLOR_WHEEL));
    13581386        }
     1387
     1388        public void setFrameName(String frameset, int i) {
     1389                setFrameset(frameset);
     1390                setFrameNumber(i);
     1391        }
     1392
     1393        /**
     1394         * Sets the item permissions to match the protection for the frame.
     1395         *
     1396         */
     1397        public void refreshItemPermissions() {
     1398                int permission = Item.PERMISSION_FULL;
     1399                try{
     1400                        permission = Integer.parseInt(_protection);
     1401                }catch(Exception e){
     1402                }
     1403               
     1404                _frameName.Permission = permission;
     1405                if(permission < Item.PERMISSION_COPY){
     1406                        _frameName.setBackgroundColor(new Color(255, 220, 220));
     1407                }else if (permission == Item.PERMISSION_COPY){
     1408                        _frameName.setBackgroundColor(new Color(255, 230, 135));
     1409                }else if (permission == Item.PERMISSION_TDFC){
     1410                        _frameName.setBackgroundColor(new Color(220, 255, 220));
     1411                }else {
     1412                        _frameName.setBackgroundColor(null);
     1413                }
     1414               
     1415               
     1416                for(Item i: _body) {
     1417                        i.Permission = permission;
     1418                }
     1419        }
    13591420}
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r70 r72  
    1212import java.awt.RenderingHints;
    1313import java.awt.image.VolatileImage;
     14import java.util.Collection;
    1415import java.util.LinkedList;
    1516import java.util.List;
     
    1920
    2021import org.expeditee.actions.Misc;
    21 import org.expeditee.items.Dot;
    2222import org.expeditee.items.InteractiveWidget;
    2323import org.expeditee.items.Item;
     24import org.expeditee.items.ItemUtils;
    2425import org.expeditee.items.Line;
    2526import org.expeditee.items.Picture;
     
    6465
    6566        // if true, error messages are not shown to the user
    66         private static boolean _SupressErrors = false;
     67        private static boolean _SupressMessages = false;
    6768
    6869        public static String MESSAGES_FRAMESET_NAME = "Messages";
     
    7980         */
    8081        public static void ToggleAudienceMode() {
     82                Frame current = DisplayIO.getCurrentFrame();
    8183                if (_Mode == MODE_AUDIENCE)
    8284                        _Mode = MODE_NORMAL;
    83                 else
     85                else {
    8486                        _Mode = MODE_AUDIENCE;
    85 
    86                 FrameUtils.Parse(DisplayIO.getCurrentFrame());
     87                        ItemUtils.UpdateConnectedToAnnotations(current.getItems());
     88                }
     89                FrameUtils.Parse(current);
    8790                DisplayIO.UpdateTitle();
    8891                Repaint();
     
    178181                if (g != null
    179182                                && (!isAudienceMode()
    180                                                 || (isAudienceMode() && !i.isAnnotation()) || i == FrameUtils.LastEdited)) {
     183                                                || (isAudienceMode() && !i.isConnectedToAnnotation() && !i
     184                                                                .isAnnotation()) || i == FrameUtils.LastEdited)) {
    181185
    182186                        Graphics2D tg = (Graphics2D) g.create();
     
    503507                        if (i instanceof Picture)
    504508                                PaintItem(g, i);
    505                         else if (i instanceof Dot)
    506                                 ((Dot) i).paintFill(g);
     509                        else if (i.isLineEnd() && (!isAudienceMode() ||
     510                                        !i.isConnectedToAnnotation()))
     511                                i.paintFill(g);
    507512                }
    508513        }
     
    538543                                toDisconnect.setSelectedMode(newMode);
    539544                        } else {
    540                                 List<Item> connected = i.getAllConnected();
     545                                Collection<Item> connected = i.getAllConnected();
    541546                                for (Item conn : connected) {
    542547                                        conn.setSelectedMode(Item.SelectedMode.Connected);
     
    585590        public static void DisplayMessage(String message, Color textColor) {
    586591                displayMessage(message, null, null, textColor);
    587                 //Misc.Beep();
     592                // Misc.Beep();
    588593        }
    589594
    590595        public static void DisplayMessage(Text message) {
    591                 displayMessage(message.getFirstLine(), message.getLink(), message.getAction(), message.getColor());
     596                displayMessage(message.getFirstLine(), message.getLink(), message
     597                                .getAction(), message.getColor());
    592598                // Misc.Beep();
    593599        }
     
    596602                // _lastMessage = null;
    597603                displayMessage(message, null, null, Color.BLACK);
    598                 //Misc.Beep();
     604                // Misc.Beep();
    599605        }
    600606
    601607        public static void WarningMessage(String message) {
    602608                displayMessage(message, null, null, Color.MAGENTA);
    603                 //Misc.Beep();
     609                // Misc.Beep();
    604610        }
    605611
     
    608614        private static void displayMessage(String message, String link,
    609615                        List<String> actions, Color color) {
    610                 // add timestamp to message
    611                 // if (message.equals(_lastMessage))
    612                 // return;
    613                 // _lastMessage = message;
    614 
    615                 // message += _formatter.format(Calendar.getInstance().getTime());
    616 
    617                 // if the creator needs to be initialised (happens on first message)
     616                if (_SupressMessages)
     617                        return;
     618
    618619                if (_creator == null) {
    619620                        _creator = new FrameCreator(MESSAGES_FRAMESET_NAME, true);
     
    682683         */
    683684        public static void LinkedErrorMessage(String message) {
    684                 if (_SupressErrors)
     685                if (_SupressMessages)
    685686                        return;
    686687                Misc.Beep();
     
    693694
    694695        public static void ErrorMessage(String message) {
    695                 if (_SupressErrors)
     696                if (_SupressMessages)
    696697                        return;
    697698                Misc.Beep();
     
    745746        }
    746747
    747         public static void SupressErrors(boolean val) {
    748                 _SupressErrors = val;
     748        public static void SupressMessages(boolean val) {
     749                _SupressMessages = val;
    749750        }
    750751
  • trunk/src/org/expeditee/gui/FrameIO.java

    r70 r72  
    113113                // do not display errors encountered to the user
    114114                // (they will be shown at load time)
    115                 FrameGraphics.SupressErrors(true);
     115                FrameGraphics.SupressMessages(true);
    116116                // loading automatically caches the frame is caching is turned on
    117117                LoadUnknownPath(framename);
    118                 FrameGraphics.SupressErrors(false);
     118                FrameGraphics.SupressMessages(false);
    119119        }
    120120
     
    422422                if (toDelete == null)
    423423                        return false;
     424
     425                // Dont delete the zero frame
     426                if (toDelete.getFrameNumber() == 0) {
     427                        FrameGraphics.ErrorMessage("Zero frame's can not be deleted");
     428                        return false;
     429                }
    424430
    425431                SaveFrame(toDelete);
     
    474480         */
    475481        public static Frame CreateFrame(String frameset, String frameTitle,
    476                         String templateFrame) {
    477 
     482                        String templateFrame) throws RuntimeException {
     483
     484                if (!FrameIO.isValidFramesetName(frameset)) {
     485                        throw new RuntimeException(frameset + " is not a valid frameset name");
     486                }
     487               
    478488                int next = -1;
    479489
    480490                // disable caching of 0 frames
    481491                SuspendCache();
     492                String zeroFrameName = frameset + "0";
     493                Frame destFramesetZero = LoadFrame(zeroFrameName);
     494                if (destFramesetZero == null) {
     495                        throw new RuntimeException(zeroFrameName + " could not be found");
     496                }
    482497
    483498                Frame template = null;
    484                 if (templateFrame == null)
     499                if (templateFrame == null) {
    485500                        // load in frame.0
    486                         template = LoadFrame(frameset + "0");
    487                 else
     501                        template = destFramesetZero;
     502                } else {
    488503                        template = LoadFrame(templateFrame);
     504                        if (template == null) {
     505                                throw new RuntimeException("LinkTemplate " + templateFrame
     506                                                + " could not be found");
     507                        }
     508                }
    489509
    490510                ResumeCache();
     
    492512                // read the next number from the INF file
    493513                try {
    494                         next = ReadINF(template.path, frameset);
     514                        next = ReadINF(destFramesetZero.path, frameset);
    495515                } catch (IOException ioe) {
    496516                        ioe.printStackTrace();
    497                         Logger.Log(ioe);
    498                         return null;
     517                        throw new RuntimeException("INF file could not be read");
    499518                }
    500519
    501520                // set the number and title of the new frame
    502                 template.setFrameNumber(++next);
     521                template.setFrameName(frameset, ++ next);
    503522                template.setTitle(frameTitle);
    504523
     
    634653
    635654                if (!toSave.hasChanged() || toSave.isSaved())
     655                        return "";
     656               
     657                //Dont save if the frame is protected
     658                if (toSave.getFrameNameItem().Permission < Item.PERMISSION_TDFC)
    636659                        return "";
    637660
     
    702725                                // backup tag will be ignored
    703726                                original.setFrameNumber(nextnum);
     727                                original.setProtection("" + Item.PERMISSION_COPY);
    704728                                original.change();
    705729                                SaveFrame(original, false, false);
     
    845869                }
    846870
    847                 assert (IsValidFramesetName(result.toString()));
     871                assert (isValidFramesetName(result.toString()));
    848872                return result.toString();
    849873        }
    850874
    851         public static Frame CreateNewFrame(Item linker) {
     875        public static Frame CreateNewFrame(Item linker) throws RuntimeException {
    852876                String title = null;
    853877                if (linker instanceof Text)
    854878                        title = ((Text) linker).getFirstLine();
    855879
    856                 String frameset = DisplayIO.getCurrentFrame().getFramesetName();
    857 
    858880                String templateLink = linker.getLinkTemplate();
     881                String framesetLink = linker.getLinkFrameset();
     882                String frameset = (framesetLink != null ? framesetLink : DisplayIO
     883                                .getCurrentFrame().getFramesetName());
    859884
    860885                Frame newFrame = FrameIO.CreateFrame(frameset, title, templateLink);
     
    942967                String conversion = frameset + " --> ";
    943968
    944                 if (!IsValidFramesetName(frameset)) {
     969                if (!isValidFramesetName(frameset)) {
    945970                        throw new Exception("Invalid frameset name");
    946971                }
     
    10161041         * @return true if the frameset name is valid
    10171042         */
    1018         public static boolean IsValidFramesetName(String frameset) {
     1043        public static boolean isValidFramesetName(String frameset) {
    10191044                if (frameset == null) {
    10201045                        return false;
     
    11231148        }
    11241149
     1150        public static boolean isValidLink(String frameName) {
     1151                return frameName == null || isPositiveInteger(frameName) || isValidFrameName(frameName);
     1152        }
     1153
    11251154}
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r70 r72  
    99import java.awt.event.KeyListener;
    1010import java.util.ArrayList;
     11import java.util.Collection;
    1112import java.util.LinkedList;
    1213import java.util.List;
     
    5556        public static final int FORCE_REPAINT = 12;
    5657
    57         public static final int MINIMUM_SIZE = 10;
    58 
    5958        public synchronized void keyTyped(KeyEvent e) {
    6059                if (Simple.isProgramRunning()) {
     
    7170                        return;
    7271
     72                if (FrameMouseActions.isWaitingForRobot()) {
     73//                      try{
     74//                      Thread.sleep(10000);
     75//                      }catch(Exception ex){
     76//                             
     77//                      }
     78//                      keyTyped(e);
     79//                      System.out.println("Waiting: " + e.getKeyChar());
     80                        return;
     81                }
    7382                e.consume();
    7483                char ch = e.getKeyChar();
    75 
     84                //System.out.println(ch);
     85               
    7686                if (e.isAltDown()) {
    7787                        if (FrameUtils.getCurrentItem() == null
     
    125135                                return;
    126136                        }
    127                         replaceDot((Dot) on, ch);
    128                         ItemUtils.EnclosedCheck(DisplayIO.getCurrentFrame().getItems());
     137                        replaceDot((Item) on, ch);
    129138                        return;
    130139                }
     
    151160                // if the user is in free space, create a new text item
    152161                if (on == null || !on.isHighlighted()) {
    153                         SessionStats.CreatedText();
    154162                        // DisplayIO.UpdateTitle();
    155163                        text = createText(ch);
     
    188196        }
    189197
    190         public static Text replaceDot(Dot dot, char ch) {
    191                 SessionStats.CreatedText();
     198        public static Text replaceDot(Item dot, char ch) {
    192199                Text text = createText(ch);
    193                 text.setPosition(dot.getPosition());
    194                 text.setThickness(dot.getThickness());
     200                Item.DuplicateItem(dot, text);
    195201                FrameUtils.LastEdited = text;
    196202
    197                 //Copy the lines list so it can be modified
     203                // Copy the lines list so it can be modified
    198204                List<Line> lines = new LinkedList<Line>(dot.getLines());
    199205                for (Line line : lines)
    200206                        line.replaceEnd(dot, text);
    201                
    202                 DisplayIO.getCurrentFrame().removeItem(dot);
    203                 DisplayIO.getCurrentFrame().addItem(text);
     207                Frame current = DisplayIO.getCurrentFrame();
     208                current.removeItem(dot);
     209                current.addItem(text);
     210                ItemUtils.EnclosedCheck(current.getItems());
    204211                return text;
    205212        }
    206213
    207         // replaces the given text item with a dot
    208         private static void replaceText(Text text) {
    209                 Dot dot = new Dot(text.getX(), text.getY(), text.getID());
     214        /**
     215         * Replaces the given text item with a dot
     216         */
     217        public static Item replaceText(Text text) {
     218                Item dot = new Dot(text.getX(), text.getY(), text.getID());
    210219                Item.DuplicateItem(text, dot);
    211220
     
    214223                if (lines.size() > 0)
    215224                        dot.setColor(lines.get(0).getColor());
    216                 for (Line line : lines){
     225                for (Line line : lines) {
    217226                        line.replaceEnd(text, dot);
    218227                }
    219228                text.delete();
    220                 DisplayIO.getCurrentFrame().addItem(dot);
     229                Frame current = DisplayIO.getCurrentFrame();
     230                current.addItem(dot);
    221231                DisplayIO.setCursor(Item.DEFAULT_CURSOR);
     232                ItemUtils.EnclosedCheck(current.getItems());
     233                return dot;
    222234        }
    223235
     
    345357                case KeyEvent.VK_UP:
    346358                        if (e.isControlDown() || e.isShiftDown()) {
    347                                 DisplayIO.getCurrentFrame();
     359                                NextTextItem(FrameUtils.getCurrentItem(), false);
    348360                        } else {
    349361                                move(Text.UP);
     
    351363                        break;
    352364                case KeyEvent.VK_DOWN:
    353                         move(Text.DOWN);
     365                        if (e.isControlDown() || e.isShiftDown()) {
     366                                NextTextItem(FrameUtils.getCurrentItem(), true);
     367                        } else {
     368                                move(Text.DOWN);
     369                        }
    354370                        break;
    355371                case KeyEvent.VK_END:
     
    365381                        break;
    366382                }
     383        }
     384
     385        /**
     386         * Moves the cursor to the next text item on the frame
     387         *
     388         * @param currentItem
     389         * @param direction
     390         *            move up if direction is negative, down if direction is
     391         *            positive
     392         */
     393        public static void NextTextItem(Item currentItem, boolean down) {
     394                // Move the cursor to the next text item
     395                Frame current = DisplayIO.getCurrentFrame();
     396                Text title = current.getTitle();
     397                List<Text> textItems = current.getBodyTextItems(false);
     398                if (textItems.size() == 0) {
     399                        DisplayIO.setCursorPosition(title.getPosition());
     400                        FrameGraphics.Repaint();
     401                        return;
     402                }
     403
     404                if (currentItem == null) {
     405                        // find the nearest item in the correct direction
     406                        int currY = DisplayIO.getMouseY();
     407                        for (int i = 0; i < textItems.size(); i++) {
     408                                Text t = textItems.get(i);
     409                                if (currY < t.getY()) {
     410                                        if (down) {
     411                                                DisplayIO.setCursorPosition(t.getPosition());
     412                                        } else {
     413                                                if (i == 0)
     414                                                        break;
     415                                                DisplayIO.setCursorPosition(textItems.get(i - 1)
     416                                                                .getPosition());
     417                                        }
     418                                        FrameGraphics.Repaint();
     419                                        return;
     420                                }
     421                        }
     422                        DisplayIO.setCursorPosition(title.getPosition());
     423                        return;
     424                }
     425
     426                if (current.getTitle().equals(currentItem)) {
     427                        if (down) {
     428                                // Show the first item
     429                                DisplayIO.setCursorPosition(textItems.get(0).getPosition());
     430                        } else {
     431                                // Show the last item
     432                                DisplayIO.setCursorPosition(textItems.get(textItems.size() - 1)
     433                                                .getPosition());
     434                        }
     435                        FrameGraphics.Repaint();
     436                        return;
     437                }
     438                // Find the current item... then move to the next item
     439                for (int i = 0; i < textItems.size(); i++) {
     440                        if (textItems.get(i).equals(currentItem)) {
     441                                int nextIndex = i + (down ? 1 : -1);
     442                                if (nextIndex >= 0 && nextIndex < textItems.size()) {
     443                                        DisplayIO.setCursorPosition(textItems.get(nextIndex)
     444                                                        .getPosition());
     445                                } else {
     446                                        DisplayIO.setCursorPosition(title.getPosition());
     447                                }
     448                                FrameGraphics.Repaint();
     449                                return;
     450                        }
     451                }
     452
    367453        }
    368454
     
    399485         */
    400486        private static void controlChar(KeyEvent e, String ch) {
     487                if (ch.length() > 1)
     488                        return;
     489
    401490                // if this is a paste command
    402491                if (ch.charAt(0) == KeyEvent.VK_V) {
     
    422511                                        List<Item> clipboard = new ArrayList<Item>();
    423512                                        clipboard.add(text);
    424                                         List<Item> left = FrameMouseActions.merge(clipboard,
     513                                        Collection<Item> left = FrameMouseActions.merge(clipboard,
    425514                                                        clicked);
    426515                                        FrameMouseActions.anchor(left);
     
    577666
    578667                // check for enclosed mode
    579                 if (on == null || on == null) {
    580                         List<Item> enclosed = FrameUtils.getCurrentItems();
     668                if (on == null) {
     669                        Collection<Item> enclosed = FrameUtils.getCurrentItems();
    581670
    582671                        if (enclosed != null && enclosed.size() > 0) {
    583672                                // ensure only one dot\line is present in the list
    584                                 List<Item> dots = FrameUtils.getEnclosingDots();
    585                                 List<Item> connected = dots.get(0).getAllConnected();
     673                                Collection<Item> dots = FrameUtils.getEnclosingDots();
     674                                Item firstConnected = dots.iterator().next();
     675                                Collection<Item> connected = firstConnected.getAllConnected();
    586676
    587677                                // only resize lines if they are not surrounding some non line
     
    590680                                for (Item ip : enclosed) {
    591681                                        if (ip != null) {
    592                                                 if (!(ip instanceof Line) && !(ip instanceof Dot)) {
     682                                                if (!(ip instanceof Line) && !(ip.isLineEnd())) {
    593683                                                        resizeLines = false;
    594684                                                        break;
     
    597687                                }
    598688
    599                                 for (Item ip : enclosed) {
    600                                         if (ip != null && !(connected.indexOf(ip) > 0))
    601                                                 switch (key) {
    602                                                 case SIZE_UP:
    603                                                         if (resizeLines
    604                                                                         || (!(ip instanceof Line) && !(ip instanceof Dot)))
    605                                                                 SetSize(ip, repeat, false);
    606                                                         break;
    607                                                 case SIZE_DOWN:
    608                                                         if (resizeLines
    609                                                                         || (!(ip instanceof Line) && !(ip instanceof Dot)))
    610                                                                 SetSize(ip, -repeat, false);
    611                                                         break;
    612                                                 // case COLOR_CHANGE: SetFillColor(ip); break;
    613                                                 case ANNOTATION_CHANGE:
    614                                                         ToggleAnnotation(ip);
    615                                                         break;
    616                                                 case FONT_STYLE_CHANGE:
    617                                                         ToggleFontStyle(ip);
    618                                                         break;
    619                                                 case FONT_FAMILY_CHANGE:
    620                                                         ToggleFontFamily(ip);
    621                                                         break;
    622                                                 case DATE_ITEM:
    623                                                         AddDate(ip);
    624                                                         break;
    625                                                 }
     689                                switch (key) {
     690                                case SIZE_UP:
     691                                        if (resizeLines
     692                                                        || (!(firstConnected instanceof Line) && !(firstConnected instanceof Dot)))
     693                                                SetSize(firstConnected, repeat, false);
     694                                        break;
     695                                case SIZE_DOWN:
     696                                        if (resizeLines
     697                                                        || (!(firstConnected instanceof Line) && !(firstConnected instanceof Dot)))
     698                                                SetSize(firstConnected, -repeat, false);
     699                                        break;
     700                                // case COLOR_CHANGE: SetFillColor(firstConnected); break;
     701                                case ANNOTATION_CHANGE:
     702                                        ToggleAnnotation(firstConnected);
     703                                        break;
     704                                case FONT_STYLE_CHANGE:
     705                                        ToggleFontStyle(firstConnected);
     706                                        break;
     707                                case FONT_FAMILY_CHANGE:
     708                                        ToggleFontFamily(firstConnected);
     709                                        break;
     710                                case DATE_ITEM:
     711                                        AddDate(firstConnected);
     712                                        break;
    626713                                }
    627714
     
    693780         */
    694781        private static void Drop(Item ip) {
    695                 String newItemText = DEFAULT_NEW_ITEM_TEXT;
    696 
    697                 // if a line is being rubber-banded, this is a no-op
    698                 if (Frame.rubberbandingLine())
    699                         return; // No-op
    700 
    701                 // drop requires no permissions
    702                 Item toDropFrom = null;
    703                 if (ip != null)
    704                         toDropFrom = ip;
    705 
    706                 // if the cursor is in free space then the drop will happen from the
    707                 // last non annotation text item on the frame
    708                 if (toDropFrom == null) {
    709                         toDropFrom = DisplayIO.getCurrentFrame()
    710                                         .getLastNonAnnotationTextItem();
    711                 }
    712 
    713                 // if no item was found, return
    714                 if (toDropFrom == null) {
    715                         FrameGraphics.ErrorMessage("No item could be found to drop from");
    716                         return;
    717                 }
    718 
    719                 if (!(toDropFrom instanceof Text)) {
    720                         FrameGraphics.DisplayMessage("Only text items can be dropped from");
    721                         return;
    722                 }
    723 
    724                 // Get the list of items that must be dropped
    725                 List<Item> column = DisplayIO.getCurrentFrame().getColumn(toDropFrom);
    726 
    727                 if (column == null) {
    728                         FrameGraphics.ErrorMessage("No column found to align items to");
    729                         return;
    730                 }
    731 
    732                 Text title = DisplayIO.getCurrentFrame().getTitle();
    733 
    734                 // We wont do auto bulleting when dropping from titles
    735                 if (toDropFrom != title) {
    736                         newItemText = getAutoBullet(((Text) toDropFrom).getFirstLine());
    737                 }
    738 
    739                 Text dummyItem = null;
    740 
    741                 if (Frame.textItemAttachedToCursor()) {
    742                         dummyItem = (Text) Frame.getItemAttachedToCursor();
    743                         String autoBullet = getAutoBullet(dummyItem.getTextNoList());
    744 
    745                         if (autoBullet.length() > 0)
    746                                 newItemText = "";
    747                         dummyItem.setText(newItemText + dummyItem.getTextNoList());
    748                 }
    749                 dummyItem = createText();
    750                 if (Frame.textItemAttachedToCursor()) {
    751                         Text t = (Text) Frame.getItemAttachedToCursor();
    752                         dummyItem.setSize(t.getSize());
    753                         for (int i = 0; i < t.getText().size(); i++) {
    754                                 newItemText += '\n';
    755                         }
    756                 }
    757 
    758                 dummyItem.setText(newItemText);
    759 
    760                 // If the only item on the frame is the title and the frame name just
    761                 // drop a specified distance below the title
    762                 if (column.size() == 0) {
    763                         Text itemTemplate = DisplayIO.getCurrentFrame().getItemTemplate();
    764                         int xPos = title.getX();
    765                         int yPos = title.getY() + title.getBoundsHeight()
    766                                         + itemTemplate.getBoundsHeight();
    767                         dummyItem.setPosition(xPos, yPos);
    768                         DisplayIO.setCursorPosition(xPos, yPos);
    769                 } else {
    770                         int yPos = column.get(0).getY() + 1;
    771                         // Either position the new item below the title or just above
    772                         // the first item below the title
    773                         if (toDropFrom == title)
    774                                 yPos = Math
    775                                                 .min(column.get(0).getY() - 1, title.getY()
    776                                                                 + title.getBoundsHeight()
    777                                                                 + dummyItem.getBoundsHeight());
    778                         dummyItem.setPosition(column.get(0).getX(), yPos);
    779                         column.add(dummyItem);
    780                         FrameUtils.Align(column, false, 0);
    781                         // Check if it will be outside the frame area
    782                         if (dummyItem.getY() < 0
    783                                         || dummyItem.getY() > FrameGraphics.getMaxFrameSize()
    784                                                         .getHeight()) {
    785                                 // Check for the @more tag!
    786                                 Item i = ItemUtils.FindTag(DisplayIO.getCurrentFrame()
    787                                                 .getItems(), "@More");
    788                                 if (i != null) {
    789                                         Frame firstFrame = DisplayIO.getCurrentFrame();
    790                                         boolean mouseMoved = FrameMouseActions.tdfc(i);
    791                                         Frame moreFrame = DisplayIO.getCurrentFrame();
    792                                         moreFrame.setTitle(firstFrame.getTitle().getTextNoList());
    793                                         // need to move the mouse to the top of the frame if there
    794                                         // wasnt an @start on it
    795                                         if (!mouseMoved) {
    796                                                 Item moreTitle = moreFrame.getTitle();
    797                                                 moreTitle.Permission = Item.PERMISSION_FULL;
    798                                                 Drop(moreTitle);
     782                try {
     783                        String newItemText = DEFAULT_NEW_ITEM_TEXT;
     784
     785                        // if a line is being rubber-banded, this is a no-op
     786                        if (Frame.rubberbandingLine())
     787                                return; // No-op
     788
     789                        // drop requires no permissions
     790                        Item toDropFrom = null;
     791                        if (ip != null)
     792                                toDropFrom = ip;
     793
     794                        // if the cursor is in free space then the drop will happen from the
     795                        // last non annotation text item on the frame
     796                        if (toDropFrom == null) {
     797                                toDropFrom = DisplayIO.getCurrentFrame()
     798                                                .getLastNonAnnotationTextItem();
     799                        }
     800
     801                        // if no item was found, return
     802                        if (toDropFrom == null) {
     803                                FrameGraphics
     804                                                .ErrorMessage("No item could be found to drop from");
     805                                return;
     806                        }
     807
     808                        if (!(toDropFrom instanceof Text)) {
     809                                FrameGraphics
     810                                                .DisplayMessage("Only text items can be dropped from");
     811                                return;
     812                        }
     813
     814                        // Get the list of items that must be dropped
     815                        List<Item> column = DisplayIO.getCurrentFrame().getColumn(
     816                                        toDropFrom);
     817
     818                        if (column == null) {
     819                                FrameGraphics.ErrorMessage("No column found to align items to");
     820                                return;
     821                        }
     822
     823                        Text title = DisplayIO.getCurrentFrame().getTitle();
     824
     825                        // We wont do auto bulleting when dropping from titles
     826                        if (toDropFrom != title) {
     827                                newItemText = getAutoBullet(((Text) toDropFrom).getFirstLine());
     828                        }
     829
     830                        Text dummyItem = null;
     831
     832                        if (Frame.textItemAttachedToCursor()) {
     833                                dummyItem = (Text) Frame.getItemAttachedToCursor();
     834                                String autoBullet = getAutoBullet(dummyItem.getTextNoList());
     835
     836                                if (autoBullet.length() > 0)
     837                                        newItemText = "";
     838                                dummyItem.setText(newItemText + dummyItem.getTextNoList());
     839                        }
     840                        dummyItem = createText();
     841                        if (Frame.textItemAttachedToCursor()) {
     842                                Text t = (Text) Frame.getItemAttachedToCursor();
     843                                dummyItem.setSize(t.getSize());
     844                                for (int i = 0; i < t.getText().size(); i++) {
     845                                        newItemText += '\n';
     846                                }
     847                        }
     848
     849                        dummyItem.setText(newItemText);
     850
     851                        // If the only item on the frame is the title and the frame name
     852                        // just
     853                        // drop a specified distance below the title
     854                        if (column.size() == 0) {
     855                                Text itemTemplate = DisplayIO.getCurrentFrame()
     856                                                .getItemTemplate();
     857                                int xPos = title.getX();
     858                                int yPos = title.getY() + title.getBoundsHeight()
     859                                                + itemTemplate.getBoundsHeight();
     860                                dummyItem.setPosition(xPos, yPos);
     861                                DisplayIO.setCursorPosition(xPos, yPos);
     862                        } else {
     863                                int yPos = column.get(0).getY() + 1;
     864                                // Either position the new item below the title or just above
     865                                // the first item below the title
     866                                if (toDropFrom == title)
     867                                        yPos = Math.min(column.get(0).getY() - 1, title.getY()
     868                                                        + title.getBoundsHeight()
     869                                                        + dummyItem.getBoundsHeight());
     870                                dummyItem.setPosition(column.get(0).getX(), yPos);
     871                                column.add(dummyItem);
     872                                FrameUtils.Align(column, false, 0);
     873                                // Check if it will be outside the frame area
     874                                if (dummyItem.getY() < 0
     875                                                || dummyItem.getY() > FrameGraphics.getMaxFrameSize()
     876                                                                .getHeight()) {
     877                                        // Check for the @more tag!
     878                                        Item i = ItemUtils.FindTag(DisplayIO.getCurrentFrame()
     879                                                        .getItems(), "@More");
     880                                        if (i != null) {
     881                                                Frame firstFrame = DisplayIO.getCurrentFrame();
     882                                                boolean mouseMoved = FrameMouseActions.tdfc(i);
     883                                                Frame moreFrame = DisplayIO.getCurrentFrame();
     884                                                moreFrame.setTitle(firstFrame.getTitle()
     885                                                                .getTextNoList());
     886                                                // need to move the mouse to the top of the frame if
     887                                                // there
     888                                                // wasnt an @start on it
     889                                                if (!mouseMoved) {
     890                                                        Item moreTitle = moreFrame.getTitle();
     891                                                        moreTitle.Permission = Item.PERMISSION_FULL;
     892                                                        Drop(moreTitle);
     893                                                }
     894                                                // Add the bullet text to the item
     895                                                dummyItem.setPosition(DisplayIO.getMouseX(), DisplayIO
     896                                                                .getMouseY());
     897                                        } else {
     898                                                FrameGraphics
     899                                                                .WarningMessage("Can not create items outside the frame area");
     900                                                // ensures correct repainting when items don't move
     901                                                DisplayIO.setCursorPosition(DisplayIO.getMouseX(),
     902                                                                DisplayIO.getMouseY());
     903                                                return;
    799904                                        }
    800                                         // Add the bullet text to the item
    801                                         dummyItem.setPosition(DisplayIO.getMouseX(), DisplayIO
    802                                                         .getMouseY());
     905                                }
     906                                if (!Frame.textItemAttachedToCursor() && !dummyItem.isEmpty()) {
     907                                        DisplayIO.getCurrentFrame().addItem(dummyItem);
     908                                }
     909
     910                                // Move the item to the cursor position
     911                                if (Frame.itemAttachedToCursor()) {
     912                                        DisplayIO.setCursorPosition(dummyItem.getX(), dummyItem
     913                                                        .getY());
     914                                        Item firstItem = Frame.getItemAttachedToCursor();
     915                                        int deltaX = firstItem.getX() - dummyItem.getX();
     916                                        int deltaY = firstItem.getY() - dummyItem.getY();
     917
     918                                        for (Item i : Frame.FreeItems) {
     919                                                i.setPosition(i.getX() - deltaX, i.getY() - deltaY);
     920                                        }
    803921                                } else {
    804                                         FrameGraphics
    805                                                         .WarningMessage("Can not create items outside the frame area");
    806                                         // ensures correct repainting when items don't move
    807                                         DisplayIO.setCursorPosition(DisplayIO.getMouseX(),
    808                                                         DisplayIO.getMouseY());
    809                                         return;
     922                                        DisplayIO.setCursorPosition(dummyItem
     923                                                        .getEndParagraphPosition().x, dummyItem.getY());
    810924                                }
    811925                        }
    812                         if (!Frame.textItemAttachedToCursor() && !dummyItem.isEmpty()) {
    813                                 DisplayIO.getCurrentFrame().addItem(dummyItem);
    814                         }
    815 
    816                         // Move the item to the cursor position
    817                         if (Frame.itemAttachedToCursor()) {
    818                                 DisplayIO.setCursorPosition(dummyItem.getX(), dummyItem.getY());
    819                                 Item firstItem = Frame.getItemAttachedToCursor();
    820                                 int deltaX = firstItem.getX() - dummyItem.getX();
    821                                 int deltaY = firstItem.getY() - dummyItem.getY();
    822 
    823                                 for (Item i : Frame.FreeItems) {
    824                                         i.setPosition(i.getX() - deltaX, i.getY() - deltaY);
    825                                 }
    826                         } else {
    827                                 DisplayIO
    828                                                 .setCursorPosition(
    829                                                                 dummyItem.getEndParagraphPosition().x,
    830                                                                 dummyItem.getY());
    831                         }
    832                 }
    833 
    834                 DisplayIO.resetCursorOffset();
    835                 FrameGraphics.Repaint();
     926
     927                        DisplayIO.resetCursorOffset();
     928                        FrameGraphics.Repaint();
     929                } catch (RuntimeException e) {
     930                        FrameGraphics.ErrorMessage(e.getMessage());
     931                }
    836932        }
    837933
     
    9921088         *            with resizing
    9931089         */
    994         private static void SetSize(Item ip, int diff, boolean moveCursor) {
     1090        private static void SetSize(Item item, int diff, boolean moveCursor) {
    9951091                List<Item> toSize = new ArrayList<Item>();
    9961092                // the mouse is only moved when the Item is on the frame, not free
     
    9991095
    10001096                // if the user is not pointing to any item
    1001                 if (ip == null) {
     1097                if (item == null) {
    10021098                        if (Frame.itemAttachedToCursor())
    10031099                                toSize.addAll(Frame.FreeItems);
     
    10091105                } else {
    10101106                        // check permissions
    1011                         if (ip.Permission < Item.PERMISSION_FULL) {
     1107                        if (item.Permission < Item.PERMISSION_FULL) {
    10121108                                FrameGraphics
    10131109                                                .DisplayMessage("Insufficient permission to change the size of that item");
    10141110                                return;
    10151111                        }
    1016                         toSet = ip;
    1017                         Item currentItem = FrameUtils.getCurrentItem();
    1018 
    1019                         if (currentItem != null && (currentItem instanceof Text)
    1020                                         && FrameUtils.getCurrentItems() == null) {
    1021                                 toSize.add(currentItem);
     1112                        toSet = item;
     1113
     1114                        if (!(toSet instanceof Text) && toSet.isLineEnd()) {
     1115                                toSize.addAll(toSet.getLines());
     1116                        } else if (toSet instanceof Line) {
     1117                                Line line = (Line) toSet;
     1118                                float current = Math.abs(line.getThickness());
     1119                                current = Math.max(current + diff, 1);
     1120                                line.setThickness(current);
     1121                                FrameGraphics.Repaint();
     1122                                return;
    10221123                        } else {
    1023                                 toSize.addAll(toSet.getLines());
    1024                         }
    1025                 }
    1026 
    1027                 if (toSet instanceof Line) {
    1028                         Line line = (Line) toSet;
    1029                         float current = Math.abs(line.getThickness());
    1030                         current = Math.max(current + diff, 1);
    1031                         line.setThickness(current);
    1032                         FrameGraphics.Repaint();
    1033                         return;
    1034                 }
    1035 
    1036                 /*
    1037                  * for(Item i : toSize){ if(i instanceof Dot || i instanceof Line){
    1038                  * toSize.removeAll(i.getConnected()); toSize.add(i); } }
    1039                  */
     1124                                toSize.add(toSet);
     1125                        }
     1126                }
    10401127
    10411128                int old_width = 0;
     
    10561143                                line.setThickness(current);
    10571144                        } else if (i instanceof Dot) {
    1058                                 Dot dot = (Dot) i;
     1145                                Item dot = (Item) i;
    10591146                                float current = Math.abs(dot.getThickness());
    10601147                                current = Math.max(current + diff, 1);
     
    10631150                                int current = Math.abs(i.getSize());
    10641151                                current = Math.max(current + diff, 1);
    1065                                 if (current > MINIMUM_SIZE)
    1066                                         i.setSize(current);
     1152                                i.setSize(current);
    10671153                        }
    10681154                }
     
    13531439                        return;
    13541440                }
    1355                
     1441
    13561442                if (!(item instanceof Text)) {
    13571443                        FrameGraphics
     
    13591445                        return;
    13601446                }
    1361                
    1362                 //dont create frameset if the item is linked
     1447
     1448                // dont create frameset if the item is linked
    13631449                if (item.getLink() != null) {
    13641450                        FrameGraphics
     
    13661452                        return;
    13671453                }
    1368                
     1454
    13691455                // check permissions
    13701456                if (item.Permission < Item.PERMISSION_FULL) {
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r70 r72  
    1313import java.util.Date;
    1414import java.util.HashSet;
     15import java.util.Iterator;
    1516import java.util.LinkedList;
    1617import java.util.List;
     
    8889        public static int MouseY;
    8990
    90         // Offset coordinates from the mouse position when grabbing items
     91        // Distance of mouse cursor from the origin of the item that was picked up
     92        // The are used in the move method to calculate the distance moved by the
     93        // cursor
    9194        private static int _offX;
    9295
    93         // MIKE: Thinks the offsets are used in getting items to draw in the message
    94         // window?
    9596        private static int _offY;
    9697
     
    567568                        if (clicked.Permission < Item.PERMISSION_FOLLOW_LINKS) {
    568569                                FrameGraphics
    569                                                 .DisplayMessage("Insufficient Permissions for action on item");
     570                                                .DisplayMessage("Insufficient permissions to perform action on item");
    570571                                return;
    571572                        }
     
    608609                                        return;
    609610                                }
    610 
    611                                 tdfc(clickedOn);
     611                                try {
     612                                        tdfc(clickedOn);
     613                                } catch (RuntimeException e) {
     614                                        FrameGraphics.ErrorMessage(e.getMessage());
     615                                }
    612616                                return;
    613617                        }
     
    667671                                                && clicked.getParent() != null
    668672                                                && clicked.getParent().getFrameNameItem() != clicked) {
    669                                         FrameGraphics.DisplayMessage("Insufficient Permission");
     673                                        FrameGraphics.DisplayMessage("Insufficient permission");
    670674                                        return;
    671675                                }
    672676
    673                                 Item merger  = Frame.FreeItems.get(0);
    674                                 assert(merger != null);
     677                                Item merger = Frame.FreeItems.get(0);
     678                                assert (merger != null);
    675679                                // Move the cursor if it is not Text-Text merging
    676680                                // Or Item to Line merging
     
    679683                                        DisplayIO.setCursorPosition(clicked.getPosition());
    680684                                }
    681                                 List<Item> left = merge(Frame.FreeItems, clicked);
     685                                Collection<Item> left = merge(Frame.FreeItems, clicked);
    682686                                anchor(left);
    683687                                Frame.FreeItems.clear();
     
    700704                        if (clicked.Permission < Item.PERMISSION_FULL) {
    701705                                FrameGraphics
    702                                                 .DisplayMessage("Insufficient Permission to pick up item");
     706                                                .DisplayMessage("Insufficient permission to pick up item");
    703707                                return;
    704708                        }
     
    781785                        Line newLine = createLine();
    782786                        SessionStats.CreatedItems(newLine.getAllConnected());
    783                        
     787
    784788                        // if the user can spot-weld, show the virtual spot
    785789                        if (on instanceof Line) {
     
    855859                                                && clicked.getParent().getFrameNameItem() != clicked) {
    856860                                        FrameGraphics
    857                                                         .DisplayMessage("Insufficient Permission to merge items");
     861                                                        .DisplayMessage("Insufficient permission to merge items");
    858862                                        return;
    859863                                }
     
    866870                                                // get a copy of all enclosed items before merging
    867871                                                // lineEnds
    868                                                 List<Item> items = FrameUtils.getItemsEnclosedBy(
     872                                                Collection<Item> items = FrameUtils.getItemsEnclosedBy(
    869873                                                                DisplayIO.getCurrentFrame(), d
    870874                                                                                .getEnclosedShape());
     
    892896                                                copies = copy(toCopy);
    893897                                                // Now do the merging
    894                                                 List<Item> remain = merge(Frame.FreeItems, clicked);
     898                                                Collection<Item> remain = merge(Frame.FreeItems,
     899                                                                clicked);
    895900                                                // anchor the points
    896901                                                anchor(remain);
     
    900905                                        } else if (Frame.FreeItems.size() == 2) {
    901906                                                copies = ItemUtils.UnreelLine(Frame.FreeItems);
    902                                                 List<Item> leftOver = merge(Frame.FreeItems, clicked);
     907                                                Collection<Item> leftOver = merge(Frame.FreeItems,
     908                                                                clicked);
    903909                                                anchor(leftOver);
    904910                                                if (copies == null)
     
    913919                                        } else if (Frame.FreeItems.size() == 1) {
    914920                                                copies = copy(Frame.FreeItems);
    915                                                 List<Item> remain = merge(copies, clicked);
     921                                                Collection<Item> remain = merge(copies, clicked);
    916922
    917923                                                // ignore items that could not be merged.
     
    982988                                        if (Frame.FreeItems.size() == 2) {
    983989                                                if (clicked != null) {
    984                                                         List<Item> leftOver = merge(Frame.FreeItems,
     990                                                        Collection<Item> leftOver = merge(Frame.FreeItems,
    985991                                                                        clicked);
    986992                                                        anchor(leftOver);
     
    10331039                                // Copies will NOT be null if the user right clicked on a point
    10341040                                if (copies == null) {
    1035                                         List<Item> originals = clicked.getConnected();
     1041                                        Collection<Item> originals = clicked.getConnected();
    10361042                                        copies = ItemUtils.CopyItems(originals, _extrude);
    10371043                                        if (!_extrude)
     
    10441050                                        // Set the selection mode for the items that were clicked in
    10451051                                        List<Item> enclosed = getFullyEnclosedItems(clickedIn);
    1046                                         copies = copy(enclosed);
    1047                                         // TODO figure out how to get copies to be SELECTED when
    1048                                         // they are anchored
    1049                                         // for (Item i : copies) {
    1050                                         // if (i.isEnclosed()) {
    1051                                         // i.setSelectedMode(Item.SelectedMode.Enclosed);
    1052                                         // i.setSelectedMode(Item.SelectedMode.None);
    1053                                         // }
    1054                                         // }
    1055                                         clearParent(copies);
    1056                                         pickup(copies);
     1052                                        if (enclosed.size() == 0) {
     1053                                                FrameGraphics
     1054                                                .DisplayMessage("Insufficient permission to copy items");
     1055                                        } else {
     1056                                                copies = copy(enclosed);
     1057                                                // TODO figure out how to get copies to be SELECTED when
     1058                                                // they are anchored
     1059                                                // for (Item i : copies) {
     1060                                                // if (i.isEnclosed()) {
     1061                                                // i.setSelectedMode(Item.SelectedMode.Enclosed);
     1062                                                // i.setSelectedMode(Item.SelectedMode.None);
     1063                                                // }
     1064                                                // }
     1065                                                clearParent(copies);
     1066                                                pickup(copies);
     1067                                        }
    10571068                                        // otherwise, create a rectangle
    10581069                                } else {
    10591070                                        copies = new ArrayList<Item>();
    1060                                         Dot[] d = new Dot[RECTANGLE_CORNERS];
     1071                                        Item[] d = new Item[RECTANGLE_CORNERS];
    10611072                                        // create dots
    10621073                                        for (int i = 0; i < d.length; i++) {
     
    11211132                        Item i = enclosedItems.get(0);
    11221133                        if (i.Permission >= Item.PERMISSION_COPY) {
    1123                                 List<Item> items = i.getAllConnected();
     1134                                Collection<Item> items = i.getAllConnected();
    11241135                                // Only copy if the entire shape is enclosed
    11251136                                if (enclosedItems.containsAll(items)) {
     
    11271138                                }
    11281139                                enclosedItems.removeAll(items);
     1140                        } else {
     1141                                enclosedItems.remove(0);
    11291142                        }
    11301143                }
     
    12261239
    12271240        MouseEvent _lastMouseEvent = null;
    1228 
     1241        private static Integer LastRobotX = null;
     1242        private static Integer LastRobotY = null;
     1243       
     1244        public static void setLastRobotMove(int x, int y) {
     1245                //Make sure the system is in the right state while waiting for the Robots event to arrive.
     1246                MouseX = x;
     1247                MouseY = y;
     1248               
     1249                LastRobotX = x;
     1250                LastRobotY = y;
     1251        }
     1252       
     1253        public static boolean isWaitingForRobot() {
     1254                return LastRobotX != null;
     1255        }
     1256       
     1257       
    12291258        /**
    12301259         * Updates the stored mouse position and highlights any items as necessary.
    12311260         */
    12321261        public void mouseMoved(MouseEvent e) {
     1262                if(LastRobotX != null){
     1263                        //Wait until the last Robot mouse move event arrives before processing other events
     1264                        if(LastRobotX == e.getX() && LastRobotY == e.getY()){
     1265                                LastRobotX = null;
     1266                                LastRobotY = null;
     1267                        }else
     1268                                return;
     1269                }
     1270               
    12331271                MouseX = e.getX();
    12341272                MouseY = e.getY();
     
    13341372                                // highlighting
    13351373                        } else if (on == null) {
    1336                                 List<Item> enclosure = FrameUtils.getEnclosingDots();
     1374                                Collection<Item> enclosure = FrameUtils.getEnclosingDots();
    13371375                                if (enclosure != null && enclosure.size() > 1) {
    1338                                         if (enclosure.get(0).getLines().size() > 1 &&
     1376                                        Item firstLineEnd = enclosure.iterator().next();
     1377                                        if (firstLineEnd.getLines().size() > 1 &&
    13391378                                        // check that the enclosure is not part of a point being
    13401379                                                        // dragged in space
    13411380                                                        !ContainsOneOf(enclosure, Frame.FreeItems)) {
    1342                                                 on = enclosure.get(0).getLines().get(0);
     1381                                                on = firstLineEnd.getLines().get(0);
    13431382                                                FrameGraphics.ChangeSelectionMode(on,
    13441383                                                                Item.SelectedMode.Enclosed);
     
    13791418        }
    13801419
    1381         private boolean ContainsOneOf(List<Item> enclosure, List<Item> freeItems) {
     1420        private boolean ContainsOneOf(Collection<Item> enclosure,
     1421                        Collection<Item> freeItems) {
    13821422                if (freeItems == null)
    13831423                        return false;
     
    14401480
    14411481        private static void move(List<Item> toMove) {
     1482                //System.out.println(_offX + "," + _offY);
     1483
     1484                // Gets the origin of the first item to move
    14421485                int xPos = (DisplayIO.getMouseX() - _offX);
    14431486
    14441487                Item firstDot = toMove.get(0);
    1445 
    1446                 /*
    1447                  * for (Item i: toMove) { if (i instanceof Dot){ firstDot = i; break; } }
    1448                  */
    14491488
    14501489                int deltax = firstDot.getX() - xPos;
     
    14841523         * @return
    14851524         */
    1486         public static boolean tdfc(Item linker) {
     1525        public static boolean tdfc(Item linker) throws RuntimeException {
    14871526                if (linker instanceof Line)
    14881527                        return false;
     
    14911530                if (linker.getID() < 0)
    14921531                        return false;
     1532
     1533                boolean mouseMoved;
    14931534
    14941535                linker.getParent().setChanged(true);
     
    15121553                FrameUtils.setTdfcItem(linker);
    15131554
    1514                 boolean mouseMoved = next.moveMouseToDefaultLocation();
     1555                mouseMoved = next.moveMouseToDefaultLocation();
    15151556                // this needs to be done if the user doesnt move the mouse before doing
    15161557                // tdfc while the cursor is set to the text cursor
     
    15191560                // triggers changed to be set to true when it should stay as false
    15201561                next.setChanged(false);
    1521 
    15221562                return mouseMoved;
    15231563        }
     
    15521592                        // Give the attribute text item the color of the item for which
    15531593                        // attributes are being extracted.
    1554                         attribs.setColor(item.getColor());
     1594                        // attribs.setColor(item.getColor());
    15551595                        pickup(attribs);
    15561596                }
     
    15821622                                        return;
    15831623                                }
    1584 
    15851624                                Text anchored = (Text) toDelete;
    15861625                                Text free = (Text) Frame.FreeItems.get(0);
    1587 
     1626                                SessionStats.DeletedItem(free);
    15881627                                // List<String> temp = anchored.getText();
    15891628                                anchored.setTextList(free.getText());
     
    16131652
    16141653                        if (items != null) {
    1615                                 ArrayList<Item> toRemove = new ArrayList<Item>(items.size());
    1616                                 for (Item ip : items)
     1654                                List<Item> toRemove = new ArrayList<Item>(items.size());
     1655                                for (Item ip : items) {
    16171656                                        if (ip.Permission >= Item.PERMISSION_FULL) {
     1657                                                // Only include lines if one of their enpoints are also
     1658                                                // being removed
     1659                                                if (ip instanceof Line) {
     1660                                                        Line l = (Line) ip;
     1661                                                        if (!items.contains(l.getEndItem())
     1662                                                                        && !items.contains(l.getStartItem()))
     1663                                                                continue;
     1664                                                }
    16181665                                                toRemove.add(ip);
    16191666                                        }
     1667                                }
    16201668
    16211669                                deleteItems(toRemove);
     
    16431691                        current.setChanged(true);
    16441692
    1645                         List<Item> toUndo = new LinkedList<Item>();
    1646 
     1693                        List<Item> toUndo = null;
    16471694                        if (toDelete.isLineEnd()) {
    1648                                 toUndo.addAll(deleteDot(toDelete));
    1649                         } else
    1650                                 toUndo.addAll(copy(toDelete.getConnected()));
    1651 
     1695                                toUndo = deleteLineEnd(toDelete);
     1696                        } else {
     1697                                toUndo = copy(toDelete.getConnected());
     1698                        }
     1699                        SessionStats.DeletedItems(toUndo);
    16521700                        current.addAllToUndo(toUndo);
    16531701                        current.removeAllItems(toDelete.getConnected());
     
    16771725                for (Item i : itemList) {
    16781726                        if (i.getLines().size() > 0) {
    1679                                 List<Item> copy = deleteDot(i);
     1727                                List<Item> copy = deleteLineEnd(i);
    16801728                                // add the copied items to the undo stack
    16811729                                for (Item cop : copy)
     
    16981746        }
    16991747
    1700         private static List<Item> deleteDot(Item dot) {
    1701 
    1702                 if (dot instanceof WidgetCorner) { // Brook
    1703 
    1704                         WidgetCorner wc = (WidgetCorner) dot;
     1748        private static List<Item> deleteLineEnd(Item lineEnd) {
     1749
     1750                if (lineEnd instanceof WidgetCorner) { // Brook
     1751
     1752                        WidgetCorner wc = (WidgetCorner) lineEnd;
    17051753                        List<Item> wccopy;
    17061754
     
    17121760                        }
    17131761
    1714                         if (dot.getParent() != null) {
    1715                                 dot.getParent().removeAllItems(wc.getWidgetSource().getItems());
     1762                        if (lineEnd.getParent() != null) {
     1763                                lineEnd.getParent().removeAllItems(
     1764                                                wc.getWidgetSource().getItems());
    17161765                        }
    17171766                        return wccopy;
     
    17191768
    17201769                        // create a backup copy of the dot
    1721                         List<Item> copy = copy(dot.getConnected());
     1770                        List<Item> copy = copy(lineEnd.getConnected());
    17221771                        // remove lines that are connected to anchored dots
    17231772                        // note: the line is kept so that it can be properly restored
     
    17331782
    17341783                        // remove all lines being deleted
    1735                         for (Item ic : dot.getConnected()) {
     1784                        for (Item ic : lineEnd.getConnected()) {
    17361785                                if (ic instanceof Line
    1737                                                 && ((Line) ic).getOppositeEnd(dot) != null) {
     1786                                                && ((Line) ic).getOppositeEnd(lineEnd) != null) {
    17381787                                        Line line = (Line) ic;
    17391788
    1740                                         Item d = line.getOppositeEnd(dot);
     1789                                        Item d = line.getOppositeEnd(lineEnd);
    17411790                                        d.removeLine(line);
    17421791
     
    17501799                                        }
    17511800
    1752                                         if (dot.getParent() != null)
    1753                                                 dot.getParent().removeItem(ic);
     1801                                        if (lineEnd.getParent() != null)
     1802                                                lineEnd.getParent().removeItem(ic);
    17541803                                }
    17551804                        }
     
    17721821        }
    17731822
    1774         public static List<Item> merge(List<Item> merger, Item mergee) {
     1823        public static Collection<Item> merge(List<Item> merger, Item mergee) {
    17751824                if (mergee.getParent().getFrameNameItem() == mergee) {
    17761825                        return mergee.getParent().merge(merger);
     
    17821831                        // if this is a corner of a shape
    17831832                        if (corner != null) {
    1784                                 List<Item> allConnected = corner.getAllConnected();
     1833                                Collection<Item> allConnected = corner.getAllConnected();
    17851834                                // Check if we are collapsing a rectangle
    17861835                                if (allConnected.size() == 8 && allConnected.contains(mergee)) {
     
    18981947         */
    18991948        public static void pickup(Item toGrab) {
     1949                if (toGrab.Permission < Item.PERMISSION_FULL) {
     1950                        FrameGraphics
     1951                                        .DisplayMessage("Insufficient permission pickup the item");
     1952                        return;
     1953                }
    19001954                // Brook: If the widget corner is being picked up. Instead refer to
    1901                 // picking
    1902                 // up the edge for fixed-sized widgets so it is not so confusing
     1955                // picking up the edge for fixed-sized widgets so it is not so confusing
    19031956                if (toGrab instanceof WidgetCorner) {
    19041957                        WidgetCorner wc = (WidgetCorner) toGrab;
    19051958                        if (wc.getWidgetSource().isFixedSize()) {
    1906                                 toGrab = toGrab.getConnected().get(1);
    1907                         }
    1908                 }
    1909 
     1959                                for (Item i : toGrab.getConnected()) {
     1960                                        if (i instanceof WidgetEdge) {
     1961                                                toGrab = i;
     1962                                                break;
     1963                                        }
     1964                                }
     1965                        }
     1966                }
    19101967                pickup(toGrab.getConnected());
    19111968        }
    19121969
    1913         public static void pickup(List<Item> toGrab) {
     1970        public static void pickup(Collection<Item> toGrab) {
    19141971
    19151972                String currentFrame = DisplayIO.getCurrentFrame().getFrameName();
    1916                 for (Item i : toGrab) {
     1973                Iterator<Item> iter = toGrab.iterator();
     1974                while (iter.hasNext()) {
     1975                        Item i = iter.next();
     1976                        if (i.Permission < Item.PERMISSION_FULL) {
     1977                                iter.remove();
     1978                                continue;
     1979                        }
     1980
    19171981                        // Check if it has a relative link if so make it absolute
    19181982                        i.setAbsoluteLink();
    1919 
    19201983                        // parent may be null
    19211984                        if (i.getParent() != null) {
     
    19251988                        }
    19261989                        Frame.FreeItems.add(i);
    1927 
    19281990                        i.setFloating(true);
    19291991                }
     
    19351997                if (toGrab.size() > 1) {
    19361998                        for (Item i : toGrab) {
     1999                                // MIKE: Why cant we use a line for the offset calculations?!?
    19372000                                if (!(i instanceof Line)) {
    19382001                                        _offX = DisplayIO.getMouseX() - i.getX() + i.getOffset().x;
     
    19402003
    19412004                                        // make the offset item the first item in the list (so
    1942                                         // moving code knows which item to use)
     2005                                        // move method knows which item to use)
    19432006                                        Frame.FreeItems.set(Frame.FreeItems.indexOf(i),
    19442007                                                        Frame.FreeItems.get(0));
     
    19492012
    19502013                        move(Frame.FreeItems);
     2014                        ItemUtils.EnclosedCheck(toGrab);
    19512015                        // otherwise, just use the first item
    19522016                } else if (toGrab.size() == 1) {
    1953                         _offX = DisplayIO.getMouseX() - toGrab.get(0).getX()
    1954                                         + toGrab.get(0).getOffset().x;
    1955                         _offY = MouseY - toGrab.get(0).getY() + toGrab.get(0).getOffset().y;
    1956                 }
    1957 
    1958                 ItemUtils.EnclosedCheck(toGrab);
     2017                        Item soleItem = toGrab.iterator().next();
     2018                        _offX = DisplayIO.getMouseX() - soleItem.getX()
     2019                                        + soleItem.getOffset().x;
     2020                        _offY = MouseY - soleItem.getY() + soleItem.getOffset().y;
     2021                } else {
     2022                        FrameGraphics
     2023                        .DisplayMessage("Insufficient permission pickup the items");
     2024                }
    19592025        }
    19602026
    19612027        private static Line createLine() {
    19622028                // create the two endpoints
    1963                 Dot end = DisplayIO.getCurrentFrame().createDot();
    1964                 Dot start = DisplayIO.getCurrentFrame().createDot();
     2029                Item end = DisplayIO.getCurrentFrame().createDot();
     2030                Item start = DisplayIO.getCurrentFrame().createDot();
    19652031                // create the Line
    19662032                Line line = new Line(start, end, DisplayIO.getCurrentFrame()
     
    20062072        }
    20072073
    2008         public static void anchor(List<Item> toAnchor) {
     2074        public static void anchor(Collection<Item> toAnchor) {
    20092075                // Need to make sure we check enclosure for overlays etc
    20102076                List<Frame> checkEnclosure = new ArrayList<Frame>();
     
    20702136                                clicks = (int) Math.ceil(size / 20.0 * clicks);
    20712137                        }
    2072 
    20732138                        FrameKeyboardActions.functionKey(rotationType, clicks);
     2139
    20742140                } else if (clicks == MOUSE_WHEEL_THRESHOLD) {
    2075                         Item ip = FrameUtils.getCurrentItem();
     2141                        Item item = FrameUtils.getCurrentItem();
    20762142
    20772143                        // if the user is not pointing to any item
    2078                         if (ip == null) {
    2079                                 FrameGraphics
    2080                                                 .DisplayMessage("There are no Items selected on the Frame");
     2144                        if (item == null) {
     2145                                FrameKeyboardActions.NextTextItem(null,
     2146                                                arg0.getWheelRotation() > 0);
    20812147                                return;
    2082                         } else {
     2148                        }
     2149
     2150                        if (item instanceof Line) {
    20832151                                // check permissions
    2084                                 if (ip.Permission < Item.PERMISSION_FULL) {
     2152                                if (item.Permission < Item.PERMISSION_FULL) {
    20852153                                        FrameGraphics
    2086                                                         .DisplayMessage("Insufficient permission to change the size of that item");
     2154                                                        .DisplayMessage("Insufficient permission to edit the Line");
    20872155                                        return;
    20882156                                }
    2089                         }
    2090 
    2091                         if (ip instanceof Line) {
    2092                                 Line line = (Line) ip;
     2157                                Line line = (Line) item;
    20932158                                line.toggleDashed(arg0.getWheelRotation());
    20942159                                line.getParent().change();
    20952160                                FrameGraphics.Repaint();
    20962161                                return;
     2162                        } else if (item instanceof Text) {
     2163                                FrameKeyboardActions.NextTextItem(item,
     2164                                                arg0.getWheelRotation() > 0);
    20972165                        }
    20982166                }
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r70 r72  
    55import java.io.File;
    66import java.util.ArrayList;
     7import java.util.Collection;
    78import java.util.Collections;
    89import java.util.Comparator;
     
    330331                        while (toCheck.size() > 0) {
    331332                                Item i = toCheck.get(0);
    332                                 List<Item> connected = i.getAllConnected();
     333                                Collection<Item> connected = i.getAllConnected();
    333334
    334335                                // // Only move completely enclosed items
     
    587588                                UserSettings.AnnotationTemplate = ((Text) item)
    588589                                                .getTemplateForm();
     590                        } else if (ItemUtils.isTag(item, ItemUtils.TAG_STAT_TEMPLATE)) {
     591                                UserSettings.StatTemplate = ((Text) item).getTemplateForm();
    589592                        } else if (ItemUtils.isTag(item,
    590593                                        ItemUtils.TAG_CODE_COMMENT_TEMPLATE)) {
    591594                                UserSettings.CodeCommentTemplate = ((Text) item)
    592595                                                .getTemplateForm();
    593                         } else if (ItemUtils.isTag(item,
    594                                         ItemUtils.TAG_LINE_TEMPLATE)) {
    595                                 UserSettings.LineTemplate = ((Text) item)
    596                                                 .getTemplateForm();
     596                        } else if (ItemUtils.isTag(item, ItemUtils.TAG_LINE_TEMPLATE)) {
     597                                UserSettings.LineTemplate = ((Text) item).getTemplateForm();
    597598                        } else if (ItemUtils.isTag(item, "@FramesetDir:")) {
    598599                                String dir = getDir(item, null);
     
    713714                ArrayList<String> dirsToAdd = new ArrayList<String>();
    714715                String dirListFrameName = item.getAbsoluteLink();
    715 
    716716                if (dirListFrameName != null) {
    717717                        Frame dirListFrame = FrameIO.LoadFrame(dirListFrameName);
    718                         for (Text t : dirListFrame.getBodyTextItems(false)) {
    719                                 String dirName = t.getTextNoList().trim();
    720                                 File tester = new File(dirName);
    721                                 if (tester.exists() && tester.isDirectory()) {
    722                                         if (dirName.endsWith(File.separator))
    723                                                 dirsToAdd.add(dirName);
    724                                         else
    725                                                 dirsToAdd.add(dirName + File.separator);
     718                        if (dirListFrame != null) {
     719                                for (Text t : dirListFrame.getBodyTextItems(false)) {
     720                                        String dirName = t.getTextNoList().trim();
     721                                        File tester = new File(dirName);
     722                                        if (tester.exists() && tester.isDirectory()) {
     723                                                if (dirName.endsWith(File.separator))
     724                                                        dirsToAdd.add(dirName);
     725                                                else
     726                                                        dirsToAdd.add(dirName + File.separator);
     727                                        }
    726728                                }
    727729                        }
     
    916918                                        // remove dots of size 1
    917919                                        if (i instanceof Dot) {
    918                                                 Dot dot = (Dot) i;
     920                                                Item dot = (Item) i;
    919921                                                if (dot.getSize() <= 1
    920922                                                                && (dot.getLines() == null || dot.getLines()
     
    10291031                                                // names have copy permissions only
    10301032                                                if (i == toCheck.getFrameNameItem()) {
    1031                                                         i.Permission = Item.PERMISSION_TDFC;
     1033                                                        //i.Permission = Item.PERMISSION_TDFC;
    10321034                                                        possibles.add(i);
    10331035                                                } else {
    1034                                                         i.Permission = Item.PERMISSION_FULL;
     1036                                                        //i.Permission = Item.PERMISSION_FULL;
    10351037                                                        possibles.add(i);
    10361038                                                }
     
    10561058                }
    10571059
     1060                // if there are no possible items, return null
     1061                if (possibles.size() == 0)
     1062                        return null;
     1063
    10581064                // if there is only one possibility, return it
    10591065                if (possibles.size() == 1)
    10601066                        return possibles.get(0);
    1061 
    1062                 // if there are no possible items, return null
    1063                 if (possibles.size() == 0)
    1064                         return null;
    10651067
    10661068                // return closest x,y pair to mouse
     
    10761078                                        + Math.pow(Math.abs(i.getY() - y), 2));
    10771079
    1078                         if (d < distance) {
     1080                        if (d <= distance) {
    10791081                                distance = d;
    10801082
    10811083                                // dots take precedence over lines
    1082                                 /**
    1083                                  * TODO: Remove line\dot specification
    1084                                  */
    10851084                                if ((!(closest instanceof Dot && i instanceof Line))
    10861085                                                && (!(closest instanceof Text && i instanceof Line)))
     
    11011100        public static List<Item> getCurrentItems() {
    11021101
    1103                 List<Item> enclosure = getEnclosingDots();
     1102                Collection<Item> enclosure = getEnclosingDots();
    11041103                if (enclosure == null || enclosure.size() == 0)
    11051104                        return null;
    11061105
     1106                Item firstItem = enclosure.iterator().next();
     1107               
    11071108                List<Item> enclosed = getItemsEnclosedBy(DisplayIO.getCurrentFrame(),
    1108                                 enclosure.get(0).getEnclosedShape());
     1109                                firstItem.getEnclosedShape());
    11091110                for (Item i : enclosed) {
    11101111                        if (!enclosure.contains(i))
     
    11151116        }
    11161117
    1117         public static List<Item> getEnclosingDots() {
     1118        public static Collection<Item> getEnclosingDots() {
    11181119                // update enclosed shapes
    11191120                Frame current = DisplayIO.getCurrentFrame();
    11201121                List<Item> items = current.getItems();
    1121                
    1122                 //Remove all items that are connected to freeItems
     1122
     1123                // Remove all items that are connected to freeItems
    11231124                List<Item> freeItems = new ArrayList<Item>(Frame.FreeItems);
    1124                 while(freeItems.size() > 0) {
     1125                while (freeItems.size() > 0) {
    11251126                        Item item = freeItems.get(0);
    1126                         List<Item> connected = item.getAllConnected();
     1127                        Collection<Item> connected = item.getAllConnected();
    11271128                        items.removeAll(connected);
    11281129                        freeItems.removeAll(connected);
    11291130                }
    11301131
    1131                 ArrayList<Item> used = new ArrayList<Item>(0);
    1132                 ArrayList<Item> seen = new ArrayList<Item>(0);
    1133 
    1134                 for (Item i : items)
    1135                         if (i.isLineEnd()) {
    1136                                 if (i.isEnclosed() && !seen.contains(i)) {
    1137                                         Polygon p = i.getEnclosedShape();
    1138                                         if (p
    1139                                                         .contains(DisplayIO.getMouseX(), DisplayIO
    1140                                                                         .getMouseY())) {
    1141 
    1142                                                 used.add(i);
    1143                                                 seen.addAll(i.getEnclosingDots());
    1144                                         }
    1145                                 }
    1146                         }
     1132                List<Item> used = new ArrayList<Item>(0);
     1133
     1134                while (items.size() > 0) {
     1135                        Item i = items.get(0);
     1136                        items.remove(i);
     1137                        if (i.isLineEnd() && i.isEnclosed()) {
     1138                                Polygon p = i.getEnclosedShape();
     1139                                if (p.contains(DisplayIO.getMouseX(), DisplayIO.getMouseY())) {
     1140                                        used.add(i);
     1141                                        items.removeAll(i.getEnclosingDots());
     1142                                }
     1143                        }
     1144                }
    11471145
    11481146                if (used.size() == 0)
     
    12141212                        // if the item is on the frame
    12151213                        if (item.getParent() == frame || item.getParent() == null) {
    1216                                 item.Permission = Item.PERMISSION_FULL;
     1214                                //item.Permission = Item.PERMISSION_FULL;
    12171215                                results.add(item);
    12181216                                // otherwise, it must be on an overlay frame
     
    12751273                t = profile.addText(xPos, yPos, "@CommentTemplate", null);
    12761274                t.setColor(Item.COLOR_WHEEL[3]);
     1275
     1276                yPos += spacing;
     1277                t = profile.addText(xPos, yPos, "@StatTemplate", null);
     1278                t.setColor(Color.BLACK);
     1279                t.setBackgroundColor(new Color(0.9F, 0.9F, 0.9F));
     1280                t.setFamily(Text.MONOSPACED_FONT);
     1281                t.setSize(14);
    12771282
    12781283                xPos = 600;
     
    13291334                                SessionStats.CreatedFrame();
    13301335                        }
    1331        
     1336
    13321337                        setTdfcItem(null);
    13331338                }
  • trunk/src/org/expeditee/gui/UserSettings.java

    r70 r72  
    5757        public static Text TitleTemplate = null;
    5858
     59        public static Text StatTemplate = null;
     60
    5961        // add default values
    6062        public static void Init() {
  • trunk/src/org/expeditee/io/Conversion.java

    r71 r72  
    2222public class Conversion {
    2323
    24         private static final double FONT_SCALE = 0.85;
    25 
    26         // used for rounding when converting between Sandbox and KMS font sizes.
    27         private static final double FONT_ROUNDING = 0.07;
     24private static final int PERCENT_MAX = 100;
     25private static final int RGB_MAX = 255;
     26private static final double RGB_CONVERSION_FACTOR = 2.55;
    2827
    2928        /**
     
    6160                }
    6261
    63                 float amount = 10f;
     62                final float MAX_AMOUNT = 10F;
     63                float amount = MAX_AMOUNT;
    6464                if (num.length() > 0)
    6565                        amount = Float.parseFloat(num);
    6666
    67                 if (amount > 10)
    68                         amount = 10;
     67                if (amount > MAX_AMOUNT)
     68                        amount = MAX_AMOUNT;
    6969
    7070                float color[] = { 0, 0, 0 };
    7171
    7272                if (colorCode.toLowerCase().startsWith("red"))
    73                         color[0] = amount / 10;
     73                        color[0] = amount / MAX_AMOUNT;
    7474                else if (colorCode.toLowerCase().startsWith("green"))
    75                         color[1] = amount / 10;
     75                        color[1] = amount / MAX_AMOUNT;
    7676                else if (colorCode.toLowerCase().startsWith("blue"))
    77                         color[2] = amount / 10;
     77                        color[2] = amount / MAX_AMOUNT;
    7878                else
     79                        //TODO: Should we not throw an error here!
    7980                        return current;
    8081
     
    9394
    9495                        int red = (current == null ? 0 : toColorPercent(current.getRed()));
    95                         int green = (current == null ? 0 : toColorPercent(current.getGreen()));
     96                        int green = (current == null ? 0 : toColorPercent(current
     97                                        .getGreen()));
    9698                        int blue = (current == null ? 0 : toColorPercent(current.getBlue()));
    9799                        color[0] = (Integer) Convert(int.class, r, red);
     
    109111
    110112        private static Integer toColorPercent(int rgb) {
    111                 int percent = (int) Math.round(rgb / 2.55);
    112                 if (percent > 100)
    113                         percent = 100;
     113                int percent = (int) Math.round(rgb / RGB_CONVERSION_FACTOR);
     114                if (percent > PERCENT_MAX)
     115                        percent = PERCENT_MAX;
    114116                else if (percent < 0)
    115117                        percent = 0;
    116                
     118
    117119                return percent;
    118120        }
    119        
     121
    120122        private static Integer toRGB(int percent) {
    121                 int rgb = (int) Math.round(percent * 2.55);
    122                 if (rgb > 255)
    123                         rgb = 255;
     123                int rgb = (int) Math.round(percent * RGB_CONVERSION_FACTOR);
     124                if (rgb > RGB_MAX)
     125                        rgb = RGB_MAX;
    124126                else if (rgb < 0)
    125127                        rgb = 0;
    126                
     128
    127129                return rgb;
    128130        }
    129131
     132       
     133       
    130134        /**
    131135         * Converts the given Color object to the corresponding KMS color code
     
    140144                        return null;
    141145
    142                 int r = (int) ((color.getRed() / 255.0) * 100 + 0.5);
    143                 int g = (int) ((color.getGreen() / 255.0) * 100 + 0.5);
    144                 int b = (int) ((color.getBlue() / 255.0) * 100 + 0.5);
     146                int r = (int) Math.round((color.getRed() / RGB_CONVERSION_FACTOR));
     147                int g = (int) Math.round((color.getGreen() / RGB_CONVERSION_FACTOR));
     148                int b = (int) Math.round((color.getBlue() / RGB_CONVERSION_FACTOR));
    145149
    146150                return r + " " + g + " " + b;
     
    179183                        break;
    180184                }
    181 
    182                 double dsize = font.getSize() / FONT_SCALE;
    183                 if ((Math.ceil(dsize)) - dsize < FONT_ROUNDING)
    184                         dsize = Math.ceil(dsize);
    185                 else
    186                         dsize = Math.floor(dsize);
    187 
    188                 code += (int) dsize;
    189 
     185               
     186                code += font.getSize();
    190187                return code;
    191188        }
     
    232229                try {
    233230                        int size = Integer.parseInt(fontCode.substring(2));
    234                         double dsize = size * FONT_SCALE;
    235                         if (dsize - ((int) dsize) > FONT_ROUNDING)
    236                                 dsize = Math.ceil(dsize);
    237 
    238                         code += (int) dsize;
    239 
     231                        //double dsize = size * FONT_SCALE;
     232                        //if (dsize - ((int) dsize) > FONT_ROUNDING)
     233                        //      dsize = Math.ceil(dsize);
     234
     235                        //code += (int) dsize;
     236                        code += size;
     237                       
    240238                        font = Font.decode(code);
    241239                } catch (NumberFormatException nfe) {
     
    368366        public static Object Convert(Class type, String value, Object orig) {
    369367                // System.out.println("Orig: " + orig);
    370                 assert (value != null);
     368                if (value == null)
     369                        return null;
    371370                value = value.trim();
    372371
     
    387386                        try {
    388387                                // Find the field and value of colorName
    389                                 Field field = Class.forName("java.awt.Color").getField(
    390                                                 value.toLowerCase());
     388                                Field[] fields = Class.forName("java.awt.Color").getFields();
     389                                Field field = null;
     390                                for (int i = 0; i < fields.length; i++) {
     391                                        if (fields[i].getName().equalsIgnoreCase(value)) {
     392                                                field = fields[i];
     393                                                break;
     394                                        }
     395                                }
    391396                                return (Color) field.get(null);
    392397                        } catch (Exception e) {
     
    482487                Class[] types = method.getParameterTypes();
    483488                if (name.equals("setPosition")) {
    484 
    485489                        Point[] p = new Point[1];
    486490                        p[0] = new Point();
     
    493497                        } else {
    494498                                assert (current instanceof Point);
     499                                assert (p.length == 1);
    495500                                Point originalPoint = (Point) current;
    496501                                p[0].x = (Integer) Convert(int.class, xPos, originalPoint.x);
     
    547552                        return null;
    548553
    549                 if (method == null) {
    550                         System.out.println("Output: " + output);
    551                 }
     554                assert(method != null);
    552555
    553556                String name = method.getName();
     
    581584                // covert points
    582585                if (output instanceof Point)
    583                         return ((Point) output).x + " "
    584                                         + ((Point) output).y;
     586                        return ((Point) output).x + " " + ((Point) output).y;
    585587
    586588                if (output instanceof Boolean)
  • trunk/src/org/expeditee/io/ExpReader.java

    r67 r72  
    145145                }
    146146
     147                newFrame.refreshItemPermissions();
    147148                _reader.close();
    148149                newFrame.setChanged(false);
  • trunk/src/org/expeditee/io/ItemWriter.java

    r4 r72  
    3737
    3838                if (toWrite instanceof Dot)
    39                         writeDot((Dot) toWrite);
     39                        writeDot((Item) toWrite);
    4040        }
    4141
     
    5151
    5252                if (toWrite instanceof Dot)
    53                         writeAnnotationDot((Dot) toWrite);
     53                        writeAnnotationDot((Item) toWrite);
    5454        }
    5555
     
    6363        }
    6464
    65         protected void writeAnnotationDot(Dot toWrite) throws IOException {
     65        protected void writeAnnotationDot(Item toWrite) throws IOException {
    6666        }
    6767
     
    7575        }
    7676
    77         protected void writeDot(Dot toWrite) throws IOException {
     77        protected void writeDot(Item toWrite) throws IOException {
    7878        }
    7979
  • trunk/src/org/expeditee/io/KMSReader.java

    r67 r72  
    106106                        _ItemTags.put("k", Text.class.getMethod("setJustification", pInt));
    107107
    108                         _ItemTags.put("h", Dot.class.getMethod("setThickness", pFloat));
     108                        _ItemTags.put("h", Item.class.getMethod("setThickness", pFloat));
    109109                        _ItemTags.put("l", Item.class.getMethod("setLineIDs", pString));
    110110                        _ItemTags
    111                                         .put("c", Dot.class.getMethod("setConstraintIDs", pString));
     111                                        .put("c", Item.class.getMethod("setConstraintIDs", pString));
    112112
    113113                        // Lines and constraints are created differently
     
    178178                        System.out.println("Error reading bodyLine: " + next + " "
    179179                                        + e.getMessage());
     180                        e.printStackTrace();
    180181                }
    181182
     
    188189
    189190                _reader.close();
    190 
    191                 if (newFrame != null)
     191                if (newFrame != null){
     192                        newFrame.refreshItemPermissions();
    192193                        newFrame.setChanged(false);
    193 
     194                }
    194195                return newFrame;
    195196        }
     
    261262                java.awt.Point startend = separateValues(_data.get("s"));
    262263
    263                 Dot a = (Dot) _linePoints.get(startend.x);
    264                 Dot b = (Dot) _linePoints.get(startend.y);
     264                Item a = _linePoints.get(startend.x);
     265                Item b = _linePoints.get(startend.y);
    265266
    266267                new Constraint(a, b, idtype.x, idtype.y);
     
    488489
    489490                                try {
    490                                         if (vals != null)
     491                                        if (vals != null){
    491492                                                toRun.invoke(toMake, vals);
     493                                        }
    492494                                } catch (IllegalArgumentException e) {
    493495                                        // TODO Auto-generated catch block
     
    498500                                } catch (InvocationTargetException e) {
    499501                                        // TODO Auto-generated catch block
     502                                        e.printStackTrace();
     503                                } catch (ClassCastException e) {
     504                                        System.out.println(toRun.getName());
    500505                                        e.printStackTrace();
    501506                                }
  • trunk/src/org/expeditee/io/KMSWriter.java

    r67 r72  
    203203
    204204                        if (i instanceof Dot) {
    205                                 Dot p = (Dot) i;
     205                                Item p = (Item) i;
    206206
    207207                                // if there are any constraints to write
  • trunk/src/org/expeditee/items/Dot.java

    r70 r72  
    99import java.util.List;
    1010
     11import org.expeditee.gui.DisplayIO;
    1112import org.expeditee.gui.Frame;
     13import org.expeditee.gui.FrameKeyboardActions;
    1214
    1315/**
     
    9092                for (Line line : getLines())
    9193                        line.setColor(c);
    92         }
    93 
    94         public void paintFill(Graphics2D g) {
    95                 if (getFillColor() != null && getEnclosingDots() != null) {
    96                         g.setColor(getFillColor());
    97                         g.fillPolygon(getEnclosedShape());
    98                 }
    9994        }
    10095
     
    186181
    187182        @Override
    188         public Dot copy() {
     183        public Item copy() {
    189184                Dot copy = new Dot(getX(), getY(), getID());
    190185
     
    207202        @Override
    208203        public void setAnnotation(boolean val) {
    209         }
    210 
    211         @Override
    212         public boolean isAnnotation() {
    213                 return false;
     204                DisplayIO.setCursorPosition(this.getPosition());
     205                //Make all the dots this dot is connected to be annotations
     206                for(Item i: getAllConnected())
     207                        if (i.isLineEnd())
     208                                i._connectedToAnnotation = val;
     209               
     210                FrameKeyboardActions.replaceDot(this, '@');
    214211        }
    215212
     
    218215                // if the item being merged with is another Dot
    219216                if (merger instanceof Dot) {
    220                         Dot dot = (Dot) merger;
     217                        Item dot = (Item) merger;
    221218                        merger.setPosition(this.getPosition());
    222219                        // prevent concurrency issues if removing lines
     
    231228                                } else {
    232229                                        // check for duplicated lines as a result of merging
    233                                         Dot check = (Dot) line.getOppositeEnd(dot);
     230                                        Item check = (Item) line.getOppositeEnd(dot);
    234231                                        boolean dup = false;
    235232
  • trunk/src/org/expeditee/items/Item.java

    r71 r72  
    1010import java.awt.geom.Area;
    1111import java.util.ArrayList;
     12import java.util.Collection;
    1213import java.util.ConcurrentModificationException;
     14import java.util.LinkedHashSet;
    1315import java.util.LinkedList;
    1416import java.util.List;
     
    3739        // contains all dots (including this one) that form an enclosure
    3840        // if this dot is part of an enclosing shape
    39         private List<Item> _enclosure = null;
     41        private Collection<Item> _enclosure = null;
     42
     43        protected boolean _connectedToAnnotation = false;
    4044
    4145        public static int PERMISSION_NONE = 0;
     
    7781        public static final int XGRAVITY = 3;
    7882
    79         public static final int MARGIN_RIGHT = 5;
    80 
    81         public static final int MARGIN_LEFT = 20;
     83        public static final int MARGIN_RIGHT = 2;
     84
     85        public static final int MARGIN_LEFT = 15;
    8286
    8387        protected static final double DEFAULT_ARROWHEAD_RATIO = 0.5;
     
    109113
    110114        public static final int JUSTIFICATION_NONE = -1;
    111 
    112         // private boolean _isValidLink = true;
    113115
    114116        public static final int JUSTIFICATION_FULL = 0;
     
    134136                dest.setActionLeaveFrame(source.getActionLeaveFrame());
    135137                dest.setActionMark(source.getActionMark());
    136                 dest.setAnnotation(source.isAnnotation());
    137138
    138139                dest.setBackgroundColor(source.getBackgroundColor());
     
    162163
    163164                dest.setParent(source.getParent());
    164                 dest.setID(source.getParentOrCurrentFrame().getNextItemID());
     165                Frame parent = source.getParentOrCurrentFrame();
     166                // TODO MIKE says maybe we could tighten up and only give items ID's if
     167                // their
     168                // current ID is negative?
     169                if (parent != null) {
     170                        dest.setID(source.getParentOrCurrentFrame().getNextItemID());
     171                }
    165172        }
    166173
     
    290297        }
    291298
    292         public void addAllConnected(List<Item> connected) {
     299        public void addAllConnected(Collection<Item> connected) {
    293300                if (!connected.contains(this))
    294301                        connected.add(this);
     
    430437        }
    431438
    432         public List<Item> getAllConnected() {
    433                 List<Item> list = new LinkedList<Item>();
     439        /**
     440         * Gets all the items connected to this item. Uses a recursive approach to
     441         * search connected points.
     442         *
     443         * @return
     444         */
     445        public Collection<Item> getAllConnected() {
     446                Collection<Item> list = new LinkedHashSet<Item>();
    434447                addAllConnected(list);
    435448                return list;
     
    548561        }
    549562
    550         public List<Item> getConnected() {
     563        public Collection<Item> getConnected() {
    551564                List<Item> conn = new LinkedList<Item>();
    552565                conn.add(this);
     
    820833         * @return True if this Item is an annotation, False otherwise.
    821834         */
    822         public abstract boolean isAnnotation();
     835        public boolean isAnnotation() {
     836                return false;
     837        }
    823838
    824839        public boolean isFloating() {
     
    913928         */
    914929        public abstract void paint(Graphics2D g);
     930       
     931        public void paintFill(Graphics2D g) {
     932                if (getFillColor() != null && getEnclosingDots() != null) {
     933                        g.setColor(getFillColor());
     934                        g.fillPolygon(getEnclosedShape());
     935                }
     936        }
    915937
    916938        /**
     
    12081230         */
    12091231        public void setLink(String frameName) {
    1210                 _link = frameName;
     1232                if (FrameIO.isValidLink(frameName))
     1233                        _link = frameName;
     1234                else
     1235                        FrameGraphics.ErrorMessage("[" + frameName
     1236                                        + "] is not a valid frame name");
     1237                // TODO make this throw exceptions etc...
    12111238        }
    12121239
    12131240        public void setLinkFrameset(String frameset) {
    1214                 _link_frameset = frameset;
     1241                if (frameset == null || FrameIO.isValidFramesetName(frameset))
     1242                        _link_frameset = frameset;
     1243                else
     1244                        FrameGraphics.ErrorMessage("[" + frameset
     1245                                        + "] is not a valid frameset name");
     1246                // TODO make this throw exceptions etc...
    12151247        }
    12161248
     
    12201252
    12211253        public void setLinkTemplate(String template) {
    1222                 _link_template = template;
     1254                if (FrameIO.isValidLink(template))
     1255                        _link_template = template;
     1256                else
     1257                        FrameGraphics.ErrorMessage("[" + template
     1258                                        + "] is not a valid frame name");
     1259                // TODO make this throw exceptions etc...
    12231260        }
    12241261
     
    14841521         *            or null.
    14851522         */
    1486         public void setEnclosedList(List<Item> enclosed) {
     1523        public void setEnclosedList(Collection<Item> enclosed) {
    14871524                _enclosure = enclosed;
    14881525        }
     
    15141551         *         null if this Dot is not part of an enclosure.
    15151552         */
    1516         public List<Item> getEnclosingDots() {
     1553        public Collection<Item> getEnclosingDots() {
    15171554                return _enclosure;
    15181555        }
     
    15681605                return true;
    15691606        }
     1607
     1608        public void setConnectedToAnnotation(boolean val) {
     1609                _connectedToAnnotation = val;
     1610        }
     1611
     1612        public boolean isConnectedToAnnotation() {
     1613                return _connectedToAnnotation;
     1614        }
    15701615}
  • trunk/src/org/expeditee/items/ItemUtils.java

    r70 r72  
    1313import java.util.HashMap;
    1414import java.util.HashSet;
     15import java.util.LinkedHashSet;
    1516import java.util.LinkedList;
    1617import java.util.List;
     
    2122import org.expeditee.gui.DisplayIO;
    2223import org.expeditee.gui.Frame;
    23 import org.expeditee.stats.SessionStats;
    2424
    2525//Static methods that provide functions for the objects\
     
    7070        public static final int TAG_LINE_TEMPLATE = 17;
    7171
     72        public static final int TAG_STAT_TEMPLATE = 18;
     73
    7274        public static final int TAG_MIN = 0;
    7375
    74         public static final int TAG_MAX = 17;
     76        public static final int TAG_MAX = 18;
    7577
    7678        /**
     
    164166                return isTag(toCheck, GetTag(tag));
    165167        }
    166        
     168
    167169        public static boolean isTag(Item toCheck, int tag, boolean hasValue) {
    168170                return isTag(toCheck, GetTag(tag), hasValue);
     
    187189                // tags are ase-insensitive
    188190                return String.CASE_INSENSITIVE_ORDER.compare(txt.getFirstLine().trim(),
    189                                 tag) == 0 || (hasValue && txt.startsWith(tag + " ", true));
     191                                tag) == 0
     192                                || (hasValue && txt.startsWith(tag + " ", true));
    190193        }
    191194
     
    272275         */
    273276        public static String GetTag(int tag) {
     277                // TODO refactor so that this uses a map for INT to tags
    274278                switch (tag) {
    275279                case TAG_SORT:
     
    289293                case TAG_ANNOTATION_TEMPLATE:
    290294                        return "@annotationtemplate";
     295                case TAG_STAT_TEMPLATE:
     296                        return "@stattemplate";
    291297                case TAG_CODE_COMMENT_TEMPLATE:
    292298                        return "@commenttemplate";
     
    618624                copy.removeAllConstraints();
    619625
    620                 int num = 0;
    621 
    622                 // Mike: WHAT IS THIS CODE DOING?!!?
    623                 for (Line line : origEnd.getLines())
    624                         num = Math.min(num, line.getID());
    625 
    626                 num--;
    627 
    628626                // create a new line
    629                 Line line = new Line(origEnd, copy, num);
     627                Line line = new Line(origEnd, copy, DisplayIO.getCurrentFrame()
     628                                .getNextItemID());
    630629                // copy.setFloating(true);
    631630                origEnd.setArrowheadLength(0);
     
    636635                toReturn.add(line);
    637636                return toReturn;
     637        }
     638
     639        public static void New() {
     640                EnclosedCheck(DisplayIO.getCurrentFrame().getItems());
     641        }
     642
     643        public static void Old() {
     644                OldEnclosedCheck(DisplayIO.getCurrentFrame().getItems());
     645        }
     646
     647        /**
     648         * Updates the connectedToAnnotation flags for all items
     649         */
     650        public static void UpdateConnectedToAnnotations(Collection<Item> items) {
     651                // get all lineEnds on the Frame
     652                Collection<Item> lineEnds = new LinkedHashSet<Item>();
     653                for (Item i : items) {
     654                        i.setConnectedToAnnotation(false);
     655                        if (i.isLineEnd()) {
     656                                lineEnds.add(i);
     657                        }
     658                }
     659
     660                // if there are no line endpoints on the Frame, then there can't be an
     661                // enclosure
     662                if (lineEnds.size() == 0)
     663                        return;
     664
     665                // Now find go through line ends and see if any are annotation items
     666                while (lineEnds.size() > 0) {
     667                        Item item = lineEnds.iterator().next();
     668                        // If its an annotation item then set the flag for all its connected
     669                        // items
     670                        if (item.isAnnotation()) {
     671                                Collection<Item> connected = item.getAllConnected();
     672                                for (Item i : connected)
     673                                        i.setConnectedToAnnotation(true);
     674                                lineEnds.removeAll(connected);
     675                        }
     676                        lineEnds.remove(item);
     677                }
    638678        }
    639679
     
    646686         * is done dynamically (to account for Dots being moved).
    647687         */
    648         public static void EnclosedCheck(List<Item> items) {
     688        public static void EnclosedCheck(Collection<Item> items) {
     689                // get all lineEnds on the Frame
     690                List<Item> lineEnds = new LinkedList<Item>();
     691                for (Item i : items) {
     692                        if (i.isLineEnd()) {
     693                                i.setEnclosedList(null);
     694                                // Add line ends joined to 2 other lines
     695                                if (i.getLines().size() == 2)
     696                                        lineEnds.add(i);
     697                        }
     698                }
     699
     700                // if there are no line endpoints on the Frame, then there can't be an
     701                // enclosure
     702                if (lineEnds.size() == 0)
     703                        return;
     704
     705                // New approach
     706                while (lineEnds.size() > 0) {
     707                        Item item = lineEnds.get(0);
     708                        // Get the lineEnds connected to this item
     709                        Collection<Item> connected = item.getAllConnected();
     710                        Collection<Item> connectedLineEnds = new LinkedHashSet<Item>();
     711                        for (Item itemToCheck : connected) {
     712                                if (itemToCheck.isLineEnd())
     713                                        connectedLineEnds.add(itemToCheck);
     714                        }
     715                        // Check that all the line ends are in our lineEnds list
     716                        int oldSize = lineEnds.size();
     717                        // Remove all the items from our line ends list
     718                        lineEnds.removeAll(connectedLineEnds);
     719                        int newSize = lineEnds.size();
     720                        int connectedSize = connectedLineEnds.size();
     721                        // Check if all the connectedItems were in the lineEnds collection
     722                        if (oldSize == newSize + connectedSize) {
     723                                // Set them to be the enclosed list for each of the items
     724                                for (Item enclosedLineEnd : connectedLineEnds) {
     725                                        enclosedLineEnd.setEnclosedList(connectedLineEnds);
     726                                }
     727                        }
     728
     729                }
     730        }
     731
     732        /**
     733         * Checks through all Lines and Dots on the current Frame to detect if any
     734         * form an enclosure, which can then be used to manipulate items within the
     735         * polygon. If an enclosure is found, then the dots will have their
     736         * enclosure value set to true, and a List is created that contains all the
     737         * Dots in the order they were processed. Actual calculation of the Polygon
     738         * is done dynamically (to account for Dots being moved).
     739         */
     740        public static void OldEnclosedCheck(Collection<Item> items) {
    649741                _seen.clear();
    650742
  • trunk/src/org/expeditee/items/Line.java

    r50 r72  
    1212import java.awt.geom.AffineTransform;
    1313import java.util.ArrayList;
     14import java.util.Collection;
    1415import java.util.List;
    1516
     
    586587        @Override
    587588        public void setAnnotation(boolean val) {
     589                if (_end.isAnnotation() != val)
     590                        _end.setAnnotation(val);
     591                else if (_start instanceof Text && _start.isAnnotation() != val)
     592                        _start.setAnnotation(val);
    588593        }
    589594
    590595        @Override
    591596        public boolean isAnnotation() {
    592                 return false;
     597                return _start.isAnnotation() || _end.isAnnotation();
     598        }
     599
     600        @Override
     601        public boolean isConnectedToAnnotation() {
     602                return _start.isConnectedToAnnotation()
     603                                || _end.isConnectedToAnnotation();
    593604        }
    594605
     
    740751        }
    741752
    742         private Dot _virtualSpot = null;
     753        private Item _virtualSpot = null;
    743754
    744755        public void showVirtualSpot(Item orig, int mouseX, int mouseY) {
     
    750761                        return;
    751762
    752                 Dot spot = new Dot(-1, orig.getX(), orig.getY());
     763                Item spot = new Dot(-1, orig.getX(), orig.getY());
    753764                Item.DuplicateItem(orig, spot);
    754765                spot.setThickness(Math.max(this.getThickness(), 5));
     
    789800
    790801        public void showVirtualSpot(int mouseX, int mouseY) {
    791                 Dot spot = new Dot(mouseX, mouseY, -1);
     802                Item spot = new Dot(mouseX, mouseY, -1);
    792803                spot.setThickness(Math.max(this.getThickness(), 5));
    793804                if (this.getColor() != Color.RED)
     
    898909
    899910        @Override
    900         public List<Item> getConnected() {
     911        public Collection<Item> getConnected() {
    901912                return getAllConnected();
    902913        }
    903914
    904         public List<Item> getAllConnected() {
    905                 ArrayList<Item> list = new ArrayList<Item>();
    906                 addAllConnected(list);
    907                 return list;
    908         }
    909 
    910         public void addAllConnected(List<Item> connected) {
     915        @Override
     916        public void addAllConnected(Collection<Item> connected) {
    911917                if (!connected.contains(this))
    912918                        connected.add(this);
     
    971977                         */
    972978
    973                         Dot s = new Dot(_start.getX(), _start.getY(), -1);
    974                         Dot e = new Dot(_end.getX(), _end.getY(), -1);
     979                        Item s = new Dot(_start.getX(), _start.getY(), -1);
     980                        Item e = new Dot(_end.getX(), _end.getY(), -1);
    975981
    976982                        one = s.getPolygon().getBounds();
    977983                        two = e.getPolygon().getBounds();
    978984                } else {
    979                         Dot s = new Dot(_start.getX(), _start.getY(), -1);
    980                         Dot e = new Dot(_end.getX(), _end.getY(), -1);
     985                        Item s = new Dot(_start.getX(), _start.getY(), -1);
     986                        Item e = new Dot(_end.getX(), _end.getY(), -1);
    981987
    982988                        one = e.getPolygon().getBounds();
  • trunk/src/org/expeditee/items/Picture.java

    r24 r72  
    530530        @Override
    531531        public void setAnnotation(boolean val) {
    532                 // TODO Auto-generated method stub
    533 
    534         }
    535 
    536         @Override
    537         public boolean isAnnotation() {
    538                 // TODO Auto-generated method stub
    539                 return false;
    540532        }
    541533
  • trunk/src/org/expeditee/items/Text.java

    r71 r72  
    2222import java.util.List;
    2323
     24import org.expeditee.gui.DisplayIO;
    2425import org.expeditee.gui.FrameGraphics;
     26import org.expeditee.gui.FrameKeyboardActions;
    2527import org.expeditee.gui.FrameMouseActions;
    2628
     
    745747        }
    746748
     749        public static final String MONOSPACED_FONT = "monospaced";
     750
    747751        public static final String[] FONT_WHEEL = { "sansserif", "monospaced",
    748752                        "serif", "dialog", "dialoginput" };
     
    751755
    752756        private static final int NEARBY_GRAVITY = 2;
     757
     758        private static final int MINIMUM_FONT_SIZE = 8;
    753759
    754760        public void toggleFontFamily() {
     
    939945                }
    940946
    941                 // check if the cursor is on the left border of the bounding box
    942                 if (Math.abs(mouseX - LEFT_MARGIN - outline.x) <= gravity) {
    943                         return true;
    944                 }
    945 
    946947                for (TextLayout text : _textLayouts) {
    947948                        // check left and right of each box
     
    953954                        if (mouseY - textY > textOutline.y
    954955                                        && mouseY - textY < textOutline.y + textOutline.height
    955                                         && mouseX - textX < textOutline.width + gravity)
     956                                        && mouseX - textX < textOutline.width + gravity
     957                                                        + Item.MARGIN_RIGHT)
    956958                                return true;
    957959                        textY += getLineDrop(text);
     
    9991001                }
    10001002
    1001                 minX -= Item.MARGIN_RIGHT;
    1002 
    1003                 if (getWidth() > 0)
    1004                         maxX = getWidth();
     1003                minX -= getLeftMargin();
     1004                maxX += Item.MARGIN_RIGHT;
    10051005
    10061006                _poly.addPoint(minX - getGravity(), minY - getGravity());
     
    10081008                _poly.addPoint(maxX + getGravity(), maxY + getGravity());
    10091009                _poly.addPoint(minX - getGravity(), maxY + getGravity());
    1010 
    1011                 // _poly.addPoint(minX, minY);
    1012                 // _poly.addPoint(maxX, minY);
    1013                 // _poly.addPoint(maxX, maxY);
    1014                 // _poly.addPoint(minX, maxY);
     1010        }
     1011
     1012        /**
     1013         * Gets the distance between the start of the text and the left border of
     1014         * the item. This distance changes depending on whether or not the item is
     1015         * linked or has an associated action.
     1016         *
     1017         * @return the gap size in pixels
     1018         */
     1019        private int getLeftMargin() {
     1020                return ((getLinkMark() && getLink() != null)
     1021                                || (getActionMark() && getAction() != null) ? Item.MARGIN_LEFT
     1022                                - Item.MARGIN_RIGHT : Item.MARGIN_RIGHT);
    10151023        }
    10161024
     
    13891397        @Override
    13901398        public void setSize(int size) {
    1391                 setFont(getPaintFont().deriveFont((float) size));
     1399                if (size >= MINIMUM_FONT_SIZE)
     1400                        setFont(getPaintFont().deriveFont((float) size));
    13921401        }
    13931402
     
    13991408                                return;
    14001409
    1401                         /*
    1402                          * // Remove 'a: ' from the begining if it is there if
    1403                          * (_text.length() > 3 && _text.charAt(0) == 'a' && _text.charAt(1) ==
    1404                          * ':') { _text.delete(0, 2); while (_text.charAt(0) == ' ')
    1405                          * _text.delete(0, 1); }
    1406                          */
    14071410                        _text.insert(0, "@");
    14081411
     
    14181421                                return;
    14191422
     1423                        if (_text.length() == 1) {
     1424                                // Remove and replace with a dot
     1425                                FrameKeyboardActions.replaceText(this);
     1426
     1427                                DisplayIO.setCursorPosition(this.getPosition());
     1428                                return;
     1429                        }
     1430
    14201431                        _text.deleteCharAt(0);
    14211432
     
    14321443        @Override
    14331444        public boolean isAnnotation() {
    1434                 if (_text != null && _text.length() > 0 && _text.indexOf("@") == 0)
     1445                if (_text != null && _text.length() > 0 && _text.charAt(0) == '@')
    14351446                        return true;
    14361447
  • trunk/src/org/expeditee/stats/SessionStats.java

    r70 r72  
    66import java.text.SimpleDateFormat;
    77import java.util.ArrayList;
     8import java.util.Collection;
    89import java.util.Date;
    910import java.util.List;
     
    2122public class SessionStats {
    2223
     24        private static final int DEFAULT_RATE_WIDTH = 4;
     25
     26        private static final int DEFAULT_VALUE_WIDTH = 3;
     27
    2328        public enum ItemType {
    2429                Text, Dot, Picture, Line;
     
    7176
    7277        private static final int[] EVENT_INTERVALS = new int[] { 1, 2, 3, 4, 5, 10,
    73                         20, 30, 40, 50, 60, 120, 180, 240, 300, 600, Integer.MAX_VALUE };
     78                        20, 60, 300, 600, Integer.MAX_VALUE };
    7479
    7580        private static int[] _EventTimes = new int[EVENT_INTERVALS.length];
     
    8590                                "-->" + _DarkTime.getTime() * 100 / elapsedTime + "%\n");
    8691
     92                stats.append(getResponseStats()).append("\n");
    8793                stats.append(getFrameStats());
    88                 stats.append(getResponseStats()).append("\n");
    8994
    9095                stats.append(getCharacterStats());
     
    129134        private static String getFrameStats(boolean newline) {
    130135                StringBuffer stats = new StringBuffer();
    131                 appendStat(stats, "FramesAccessed", _AccessedFrames, newline);
    132                 appendStat(stats, "FramesEdited", _SavedFrames, newline);
     136                appendStat(stats, "FramesAccessed", _AccessedFrames, newline, false, DEFAULT_VALUE_WIDTH,
     137                                DEFAULT_RATE_WIDTH);
     138                appendStat(stats, "FramesEdited", _SavedFrames, newline, false, DEFAULT_VALUE_WIDTH, DEFAULT_RATE_WIDTH);
    133139                return stats.toString();
    134140        }
     
    168174                appendStat(stats, "Words", punct + EOS);
    169175                appendStat(stats, "Sentences", EOS);
    170                 appendStat(stats, "Text",
     176                appendStat(stats, "TextItems",
    171177                                _ItemStats[ItemType.Text.ordinal()][StatType.Created.ordinal()]);
    172178                appendStat(stats, "Frames", _CreatedFrames);
     
    192198         */
    193199        private static void appendStat(StringBuffer stats, String name, int value,
    194                         boolean newline) {
     200                        boolean newline, boolean ignoreZero, int minValueWidth,
     201                        int minRateWidth) {
    195202                // prevent divide by zero errors
    196                 if (value <= 0)
     203                if (ignoreZero && value <= 0)
    197204                        return;
    198205
    199                 int perHour = (int) (value * 60 / getMinutesUsed());
    200 
    201                 stats.append(value).append(" ").append(name).append(" @ ").append(
    202                                 perHour).append("/hour");
     206                String perHour = getRate(value);
     207                while (perHour.length() < minRateWidth)
     208                        perHour = " " + perHour;
     209                String valueString = "" + value;
     210                while (valueString.length() < minValueWidth)
     211                        valueString = " " + valueString;
     212                stats.append(valueString).append(" @ ").append(perHour.toString())
     213                                .append("/hour ").append(name);
    203214                if (newline)
    204215                        stats.append("\n");
     
    207218
    208219        }
     220       
     221        private static String getRate(int value){
     222                return "" + Math.round(value * 60 / getMinutesUsed());
     223        }
    209224
    210225        private static void appendStat(StringBuffer stats, String name, int value) {
    211                 appendStat(stats, name, value, true);
     226                appendStat(stats, name, value, true, false, DEFAULT_VALUE_WIDTH, DEFAULT_RATE_WIDTH);
    212227        }
    213228
     
    321336        }
    322337
    323         private static void ItemStats(List<Item> items, StatType stat) {
     338        private static void ItemStats(Collection<Item> items, StatType stat) {
    324339                if (items == null)
    325340                        return;
     
    336351        }
    337352
    338         public static void CreatedItems(List<Item> items) {
     353        public static void CreatedItems(Collection<Item> items) {
    339354                ItemStats(items, StatType.Created);
    340355        }
    341356
    342         public static void MovedItems(List<Item> items) {
     357        public static void MovedItems(Collection<Item> items) {
    343358                ItemStats(items, StatType.Moved);
    344359        }
    345360
    346         public static void CopiedItems(List<Item> items) {
     361        public static void CopiedItems(Collection<Item> items) {
    347362                ItemStats(items, StatType.Copied);
    348363        }
    349364
    350         public static void DeletedItems(List<Item> items) {
     365        public static void DeletedItems(Collection<Item> items) {
    351366                ItemStats(items, StatType.Deleted);
    352367        }
     
    358373        public static String getItemStats() {
    359374                StringBuffer stats = getSessionDateTime();
    360 
     375                int max = 0;
     376                for (int i = 0; i < STAT_TYPES; i++) {
     377                        for (int j = 0; j < ITEM_TYPES; j++) {
     378                                if (_ItemStats[j][i] > max)
     379                                        max = _ItemStats[j][i];
     380                        }
     381                }
     382                int maxWidthValue = ("" + max).length();
     383                int maxWidthRate = (getRate(max)).length();
     384               
    361385                for (int i = 0; i < STAT_TYPES; i++) {
    362386                        int total = 0;
     
    374398                        // statType > 1
    375399                        if (nonZeroItems > 1)
    376                                 appendStat(stats, "Total" + statName, total);
    377                 }
    378 
     400                                appendStat(stats, "Total" + statName, total, true, false, maxWidthValue , maxWidthRate);
     401                }
     402                stats.deleteCharAt(stats.length() - 1);
    379403                return stats.toString();
    380404        }
     
    382406        public static String getEventStats() {
    383407                StringBuffer stats = getSessionDateTime();
     408                int max = getMax(_EventTimes);
     409                int maxWidthEvents = ("" + max).length();
     410                int maxWidthRate = (getRate(max)).length();
    384411                for (int i = 0; i < _EventTimes.length - 1; i++) {
    385412                        String upperBound = getFormattedTime(EVENT_INTERVALS[i]);
    386                         appendStat(stats, "<" + upperBound, _EventTimes[i]);
     413                        appendStat(stats, "<" + upperBound, _EventTimes[i], true, false,
     414                                        maxWidthEvents,maxWidthRate);
    387415                }
    388416                int lastIndex = EVENT_INTERVALS.length - 1;
    389                 appendStat(stats, getFormattedTime(EVENT_INTERVALS[lastIndex - 1])
    390                                 + "+", _EventTimes[lastIndex]);
     417                appendStat(stats, "+"
     418                                + getFormattedTime(EVENT_INTERVALS[lastIndex - 1]),
     419                                _EventTimes[lastIndex], false, false, maxWidthEvents,maxWidthRate);
    391420                return stats.toString();
     421        }
     422
     423        /**
     424         * Gets the highest number in the list of numbers.
     425         *
     426         * @param nums list of numbers
     427         * @return highest number in the list
     428         */
     429        private static int getMax(int[] nums) {
     430                int max = 0;
     431                for (int i = 0; i < nums.length; i++)
     432                        if (nums[i] > max)
     433                                max = nums[i];
     434                return max;
    392435        }
    393436
     
    401444                        time = (secs / 60 / 60) + "h";
    402445                }
     446                if (time.length() == 2)
     447                        time = " " + time;
    403448                return time;
    404449        }
     
    424469                _EventTimes[_EventTimes.length - 1]++;
    425470        }
     471
     472        public static void DeletedItem(Item toDelete) {
     473                List<Item> items = new ArrayList<Item>();
     474                items.add(toDelete);
     475                DeletedItems(items);
     476        }
    426477}
  • trunk/tests/org/expeditee/gui/FrameIOTest.java

    r67 r72  
    1919
    2020        public void testIsValidFramesetName() {
    21                 assertTrue(FrameIO.IsValidFramesetName("a"));
    22                 assertTrue(FrameIO.IsValidFramesetName("a1c"));
    23                 assertFalse(FrameIO.IsValidFramesetName("1a"));
    24                 assertFalse(FrameIO.IsValidFramesetName("$a"));
    25                 assertFalse(FrameIO.IsValidFramesetName("a$"));
    26                 assertFalse(FrameIO.IsValidFramesetName("a.a"));
    27                 assertFalse(FrameIO.IsValidFramesetName(null));
    28                 assertFalse(FrameIO.IsValidFramesetName("1"));
     21                assertTrue(FrameIO.isValidFramesetName("a"));
     22                assertTrue(FrameIO.isValidFramesetName("a1c"));
     23                assertFalse(FrameIO.isValidFramesetName("1a"));
     24                assertFalse(FrameIO.isValidFramesetName("$a"));
     25                assertFalse(FrameIO.isValidFramesetName("a$"));
     26                assertFalse(FrameIO.isValidFramesetName("a.a"));
     27                assertFalse(FrameIO.isValidFramesetName(null));
     28                assertFalse(FrameIO.isValidFramesetName("1"));
    2929                assertFalse(FrameIO.isValidFrameName(""));
    3030                assertFalse(FrameIO
    31                                 .IsValidFramesetName("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz012345678901A"));
     31                                .isValidFramesetName("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz012345678901A"));
    3232
    3333        }
  • trunk/tests/org/expeditee/io/ConversionTest.java

    r67 r72  
    33import java.awt.Color;
    44import java.awt.Font;
     5import java.awt.Point;
     6import java.util.ArrayList;
     7import java.util.List;
    58
    69import junit.framework.TestCase;
    710
    811import org.expeditee.items.Item;
     12import org.expeditee.items.Text;
    913
    1014public class ConversionTest extends TestCase {
    1115
    1216        public final void testGetColor() {
    13                 assertTrue(Conversion.getColor("100 0 0", Color.white).equals(Color.red));
    14                 assertTrue(Conversion.getColor("0 100 0", Color.white).equals(Color.green));
    15                 assertTrue(Conversion.getColor("0 0 100", Color.white).equals(Color.blue));
    16                 assertTrue(Conversion.getColor("100 100 100", Color.white).equals(Color.white));
    17                 assertEquals(Color.green,Conversion.getColor("-100 0 100", Color.white));
    18                 assertEquals(Conversion.getColor("+0 100 0", Color.black),Color.green);
     17                assertTrue(Conversion.getColor("100 0 0", Color.white)
     18                                .equals(Color.red));
     19                assertTrue(Conversion.getColor("0 100 0", Color.white).equals(
     20                                Color.green));
     21                assertTrue(Conversion.getColor("0 0 100", Color.white).equals(
     22                                Color.blue));
     23                assertTrue(Conversion.getColor("100 100 100", Color.white).equals(
     24                                Color.white));
     25                assertEquals(Color.green, Conversion.getColor("-100 +0 -100",
     26                                Color.white));
     27                assertEquals(Conversion.getColor("+0 +100 +0", Color.black),
     28                                Color.green);
    1929                assertEquals(Color.white, Conversion.getColor("a0a0a0", Color.white));
    20                 assertEquals(Conversion.getColor("red9", Color.white),new Color(0.9F, 0.0F, 0.0F));
    21                 assertEquals(Conversion.getColor("BlUe15", Color.white),new Color(0.0F, 0.0F, 1.0F));
    22                 assertEquals(Conversion.getColor("GREEN0", Color.white),new Color(0.0F, 0.0F, 0.0F));
     30                assertEquals(Conversion.getColor("red9", Color.white), new Color(0.9F,
     31                                0.0F, 0.0F));
     32                assertEquals(Conversion.getColor("BlUe15", Color.white), new Color(
     33                                0.0F, 0.0F, 1.0F));
     34                assertEquals(Conversion.getColor("GREEN0", Color.white), new Color(
     35                                0.0F, 0.0F, 0.0F));
     36                assertEquals(Color.red, Conversion.getColor("adf", Color.red));
     37                assertEquals(Color.red, Conversion.getColor("none", Color.red));
     38                assertEquals(Color.red, Conversion.getColor("null", Color.red));
     39                assertEquals(Color.red, Conversion.getColor(null, Color.red));
    2340        }
    2441
     
    2946        }
    3047
    31         /*public final void testAdjustIntInt() {
    32                 fail("Not yet implemented");
    33         }
    34 
    35         public final void testAdjustPoint() {
    36                 fail("Not yet implemented");
    37         }
    38 
    39         public final void testDeAdjust() {
    40                 fail("Not yet implemented");
    41         }
    42 
    4348        public final void testGetKMSFontCode() {
    44                 fail("Not yet implemented");
     49                Font testFont = new Font(Text.FONT_WHEEL[1], Font.BOLD, 18);
     50                Font testFont2 = new Font(Text.FONT_WHEEL[4], Font.ITALIC, 20);
     51                Font testFont3 = new Font("xxx123", Font.ITALIC | Font.BOLD,
     52                                10);
     53                Font testFont4 = new Font(Text.FONT_WHEEL[0], Font.PLAIN, 2);
     54
     55                String result = Text.FONT_CHARS[1] + "b18";
     56                assertEquals(result, Conversion.getKMSFontCode(testFont));
     57               
     58                result = Text.FONT_CHARS[4] + "i20";
     59                assertEquals(result, Conversion.getKMSFontCode(testFont2));
     60               
     61                result = "dp10";
     62                assertEquals(result, Conversion.getKMSFontCode(testFont3));
     63               
     64                result = Text.FONT_CHARS[0] + "r2";
     65                assertEquals(result, Conversion.getKMSFontCode(testFont4));
    4566        }
    4667
    4768        public final void testGetFont() {
    48                 fail("Not yet implemented");
    49         }*/
     69                Font testFont = new Font(Text.FONT_WHEEL[1], Font.BOLD, 18);
     70                Font testFont2 = new Font(Text.FONT_WHEEL[4], Font.ITALIC, 20);
     71                Font testFont3 = new Font(Text.FONT_WHEEL[3], Font.ITALIC | Font.BOLD,
     72                                10);
     73                Font testFont4 = new Font(Text.FONT_WHEEL[0], Font.PLAIN, 2);
     74
     75                String code = Text.FONT_CHARS[1] + "b18";
     76                assertEquals(testFont, Conversion.getFont(code));
     77               
     78                code = Text.FONT_CHARS[4] + "i20";
     79                assertEquals(testFont2, Conversion.getFont(code));
     80               
     81                code = Text.FONT_CHARS[3] + "p10";
     82                assertEquals(testFont3, Conversion.getFont(code));
     83               
     84                code = Text.FONT_CHARS[0] + "r2";
     85                assertEquals(testFont4, Conversion.getFont(code));
     86        }
    5087
    5188        public final void testGetFrameNumber() {
     
    65102
    66103        public final void testGetJustification() {
    67                 assertEquals(Item.JUSTIFICATION_CENTER, Conversion.getJustification("center"));
    68                 assertEquals(Item.JUSTIFICATION_CENTER, Conversion.getJustification("c"));
     104                assertEquals(Item.JUSTIFICATION_CENTER, Conversion
     105                                .getJustification("center"));
     106                assertEquals(Item.JUSTIFICATION_CENTER, Conversion
     107                                .getJustification("c"));
    69108                assertEquals(Item.JUSTIFICATION_RIGHT, Conversion.getJustification("R"));
    70                 assertEquals(Item.JUSTIFICATION_RIGHT, Conversion.getJustification("RIGHT"));
     109                assertEquals(Item.JUSTIFICATION_RIGHT, Conversion
     110                                .getJustification("RIGHT"));
    71111                assertEquals(Item.JUSTIFICATION_LEFT, Conversion.getJustification("L"));
    72                 assertEquals(Item.JUSTIFICATION_LEFT, Conversion.getJustification("lEfT"));
     112                assertEquals(Item.JUSTIFICATION_LEFT, Conversion
     113                                .getJustification("lEfT"));
    73114                assertEquals(Item.JUSTIFICATION_FULL, Conversion.getJustification("f"));
    74                 assertEquals(Item.JUSTIFICATION_FULL, Conversion.getJustification("FuLl"));
    75                 assertEquals(Item.JUSTIFICATION_NONE, Conversion.getJustification("NONE"));
     115                assertEquals(Item.JUSTIFICATION_FULL, Conversion
     116                                .getJustification("FuLl"));
     117                assertEquals(Item.JUSTIFICATION_NONE, Conversion
     118                                .getJustification("NONE"));
    76119        }
    77120
    78121        public final void testGetKMSJustificationCode() {
    79                 assertEquals("C", Conversion.getKMSJustificationCode(Item.JUSTIFICATION_CENTER));
    80                 assertEquals("L", Conversion.getKMSJustificationCode(Item.JUSTIFICATION_LEFT));
    81                 assertEquals("R", Conversion.getKMSJustificationCode(Item.JUSTIFICATION_RIGHT));
    82                 assertEquals("F", Conversion.getKMSJustificationCode(Item.JUSTIFICATION_FULL));
    83                 assertEquals(null, Conversion.getKMSJustificationCode(Item.JUSTIFICATION_NONE));
    84                 assertEquals(null, Conversion.getKMSJustificationCode(Integer.MAX_VALUE));
    85                 assertEquals(null, Conversion.getKMSJustificationCode(Integer.MIN_VALUE));
     122                assertEquals("C", Conversion
     123                                .getKMSJustificationCode(Item.JUSTIFICATION_CENTER));
     124                assertEquals("L", Conversion
     125                                .getKMSJustificationCode(Item.JUSTIFICATION_LEFT));
     126                assertEquals("R", Conversion
     127                                .getKMSJustificationCode(Item.JUSTIFICATION_RIGHT));
     128                assertEquals("F", Conversion
     129                                .getKMSJustificationCode(Item.JUSTIFICATION_FULL));
     130                assertEquals(null, Conversion
     131                                .getKMSJustificationCode(Item.JUSTIFICATION_NONE));
     132                assertEquals(null, Conversion
     133                                .getKMSJustificationCode(Integer.MAX_VALUE));
     134                assertEquals(null, Conversion
     135                                .getKMSJustificationCode(Integer.MIN_VALUE));
    86136        }
    87137
     
    89139                assertEquals("Test", Conversion.Convert(String.class, "Test"));
    90140                assertEquals(null, Conversion.Convert(String.class, ""));
    91                 assertEquals(Conversion.getFont("tr16"), Conversion.Convert(Font.class, "tr16"));
     141                assertEquals(Conversion.getFont("tr16"), Conversion.Convert(Font.class,
     142                                "tr16"));
     143                // Test Color Conversion
     144                assertEquals(Color.darkGray, Conversion.Convert(Color.class,
     145                                "dark_gray"));
     146                assertEquals(Color.darkGray, Conversion
     147                                .Convert(Color.class, "DARKGRAY"));
    92148                assertEquals(Color.red, Conversion.Convert(Color.class, "red"));
    93149                assertEquals(Color.red, Conversion.Convert(Color.class, "Red"));
     
    96152                assertEquals(Color.green, Conversion.Convert(Color.class, "0  100"));
    97153                assertEquals(Color.blue, Conversion.Convert(Color.class, "0 0 100"));
     154                // Test Boolean Conversion
     155                assertEquals(true, Conversion.Convert(boolean.class, "tRuE"));
     156                assertEquals(true, Conversion.Convert(boolean.class, "T"));
     157                assertEquals(true, Conversion.Convert(boolean.class, "yes"));
     158                assertEquals(true, Conversion.Convert(boolean.class, "Y"));
     159                assertEquals(true, Conversion.Convert(boolean.class, ""));
     160                assertEquals(false, Conversion.Convert(boolean.class, "FALSE"));
     161                assertEquals(false, Conversion.Convert(boolean.class, "no"));
     162                assertEquals(false, Conversion.Convert(boolean.class, "n"));
     163                assertEquals(false, Conversion.Convert(boolean.class, "f"));
    98164        }
    99165
    100166        public final void testConvertClassStringObject() {
    101                 assertEquals(Color.red, Conversion.Convert(Color.class, "+100 0 -100", Color.blue));
    102                 assertEquals(Color.black, Conversion.Convert(Color.class, "-0 0 100", Color.blue));
    103                 //TODO add more stuff to here
     167                assertEquals(Color.red, Conversion.Convert(Color.class, "+100 +0 -100",
     168                                Color.blue));
     169                assertEquals(Color.black, Conversion.Convert(Color.class, "-0 +0 -100",
     170                                Color.blue));
     171                // Float test
     172                assertEquals(2.0F, Conversion.Convert(float.class, "2.0", null));
     173                assertEquals(-8.0F, Conversion.Convert(float.class, "+2.0", -10.0F));
     174                assertEquals(8.0F, Conversion.Convert(float.class, "-2.0", 10.0F));
     175                // Double test
     176                assertEquals(2.0, Conversion.Convert(double.class, "2.0", null));
     177                assertEquals(-8.0, Conversion.Convert(double.class, "+2.0", -10.0));
     178                assertEquals(8.0, Conversion.Convert(double.class, "-2.0", 10.0));
     179                // Integer test
     180                assertEquals(2, Conversion.Convert(int.class, "2", null));
     181                assertEquals(-8, Conversion.Convert(int.class, "+2", -10));
     182                assertEquals(8, Conversion.Convert(int.class, "-2", 10));
    104183        }
    105184
     
    111190
    112191        public final void testConvertToKMS() {
     192                try {
     193                        java.lang.reflect.Method getPosition = Item.class.getMethod(
     194                                        "getPosition", new Class[] {});
     195                        java.lang.reflect.Method getJustification = Text.class.getMethod(
     196                                        "getJustification", new Class[] {});
     197
     198                        assertEquals("C", Conversion.ConvertToKMS(getJustification,
     199                                        Item.JUSTIFICATION_CENTER));
     200
     201                        assertEquals("Test", Conversion.ConvertToKMS(getPosition,
     202                                        (Object) "Test"));
     203                        assertEquals("0", Conversion.ConvertToKMS(getPosition, (Object) 0));
     204                        assertEquals("0.0", Conversion.ConvertToKMS(getPosition,
     205                                        (Object) 0.0F));
     206                        assertEquals(null, Conversion.ConvertToKMS(getPosition,
     207                                        (new Integer(-1))));
     208                        assertEquals(null, Conversion.ConvertToKMS(getPosition, (new Float(
     209                                        -0.1F))));
     210                        assertEquals(null, Conversion.ConvertToKMS(getPosition,
     211                                        (new Boolean(true))));
     212                        assertEquals("F", Conversion.ConvertToKMS(getPosition,
     213                                        (new Boolean(false))));
     214                        assertEquals(null, Conversion.ConvertToKMS(getPosition,
     215                                        (new int[] {})));
     216                        assertEquals("1 22 333", Conversion.ConvertToKMS(getPosition,
     217                                        (new int[] { 1, 22, 333 })));
     218
     219                        assertEquals("22 44", Conversion.ConvertToKMS(getPosition,
     220                                        (new Point(22, 44))));
     221
     222                        assertEquals("100 0 0", Conversion.ConvertToKMS(getPosition,
     223                                        Color.red));
     224
     225                        assertEquals(null, Conversion.ConvertToKMS(getPosition, null));
     226                        List<String> testList = new ArrayList<String>();
     227                        testList.add("test");
     228
     229                        assertEquals(testList, Conversion.ConvertToKMS(getPosition,
     230                                        testList));
     231
     232                        Font testFont = new Font(Text.FONT_WHEEL[1], Font.BOLD, 18);
     233                        String result = Text.FONT_CHARS[1] + "b18";
     234                        assertEquals(result, Conversion.ConvertToKMS(getPosition, testFont));
     235                } catch (Exception e) {
     236                        e.printStackTrace();
     237                        fail();
     238                }
    113239        }
    114240
Note: See TracChangeset for help on using the changeset viewer.