Changeset 105


Ignore:
Timestamp:
06/20/08 12:55:35 (16 years ago)
Author:
ra33
Message:

Made a whole lot of changes...

Including using polyLine etc for drawing rectangles nicer

Location:
trunk
Files:
1 added
20 edited

Legend:

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

    r97 r105  
    3030
    3131/**
    32  * A list of miscellaneous KMS Actions and Actions specific to Expeditee
     32 * A list of miscellaneous Actions and Actions specific to Expeditee
    3333 *
    3434 */
     
    181181                // copy the item and switch
    182182                item = item.copy();
    183                 item.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());
     183                item.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
    184184                item.setParent(null);
    185185
     
    238238                FrameGraphics.DisplayMessage("Computing comet stats...");
    239239
    240                 CometStats cometStats = new CometStats(frame, true);
     240                CometStats cometStats = new CometStats(frame);
    241241                CreateTextItem(cometStats.toString());
    242242                FrameGraphics.OverwriteMessage("Comet stats time: "
     
    248248                FrameGraphics.DisplayMessage("Computing tree stats...");
    249249
    250                 TreeStats treeStats = new TreeStats(frame, true);
     250                TreeStats treeStats = new TreeStats(frame);
    251251                CreateTextItem(treeStats.toString());
    252252                FrameGraphics.OverwriteMessage("Tree stats time: "
     
    299299                text.setText(fileContents);
    300300
    301                 text.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());
     301                text.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
    302302                text.setSize(FRAME_FILE_FONT_SIZE);
    303303
     
    324324                text.setText(fontsList.toString());
    325325
    326                 text.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());
     326                text.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
    327327                text.setSize(FRAME_FILE_FONT_SIZE);
    328328
  • trunk/src/org/expeditee/actions/NavigationActions.java

    r80 r105  
    1111
    1212/**
    13  * Provides the Navigation related KMS action procedures
     13 * Provides the Navigation related action procedures
    1414 *
    1515 * @author jdm18
  • trunk/src/org/expeditee/actions/Simple.java

    r97 r105  
    21092109
    21102110                        int initialX = DisplayIO.getMouseX();
    2111                         int initialY = DisplayIO.getMouseY();
     2111                        int initialY = FrameMouseActions.getY();
    21122112
    21132113                        final int timeInterval = 40;
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r104 r105  
    5858         * The title to display in the Title bar.
    5959         */
    60         public static final String TITLE = "Exp16Jun2008A";
     60        public static final String TITLE = "Exp20Jun2008A";
    6161
    6262        private DisplayIO() {
     
    8181        }
    8282
    83         public static void setTextCursor(int size) {
    84                 setTextCursor(size, false);
    85         }
    86 
    87         public static void setTextCursor(int size, boolean newSize) {
    88                 if (!newSize && cursorType == Item.TEXT_CURSOR)
     83        public static void setTextCursor(Text text, int cursorMovement) {
     84                setTextCursor(text, cursorMovement, false);
     85        }
     86
     87        public static void setTextCursor(Text text, int cursorMovement,
     88                        boolean newSize) {
     89
     90                int size = text.getSize();
     91                Point newMouse = text.moveCursor(cursorMovement, DisplayIO.getMouseX(),
     92                                FrameMouseActions.getY());
     93
     94                if (!newSize && cursorType == Item.TEXT_CURSOR) {
     95                        if (cursorMovement != 0)
     96                                DisplayIO.setCursorPosition(newMouse, false);
    8997                        return;
     98                }
    9099
    91100                cursorType = Item.TEXT_CURSOR;
     
    126135                                image, new Point(0, hotspotPos), "textcursor");
    127136                _Browser.setCursor(textCursor);
     137                DisplayIO.setCursorPosition(newMouse, false);
    128138        }
    129139
     
    169179         *            The y coordinate
    170180         */
    171         public static void setCursorPosition(int x, int y) {
     181        public static void setCursorPosition(float x, float y) {
    172182                setCursorPosition(x, y, true);
    173183        }
    174184
    175         public static void setCursorPosition(int x, int y, boolean forceArrow) {
     185        public static void setCursorPosition(float x, float y, boolean forceArrow) {
    176186                // Adjust the position to move the mouse to to account for being in
    177187                // TwinFramesMode
     
    183193                }
    184194
    185                 int deltax = x - FrameMouseActions.MouseX;
    186                 int deltay = y - FrameMouseActions.MouseY;
     195                float deltax = x - FrameMouseActions.MouseX;
     196                float deltay = y - FrameMouseActions.MouseY;
    187197
    188198                // When the Robot moves the cursor... a short time later a mouseMoved
     
    203213                int mouseX = (int) _Browser.getContentPane().getLocationOnScreen()
    204214                                .getX()
    205                                 + x;
     215                                + (int) (x + 0.5);
    206216                int mouseY = (int) _Browser.getContentPane().getLocationOnScreen()
    207217                                .getY()
    208                                 + y;
     218                                + (int) (y + 0.5);
    209219                _Robot.mouseMove(mouseX, mouseY);
    210220                // System.out.println("MouseMoved: " + x + "," + y);
     
    261271                int side = getCurrentSide();
    262272
    263 //              // do not allow duplicate frames
    264 //              if (_VisitedFrames[side].size() > 0)
    265 //                      if (_VisitedFrames[side].peek().equals(toAdd.getName())) {
    266 //                              return;
    267 //                      }
     273                // // do not allow duplicate frames
     274                // if (_VisitedFrames[side].size() > 0)
     275                // if (_VisitedFrames[side].peek().equals(toAdd.getName())) {
     276                // return;
     277                // }
    268278
    269279                Item ip = FrameUtils.getCurrentItem();
     
    272282                else
    273283                        _VisitedFrames[side].push(toAdd.getName());
    274                
    275                 //System.out.println("Added: " + _VisitedFrames[side].size());
     284
     285                // System.out.println("Added: " + _VisitedFrames[side].size());
    276286        }
    277287
     
    283293                        _VisitedFrames[side].pop();
    284294                }
    285                 //System.out.println("Removed: " + _VisitedFrames[side].size());
     295                // System.out.println("Removed: " + _VisitedFrames[side].size());
    286296        }
    287297
     
    543553         * @return The X coordinate of the mouse.
    544554         */
     555        public static float getFloatMouseX() {
     556                if (_TwinFrames
     557                                && FrameMouseActions.MouseY < FrameGraphics.getMaxSize().height)
     558                        return FrameMouseActions.MouseX % (_Browser.getWidth() / 2);
     559
     560                return FrameMouseActions.MouseX;
     561        }
     562
     563        /**
     564         * Returns the current mouse X coordinate. This coordinate is relative to
     565         * the left edge of the frame the mouse is in. It takes into account the
     566         * user being in twin frames mode.
     567         *
     568         * @return The X coordinate of the mouse.
     569         */
    545570        public static int getMouseX() {
    546                 if (_TwinFrames && getMouseY() < FrameGraphics.getMaxSize().height)
    547                         return FrameMouseActions.MouseX % (_Browser.getWidth() / 2);
    548 
    549                 return FrameMouseActions.MouseX;
    550         }
    551 
    552         /**
    553          * Returns the current mouse Y coordinate. This is relative to the top of
    554          * the frame.
    555          *
    556          * @return The Y coordinate of the mouse.
    557          */
    558         public static int getMouseY() {
    559                 return FrameMouseActions.MouseY;
    560         }
    561 
    562         public static int getRealMouseX() {
    563                 return FrameMouseActions.MouseX;
    564         }
    565 
    566         public static int getRealMouseY() {
    567                 return FrameMouseActions.MouseY;
     571                return Math.round(getFloatMouseX());
    568572        }
    569573
     
    589593                        FrameIO.SuspendCache();
    590594                Frame frame = FrameIO.LoadFrame(_VisitedFrames[side].pop());
    591                 //If the top frame on the backup stack is the current frame go back again...
    592                 if(frame.equals(getCurrentFrame())){
     595                // If the top frame on the backup stack is the current frame go back
     596                // again...
     597                if (frame.equals(getCurrentFrame())) {
    593598                        Back();
    594599                        return;
     
    708713         */
    709714        public static void MoveCursorToEndOfItem(Item i) {
    710                 setCursorPosition(i.getPosition());
    711                 Point newMouse = ((Text) i).moveCursor(Text.END, getMouseX(),
    712                                 getMouseY());
    713                 setTextCursor(((Item) i).getSize());
    714                 setCursorPosition(newMouse, false);
     715                setTextCursor((Text) i, Text.END);
    715716        }
    716717}
  • trunk/src/org/expeditee/gui/Frame.java

    r104 r105  
    3131
    3232/**
    33  * Represents a KMS Frame that is displayed on the screen. Also is a registered
     33 * Represents a Expeditee Frame that is displayed on the screen. Also is a registered
    3434 * MouseListener on the Browser, and processes any MouseEvents directly.
    3535 *
     
    400400                t.setMaxSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    401401                t.setText(itemText);
    402                 t.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());
     402                t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
    403403               
    404404                //The next line is needed to allow the link to be set properly when the item is picked up
     
    765765         * @return The version of this Frame.
    766766         */
    767         public int getVersion(boolean increment) {
    768                 // System.out.println("Version: " + _version);
    769                 if (increment)
    770                         _version++;
     767        public int getVersion() {
    771768                return _version;
    772         }
    773 
    774         public int getVersion() {
    775                 return getVersion(true);
    776769        }
    777770
     
    13111304                t.setID(getNextItemID());
    13121305                t.setMaxSize(FrameGraphics.getMaxFrameSize());
    1313                 t.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());
     1306                t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
    13141307                t.setText("");
    13151308                t.setParent(this);
     
    13181311
    13191312        public Item createDot() {
    1320                 Item dot = new Dot(DisplayIO.getMouseX(), DisplayIO.getMouseY(),
     1313                Item dot = new Dot(DisplayIO.getMouseX(), FrameMouseActions.getY(),
    13211314                                getNextItemID());
    13221315
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r102 r105  
    1212import java.awt.Point;
    1313import java.awt.RenderingHints;
     14import java.awt.Stroke;
    1415import java.awt.image.BufferedImage;
    1516import java.awt.image.VolatileImage;
    1617import java.util.Collection;
     18import java.util.Collections;
     19import java.util.Comparator;
    1720import java.util.HashSet;
    1821import java.util.Iterator;
     
    7477
    7578        // The link to the message frameset
    76         public static Item MessageLink= new Text(-2, "@" + MESSAGES_FRAMESET_NAME,Color.black, Color.white);
     79        public static Item MessageLink = new Text(-2, "@" + MESSAGES_FRAMESET_NAME,
     80                        Color.black, Color.white);
    7781
    7882        // creator for creating the message frames
    7983        private static FrameCreator _creator;
    80        
     84
    8185        /**
    8286         * If Audience Mode is on this method will toggle it to be off, or
     
    140144                int newMaxHeight = max.height
    141145                                - (isAudienceMode() ? 0 : MESSAGE_BUFFER_HEIGHT);
    142                 if (newMaxHeight > 0)
     146                if (newMaxHeight > 0) {
    143147                        _MaxSize.setSize(max.width, newMaxHeight);
     148                }
    144149
    145150                if (DisplayIO.getCurrentFrame() != null) {
     
    237242         */
    238243        public static void AddAllVectorItems(List<Item> items, Frame vector,
    239                         Collection<Frame> seenVectors, Point origin, Float scale) {
     244                        Collection<Frame> seenVectors, Point origin, Float scale,
     245                        Color defaultForeground, Color defaultBackground) {
    240246
    241247                // Check all the vector items and add the items on the vectors
    242 
    243248                if (seenVectors.contains(vector))
    244249                        return;
     
    251256                        AddAllVectorItems(items, o.Frame, new HashSet<Frame>(seenVectors),
    252257                                        new Point(originX + Math.round(o.Origin.x * scale), originY
    253                                                         + Math.round(o.Origin.y * scale)), o.Scale * scale);
     258                                                        + Math.round(o.Origin.y * scale)), o.Scale * scale,
     259                                        o.Foreground, o.Background);
    254260                // if its the original frame then were done
    255261                if (origin == null) {
     
    273279                        i.setActionMark(false);
    274280                        if (!(i instanceof Line)) {
    275                                 i.setPosition((int) (i.getX() * scale + dx + 0.5), (int) (i
    276                                                 .getY()
     281                                i.setXY((int) (i.getX() * scale + dx + 0.5), (int) (i.getY()
    277282                                                * scale + dy + 0.5));
    278283                                i.setThickness((int) (i.getThickness() * scale + 0.5));
     
    280285                                                .setArrowheadLength((int) (i.getArrowheadLength()
    281286                                                                * scale + 0.5));
     287                                if (i.getColor() == null) {
     288                                        i.setColor(defaultForeground);
     289                                }
     290                                if (i.getBackgroundColor() == null) {
     291                                        i.setBackgroundColor(defaultBackground);
     292                                }
     293                                if (i.getFillColor() == null) {
     294                                        i.setFillColor(defaultBackground);
     295                                }
    282296                        }
    283297                        if (i instanceof Text)
     
    364378
    365379                        AddAllVectorItems(paintItems, toPaint, new LinkedList<Frame>(),
    366                                         null, 1F);
     380                                        null, 1F, null, null);
    367381
    368382                        if (isActualFrame) {
     
    404418                                                                        ^ line.getStartItem().isFloating()) {
    405419                                                                lines.add(TransposeLine(line,
    406                                                                                 line.getEndItem(), toPaint, DisplayIO
    407                                                                                                 .getRealMouseX(), -DisplayIO
     420                                                                                line.getEndItem(), toPaint,
     421                                                                                FrameMouseActions.getY(), -DisplayIO
    408422                                                                                                .getMiddle()));
    409423                                                                lines.add(TransposeLine(line, line
    410                                                                                 .getStartItem(), toPaint, DisplayIO
    411                                                                                 .getRealMouseX(), -DisplayIO
    412                                                                                 .getMiddle()));
     424                                                                                .getStartItem(), toPaint,
     425                                                                                FrameMouseActions.getY(), -DisplayIO
     426                                                                                                .getMiddle()));
    413427                                                        }
    414428                                                } else {
     
    604618
    605619        private static void PaintLines(Graphics2D g, List<Item> toPaint) {
     620                Stroke oldStroke = g.getStroke();
     621                // Use this set to keep track of the items that have been painted
     622                Collection<Item> done = new HashSet<Item>();
    606623                for (Item i : toPaint)
    607                         if (i instanceof Line)
    608                                 PaintItem(g, i);
     624                        if (i instanceof Line) {
     625                                Line l = (Line)i;
     626                                if (done.contains(l)) {
     627                                        l.paintArrows(g);
     628                                } else {
     629                                        // When painting a line all connected lines are painted too
     630                                        done.addAll(l.getAllConnected());
     631                                        if (l.getStartItem().getEnclosedArea() == 0)
     632                                                PaintItem(g, i);
     633                                }
     634                        }
     635                g.setStroke(oldStroke);
    609636        }
    610637
    611638        private static void PaintPictures(Graphics2D g, List<Item> toPaint) {
     639                // Use this set to keep track of the items that dont need to be
     640                // repainted
     641                Collection<Item> done = new HashSet<Item>();
     642                List<Item> toFill = new LinkedList<Item>();
    612643                for (Item i : toPaint) {
     644                        // Ignore items that have already been done!
     645                        if (done.contains(i))
     646                                continue;
    613647                        if (i instanceof Picture) {
    614648                                PaintItem(g, i);
    615649                        } else if (i.isLineEnd()
    616650                                        && (!isAudienceMode() || !i.isConnectedToAnnotation())) {
    617                                 i.paintFill(g);
    618                         }
     651                                toFill.add(i);
     652                                done.addAll(i.getAllConnected());
     653                        }
     654                }
     655                //Sort the items to fill
     656                Collections.sort(toFill, new Comparator<Item>() {
     657                        public int compare(Item a, Item b) {
     658                                Integer aArea = a.getEnclosedArea();
     659                                Integer bArea = b.getEnclosedArea();
     660                                return aArea.compareTo(bArea) * -1;
     661                        }
     662                });
     663                for(Item i: toFill){
     664                        i.paintFill(g);
     665                        PaintItem(g, i.getLines().get(0));
    619666                }
    620667        }
     
    635682                        // Check if within 20% of the end of the line
    636683                        Line l = (Line) i;
    637                         Item toDisconnect = l.getEndPointToDisconnect(
    638                                         FrameMouseActions.MouseX, FrameMouseActions.MouseY);
     684                        Item toDisconnect = l.getEndPointToDisconnect(Math
     685                                        .round(FrameMouseActions.MouseX), Math
     686                                        .round(FrameMouseActions.MouseY));
    639687
    640688                        // Brook: Widget Edges do not have such a context
     
    658706                        }
    659707                } else {
     708                        //FrameGraphics.ChangeSelectionMode(i,
     709                        //              Item.SelectedMode.Normal);
     710                        //For polygons need to make sure all other endpoints are unHighlighted
     711                        for (Item conn : i.getAllConnected()) {
     712                                conn.setSelectedMode(Item.SelectedMode.None);
     713                        }
    660714                        i.setSelectedMode(Item.SelectedMode.Normal);
    661715                }
     
    785839                Text last = Messages[Messages.length - 1];
    786840                last.setColor(color);
    787                 //Make set the text for the new message
     841                // Make set the text for the new message
    788842                last.setText(getMessagePrefix(true) + message);
    789843                last.setLink(link);
  • trunk/src/org/expeditee/gui/FrameIO.java

    r104 r105  
    99import java.io.FileWriter;
    1010import java.io.IOException;
     11import java.sql.Time;
    1112import java.util.HashMap;
    1213
     
    629630         *
    630631         * @param toSave
    631          *            The Frame to save to disk in KMS format.
     632         *            The Frame to save to disk
    632633         */
    633634        public static String SaveFrame(Frame toSave) {
     
    645646         *
    646647         * @param toSave
    647          *            The Frame to save to disk in KMS format.
     648         *            The Frame to save to disk
    648649         * @param inc
    649650         *            True if the saved frames counter should be incremented, false
     
    655656                        boolean checkBackup) {
    656657
    657                 if (toSave == null)
     658                // TODO When loading a frame maybe append onto the event history too- with a
     659                // break to indicate the end of a session
     660
     661                if (toSave == null ||!toSave.hasChanged() || toSave.isSaved()){
     662                        SessionStats.NewFrameSession();
    658663                        return "";
    659 
    660                 if (!toSave.hasChanged() || toSave.isSaved())
    661                         return "";
    662 
     664                }
    663665                // Get the full path only to determine which format to use for saving
    664666                // the frame
     
    672674                                && toSave.getNameItem().Permission < Item.PERMISSION_TDFC) {
    673675                        _Cache.remove(toSave.getName().toLowerCase());
     676                        SessionStats.NewFrameSession();
    674677                        return "";
    675678                }
     
    694697                        }
    695698                        // Check if we are trying to save an out of date version
    696                         if (savedVersion > toSave.getVersion(false)
     699                        if (savedVersion > toSave.getVersion()
    697700                                        && !toSave.getFramesetName().equalsIgnoreCase(
    698701                                                        FrameGraphics.MESSAGES_FRAMESET_NAME)) {
     
    741744                                ResumeCache();
    742745                        }
    743                         toSave.setActiveTime(SessionStats.getFrameActiveTime());
    744                         toSave.setDarkTime(SessionStats.getFrameDarkTime());
     746                        // Update general stuff about frame
    745747                        toSave.setLastModifyDate(Logger.EasyDateFormat("ddMMMyyyy:HHmm"));
    746748                        toSave.setLastModifyUser(UserSettings.Username);
     749                        toSave.setVersion(toSave.getVersion() + 1);
     750                        Time darkTime = new Time(SessionStats.getFrameDarkTime().getTime()
     751                                        + toSave.getDarkTime().getTime());
     752                        Time activeTime = new Time(SessionStats.getFrameActiveTime()
     753                                        .getTime()
     754                                        + toSave.getActiveTime().getTime());
     755                        toSave.setDarkTime(darkTime);
     756                        toSave.setActiveTime(activeTime);
     757
    747758                        writer.writeFrame(toSave);
    748759                        toSave.setSaved();
    749                         if (inc)
     760                        if (inc) {
    750761                                SessionStats.SavedFrame(toSave.getName());
     762                        }
    751763
    752764                        // avoid out-of-sync frames (when in TwinFrames mode)
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r97 r105  
    136136                        FrameUtils.LastEdited = text;
    137137                        DisplayIO.getCurrentFrame().addItem(text);
    138                         DisplayIO.setTextCursor(text.getSize());
    139                         return;
    140                 }
    141 
    142                 DisplayIO.setTextCursor(text.getSize());
     138                        DisplayIO.setTextCursor(text, Text.NONE);
     139                        return;
     140                }
     141
     142                DisplayIO.setTextCursor(text, Text.NONE);
    143143                Point newMouse = null;
    144144                if (ch == '\t') {
    145145                        if (isShiftDown) {
    146                                 newMouse = text.removeTab(ch, DisplayIO.getMouseX(), DisplayIO
    147                                                 .getMouseY());
     146                                newMouse = text.removeTab(ch, DisplayIO.getMouseX(),
     147                                                FrameMouseActions.getY());
    148148                        } else {
    149                                 newMouse = text.insertTab(ch, DisplayIO.getMouseX(), DisplayIO
    150                                                 .getMouseY());
     149                                newMouse = text.insertTab(ch, DisplayIO.getMouseX(),
     150                                                FrameMouseActions.getY());
    151151                        }
    152152                } else {
    153                         newMouse = text.insertChar(ch, DisplayIO.getMouseX(), DisplayIO
    154                                         .getMouseY());
     153                        newMouse = text.insertChar(ch, DisplayIO.getMouseX(),
     154                                        FrameMouseActions.getY());
    155155                }
    156156                DisplayIO.setCursorPosition(newMouse.x, newMouse.y, false);
    157157
     158                //This repaint is needed for WINDOWS only?!?!? Mike is not sure why!
     159                if(ch == KeyEvent.VK_DELETE)
     160                        FrameGraphics.Repaint();
     161               
    158162                // a change has occured to the Frame
    159163                text.getParent().setChanged(true);
     
    229233                Text t = DisplayIO.getCurrentFrame().createBlankText("" + start);
    230234
    231                 Point newMouse = t.insertChar(start, DisplayIO.getMouseX(), DisplayIO
    232                                 .getMouseY());
     235                Point newMouse = t.insertChar(start, DisplayIO.getMouseX(),
     236                                FrameMouseActions.getY());
    233237                DisplayIO.setCursorPosition(newMouse.x, newMouse.y, false);
    234238
     
    248252
    249253        private void move(int direction) {
    250                 Item ip = FrameUtils.getCurrentItem();
    251 
    252                 if (ip == null) {
     254                Item on = FrameUtils.getCurrentItem();
     255
     256                if (on == null) {
    253257                        navigateFrame(direction);
    254258                        return;
    255259                }
    256260
    257                 Item on = ip;
    258261                if (on instanceof Text) {
    259262                        // When the user hits the left and right button with mouse
     
    264267                        } else {
    265268                                FrameUtils.LastEdited = on;
    266                                 Point newMouse = ((Text) on).moveCursor(direction, DisplayIO
    267                                                 .getMouseX(), DisplayIO.getMouseY());
    268                                 DisplayIO.setTextCursor(((Item) on).getSize());
    269                                 DisplayIO.setCursorPosition(newMouse, false);
     269                                DisplayIO.setTextCursor((Text) on, direction);
    270270                        }
    271271                }
     
    323323                        return;
    324324                } else if (e.isControlDown() && e.getKeyCode() != KeyEvent.VK_CONTROL)
    325                         controlChar(e, KeyEvent.getKeyText(e.getKeyCode()));
     325                        controlChar(e, e.getKeyCode());
    326326
    327327                switch (e.getKeyCode()) {
     
    392392                if (currentItem == null) {
    393393                        // find the nearest item in the correct direction
    394                         int currY = DisplayIO.getMouseY();
     394                        int currY = FrameMouseActions.getY();
    395395                        for (int i = 0; i < textItems.size(); i++) {
    396396                                Item t = textItems.get(i);
     
    473473        }
    474474
     475        private static void copyItemToClipboard(Item on){
     476                if (on == null || !(on instanceof Text))
     477                        return;
     478
     479                String text = "";
     480
     481                List<String> lines = ((Text) on).getTextList();
     482                for (String s : lines)
     483                        text += s + "\n";
     484                // remove the last '\n'
     485                text = text.substring(0, text.length() - 1);
     486
     487                // add the text of the item to the clipboard
     488                StringSelection selection = new StringSelection(text);
     489                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
     490                                selection, null);
     491        }
     492       
    475493        /**
    476494         * Processes all control character keystrokes. Currently Ctrl+C and Ctrl+V
     
    480498         *            The character being pressed along with the control key
    481499         */
    482         private static void controlChar(KeyEvent e, String ch) {
    483                 if (ch.length() > 1)
    484                         return;
     500        private static void controlChar(KeyEvent e, int key) {
    485501                Logger.Log(Logger.USER, Logger.CONTROL_CHAR, "User pressing: Ctrl+"
    486                                 + ch);
     502                                + KeyEvent.getKeyText(key));
    487503                //
    488504                // if (FrameUtils.getCurrentItem() == null
     
    495511                Frame currentFrame = DisplayIO.getCurrentFrame();
    496512                // Link or delink an item
    497                 if (ch.charAt(0) == KeyEvent.VK_L) {
     513                if (key == KeyEvent.VK_L) {
    498514                        // If its not linked then link it to its self
    499515                        if (current instanceof Text && current.getLink() == null) {
     
    508524                                current.setLink(null);
    509525                        }
    510                 } else if (ch.charAt(0) == KeyEvent.VK_G) {
     526                } else if (key == KeyEvent.VK_G) {
    511527                        // If its not linked then link it to its self
    512528                        if (current instanceof Text) {
     
    522538                                return;
    523539                        }
    524                 } else if (ch.charAt(0) == KeyEvent.VK_A) {
     540                } else if (key == KeyEvent.VK_A) {
    525541                        // If its not linked then link it to its self
    526542                        if (current instanceof Text && current.getAction() == null) {
     
    543559                                current.setActions(null);
    544560                        }
    545                 } else if (ch.charAt(0) == KeyEvent.VK_V) {
     561                } else if (key == KeyEvent.VK_V) {
    546562                        try {
    547563                                // read in the data from the clipboard
     
    573589
    574590                                        String temp = "";
    575                                         int y = DisplayIO.getMouseY();
     591                                        int y = FrameMouseActions.getY();
    576592
    577593                                        // separate the clipboard content into items based on
     
    595611                        }
    596612                        // if this is a copy command
    597                 } else if (ch.charAt(0) == KeyEvent.VK_C) {
    598                         Item ip = FrameUtils.getCurrentItem();
    599 
    600                         if (ip != null && ip.Permission < Item.PERMISSION_COPY) {
     613                } else if (key == KeyEvent.VK_C) {
     614                        Item on = FrameUtils.getCurrentItem();
     615                        if (on != null && on.Permission < Item.PERMISSION_COPY) {
    601616                                FrameGraphics
    602                                                 .DisplayMessage("Insufficient permission to copy that item");
    603                                 return;
    604                         }
    605 
    606                         Item on = null;
    607                         if (ip != null)
    608                                 on = ip;
    609 
    610                         if (on == null || !(on instanceof Text))
    611                                 return;
    612 
    613                         String text = "";
    614 
    615                         List<String> lines = ((Text) on).getTextList();
    616                         for (String s : lines)
    617                                 text += s + "\n";
    618                         // remove the last '\n'
    619                         text = text.substring(0, text.length() - 1);
    620 
    621                         // add the text of the item to the clipboard
    622                         StringSelection selection = new StringSelection(text);
    623                         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
    624                                         selection, null);
    625                         FrameGraphics.DisplayMessage("Item copied to clipboard");
    626                         return;
    627                 } else if (ch.charAt(0) == KeyEvent.VK_D) {
     617                                                .DisplayMessage("Insufficient permission to copy that item" );
     618                                return;
     619                        }
     620                        copyItemToClipboard(on);
     621                        //FrameGraphics.DisplayMessage("Item copied to clipboard");
     622                        return;
     623                } else if (key == KeyEvent.VK_X) {
     624                        Item on = FrameUtils.getCurrentItem();
     625                        if (on != null && on.Permission < Item.PERMISSION_FULL) {
     626                                FrameGraphics
     627                                                .DisplayMessage("Insufficient permission to cut that item" );
     628                                return;
     629                        }
     630                        copyItemToClipboard(on);
     631                        FrameMouseActions.delete(current);
     632                        return;
     633                }else if (key == KeyEvent.VK_D) {
    628634                        // perform a delete operation
    629635                        processChar((char) KeyEvent.VK_DELETE, e.isShiftDown());
     636                } else if (key == KeyEvent.VK_DELETE) {
     637                        // perform a delete operation
    630638                        FrameMouseActions.delete(current);
    631                 } else if (ch.charAt(0) == KeyEvent.VK_F) {
     639                } else if (key == KeyEvent.VK_F) {
    632640                        // perform a delete operation
    633641                        Actions.PerformAction(currentFrame, null, "Format");
    634642                        return;
    635                 } else if (ch.charAt(0) == KeyEvent.VK_J) {
     643                } else if (key == KeyEvent.VK_J) {
    636644
    637645                        Text text = getCurrentTextItem();
     
    644652
    645653                        text.setJustification(Justification.left);
    646                 } else if (ch.charAt(0) == KeyEvent.VK_S) {
     654                } else if (key == KeyEvent.VK_S) {
    647655                        // split the current text item
    648656                        Text text = getCurrentTextItem();
     
    788796                case SizeUp:
    789797                        SetSize(on, repeat, true);
    790                         DisplayIO.setTextCursor(on.getSize(), true);
     798                        if (on instanceof Text) {
     799                                DisplayIO.setTextCursor((Text) on, Text.NONE, true);
     800                        }
    791801                        break;
    792802                case SizeDown:
    793803                        SetSize(on, -repeat, true);
    794                         DisplayIO.setTextCursor(on.getSize(), true);
     804                        if (on instanceof Text) {
     805                                DisplayIO.setTextCursor((Text) on, Text.NONE, true);
     806                        }
    795807                        break;
    796808                case ChangeColor:
     
    952964                                                }
    953965                                                // Add the bullet text to the item
    954                                                 dummyItem.setPosition(DisplayIO.getMouseX(), DisplayIO
    955                                                                 .getMouseY());
     966                                                dummyItem.setPosition(DisplayIO.getMouseX(),
     967                                                                FrameMouseActions.getY());
    956968                                        } else {
    957969                                                FrameGraphics
     
    959971                                                // ensures correct repainting when items don't move
    960972                                                DisplayIO.setCursorPosition(DisplayIO.getMouseX(),
    961                                                                 DisplayIO.getMouseY());
     973                                                                FrameMouseActions.getY());
    962974                                                return;
    963975                                        }
     
    12221234                                dot.setThickness(current);
    12231235                        } else {
    1224                                 int current = Math.abs(i.getSize());
    1225                                 current = Math.max(current + diff, 1);
    1226                                 i.setSize(current);
     1236                                int oldSize = Math.abs(i.getSize());
     1237                                int newSize = Math.max(oldSize + diff, 1);
     1238                                i.setSize(newSize);
     1239                                if (i instanceof Text) {
     1240                                        // Move the cursor as close as we can to where it should be
     1241                                        int itemX = i.getX();
     1242                                        int itemY = i.getY();
     1243                                        float resizeRatio = (float) newSize / oldSize;
     1244                                        float fromOriginX = DisplayIO.getFloatMouseX() - itemX;
     1245                                        float fromOriginY = FrameMouseActions.MouseY - itemY;
     1246                                        float newX = itemX + fromOriginX * resizeRatio;
     1247                                        float newY = itemY + fromOriginY * resizeRatio;
     1248                                        if (i instanceof Text)
     1249                                                newY--;
     1250                                        DisplayIO.setCursorPosition(newX, newY, false);
     1251                                        toSet.getParent().setChanged(true);
     1252                                        return;
     1253                                }
    12271254                        }
    12281255                }
     
    12301257                // center the mouse cursor on the item
    12311258                if (moveCursor && toSet != null) {
    1232                         if (!toSet.contains(DisplayIO.getMouseX(), DisplayIO.getMouseY())) {
     1259                        if (!toSet
     1260                                        .contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) {
    12331261                                int x = DisplayIO.getMouseX();
    1234                                 int y = DisplayIO.getMouseY();
     1262                                int y = FrameMouseActions.getY();
    12351263
    12361264                                if (!toSet.contains(x, toSet.getY()))
     
    12471275                                                                        .getBoundsHeight()));
    12481276
    1249                                 DisplayIO.setCursorPosition(x, y);
     1277                                DisplayIO.setCursorPosition(x, y, false);
    12501278                        }
    12511279
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r102 r105  
    8787         * The last known mouse X coordinate
    8888         */
    89         public static int MouseX;
     89        public static float MouseX;
    9090
    9191        /**
     
    9393         * application.
    9494         */
    95         public static int MouseY;
     95        public static float MouseY;
    9696
    9797        // Distance of mouse cursor from the origin of the item that was picked up
     
    335335                        _lastRanged = (Text) on;
    336336                        // set start-drag point
    337                         _lastRanged.setSelectionStart(DisplayIO.getMouseX(), DisplayIO
    338                                         .getMouseY());
     337                        _lastRanged.setSelectionStart(DisplayIO.getMouseX(), FrameMouseActions.getY());
    339338                }
    340339
     
    343342                        _lastCropped = (Picture) on;
    344343                        // set start crop point
    345                         _lastCropped.setStartCrop(DisplayIO.getMouseX(), DisplayIO
    346                                         .getMouseY());
     344                        _lastCropped.setStartCrop(DisplayIO.getMouseX(), FrameMouseActions.getY());
    347345                        _lastCropped.setShowCrop(true);
    348346                }
     
    537535                        ranged.setLink(null);
    538536                        ranged.setParent(null);
    539                         ranged.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());
     537                        ranged.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
    540538                        pickup(ranged);
    541539
     
    607605                        // Check if the user is nearby another item...
    608606                        int mouseX = DisplayIO.getMouseX();
    609                         int mouseY = DisplayIO.getMouseY();
     607                        int mouseY = FrameMouseActions.getY();
    610608                        // System.out.println(mouseX + "," + mouseY);
    611609                        for (Item i : DisplayIO.getCurrentFrame().getItems()) {
     
    636634
    637635                        // actions take priority
    638                         if (_lastMouseClick != null && !_lastMouseClick.isShiftDown()
     636                        if (_lastMouseClick != null && !_lastMouseClick.isControlDown()
    639637                                        && clickedOn.getAction() != null) {
    640638                                clickedOn.performActions();
     
    846844                        // otherwise the user is creating a line
    847845                } else {
    848                         Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), MouseX,
    849                                         MouseY);
     846                        Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), Math.round(MouseX),
     847                                        Math.round(MouseY));
    850848                        // If we have permission to copy this item then pick it up
    851849                        if (on != null && on.isLineEnd()
     
    861859                                Frame current = DisplayIO.getCurrentFrame();
    862860                                // create the two endpoints
    863                                 Item newPoint = DisplayIO.getCurrentFrame().createDot();
    864 
    865861                                Line oldLine = (Line) on;
     862                                Item newPoint = oldLine.getStartItem().copy();
     863                                newPoint.setPosition(MouseX, MouseY);
     864                               
    866865                                Item end = oldLine.getEndItem();
    867866                                // create the Line
     
    10441043                                                        // Find the closest item to the mouse cursor
    10451044                                                        double currentX = DisplayIO.getMouseX();
    1046                                                         double currentY = DisplayIO.getMouseY();
     1045                                                        double currentY = FrameMouseActions.getY();
    10471046                                                        Item closest = null;
    10481047                                                        double shortestDistance = Double.MAX_VALUE;
     
    11761175                                                        && on.Permission >= Item.PERMISSION_FULL) {
    11771176
    1178                                                 Line newLine = createLine();
     1177                                                Line onLine = (Line)on;
     1178                                                Line newLine = onLine.copy();
     1179                                                Item end = newLine.getEndItem();
     1180                                                Item start = newLine.getStartItem();
     1181                                                end.setPosition(MouseX, MouseY);
     1182                                                start.setPosition(MouseX, MouseY);
     1183                                                onLine.autoArrowheadLength();
     1184                                                // anchor the start
     1185                                                anchor(start);
     1186                                                // attach the line to the cursor
     1187                                                pickup(end);
     1188                                               
    11791189                                                List<Item> toMerge = new LinkedList<Item>();
    11801190                                                toMerge.add(newLine.getStartItem());
    11811191                                                toMerge.add(newLine);
    1182                                                 Item end = newLine.getEndItem();
    1183                                                 //Make sure the highlighting is shown when the end is anchored
     1192
     1193                                                // Make sure the highlighting is shown when the end is
     1194                                                // anchored
    11841195                                                end.setSelectedMode(Item.SelectedMode.Normal);
    11851196                                                end.setSelectedMode(Item.SelectedMode.None);
    11861197                                                merge(toMerge, on);
    1187                                                 //anchor(left);
    1188                                                 //Frame.FreeItems.clear();
     1198                                                // anchor(left);
     1199                                                // Frame.FreeItems.clear();
    11891200                                                FrameGraphics.Repaint();
    11901201                                                updateCursor();
     
    13001311                        MouseY = e.getY();
    13011312
    1302                         int distance = _lastRanged.getY() - DisplayIO.getMouseY();
     1313                        int distance = _lastRanged.getY() - FrameMouseActions.getY();
    13031314                        if (distance <= 0)
    1304                                 distance = DisplayIO.getMouseY() - _lastRanged.getY()
     1315                                distance = FrameMouseActions.getY() - _lastRanged.getY()
    13051316                                                - _lastRanged.getBoundsHeight();
    13061317
     
    13101321                        } else {
    13111322                                // update the ranged section
    1312                                 _lastRanged.setSelectionEnd(DisplayIO.getMouseX(), DisplayIO
    1313                                                 .getMouseY());
     1323                                _lastRanged.setSelectionEnd(DisplayIO.getMouseX(), FrameMouseActions.getY());
    13141324                                _isNoOp = false;
    13151325                        }
    13161326
    1317                         DisplayIO.setTextCursor(_lastRanged.getSize());
     1327                        DisplayIO.setTextCursor(_lastRanged, Text.NONE);
    13181328                        FrameGraphics.Repaint();
    13191329                        return;
     
    13391349                        }
    13401350                        // update the ranged section
    1341                         _lastCropped.setEndCrop(DisplayIO.getMouseX(), DisplayIO
    1342                                         .getMouseY());
     1351                        _lastCropped.setEndCrop(DisplayIO.getMouseX(), FrameMouseActions.getY());
    13431352
    13441353                        FrameGraphics.Repaint();
     
    13981407        private static boolean _shiftDown;
    13991408
    1400         public static void setLastRobotMove(int x, int y) {
     1409        public static void setLastRobotMove(float x, float y) {
    14011410                // Make sure the system is in the right state while waiting for the
    14021411                // Robots event to arrive.
     
    14051414                // System.out.println("MouseMoved: " + MouseX + "," + MouseY + " " +
    14061415                // System.currentTimeMillis());
    1407                 LastRobotX = x;
    1408                 LastRobotY = y;
     1416                LastRobotX = (int) (x + 0.5);
     1417                LastRobotY = (int) (y + 0.5);
    14091418                _RobotTimer.start();
    14101419        }
     
    16291638                                        // Checks that we are actually pointing on a character
    16301639                                        // not just space in the text box's bounding box
    1631                                         if (((Item) on).contains(DisplayIO.getMouseX(), DisplayIO
    1632                                                         .getMouseY())) {
     1640                                        if (((Item) on).contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) {
    16331641                                                _context = CONTEXT_AT_TEXT;
    16341642                                        } else {
     
    16571665                                        if (lineEnd != null) {
    16581666                                                line.showVirtualSpot(lineEnd, DisplayIO.getMouseX(),
    1659                                                                 DisplayIO.getMouseY());
     1667                                                                FrameMouseActions.getY());
    16601668                                        } else
    16611669                                                // The user is pointing at another point or text item
     
    17801788                        return;
    17811789                }
     1790                //This is to make sure the TEXT_CURSOR doesnt get inadvertantly turned off!
     1791                Item on = FrameUtils.getCurrentItem();
     1792                if(on != null && on instanceof Text){
     1793                        return;
     1794                }
    17821795                DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    17831796        }
     
    17911804                        _offX = DisplayIO.getMouseX() - Frame.FreeItems.get(0).getX()
    17921805                                        + Frame.FreeItems.get(0).getOffset().x;
    1793                         _offY = MouseY - Frame.FreeItems.get(0).getY()
     1806                        _offY = getY() - Frame.FreeItems.get(0).getY()
    17941807                                        + Frame.FreeItems.get(0).getOffset().y;
    17951808                }
     
    18041817
    18051818                int deltax = firstDot.getX() - xPos;
    1806                 int deltay = firstDot.getY() - (MouseY - _offY);
     1819                int deltay = firstDot.getY() - (getY() - _offY);
    18071820
    18081821                for (Item move : toMove) {
     
    19541967                                _offX = DisplayIO.getMouseX() - anchored.getX()
    19551968                                                + anchored.getOffset().x;
    1956                                 _offY = MouseY - anchored.getY() + anchored.getOffset().y;
     1969                                _offY = getY() - anchored.getY() + anchored.getOffset().y;
    19571970                        } else {
    19581971                                deleteItems(Frame.FreeItems);
     
    21672180
    21682181        public static Collection<Item> merge(List<Item> merger, Item mergee) {
    2169                 assert(mergee != null);
     2182                assert (mergee != null);
    21702183                if (mergee.isFrameName()) {
    21712184                        return mergee.getParent().merge(merger);
     
    22422255                                                if (mergee instanceof Text)
    22432256                                                        ((Text) mergee).insertText(txt.getText(), DisplayIO
    2244                                                                         .getMouseX(), DisplayIO.getMouseY());
     2257                                                                        .getMouseX(), FrameMouseActions.getY());
    22452258
    22462259                                                else if (mergee instanceof Dot) {
     
    22632276                                                // Dot override doesnt use the x and y coords
    22642277                                                // Text does... but could be removed
    2265                                                 res = mergee.merge(i, DisplayIO.getMouseX(), MouseY);
     2278                                                res = mergee.merge(i, DisplayIO.getMouseX(), getY());
    22662279                                                if (res != null) {
    22672280                                                        remain.add(res);
     
    22732286                                        }
    22742287                                        // Moving the cursor ensures shapes are anchored correctly
    2275                                         res = mergee.merge(i, DisplayIO.getMouseX(), MouseY);
     2288                                        res = mergee.merge(i, DisplayIO.getMouseX(), getY());
    22762289                                        if (res != null)
    22772290                                                remain.addAll(res.getConnected());
     
    23532366                                if (!(i instanceof Line)) {
    23542367                                        _offX = DisplayIO.getMouseX() - i.getX() + i.getOffset().x;
    2355                                         _offY = MouseY - i.getY() + i.getOffset().y;
     2368                                        _offY = getY() - i.getY() + i.getOffset().y;
    23562369
    23572370                                        // make the offset item the first item in the list (so
     
    23712384                        _offX = DisplayIO.getMouseX() - soleItem.getX()
    23722385                                        + soleItem.getOffset().x;
    2373                         _offY = MouseY - soleItem.getY() + soleItem.getOffset().y;
     2386                        _offY = getY() - soleItem.getY() + soleItem.getOffset().y;
    23742387                        // Now call move so that if we are on a message in the message box
    23752388                        // It doesnt appear up the top of the scree!!
     
    23792392                                        .DisplayMessage("Insufficient permission pickup the items");
    23802393                }
     2394                FrameGraphics.Repaint();
    23812395        }
    23822396
     
    24152429
    24162430                if (checkEnclosure) {
    2417                         FrameGraphics.Repaint();
    24182431                        ItemUtils.EnclosedCheck(toAnchor.getParentOrCurrentFrame()
    24192432                                        .getItems());
     2433                        FrameGraphics.Repaint();
    24202434                }
    24212435        }
     
    24332447                }
    24342448                toAnchor.clear();
    2435                 FrameGraphics.Repaint();
    24362449                // Check enclosure for all the frames of the items that were anchored
    24372450                for (Frame f : checkEnclosure) {
    24382451                        ItemUtils.EnclosedCheck(f.getItems());
    24392452                }
     2453                FrameGraphics.Repaint();
    24402454        }
    24412455
     
    25812595                updateCursor();
    25822596        }
     2597
     2598        public static int getX() {
     2599                return (int)(MouseX + 0.5);
     2600        }
     2601       
     2602        public static int getY() {
     2603                return (int)(MouseY + 0.5);
     2604        }
    25832605}
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r103 r105  
    909909                                                        }
    910910                                                        vectors.add(new Vector(vector, i.getPosition(),
    911                                                                         scale));
     911                                                                        scale, i.getColor(), i.getBackgroundColor()));
    912912                                                }
    913913                                        }
     
    10981098         * @return The Item at the given coordinates, or NULL if none is found.
    10991099         */
    1100         public static Item onItem(Frame toCheck, int x, int y) {
     1100        public static Item onItem(Frame toCheck, float floatX, float floatY) {
     1101                int x = Math.round(floatX);
     1102                int y = Math.round(floatY);
    11011103                if (toCheck == null)
    11021104                        return null;
     
    12141216        public static Item getCurrentItem() {
    12151217                return onItem(DisplayIO.getCurrentFrame(), DisplayIO.getMouseX(),
    1216                                 DisplayIO.getMouseY());
     1218                                FrameMouseActions.getY());
    12171219        }
    12181220
     
    12731275                        if (i.isLineEnd() && i.isEnclosed()) {
    12741276                                Polygon p = i.getEnclosedShape();
    1275                                 if (p.contains(DisplayIO.getMouseX(), DisplayIO.getMouseY())) {
     1277                                if (p.contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) {
    12761278                                        used.add(i);
    12771279                                        items.removeAll(i.getEnclosingDots());
     
    12971299
    12981300                                        int mouseX = DisplayIO.getMouseX();
    1299                                         int mouseY = DisplayIO.getMouseY();
     1301                                        int mouseY = FrameMouseActions.getY();
    13001302
    13011303                                        for (int i = 0; i < p1.npoints; i++) {
  • trunk/src/org/expeditee/gui/Vector.java

    r79 r105  
    11package org.expeditee.gui;
    22
     3import java.awt.Color;
    34import java.awt.Point;
    45
     
    1011        public float Scale;
    1112
    12         public Vector(Frame overlay, Point origin, Float scale) {
     13        public Color Foreground;
     14        public Color Background;
     15
     16        public Vector(Frame overlay, Point origin, Float scale, Color color, Color background) {
    1317                Frame = overlay;
    1418                Origin = origin;
    1519                Scale = scale;
     20                Foreground = color;
     21                Background = background;
    1622        }
    1723
  • trunk/src/org/expeditee/io/ExpReader.java

    r97 r105  
    4040
    4141        /**
    42          * Determines whether a string begins with a KMS tag.
     42         * Determines whether a string begins with tag.
    4343         *
    4444         * @param s
    4545         *            a line of text
    46          * @return true if s begins with a KMS tag
     46         * @return true if s begins with a tag
    4747         */
    4848        private static boolean isValidLine(String s) {
     
    5252
    5353        /**
    54          * Reads a KMS file with the given name from disk.
     54         * Reads a file with the given name from disk.
    5555         *
    5656         * @param frameName
  • trunk/src/org/expeditee/io/ExpWriter.java

    r97 r105  
    103103                writeTerminator();
    104104                writeConstraintData();
    105 
     105                writeTerminator();
     106                writeLine(SessionStats.getFrameEventList(frame));
     107               
    106108                return;
    107109        }
     
    249251        @Override
    250252        protected String finaliseFrame() throws IOException {
    251                 writeTerminator();
    252 
    253                 writeLine(SessionStats.getFrameEventList());
    254 
    255253                _writer.flush();
    256254                _writer.close();
  • trunk/src/org/expeditee/items/Item.java

    r97 r105  
    6767        public static final Color DEPRESSED_HIGHLIGHT = Color.GREEN;
    6868
    69         public static final Color DISCONNECT_HIGHLIGHT = Color.BLUE;
     69        public static final Color ALTERNATE_HIGHLIGHT = Color.BLUE;
    7070
    7171        public static final Color LINK_COLOR = Color.BLACK;
     
    291291         *
    292292         * @param action
    293          *            The KMS action language to add to this Item
     293         *            The action to add to this Item
    294294         */
    295295        public void addAction(String action) {
     
    393393
    394394        /**
    395          * Returns a list of any action code (KMS action language) that is currently
    396          * associated with this Item
     395         * Returns a list of any action code that is currently associated with this
     396         * Item
    397397         *
    398398         * @return A List of action code associated with this Item, or null if none
     
    785785         */
    786786        public int getX() {
    787                 return (int)(_x + 0.5);
     787                return (int) (_x + 0.5);
    788788        }
    789789
     
    794794         */
    795795        public int getY() {
    796                 return (int)(_y + 0.5);
     796                return (int) (_y + 0.5);
    797797        }
    798798
     
    883883                                + getBoundsHeight() + NEAR_DISTANCE);
    884884        }
    885 
    886         /**
    887          * Checks if this item is a frame title.
    888          *
    889          * @return true if the item is a frame title
    890          */
    891         /*
    892          * public boolean isTitle() { // check if the title has been assigned if
    893          * (getID() >= 0 && this instanceof Text) if (getX() < 200 && getY() <
    894          * getSize() + system.io.KMSConversion.Y_ADJUST) return true; return false; }
    895          */
    896885
    897886        public boolean isOldTag() {
     
    925914                if (getFillColor() != null && getEnclosingDots() != null) {
    926915                        g.setColor(getFillColor());
     916                        // The painting is not efficient enough for gradients...
    927917                        // Shape s = getEnclosedShape();
    928918                        // Rectangle b = s.getBounds();
     
    13301320                                        }
    13311321                                } else if (c.isDiagonal()) {
    1332                                         if (Math.abs(other._x - x) != Math
    1333                                                         .abs(other._y - y)) {
    1334                                                
     1322                                        if (Math.abs(other._x - x) != Math.abs(other._y - y)) {
     1323
    13351324                                                float m1 = c.getGradient();
    13361325                                                float c1 = y - m1 * x;
     
    13411330                                                // If there is only one line...
    13421331                                                if (lines.size() == 1) {
    1343                                                         if (m1 != 0){
    1344                                                                 if(Math.abs(deltaX) > Math.abs(deltaY)){
     1332                                                        if (m1 != 0) {
     1333                                                                if (Math.abs(deltaX) > Math.abs(deltaY)) {
    13451334                                                                        other.setX((other._y - c1) / m1);
    1346                                                                 }else {
     1335                                                                } else {
    13471336                                                                        other.setY(m1 * other._x + c1);
    13481337                                                                }
     
    13621351                                                                other.setY(m1 * other._x + c1);
    13631352                                                        } else if (Math.abs(xDiff) == Math.abs(yDiff)
    1364                                                                         && !this.isFloating() && deltaX == 0 && deltaY == 0){
     1353                                                                        && !this.isFloating() && deltaX == 0
     1354                                                                        && deltaY == 0) {
    13651355                                                                if (deltaX == 0) {
    1366                                                                         _x = (_y - other._y) * m1
    1367                                                                                         + other._x;
     1356                                                                        _x = (_y - other._y) * m1 + other._x;
    13681357                                                                } else {
    1369                                                                         _y = (_x - other._x) * m1
    1370                                                                                         + other._y;
     1358                                                                        _y = (_x - other._x) * m1 + other._y;
    13711359                                                                }
    13721360                                                        } else {
     
    15431531
    15441532        public void setSelectedMode(SelectedMode mode, Color color) {
     1533                if (color != null && color.equals(getPaintColor())) {
     1534                        color = ALTERNATE_HIGHLIGHT;
     1535                }
    15451536                setSelectionColor(color);
    15461537                _lastMode = _mode;
     
    18231814                return link;
    18241815        }
     1816
     1817        /**
     1818         * Sets the x and y values of this item ignoring constraints.
     1819         *
     1820         * @param x
     1821         *            new x position
     1822         * @param y
     1823         *            new y position
     1824         */
     1825        public void setXY(int x, int y) {
     1826                _x = x;
     1827                _y = y;
     1828        }
     1829
     1830        /**
     1831         * Recursive function for getting the path around a shape. This is used to
     1832         * get the path that is painted on the screen.
     1833         *
     1834         * @param visited
     1835         * @param points
     1836         * @param addToEnd
     1837         * @param toExplore
     1838         */
     1839        public void appendPath(Collection<Line> visited, LinkedList<Point> points,
     1840                        boolean addToEnd, Collection<Line> toExplore) {
     1841
     1842                if (addToEnd) {
     1843                        // put the start item points into our list
     1844                        points.addLast(getPosition());
     1845                } else {
     1846                        points.addFirst(getPosition());
     1847                }
     1848
     1849                // Find the line that has not been added yet
     1850                LinkedList<Line> lines = new LinkedList<Line>();
     1851                lines.addAll(getLines());
     1852
     1853                while (!lines.isEmpty()) {
     1854                        Line l = lines.remove();
     1855                        // if we havnt visited the line yet visit it
     1856                        if (!visited.contains(l)) {
     1857                                visited.add(l);
     1858                                Item otherEnd = l.getOppositeEnd(this);
     1859                                // Add all the enexplored lines to our list
     1860                                while (!lines.isEmpty()) {
     1861                                        l = lines.remove();
     1862                                        // Get the paths for the rest of the lines to be explored
     1863                                        // later
     1864                                        if (!toExplore.contains(l) && !visited.contains(l)) {
     1865                                                toExplore.add(l);
     1866                                        }
     1867                                }
     1868                                otherEnd.appendPath(visited, points, addToEnd, toExplore);
     1869                        }
     1870                }
     1871        }
     1872
     1873        /**
     1874         * Gets the size of the enclosure that this item is part of.
     1875         * @return the area of the box surrounding the enclosed shape that this item is part of
     1876         */
     1877        public Integer getEnclosedArea() {
     1878                if (_enclosure == null)
     1879                        return 0;
     1880                Rectangle box = getEnclosedShape().getBounds();
     1881                Integer area = box.width * box.height;
     1882               
     1883                if (getFillColor() == null)
     1884                        return -area;
     1885               
     1886                return area;
     1887        }
    18251888}
  • trunk/src/org/expeditee/items/Line.java

    r102 r105  
    1313import java.util.ArrayList;
    1414import java.util.Collection;
     15import java.util.HashSet;
     16import java.util.Iterator;
     17import java.util.LinkedList;
    1518import java.util.List;
    1619
     
    3336        private static final int MINIMUM_ARROW_HEAD_LENGTH = 8;
    3437
     38        private static final int MAXIMUM_ARROW_HEAD_LENGTH = 60;
     39
    3540        public static final Float DEFAULT_THICKNESS = 2f;
    3641
     
    5358        private boolean _isCircle = false;
    5459
     60        // TODO find out why bevel is not working
     61        private final int JOIN = BasicStroke.JOIN_ROUND;
     62
     63        private final int CAP = BasicStroke.CAP_BUTT;
     64
    5565        // brush strokes used for painting this line and highlighting
    56         private Stroke _lineStroke = new BasicStroke(DEFAULT_THICKNESS,
    57                         BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
     66        private Stroke _lineStroke = new BasicStroke(DEFAULT_THICKNESS, CAP, JOIN,
     67                        4.0F);
    5868
    5969        // private Stroke _highlightStroke = new BasicStroke (1f + /*GRAVITY +
     
    292302                                dash[i] = (float) pattern[i];
    293303                        _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS),
    294                                         BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, dash,
    295                                         0.0f);
     304                                        CAP, JOIN, 10f, dash, 0.0f);
    296305                } else
    297306                        _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS),
    298                                         BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
     307                                        CAP, JOIN);
    299308
    300309                if (_start.getLinePattern() != pattern)
     
    321330                        _isCircle = true;
    322331                } else {
     332                        // Get a path of points
     333                        int[][][] paths = getPaths();
     334                        g.setStroke(_lineStroke);
     335                        for (int i = 0; i < paths.length; i++) {
     336                                int[][] path = paths[i];
     337                                int last = path[0].length - 1;
     338                                if (path[0][0] == path[0][last] && path[1][0] == path[1][last]) {
     339                                        g.drawPolygon(path[0], path[1], last);
     340                                } else {
     341                                        g.drawPolyline(path[0], path[1], last + 1);
     342                                }
     343                        }
    323344                        // paint the arrowhead (if necessary)
    324                         g.setStroke(new BasicStroke(getThickness(), BasicStroke.CAP_BUTT,
    325                                         BasicStroke.JOIN_MITER));
    326 
    327                         paintArrow(g, _start, _startOffset, _endOffset);
    328                         paintArrow(g, _end, _endOffset, _startOffset);
    329 
    330                         g.setStroke(_lineStroke);
    331                         g.drawLine(_start.getX() + _startOffset.x, _start.getY()
    332                                         + _startOffset.y, _end.getX() + _endOffset.x, _end.getY()
    333                                         + _endOffset.y);
    334 
     345                        paintArrows(g);
     346                        // g.drawLine(_start.getX() + _startOffset.x, _start.getY()
     347                        // + _startOffset.y, _end.getX() + _endOffset.x, _end.getY()
     348                        // + _endOffset.y);
     349                        // TODO deal with the offset
    335350                        _isCircle = false;
    336351                }
     
    345360                if (showLineHighlight() && isHighlighted()) {
    346361                        g.setColor(getHighlightColor());
    347                         g.setStroke(new BasicStroke(MINIMUM_THICKNESS,
    348                                         BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
     362                        g.setStroke(new BasicStroke(MINIMUM_THICKNESS, CAP, JOIN));
    349363                        ((Graphics2D) g).draw(this.getArea());
    350364                }
     365        }
     366
     367        protected int[][][] getPaths() {
     368                List<List<Point>> pointPaths = new LinkedList<List<Point>>();
     369                Collection<Line> visited = new HashSet<Line>();
     370                LinkedList<Line> toExplore = new LinkedList<Line>();
     371                toExplore.add(this);
     372                while (toExplore.size() > 0) {
     373                        Line nextLine = toExplore.remove(0);
     374                        // Start at the item we have already explored... unless both have
     375                        // been explored
     376                        if (!visited.contains(nextLine)) {
     377                                pointPaths.add(nextLine.getPath(visited, toExplore));
     378                        }
     379                }
     380                // Put the paths into int arrays
     381                int[][][] paths = new int[pointPaths.size()][][];
     382                Iterator<List<Point>> iter = pointPaths.iterator();
     383
     384                for (int i = 0; i < paths.length; i++) {
     385                        List<Point> pointPath = iter.next();
     386                        int[][] path = new int[2][pointPath.size()];
     387                        paths[i] = path;
     388                        // Add all the x and y's to the array
     389                        for (int j = 0; j < path[0].length; j++) {
     390                                path[0][j] = pointPath.get(j).x;
     391                                path[1][j] = pointPath.get(j).y;
     392                        }
     393                }
     394                return paths;
     395        }
     396
     397        protected List<Point> getPath(Collection<Line> visited,
     398                        LinkedList<Line> toExplore) {
     399                LinkedList<Point> points = new LinkedList<Point>();
     400                // put the start item points into our list
     401                Item start = getStartItem();
     402                Item end = getEndItem();
     403                visited.add(this);
     404
     405                start.appendPath(visited, points,
     406                                                true, toExplore);
     407                end.appendPath(visited, points, false,
     408                                                toExplore);
     409                return points;
     410        }
     411
     412        public void paintArrows(Graphics2D g) {
     413                g.setColor(getPaintColor());
     414                g
     415                                .setStroke(new BasicStroke(getThickness(), CAP,
     416                                                BasicStroke.JOIN_MITER));
     417                paintArrow(g, _start, _startOffset, _endOffset);
     418                paintArrow(g, _end, _endOffset, _startOffset);
    351419
    352420                if (_virtualSpot != null) {
     
    393461                int length = (int) Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
    394462
    395                 if (arrowLength < 0 && length > MINIMUM_ARROW_HEAD_LENGTH) {
     463                // The length of the line must at least be as long as the arrow or we
     464                // wont show the arrow
     465                if (length <= MINIMUM_ARROW_HEAD_LENGTH)
     466                        return;
     467                if (arrowLength == AUTO_ARROWHEAD_LENGTH) {
    396468                        arrowLength = length / ARROW_HEAD_TO_LENGTH_RATIO;
    397469                        arrowLength = Math.max(MINIMUM_ARROW_HEAD_LENGTH, arrowLength);
     470                        arrowLength = Math.min(MAXIMUM_ARROW_HEAD_LENGTH, arrowLength);
    398471                        withArrow.setArrowhead(null);
    399472                        if (arrowRatio < 0)
     
    571644                                dash[i] = (float) pattern[i];
    572645                        _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS),
    573                                         BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, dash,
    574                                         0.0f);
     646                                        CAP, JOIN, 10f, dash, 0.0f);
    575647                } else
    576648                        _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS),
    577                                         BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
     649                                        CAP, JOIN);
    578650        }
    579651
     
    629701                int length = (int) Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
    630702                length /= ARROW_HEAD_TO_LENGTH_RATIO;
    631                 arrow.setArrowheadLength(Math.max(MINIMUM_ARROW_HEAD_LENGTH, length));
     703                arrow.setArrowheadLength(Math.min(MAXIMUM_ARROW_HEAD_LENGTH,Math.max(MINIMUM_ARROW_HEAD_LENGTH, length)));
    632704        }
    633705
     
    718790
    719791        private static int[] ArrowHeadLength = new int[] { /* AUTO_ARROWHEAD_LENGTH, */
    720         0, 20, 40, 80 };
     792        0, 20, 40, MAXIMUM_ARROW_HEAD_LENGTH };
    721793
    722794        /**
     
    805877                Item spot = new Dot(mouseX, mouseY, -1);
    806878                spot.setThickness(Math.max(this.getThickness(), 5));
    807                 if (this.getColor() != Color.RED)
    808                         spot.setColor(Color.RED);
     879                if (DEFAULT_HIGHLIGHT.equals(this.getColor()))
     880                        spot.setColor(ALTERNATE_HIGHLIGHT);
    809881                else
    810                         spot.setColor(Color.BLUE);
     882                        spot.setColor(DEFAULT_HIGHLIGHT);
    811883
    812884                // calculate nearest point on line from spot
     
    913985
    914986                // lines that are in 'connected' mode, also cannot be attached
    915                 if (spot.isFloating() && spot.getLines().get(0).getOppositeEnd(spot).isFloating())
     987                if (spot.isFloating()
     988                                && spot.getLines().get(0).getOppositeEnd(spot).isFloating())
    916989                        return merger;
    917990
     
    10741147
    10751148        public Integer getPossibleConstraint() {
    1076                 if (_start.getY() == _end.getY()
    1077                                 && _start.getX() != _end.getX())
     1149                if (_start.getY() == _end.getY() && _start.getX() != _end.getX())
    10781150                        return Constraint.HORIZONTAL;
    1079                 else if (_start.getX() == _end.getX()&& _start.getY() != _end.getY())
     1151                else if (_start.getX() == _end.getX() && _start.getY() != _end.getY())
    10801152                        return Constraint.VERTICAL;
    10811153                return null;
  • trunk/src/org/expeditee/items/Picture.java

    r97 r105  
    229229        /**
    230230         * Returns the Text Item that was used to create this Picture object. This
    231          * is required by KMSWriter for saving the Frame.
     231         * is required when saving the Frame.
    232232         *
    233233         * @return The Text Item used to create this Picture.
  • trunk/src/org/expeditee/items/Text.java

    r98 r105  
    5858        public static final int MINIMUM_RANGED_CHARS = 2;
    5959
    60         public static final int UP = 0;
    61 
    62         public static final int DOWN = 1;
    63 
    64         public static final int LEFT = 2;
    65 
    66         public static final int RIGHT = 3;
    67 
    68         public static final int HOME = 4;
    69 
    70         public static final int END = 5;
    71 
    72         public static final int PAGE_DOWN = 6;
    73 
    74         public static final int PAGE_UP = 7;
     60        public static final int NONE = 0;
     61
     62        public static final int UP = 1;
     63
     64        public static final int DOWN = 2;
     65
     66        public static final int LEFT = 3;
     67
     68        public static final int RIGHT = 4;
     69
     70        public static final int HOME = 5;
     71
     72        public static final int END = 6;
     73
     74        public static final int PAGE_DOWN = 7;
     75
     76        public static final int PAGE_UP = 8;
    7577
    7678        private int _maxWidth = -1;
     
    392394                // move the cursor to the new location
    393395                float[] caret = last.getCaretInfo(hit);
    394                 int y = getLineDrop(last) * line;
    395 
    396                 int x = ((int) (getX() + caret[0]) + getJustOffset(last));
     396                float y = getLineDrop(last) * line;
     397
     398                int x = ((int) (getX() + caret[0] + 0.5) + getJustOffset(last));
    397399                x = Math
    398400                                .min(
    399401                                                x,
    400402                                                (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
    401                 return new Point(x, getY() + /* DisplayIO.getOffset() + */y
    402                                 + (int) caret[1]);
     403                return new Point(x, (int) (getY() + y + caret[1] + 0.5));
    403404        }
    404405
     
    614615                // move the cursor to the new location
    615616                float[] caret = current.getCaretInfo(hit);
    616                 int y = getLineDrop(current) * line;
    617 
    618                 int x = ((int) (getX() + caret[0]) + getJustOffset(current));
     617                float y = getLineDrop(current) * line;
     618
     619                int x = (int) (getX() + caret[0] + 0.5) + getJustOffset(current);
    619620                x = Math
    620621                                .min(
    621622                                                x,
    622623                                                (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
    623                 return new Point(x, getY() + y + (int) caret[1]);
     624                return new Point(x, (int) (getY() + y + caret[1] + 0.5));
    624625        }
    625626
     
    698699                // move the cursor to the new location
    699700                float[] caret = current.getCaretInfo(hit);
    700                 int y = getLineDrop(current) * line;
    701 
    702                 return new Point((int) (getX() + caret[0]) + getJustOffset(current),
    703                                 getY() + y + (int) caret[1]);
     701                float y = getLineDrop(current) * line;
     702
     703                return new Point((int) (getX() + caret[0] + 0.5)
     704                                + getJustOffset(current), (int) (getY() + y + caret[1] + 0.5));
    704705        }
    705706
     
    937938        }
    938939
    939         private int getLineDrop(TextLayout layout) {
     940        private float getLineDrop(TextLayout layout) {
    940941                if (getSpacing() < 0)
    941                         return (int) (layout.getAscent() + layout.getDescent() + layout
    942                                         .getLeading());
    943 
    944                 return (int) (layout.getAscent() + layout.getDescent() + getSpacing());
     942                        return layout.getAscent() + layout.getDescent()
     943                                        + layout.getLeading();
     944
     945                return layout.getAscent() + layout.getDescent() + getSpacing();
    945946        }
    946947
  • trunk/src/org/expeditee/stats/CometStats.java

    r103 r105  
    44
    55import org.expeditee.gui.Frame;
    6 import org.expeditee.gui.FrameGraphics;
    76import org.expeditee.io.Logger;
    87
    98public class CometStats {
    10         protected static String COLUMN_SEPARATOR = " | ";
    11        
     9        static String COLUMN_SEPARATOR = " | ";
     10
    1211        protected int _sessions = 0;
    1312
     
    1817        protected long _dark = 0;
    1918
     19        /*
     20         * public CometStats(Frame topFrame) { this(topFrame, false); }
     21         *
     22         * public CometStats(Frame topFrame, boolean includeCurrentSession) { _name =
     23         * topFrame.getName(); Frame backupFrame = topFrame; if
     24         * (includeCurrentSession) { _active =
     25         * SessionStats.getFrameActiveTime().getTime(); if (_active > 0) { _sessions =
     26         * 1; _dark = SessionStats.getFrameDarkTime().getTime(); } }
     27         *  // Keep going back until we have reached the end of the comet tail while
     28         * (backupFrame != null) { long backupActive =
     29         * backupFrame.getActiveTime().getTime(); // Update the time if user spent
     30         * time editing the frame // backupActive will be zero if the frame has not
     31         * been saved yet if (backupActive > 0) { _sessions++; _active +=
     32         * backupActive; _dark += backupFrame.getDarkTime().getTime(); }
     33         * FrameGraphics.OverwriteMessage("Computed: " + backupFrame.getName()); //
     34         * Get the backup of the backup; backupFrame = backupFrame.getBackupFrame(); }
     35         * _sessions = topFrame.getVersion() + 1; }
     36         */
     37
    2038        public CometStats(Frame topFrame) {
    21                 this(topFrame, false);
    22         }
     39                _name = topFrame.getName();
    2340
    24         public CometStats(Frame topFrame, boolean includeCurrentSession) {
    25                 _name = topFrame.getName();
    26                 Frame backupFrame = topFrame;
    27                 if (includeCurrentSession) {
    28                         _active = SessionStats.getFrameActiveTime().getTime();
    29                         if (_active > 0) {
    30                                 _sessions = 1;
    31                                 _dark = SessionStats.getFrameDarkTime().getTime();
    32                         }
    33                 }
    34 
    35                 // Keep going back until we have reached the end of the comet tail
    36                 while (backupFrame != null) {
    37                         long backupActive = backupFrame.getActiveTime().getTime();
    38                         // Update the time if user spent time editing the frame
    39                         // backupActive will be zero if the frame has not been saved yet
    40                         if (backupActive > 0) {
    41                                 _sessions++;
    42                                 _active += backupActive;
    43                                 _dark += backupFrame.getDarkTime().getTime();
    44                         }
    45                         FrameGraphics.OverwriteMessage("Computed: " + backupFrame.getName());
    46                         // Get the backup of the backup;
    47                         backupFrame = backupFrame.getBackupFrame();
    48                 }
     41                _active = SessionStats.getFrameActiveTime().getTime()
     42                                + topFrame.getActiveTime().getTime();
     43                _dark = SessionStats.getFrameDarkTime().getTime()
     44                                + topFrame.getDarkTime().getTime();
     45                _sessions = topFrame.getVersion() + 1;
    4946        }
    5047
     
    5754                StringBuffer sb = new StringBuffer();
    5855                sb.append(SessionStats.getDate());
    59                 sb.append("CometName: ").append(_name).append('\n');
     56                sb.append("CometStats: ").append(_name).append('\n');
    6057                sb.append("Versions: ").append(_sessions).append('\n');
    61                 sb.append("            Current  | Average  | Total").append('\n');
     58                sb.append("           | Current  | Average  | Total").append('\n');
     59                sb.append("-----------|----------|----------|---------").append('\n');
    6260                Time averageActive = new Time((long) (0.5 + active.getTime()
    6361                                / (1.0 * _sessions)));
     
    7068                Time currentTotal = SessionStats.getFrameTotalTime();
    7169
    72                 sb.append("ActiveTime: ").append(Logger.EasyTimeFormat(currentActive))
    73                                 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageActive))
    74                                 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(active)).append('\n');
    75                 sb.append("  DarkTime: ").append(Logger.EasyTimeFormat(currentDark))
    76                                 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageDark)).append(
    77                                                 COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(dark)).append('\n');
    78                 sb.append(" TotalTime: ").append(Logger.EasyTimeFormat(currentTotal))
    79                                 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageTotal))
    80                                 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(total));
     70                sb.append("ActiveTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(currentActive))
     71                                .append(COLUMN_SEPARATOR).append(
     72                                                Logger.EasyTimeFormat(averageActive)).append(
     73                                                COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(active))
     74                                .append('\n');
     75                sb.append("  DarkTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(currentDark))
     76                                .append(COLUMN_SEPARATOR).append(
     77                                                Logger.EasyTimeFormat(averageDark)).append(
     78                                                COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(dark))
     79                                .append('\n');
     80                sb.append(" TotalTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(currentTotal))
     81                                .append(COLUMN_SEPARATOR).append(
     82                                                Logger.EasyTimeFormat(averageTotal)).append(
     83                                                COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(total));
    8184                return sb.toString();
    8285        }
  • trunk/src/org/expeditee/stats/SessionStats.java

    r104 r105  
    1010
    1111import org.expeditee.gui.DisplayIO;
     12import org.expeditee.gui.Frame;
     13import org.expeditee.gui.FrameMouseActions;
    1214import org.expeditee.gui.FrameUtils;
    1315import org.expeditee.gui.TimeKeeper;
     
    2123public class SessionStats {
    2224
     25        public static final String COLUMN_SEPARATOR = CometStats.COLUMN_SEPARATOR;
     26
     27        public static final String COLUMN_SEPARATOR2 = "-|-";
     28
    2329        public static final String DARK_TIME_ATTRIBUTE = "DarkTime:";
    2430
     
    3036
    3137        public enum ItemType {
    32                 Text, Dot, Picture, Line;
     38                Text, Dot, Line, Picture, Total;
    3339        }
    3440
     
    3743        }
    3844
    39         private static final int STAT_TYPES = 4;
    40 
    41         private static final int ITEM_TYPES = 4;
     45        private static final int STAT_TYPES = StatType.values().length;
     46
     47        private static final int ITEM_TYPES = ItemType.values().length;
    4248
    4349        private static int[][] _ItemStats = new int[ITEM_TYPES][STAT_TYPES];
     
    108114                Date currentTime = new Date();
    109115                long elapsedTime = currentTime.getTime() - _StartTime.getTime();
    110                 String time = "" + (int) ((double)elapsedTime / MILLISECONDS_PER_MINUTE + 0.5); // (new
     116                String time = ""
     117                                + (int) ((double) elapsedTime / MILLISECONDS_PER_MINUTE + 0.5); // (new
    111118                // SimpleDateFormat("m").format(elapsedTime));
    112119
     
    222229        }
    223230
     231        private static StringBuffer getCompactStat(String name, int value,
     232                        int minValueWidth, int minTotalWidth) {
     233                StringBuffer stats = new StringBuffer();
     234                // prevent divide by zero errors
     235                if (value > 0) {
     236                        String perHour = getRate(value);
     237                        String valueString = "" + value;
     238                        while (valueString.length() < minValueWidth)
     239                                valueString = " " + valueString;
     240                        stats.append(valueString).append("@").append(perHour.toString())
     241                                        .append("/h");
     242                }
     243                while (stats.length() < minTotalWidth) {
     244                        stats.append(' ');
     245                }
     246                return stats.append(COLUMN_SEPARATOR);
     247        }
     248
    224249        private static String getRate(int value) {
    225250                return "" + Math.round(value * 60 / getMinutesUsed());
     
    262287                FrameEdited(frameName);
    263288                _SavedFrames++;
    264                
    265                 _FrameEvents.clear();
    266                 _FrameAccessTime = new Date();
    267                 _FrameAccessDarkTime = (Time) _DarkTime.clone();
     289
     290                NewFrameSession();
    268291        }
    269292
     
    302325
    303326                _FrameEvents.add(Logger.EasyDateFormat("mm:ss:SSS", elapsedTime) + " "
    304                                 + DisplayIO.getMouseX() + " " + DisplayIO.getMouseY() + " "
     327                                + DisplayIO.getMouseX() + " " + FrameMouseActions.getY() + " "
    305328                                + description);
    306329        }
    307330
    308331        public static Time getFrameDarkTime() {
    309                 return new Time(_DarkTime.getTime()
    310                                 - _FrameAccessDarkTime.getTime());
    311         }
    312        
     332                return new Time(_DarkTime.getTime() - _FrameAccessDarkTime.getTime());
     333        }
    313334
    314335        public static Time getFrameActiveTime() {
    315                 return new Time(getFrameTotalTime().getTime() - getFrameDarkTime().getTime());
     336                return new Time(getFrameTotalTime().getTime()
     337                                - getFrameDarkTime().getTime());
    316338        }
    317339
    318340        public static Time getFrameTotalTime() {
    319                 return new Time((new Date()).getTime()
    320                                 - _FrameAccessTime.getTime());
    321         }
    322        
    323         public static String getFrameEventList() {
     341                return new Time((new Date()).getTime() - _FrameAccessTime.getTime());
     342        }
     343
     344        public static String getFrameEventList(Frame currentFrame) {
    324345                StringBuilder eventList = new StringBuilder();
    325346                // First put on the session and darkTime
    326                 Time darkTime = getFrameDarkTime();
    327                 Time activeTime = getFrameActiveTime();
     347                Time darkTime = currentFrame == null ? getFrameDarkTime()
     348                                : currentFrame.getDarkTime();
     349                Time activeTime = currentFrame == null ? getFrameActiveTime()
     350                                : currentFrame.getActiveTime();
    328351                eventList.append(ACTIVE_TIME_ATTRIBUTE).append(
    329352                                Logger.EasyTimeFormat(activeTime)).append('\n');
     
    335358                        eventList.deleteCharAt(eventList.length() - 1);
    336359                return eventList.toString();
     360        }
     361
     362        public static String getFrameEventList() {
     363                return getFrameEventList(null);
    337364        }
    338365
     
    399426
    400427        public static String getItemStats() {
    401                 StringBuffer stats = getLength();
     428
     429                StringBuffer sb = getLength();
     430
    402431                int max = 0;
     432                final int TOTAL_INDEX = ITEM_TYPES - 1;
    403433                for (int i = 0; i < STAT_TYPES; i++) {
    404                         for (int j = 0; j < ITEM_TYPES; j++) {
    405                                 if (_ItemStats[j][i] > max)
    406                                         max = _ItemStats[j][i];
     434                        _ItemStats[TOTAL_INDEX][i] = 0;
     435                        for (int j = 0; j < TOTAL_INDEX; j++) {
     436                                _ItemStats[TOTAL_INDEX][i] += _ItemStats[j][i];
    407437                        }
     438                }
     439                for (int i = 0; i < STAT_TYPES; i++) {
     440                        max = Math.max(_ItemStats[TOTAL_INDEX][i], max);
    408441                }
    409442                int maxWidthValue = ("" + max).length();
    410443                int maxWidthRate = (getRate(max)).length();
    411444
     445                int maxNameWidth = 0;
     446                int maxColumnWidth = 0;
     447                ItemType[] itemTypes = ItemType.values();
     448                StatType[] statTypes = StatType.values();
     449                // Get the width of the longest itemType
     450                for (int i = 0; i < ITEM_TYPES; i++) {
     451                        maxNameWidth = Math.max(maxNameWidth, itemTypes[i].toString()
     452                                        .length());
     453                }
     454
    412455                for (int i = 0; i < STAT_TYPES; i++) {
    413                         int total = 0;
    414                         int nonZeroItems = 0;
    415                         String statName = StatType.values()[i].toString();
    416                         for (int j = 0; j < ITEM_TYPES; j++) {
     456                        maxNameWidth = Math.max(maxColumnWidth, statTypes[i].toString()
     457                                        .length());
     458                }
     459                maxColumnWidth = Math.max(maxWidthRate + maxWidthValue + 3,
     460                                maxNameWidth);
     461
     462                sb.append(getBufferedString("", maxNameWidth)).append(COLUMN_SEPARATOR);
     463
     464                StringBuffer lineSeparator = getBufferedString("", maxNameWidth, '-');
     465                lineSeparator.append(COLUMN_SEPARATOR2);
     466
     467                for (int i = 0; i < STAT_TYPES; i++) {
     468                        sb.append(
     469                                        getBufferedString(statTypes[i].toString(), maxColumnWidth))
     470                                        .append(COLUMN_SEPARATOR);
     471                        lineSeparator.append(getBufferedString("", maxColumnWidth, '-')
     472                                        .append(COLUMN_SEPARATOR2));
     473                }
     474                //Remove the last column separator
     475                lineSeparator.delete(lineSeparator.length()
     476                                - COLUMN_SEPARATOR2.length(), lineSeparator.length() - 1);
     477                sb.delete(sb.length() - COLUMN_SEPARATOR.length(), sb.length() - 1);
     478                sb.append('\n');
     479                sb.append(lineSeparator).append('\n');
     480
     481                for (int j = 0; j < ITEM_TYPES; j++) {
     482                        sb.append(getBufferedString(itemTypes[j].toString(), maxNameWidth))
     483                                        .append(COLUMN_SEPARATOR);
     484                        for (int i = 0; i < STAT_TYPES; i++) {
     485                                int total = 0;
     486                                int nonZeroItems = 0;
     487                                String statName = StatType.values()[i].toString();
     488
    417489                                int value = _ItemStats[j][i];
    418490                                if (value > 0)
    419491                                        nonZeroItems++;
    420492                                total += value;
    421                                 appendStat(stats, ItemType.values()[j].toString() + statName,
    422                                                 value);
     493                                sb.append(getCompactStat(ItemType.values()[j].toString()
     494                                                + statName, value, maxWidthValue, maxColumnWidth));
    423495                        }
    424                         // Only display a total if the number of items to be counted for the
    425                         // statType > 1
    426                         if (nonZeroItems > 1)
    427                                 appendStat(stats, "Total" + statName, total, true, false,
    428                                                 maxWidthValue, maxWidthRate);
    429                 }
    430                 stats.deleteCharAt(stats.length() - 1);
    431                 return stats.toString();
     496                        sb.delete(sb.length() - COLUMN_SEPARATOR.length(), sb.length() - 1);
     497                        sb.append('\n');
     498                }
     499                // Remove the last newline character
     500                sb.deleteCharAt(sb.length() - 1);
     501                return sb.toString();
     502        }
     503
     504        private static StringBuffer getBufferedString(String string, int width) {
     505                return getBufferedString(string, width, ' ');
     506        }
     507
     508        private static StringBuffer getBufferedString(String string, int width,
     509                        char bufferChar) {
     510                StringBuffer sb = new StringBuffer(string);
     511                while (sb.length() < width) {
     512                        sb.append(bufferChar);
     513                }
     514                return sb;
    432515        }
    433516
     
    487570                return stats;
    488571        }
    489        
     572
    490573        public static StringBuffer getDate() {
    491574                StringBuffer stats = new StringBuffer("Date: ");
     
    510593                DeletedItems(items);
    511594        }
     595
     596        public static void NewFrameSession() {
     597                _FrameEvents.clear();
     598                _FrameAccessTime = new Date();
     599                _FrameAccessDarkTime = (Time) _DarkTime.clone();
     600        }
    512601}
  • trunk/src/org/expeditee/stats/TreeStats.java

    r103 r105  
    2020        protected long _treeDark = 0;
    2121
    22         public TreeStats(Frame topFrame, Set<String> visited) {
    23                 this(topFrame, false, visited);
     22
     23        public TreeStats(Frame topFrame) {
     24                this(topFrame, new HashSet<String>());
    2425        }
    2526
    26         public TreeStats(Frame topFrame, boolean includeCurrentSession) {
    27                 this(topFrame, includeCurrentSession, new HashSet<String>());
    28         }
    29 
    30         public TreeStats(Frame topFrame, boolean includeCurrentSession, Set<String> visited) {
    31                 super(topFrame, includeCurrentSession);
     27        public TreeStats(Frame topFrame, Set<String> visited) {
     28                super(topFrame);
    3229                visited.add(_name.toLowerCase());
    3330                FrameGraphics.OverwriteMessage("Computed: " + _name);
     
    6966                StringBuffer sb = new StringBuffer();
    7067                sb.append(SessionStats.getDate());
    71                 sb.append("TopFrame: ").append(_name).append('\n');
     68                sb.append("TreeStats: ").append(_name).append('\n');
    7269                sb.append("Frames:   ").append(_treeFrames).append('\n');
    7370                sb.append("Versions: ").append(_treeSessions).append('\n');
    74                 sb.append("           VersionAve| FrameAve | Total").append('\n');
     71                sb.append("           |VersionAve| FrameAve | Total").append('\n');
     72                sb.append("-----------|----------|----------|---------").append('\n');
    7573                Time averageActive = new Time((long) (0.5 + active.getTime()
    7674                                / (1.0 * _treeFrames)));
     
    8684                                / (1.0 * _treeSessions)));
    8785
    88                 sb.append("ActiveTime: ").append(Logger.EasyTimeFormat(averageActiveEdit))
     86                sb.append("ActiveTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageActiveEdit))
    8987                                .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageActive))
    9088                                .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(active)).append('\n');
    91                 sb.append("  DarkTime: ").append(Logger.EasyTimeFormat(averageDarkEdit))
     89                sb.append("  DarkTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageDarkEdit))
    9290                                .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageDark)).append(
    9391                                                COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(dark)).append('\n');
    94                 sb.append(" TotalTime: ").append(Logger.EasyTimeFormat(averageTotalEdit))
     92                sb.append(" TotalTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageTotalEdit))
    9593                                .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageTotal))
    9694                                .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(total));
Note: See TracChangeset for help on using the changeset viewer.