Changeset 67


Ignore:
Timestamp:
05/19/08 12:03:18 (16 years ago)
Author:
ra33
Message:

Fixed a bunch of problems with rectangles and resizing the window, as well as adding some more unit tests etc.

Location:
trunk
Files:
3 added
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/.classpath

    r62 r67  
    22<classpath>
    33        <classpathentry kind="src" path="src"/>
     4        <classpathentry kind="src" path="tests"/>
    45        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    56        <classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/>
  • trunk/src/org/expeditee/actions/NavigationActions.java

    r65 r67  
    117117       
    118118        public static void NextFrame(boolean addToBack) {
     119                addToBack = adjustAddToBack(addToBack);
    119120                Frame next = FrameIO.LoadNext();
    120                 FrameUtils.DisplayFrame(next, true);
     121                FrameUtils.DisplayFrame(next, addToBack);
    121122        }
    122123       
     
    145146       
    146147        public static void PreviousFrame(boolean addToBack) {
     148                addToBack = adjustAddToBack(addToBack);
    147149                Frame prev = FrameIO.LoadPrevious();
    148150                FrameUtils.DisplayFrame(prev, addToBack);
     
    213215                // ByMike: Find the first occurence of a ParentItem linked to the source
    214216                while (parentItemLinkedToSource < items.size()
    215                                 && (items.get(parentItemLinkedToSource).getLink() == null || !items
    216                                                 .get(parentItemLinkedToSource).getLink().toLowerCase()
     217                                && (items.get(parentItemLinkedToSource).getAbsoluteLink() == null || !items
     218                                                .get(parentItemLinkedToSource).getAbsoluteLink().toLowerCase()
    217219                                                .equals(sourceName))) {
    218220                        parentItemLinkedToSource++; // ByRob: this increments to the next
     
    224226                        if (items.get(i).isLinkValid()
    225227                                        && !items.get(i).isAnnotation()
    226                                         && !items.get(i).getLink().toLowerCase().equals(
     228                                        && !items.get(i).getAbsoluteLink().toLowerCase().equals(
    227229                                                        source.getFrameName().toLowerCase())) {
    228230                                _LastItemUsed = items.get(i);
     
    250252                        DisplayIO.ToggleTwinFrames();
    251253        }
     254       
     255        // When display frame is called with addToBack set to false multiple
     256        // times...
     257        // The first time we add to back but after that we dont
     258        // This flag stores the state for the addToBack parameter the last time this
     259        // method was called
     260        private static boolean _lastAddToBack = true;
     261
     262        public static void ResetLastAddToBack() {
     263                _lastAddToBack = true;
     264        }
     265       
     266        private static boolean adjustAddToBack(boolean addToBack) {
     267                boolean originalAddToBack = addToBack;
     268               
     269                if (!addToBack && _lastAddToBack){
     270                        //This adds the first frame to the backup stack when the user
     271                        //navigates through a bunch of frames with the keyboard!
     272                        addToBack = true;
     273                }
     274               
     275                _lastAddToBack = originalAddToBack;
     276               
     277                return addToBack;
     278        }
    252279}
  • trunk/src/org/expeditee/actions/Simple.java

    r64 r67  
    19771977
    19781978                                item.setPosition(newX, newY);
    1979                                 DisplayIO.repaint();
     1979                                FrameGraphics.Repaint();
    19801980                        }
    19811981                        // Thread.yield();
     
    20372037                                return Status.OK;
    20382038                        } else if (tokens[0].equals("repaint")) {
    2039                                 DisplayIO.repaint();
     2039                                FrameGraphics.Repaint();
    20402040                                return Status.OK;
    20412041                        }
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r50 r67  
    587587         *            The String to strip
    588588         * @return The part of the String that is after a colon if there is one, or
    589          *         null if there is no colon
     589         *         the entire string if there is no colon
    590590         */
    591591        public static String stripValue(String toStrip) {
    592592                int ind = toStrip.lastIndexOf(SEPARATOR_CHAR);
    593593                if (ind < 0)
    594                         return null;
     594                        return toStrip;
    595595
    596596                toStrip = toStrip.substring(ind + 1);
  • trunk/src/org/expeditee/gui/Browser.java

    r50 r67  
    3131public class Browser extends JFrame implements ComponentListener,
    3232                WindowListener, WindowStateListener {
    33        
     33
    3434        /**
    3535         * Default version - just to stop eclipse from complaining about it.
     
    4040
    4141        public static Browser _theBrowser;
    42        
     42
    4343        /**
    4444         * Constructs a new Browser object, then launches it
     
    4949                _theBrowser = new Browser();
    5050                // Why do we want to ignore repaint?
    51                 // b.setIgnoreRepaint(true);
     51                //_theBrowser.setIgnoreRepaint(true);
    5252                _theBrowser.requestFocus();
    5353                // FrameGraphics.ForceRepaint();
    5454        }
    55        
     55
    5656        public void setSizes(Dimension size) {
    5757                setSize(size);
    5858                setPreferredSize(size);
    59                 addWindowListener(this);
    60                 addWindowStateListener(this);
    61 
     59
     60                FrameGraphics.setMaxSize(this.getContentPane().getSize());
     61        }
     62
     63        public Browser() {
     64                // Use the default values initially so we can load the profile frame
     65                setSizes(new Dimension(UserSettings.InitialWidth,
     66                                UserSettings.InitialHeight));
    6267                // center the frame on the screen
    6368                Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    6469                double xpos = screen.getWidth() / 2;
    6570                double ypos = screen.getHeight() / 2;
    66                 setLocation((int) (xpos - (size.getWidth() / 2)), (int) (ypos - (size
    67                                 .getHeight() / 2)));
    68 
    69                 FrameGraphics.setMaxSize(this.getContentPane().getSize());
    70         }
    71 
    72         public Browser() {
    73                 // Use the default values initially so we can load the profile frame
    74                 setSizes(new Dimension(UserSettings.InitialWidth,
    75                                 UserSettings.InitialHeight));
     71                setLocation((int) (xpos - (UserSettings.InitialWidth / 2)),
     72                                (int) (ypos - (UserSettings.InitialHeight / 2)));
     73
     74                addWindowListener(this);
     75                addWindowStateListener(this);
    7676
    7777                UserSettings.Init();
    78                 UserSettings.Username = FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"));
     78                UserSettings.Username = FrameIO.ConvertToValidFramesetName(System
     79                                .getProperty("user.name"));
    7980                String userName = UserSettings.Username;
    8081                Frame profile = FrameIO.LoadProfile(userName);
     
    8384                                profile = FrameIO.CreateNewProfile(userName);
    8485                        } catch (Exception e) {
    85                                 //TODO tell the user that there was a problem creating the profile frame and close nicely
     86                                // TODO tell the user that there was a problem creating the
     87                                // profile frame and close nicely
    8688                                e.printStackTrace();
    87                                 assert(false);
     89                                assert (false);
    8890                        }
    8991                }
     
    9597                                UserSettings.InitialHeight));
    9698
    97                 //set the layout to absolute layout for widgets
     99                // set the layout to absolute layout for widgets
    98100                this.getContentPane().setLayout(new AbsoluteLayout());
    99                 //enable the glasspane-for capturing all mouse events
    100                 this.setGlassPane(new MouseEventRouter(getJMenuBar(), getContentPane()));
     101                // enable the glasspane-for capturing all mouse events
     102                this
     103                                .setGlassPane(new MouseEventRouter(getJMenuBar(),
     104                                                getContentPane()));
    101105                this.getGlassPane().setVisible(true);
    102106                this.getContentPane().setBackground(Color.white);
    103107                this.getContentPane().setFocusTraversalKeysEnabled(false);
    104                
     108
    105109                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    106110
     
    147151        private void setupGraphics() {
    148152                g = (Graphics2D) this.getContentPane().getGraphics();
    149                 assert g != null;
     153                assert (g != null);
    150154                g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
    151155                                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     
    154158        }
    155159
     160        // private int count = 0;
    156161        @Override
    157162        public void paint(Graphics g) {
     163                // All this does is make sure the screen is repainted when the browser
     164                // is moved so that some of the window is off the edge of the display
     165                // then moved back into view
    158166                super.paint(g);
    159167                FrameGraphics.Repaint();
     168                //System.out.println("Paint " + count++);
    160169        }
    161170
     
    166175                setSizes(this.getSize());
    167176                setupGraphics();
    168                 repaint();
     177                FrameIO.RefreshCasheImages();
     178                FrameGraphics.Repaint();
    169179        }
    170180
     
    211221        }
    212222
    213         /*
    214          * public void windowGainedFocus(WindowEvent e) { FrameGraphics.Repaint(); }
    215          *
    216          * public void windowLostFocus(WindowEvent e) { //FrameGraphics.Repaint(); }
    217          */
    218223        public void windowStateChanged(WindowEvent e) {
    219                 //FrameGraphics.Repaint();
    220                 //System.out.println('C');
     224                // FrameGraphics.Repaint();
     225                // System.out.println('C');
    221226        }
    222227
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r58 r67  
    1515import javax.swing.JOptionPane;
    1616
     17import org.expeditee.actions.NavigationActions;
    1718import org.expeditee.items.Item;
    1819import org.expeditee.items.ItemParentStateChangedEvent;
     
    5455        private static Robot _Robot;
    5556
    56         // public static JMenuBar _MenuBar = new JMenuBar();
    57 
    5857        private static boolean _TwinFrames = false;
    5958
     
    6160         * The title to display in the Title bar.
    6261         */
    63         public static final String TITLE = "Exp16May2008A";
     62        public static final String TITLE = "Exp17May2008A";
    6463
    6564        private DisplayIO() {
     
    114113                }
    115114
    116                 /*
    117                  * System.out.println("hs: " + hotspotPos + " start: " + start + " font: " +
    118                  * size + " cursor: " + (cursorSize - start));
    119                  */
    120 
    121115                int[] pixels = new int[cursorSize * cursorSize];
    122116
     
    229223
    230224        /**
    231          * Forces a complete repaint of the GUI and Frame
    232          */
    233         public static void repaint() {
    234                 _Browser.repaint();
    235         }
    236 
    237         /**
    238225         * Returns the top item (last added) of the Back-Stack (which is popped off)
    239226         *
     
    519506
    520507        /**
    521          * Adds the given JMenu to the JMenuBar of the GUI
    522          *
    523          * @param menu
    524          *            The menu to add
    525          */
    526         /*
    527          * public static void addMenu(JMenu menu) { if (menu.getItemCount() == 0)
    528          * return;
    529          *
    530          * _MenuBar.add(menu); // show progress _Browser.loadedMenu(menu.getText()); }
    531          */
    532 
    533         /**
    534          * Performs the same action as if the user had clicked on the MenuItem at
    535          * the given index in the Menu at the given index.
    536          *
    537          * @param menu
    538          *            The index of the menu (starts from 0)
    539          * @param index
    540          *            The index of the Item to simulate a click on (starts from 0)
    541          */
    542         /*
    543          * public static void activateMenuItem(int menu, int index) { if
    544          * (_MenuBar.getComponentCount() < menu) return;
    545          *
    546          * JMenu act = _MenuBar.getMenu(menu);
    547          *
    548          * if (act.getComponentCount() < index) return;
    549          *
    550          * act.getItem(index).doClick(); }
    551          *
    552          * public static int getMenuHeight() { if (_MenuBar.getHeight() < 5) return
    553          * 21;
    554          *
    555          * return _MenuBar.getHeight() - 5; }
    556          */
    557 
    558         /**
    559508         * Returns the current mouse X coordinate. This coordinate is relative to
    560509         * the left edge of the frame the mouse is in. It takes into account the
     
    589538
    590539        public static void Back() {
     540                NavigationActions.ResetLastAddToBack();
     541               
    591542                int side = getCurrentSide();
    592543
  • trunk/src/org/expeditee/gui/Frame.java

    r56 r67  
    4141
    4242        // The various attributes of this Frame
    43         /**
    44          * TODO: Change these to non-string attributes (where applicable). All
    45          * processing to\from Java types should be done in KMSReader and KMSWriter.
    46          */
    4743        private String _frameset = null;
    4844
    4945        private int _number = -1;
    5046
    51         private int _version = 1;
    52 
    53         private int _fversion = -1;
     47        private int _version = 0;
    5448
    5549        private String _protection = null;
     
    9084
    9185        public static List<Item> FreeItems = new ArrayList<Item>();
    92        
     86
    9387        // for drawing purposes
    9488        private List<InteractiveWidget> _iWidgets = new ArrayList<InteractiveWidget>();
     
    10195        private Text _frameName = null;
    10296
    103         // private Text _template = UserSettings.ItemTemplate.copy();
    104 
    10597        private List<Overlay> _overlays = new ArrayList<Overlay>();
    10698
     
    122114        public void setBuffer(VolatileImage newBuffer) {
    123115                _buffer = newBuffer;
    124                 // setBufferValid(true);
    125116        }
    126117
    127118        public boolean isBufferValid() {
    128                 if (_buffer != null && _buffer.contentsLost())
     119                if (_buffer == null || _buffer.contentsLost())
    129120                        return false;
    130121
     
    132123        }
    133124
    134         public void setBufferValid(boolean newValue) {
     125        private void setBufferValid(boolean newValue) {
    135126                _validBuffer = newValue;
    136127        }
     
    147138                                i.setID(++_lineCount);
    148139        }
    149        
     140
    150141        /**
    151142         *
    152143         * @return The interactive widgets that are currently ancored in this frame.
    153          * Hence it exlcudes free-widgets. Returns a copy
     144         *         Hence it exlcudes free-widgets. Returns a copy
    154145         */
    155146        public List<InteractiveWidget> getInteractiveWidgets() {
     
    181172                _change = value;
    182173
    183                 if (_change){
     174                if (_change) {
    184175                        setBufferValid(false);
    185176                        _saved = false;
     
    204195                        _sorted = true;
    205196                }
    206                
     197
    207198                List<Item> visibleItems = new ArrayList<Item>();
    208                
    209                 for(Item i: _body) {
     199
     200                for (Item i : _body) {
    210201                        if (i.isVisible())
    211202                                visibleItems.add(i);
    212203                }
    213                
     204
    214205                return visibleItems;
    215206        }
    216        
    217         /**
    218          * @param i Item to check if contained in this frame
     207
     208        /**
     209         * @param i
     210         *            Item to check if contained in this frame
    219211         * @return True if this frame contains i.
    220212         */
    221213        public boolean containsItem(Item i) {
    222                 if (i == null) throw new NullPointerException("i");
     214                if (i == null)
     215                        throw new NullPointerException("i");
    223216                return _body.contains(i);
    224217        }
     
    234227                for (Item i : getItems()) {
    235228                        // only add up normal body text items
    236                         if ((i instanceof Text) &&
    237                                         (includeAnnotations || !i.isAnnotation())) {
     229                        if ((i instanceof Text)
     230                                        && (includeAnnotations || !i.isAnnotation())) {
    238231                                bodyTextItems.add((Text) i);
    239232                        }
     
    241234                bodyTextItems.remove(getTitle());
    242235
    243                 return bodyTextItems;           
     236                return bodyTextItems;
    244237        }
    245238
     
    316309                                frameTitle.stripFirstWord();
    317310                }
    318                 //TODO Widgets... check this out
    319                 // Brook: Cannot figure what is going on above... widget  annot titles should be stripped always
    320                 if (ItemUtils.isTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) {
     311                // TODO Widgets... check this out
     312                // Brook: Cannot figure what is going on above... widget annot titles
     313                // should be stripped always
     314                if (ItemUtils
     315                                .isTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) {
    321316                        frameTitle.stripFirstWord();
    322317                }
     
    425420
    426421                for (Item i : _body)
    427                         if (i.isVisible() /*&& i != _frameName*/ && i.intersects(poly)) {
     422                        if (i.isVisible() /* && i != _frameName */&& i.intersects(poly)) {
    428423                                if (!results.contains(i))
    429424                                        results.add(i);
     
    462457         */
    463458        public void setFrameNumber(int number) {
     459                assert (number >= 0);
     460
     461                if (_number == number)
     462                        return;
     463
    464464                _number = number;
    465465                boolean oldchange = _change;
     
    469469                if (_frameName != null) {
    470470                        id = _frameName.getID();
    471                 } else{
     471                } else {
    472472                        id = -1 * getNextItemID();
    473473                }
     
    493493
    494494        /**
    495          * Sets the version of this Frame to the given String.
     495         * Increments the version of this Frame to the given String.
    496496         *
    497497         * @param version
     
    500500        public void setVersion(int version) {
    501501                _version = version;
    502         }
    503 
    504         /**
    505          * Sets the format version of this Frame to the given String.
    506          *
    507          * @param version
    508          *            The format version to use for this Frame.
    509          */
    510         public void setFormatVersion(int version) {
    511                 _fversion = version;
    512502        }
    513503
     
    593583                if (item != null) {
    594584                        if (_body.contains(item)) {
    595                                 //System.out.println("Item (" + item.getClass().getSimpleName()
    596                                 //              + ") with ID " + item.getID() + " already in body.");
     585                                // System.out.println("Item (" + item.getClass().getSimpleName()
     586                                // + ") with ID " + item.getID() + " already in body.");
    597587                                return;
    598588                        }
     
    600590                        if (item instanceof Line)
    601591                                _lineCount++;
    602                        
     592
    603593                        _itemCount = Math.max(_itemCount, item.getID());
    604594
     
    609599
    610600                        item.setMaxSize(FrameGraphics.getMaxFrameSize());
    611                         //add widget items to the list of widgets
     601                        // add widget items to the list of widgets
    612602                        if (item instanceof WidgetCorner) {
    613                                 InteractiveWidget iw = ((WidgetCorner)item).getWidgetSource();
    614                                 if (!this._iWidgets.contains(iw)) { // A set would have been best
    615                                         _iWidgets.add(iw);
     603                                InteractiveWidget iw = ((WidgetCorner) item).getWidgetSource();
     604                                if (!this._iWidgets.contains(iw)) { // A set would have been
     605                                                                                                        // best
     606                                        _iWidgets.add(iw);
    616607                                }
    617608                        }
    618                        
    619                         item.onParentStateChanged(new ItemParentStateChangedEvent(
    620                                         this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED));
     609
     610                        item.onParentStateChanged(new ItemParentStateChangedEvent(this,
     611                                        ItemParentStateChangedEvent.EVENT_TYPE_ADDED));
    621612
    622613                        change();
     
    648639
    649640        public void removeItem(Item item) {
    650                 if (_body.remove(item))
     641                if (_body.remove(item)) {
    651642                        change();
    652                
    653                 // Remove widgets from the widget list
    654                 if (item != null) {
    655                         item.onParentStateChanged(new ItemParentStateChangedEvent(
    656                                         this, ItemParentStateChangedEvent.EVENT_TYPE_REMOVED));
    657                         if (item instanceof WidgetCorner) {
    658                                 _iWidgets.remove(((WidgetCorner)item).getWidgetSource());
    659                         }
    660                 }
    661                
     643                        // Remove widgets from the widget list
     644                        if (item != null) {
     645                                item.onParentStateChanged(new ItemParentStateChangedEvent(this,
     646                                                ItemParentStateChangedEvent.EVENT_TYPE_REMOVED));
     647                                if (item instanceof WidgetCorner) {
     648                                        _iWidgets.remove(((WidgetCorner) item).getWidgetSource());
     649                                }
     650                        }
     651                }
    662652        }
    663653
     
    760750         * @return The version of this Frame.
    761751         */
     752        public int getVersion(boolean increment) {
     753                // System.out.println("Version: " + _version);
     754                if (increment)
     755                        _version++;
     756                return _version;
     757        }
     758
    762759        public int getVersion() {
    763                 return _version;
    764         }
    765 
    766         public int getFormatVersion() {
    767                 return _fversion;
     760                return getVersion(true);
    768761        }
    769762
     
    843836                s += "Name: " + _frameset + _number + "\n";
    844837                s += "Version: " + _version + "\n";
    845                 s += "Format Version: " + _fversion + "\n";
    846838                s += "Protection: " + _protection + "\n";
    847839                s += "Owner: " + _owner + "\n";
     
    935927         * @param overlay
    936928         *            The Frame to add
    937          *            
     929         *
    938930         * @throws NullPointerException
    939          *            If overlay is null.
     931         *             If overlay is null.
    940932         */
    941933        public void addOverlay(Overlay overlay) {
    942                 if (overlay == null) throw new NullPointerException("overlay");
    943                 if (_overlays.contains(overlay)) return;
    944                
     934                if (overlay == null)
     935                        throw new NullPointerException("overlay");
     936                // make sure we dont add this frame as an overlay of itself
     937                if (overlay.Frame == this)
     938                        return;
     939
     940                if (_overlays.contains(overlay))
     941                        return;
     942
    945943                _overlays.add(overlay);
    946                
    947                 // Items must be notified that they have been added to this frame via the overlay...
     944
     945                // Items must be notified that they have been added to this frame via
     946                // the overlay...
    948947                List<Item> items = new LinkedList<Item>();
    949                 FrameGraphics.AddAllOverlayItems(items, overlay.Frame, new LinkedList<Frame>());
     948                FrameGraphics.AddAllOverlayItems(items, overlay.Frame,
     949                                new LinkedList<Frame>());
    950950                for (Item i : items) {
    951                         i.onParentStateChanged(new ItemParentStateChangedEvent(
    952                                         this,
    953                                         ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY,
     951                        i.onParentStateChanged(new ItemParentStateChangedEvent(this,
     952                                        ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY,
    954953                                        overlay.Level));
    955954                }
     
    957956
    958957        /**
    959          * Removes the given overlay from the list of overlays being drawn with this Frame.
     958         * Removes the given overlay from the list of overlays being drawn with this
     959         * Frame.
    960960         *
    961961         * @param overlay
    962962         *            The overlay to remove
    963          *            
     963         *
    964964         * @throws NullPointerException
    965          *            If overlay is null.
     965         *             If overlay is null.
    966966         */
    967967        public void removeOverlay(Overlay overlay) {
    968                 if (overlay == null) throw new NullPointerException("overlay");
    969        
     968                if (overlay == null)
     969                        throw new NullPointerException("overlay");
     970
    970971                this._overlays.remove(overlay);
    971                
    972                 // Items must be notified that they have been removed from this frame via the overlay...
     972
     973                // Items must be notified that they have been removed from this frame
     974                // via the overlay...
    973975                List<Item> items = new LinkedList<Item>();
    974                 FrameGraphics.AddAllOverlayItems(items, overlay.Frame, new LinkedList<Frame>());
     976                FrameGraphics.AddAllOverlayItems(items, overlay.Frame,
     977                                new LinkedList<Frame>());
    975978                for (Item i : items) {
    976                         i.onParentStateChanged(new ItemParentStateChangedEvent(
    977                                         this,
    978                                         ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY,
     979                        i.onParentStateChanged(new ItemParentStateChangedEvent(this,
     980                                        ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY,
    979981                                        overlay.Level));
    980982                }
    981983        }
    982        
    983         /**
    984          * Removes the given Frame from the list of overlayed Frames being drawn with
    985          * this Frame.
     984
     985        /**
     986         * Removes the given Frame from the list of overlayed Frames being drawn
     987         * with this Frame.
    986988         *
    987989         * @param overlayedFrame
    988990         *            The Frame to remove
    989          *            
     991         *
    990992         * @throws NullPointerException
    991          *            If overlayedFrame is null.
     993         *             If overlayedFrame is null.
    992994         */
    993995        public void removeOverlay(Frame overlayedFrame) {
    994                 if (overlayedFrame == null) throw new NullPointerException("overlay");
    995                
     996                if (overlayedFrame == null)
     997                        throw new NullPointerException("overlay");
     998
    996999                // Locate the oveylay(s) that match this
    9971000                List<Overlay> overlaysToRemove = new LinkedList<Overlay>();
    9981001                for (Overlay o : _overlays) {
    999                         if (overlayedFrame.equals(o.Frame)) overlaysToRemove.add(o);
    1000                 }
    1001                 for (Overlay o : overlaysToRemove) { // must be enumerated seperate to above...
     1002                        if (overlayedFrame.equals(o.Frame))
     1003                                overlaysToRemove.add(o);
     1004                }
     1005                for (Overlay o : overlaysToRemove) { // must be enumerated seperate
     1006                                                                                                // to above...
    10021007                        removeOverlay(o);
    10031008                }
    1004                
     1009
    10051010        }
    10061011
     
    10101015                return l;
    10111016        }
    1012        
    1013         /**
    1014          * @return All overlays seen by this frame (including its overlays' overlays).
     1017
     1018        /**
     1019         * @return All overlays seen by this frame (including its overlays'
     1020         *         overlays).
    10151021         */
    10161022        public List<Overlay> getOverlaysDeep() {
     
    10191025                return l;
    10201026        }
    1021        
    1022         private boolean getOverlaysDeep(List<Overlay> overlays, Frame overlay, List<Frame> seenOverlays) {
    1023 
    1024                         if (seenOverlays.contains(overlay))
    1025                                 return false;
    1026 
    1027                         seenOverlays.add(overlay);
    1028 
    1029                         for (Overlay o : overlay.getOverlays()) {
    1030                                 if (getOverlaysDeep(overlays, o.Frame, seenOverlays)) {
    1031                                         overlays.add(o);
    1032                                 }
    1033                         }
    1034                        
    1035                         return true;
    1036         }
    1037        
     1027
     1028        private boolean getOverlaysDeep(List<Overlay> overlays, Frame overlay,
     1029                        List<Frame> seenOverlays) {
     1030
     1031                if (seenOverlays.contains(overlay))
     1032                        return false;
     1033
     1034                seenOverlays.add(overlay);
     1035
     1036                for (Overlay o : overlay.getOverlays()) {
     1037                        if (getOverlaysDeep(overlays, o.Frame, seenOverlays)) {
     1038                                overlays.add(o);
     1039                        }
     1040                }
     1041
     1042                return true;
     1043        }
     1044
    10381045        /**
    10391046         * Gets the overlay on this frame which owns the given item.
    1040          * @param item The item - must not be null.
    1041          * @return The overlay that contains the itm. Null if no overlay owns the item.
     1047         *
     1048         * @param item
     1049         *            The item - must not be null.
     1050         * @return The overlay that contains the itm. Null if no overlay owns the
     1051         *         item.
    10421052         */
    10431053        public Overlay getOverlayOwner(Item item) {
    1044                 if (item == null) throw new NullPointerException("item");
     1054                if (item == null)
     1055                        throw new NullPointerException("item");
    10451056                List<Overlay> overlays = getOverlaysDeep();
    10461057                for (Overlay l : overlays) {
    1047                         //if (l.Frame.containsItem(item)) return l;
    1048                         if (item.getParent() == l.Frame) return l;
    1049                 }
    1050                
     1058                        // if (l.Frame.containsItem(item)) return l;
     1059                        if (item.getParent() == l.Frame)
     1060                                return l;
     1061                }
     1062
    10511063                return null;
    10521064        }
     
    10891101                List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems());
    10901102                copies.remove(toMergeWith.getFrameNameItem());
    1091                
     1103
    10921104                for (Item i : copies) {
    10931105                        if (i.getID() >= 0) {
     
    11431155        /**
    11441156         * Creates a new text item with the given text.
     1157         *
    11451158         * @param text
    11461159         * @return
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r48 r67  
    5959        public static final int MODE_XRAY = 2;
    6060
     61        public static final Color ERROR_COLOR = Color.red;
     62
    6163        private static int _Mode = MODE_NORMAL;
    6264
     
    6466        private static boolean _SupressErrors = false;
    6567
     68        public static String MESSAGES_FRAMESET_NAME = "Messages";
    6669        // The link to the message frameset
    67         public static Text MessageLink = new Text(-2, "Messages");
    68 
    69         // Date\time formatter for timestamping the messages
    70         /*
    71          * private static SimpleDateFormat _formatter = new SimpleDateFormat( "
    72          * [ddMMMyyyy:HHmm]");
    73          */
     70        public static Text MessageLink = new Text(-2, MESSAGES_FRAMESET_NAME);
    7471
    7572        // creator for creating the message frames
    7673        private static FrameCreator _creator;
    77 
    78         /**
    79          * Returns the Graphics2D object currently being used to draw with, this may
    80          * be null if no Graphics2D has been assigned yet.
    81          *
    82          * @return the Graphics2D object being used to draw, or null.
    83          */
    84         public static Graphics2D getGraphics() {
    85                 return _DisplayGraphics;
    86         }
    8774
    8875        /**
     
    154141                                MESSAGE_LINK_X);
    155142
    156                 Repaint();
     143                //Repaint();
    157144        }
    158145
     
    471458         */
    472459        public static void Repaint() {
     460                //Thread.dumpStack();
    473461                if (_DisplayGraphics == null)
    474462                        return;
     
    627615                // if the creator needs to be initialised (happens on first message)
    628616                if (_creator == null) {
    629                         _creator = new FrameCreator("Messages", true);
     617                        _creator = new FrameCreator(MESSAGES_FRAMESET_NAME, true);
    630618
    631619                        // set up 'Messages' link on the right hand side
     
    699687                if (tokens.length > 1)
    700688                        link = tokens[tokens.length - 1];
    701                 displayMessage(message, link, Color.RED);
     689                displayMessage(message, link, ERROR_COLOR);
    702690        }
    703691
     
    706694                        return;
    707695                Misc.Beep();
    708                 displayMessage(message, null, Color.RED);
    709 
    710                 // Michael is confused about why this code is gettting into infinite
    711                 // loop
    712 
    713                 /*
    714                  * Exception e = new Exception();
    715                  *
    716                  * try{ throw e; }catch(Exception ex){ StackTraceElement[] trace =
    717                  * ex.getStackTrace(); message += " (" + trace[1].getFileName() + ":" +
    718                  * trace[1].getLineNumber() + ")";
    719                  *
    720                  * String source = trace[1].getClassName(); source = "src.java." +
    721                  * source; source = source.replace(".", File.separator); source +=
    722                  * ".java";
    723                  *
    724                  * try{ BufferedReader reader = new BufferedReader(new
    725                  * FileReader(source)); FrameCreator creator = new
    726                  * FrameCreator("Messages", false);
    727                  *
    728                  * int min = trace[1].getLineNumber() - 10; int max =
    729                  * trace[1].getLineNumber() + 3;
    730                  *
    731                  * int line = 0; while(reader.ready()){ if(line > min && line < max)
    732                  * if(line == trace[1].getLineNumber() - 1)
    733                  * creator.addText(reader.readLine(), Color.RED); else
    734                  * creator.addText(reader.readLine()); else if(line > max) break; else
    735                  * reader.readLine();
    736                  *
    737                  * line++; }
    738                  *
    739                  * reader.close();
    740                  *
    741                  * displayMessage(message, creator.getCurrent(), Color.RED);
    742                  * }catch(Exception ioe){ ioe.printStackTrace(); } }
    743                  */
     696                displayMessage(message, null, ERROR_COLOR);
    744697        }
    745698
  • trunk/src/org/expeditee/gui/FrameIO.java

    r64 r67  
    548548        }
    549549
     550        public static void RefreshCasheImages() {
     551                SuspendCache();
     552                for (Frame f : _Cache.values())
     553                        f.setBuffer(null);
     554                ResumeCache();
     555        }
     556
    550557        /**
    551558         * Creates a new frameset using the given name. This includes creating a new
     
    603610        }
    604611
     612        public static String SaveFrame(Frame toSave, boolean inc) {
     613                return SaveFrame(toSave, inc, true);
     614        }
     615
    605616        /**
    606617         * Saves the given Frame to disk in the corresponding frameset directory, if
     
    613624         *            True if the saved frames counter should be incremented, false
    614625         *            otherwise.
    615          */
    616         public static String SaveFrame(Frame toSave, boolean inc) {
     626         * @param checkBackup
     627         *            True if the frame should be checked for the back up tag
     628         */
     629        public static String SaveFrame(Frame toSave, boolean inc,
     630                        boolean checkBackup) {
    617631
    618632                if (toSave == null)
     
    630644                                .getFrameName());
    631645
     646                // Check if the frame exists
     647                if (checkBackup && fullPath == null) {
     648                        // The first time a frame with the backup tag is saved, dont back it
     649                        // up
     650                        checkBackup = false;
     651                }
     652
    632653                FrameWriter writer = null;
     654                int savedVersion;
    633655                try {
    634656                        // if its a new frame or an existing Exp frame...
    635657                        if (fullPath == null || fullPath.endsWith(ExpReader.EXTENTION)) {
    636658                                writer = new ExpWriter();
     659                                savedVersion = ExpReader.getVersion(fullPath);
    637660                        } else {
    638661                                writer = new KMSWriter();
     662                                savedVersion = KMSReader.getVersion(fullPath);
    639663                        }
    640 
    641                         if (toSave.getFrameNumber() > 0
     664                        // Check if we are trying to save an out of date version
     665                        if (savedVersion > toSave.getVersion(false)
     666                                        && !toSave.getFramesetName().equalsIgnoreCase(
     667                                                        FrameGraphics.MESSAGES_FRAMESET_NAME)) {
     668                                // remove this frame from the cache if it is there
     669                                // This will make sure links to the original are set correctly
     670                                _Cache.remove(toSave.getFrameName().toLowerCase());
     671                                int nextnum = ReadINF(toSave.path, toSave.getFramesetName()) + 1;
     672                                SuspendCache();
     673                                Frame original = LoadFrame(toSave.getFrameName());
     674                                toSave.setFrameNumber(nextnum);
     675                                ResumeCache();
     676                                // Put the modified version in the cache
     677                                _Cache.put(toSave.getFrameName().toLowerCase(), toSave);
     678                                // Show the messages alerting the user
     679                                Text originalMessage = new Text(-1);
     680                                originalMessage.setColor(FrameGraphics.ERROR_COLOR);
     681                                originalMessage.setText(original.getFrameName()
     682                                                + " was updated by another user.");
     683                                originalMessage.setLink(original.getFrameName());
     684                                Text yourMessage = new Text(-1);
     685                                yourMessage.setColor(FrameGraphics.ERROR_COLOR);
     686                                yourMessage.setText("Your version was renamed "
     687                                                + toSave.getFrameName());
     688                                yourMessage.setLink(toSave.getFrameName());
     689                                FrameGraphics.DisplayMessage(originalMessage);
     690                                FrameGraphics.DisplayMessage(yourMessage);
     691                        } else if (checkBackup
    642692                                        && ItemUtils.ContainsTag(toSave.getItems(),
    643693                                                        ItemUtils.TAG_BACKUP)) {
     
    649699                                int nextnum = ReadINF(toSave.path, toSave.getFramesetName()) + 1;
    650700
    651                                 original.setFrameNumber(-nextnum);
    652                                 SaveFrame(original, inc);
     701                                // Give it a negative framenumber so that when it is saved the
     702                                // backup tag will be ignored
     703                                original.setFrameNumber(nextnum);
     704                                original.change();
     705                                SaveFrame(original, false, false);
    653706
    654707                                Item i = ItemUtils.FindTag(toSave.getItems(),
     
    657710                                toSave.setFrameNumber(orignum);
    658711                                ResumeCache();
    659                         } else if (toSave.getFrameNumber() < 0) {
    660                                 toSave.setFrameNumber(-toSave.getFrameNumber());
    661712                        }
    662713
     
    10001051                                int copyNumber = 1;
    10011052                                File dest = new File(destPath + File.separator);
    1002                                 //Create the trash folder if it doesnt already exist
     1053                                // Create the trash folder if it doesnt already exist
    10031054                                if (!dest.getParentFile().exists())
    10041055                                        dest.mkdirs();
     
    10061057                                // a number to the end
    10071058                                while (dest.exists()) {
    1008                                         dest = new File(destPath + ++copyNumber + File.separator );
     1059                                        dest = new File(destPath + ++copyNumber + File.separator);
    10091060                                }
    10101061                                return framesetDirectory.renameTo(dest);
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r65 r67  
    1717import org.expeditee.actions.Simple;
    1818import org.expeditee.io.Logger;
    19 import org.expeditee.items.Constraint;
    2019import org.expeditee.items.Dot;
    2120import org.expeditee.items.Item;
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r58 r67  
    11package org.expeditee.gui;
    22
     3import java.awt.Point;
    34import java.awt.event.ActionEvent;
    45import java.awt.event.ActionListener;
     
    261262                // pre-cache the frame if it is linked
    262263                if (on != null && on.getLink() != null && on.isLinkValid()) {
    263                         FrameIO.Precache(on.getLink());
     264                        FrameIO.Precache(on.getAbsoluteLink());
    264265                }
    265266
     
    739740                                                                        .getPosition(), false);
    740741                                                        pickup(newPoint);
    741                                                         ItemUtils.EnclosedCheck(toDisconnect.getCurrentFrame().getItems());
     742                                                        ItemUtils.EnclosedCheck(toDisconnect
     743                                                                        .getParentOrCurrentFrame().getItems());
    742744                                                        return;
    743745                                                }
     
    913915
    914916                                                if (toCopy.size() > 0) {
     917                                                        //Find the closest item to the mouse cursor
     918                                                        double currentX = DisplayIO.getMouseX();
     919                                                        double currentY = DisplayIO.getMouseY();
     920                                                        Item closest = null;
     921                                                        double shortestDistance = Double.MAX_VALUE;
     922                                                        for(int i = 0; i < toCopy.size(); i++) {
     923                                                                Item next = toCopy.get(i);
     924                                                                if (next instanceof Line)
     925                                                                        continue;
     926                                                                double distance = Point.distance(currentX, currentY, next.getX(), next.getY());
     927                                                                if (distance  < shortestDistance) {
     928                                                                        shortestDistance = distance;
     929                                                                        closest = next;
     930                                                                }
     931                                                        }
     932                                                        //Move the cursor to closest item
     933                                                        DisplayIO.setCursorPosition(closest.getPosition());
     934                                                        //Pickup copy of the stuff inside the rectange
    915935                                                        pickup(copy(toCopy));
     936                                                        //Remove the rectangle
    916937                                                        DisplayIO.getCurrentFrame().removeAllItems(
    917938                                                                        d.getAllConnected());
    918939                                                } else {
     940                                                        //Pick up a copy of the rectangle
    919941                                                        pickup(copy(d.getAllConnected()));
    920942                                                }
     
    14431465                setTdfcItem(linker);
    14441466
    1445                 // Set the link for an @Parent annotation item if one is on the frame
    1446                 for (Item i : next.getItems()) {
    1447                         if ((i instanceof Text) && ItemUtils.isTag(i, ItemUtils.TAG_PARENT)
    1448                                         && i.getLink() == null)
    1449                                 i.setLink(DisplayIO.getCurrentFrame().getFrameName());
     1467                for (Text i : next.getBodyTextItems(true)) {
     1468                        // Set the link for @Parent annotation item if one
     1469                        if (ItemUtils.isTag(i, ItemUtils.TAG_PARENT) && i.getLink() == null) {
     1470                                Frame parent = linker.getParentOrCurrentFrame();
     1471                                i.setLink(parent.getFrameName());
     1472                        } else if (ItemUtils.isTag(i, ItemUtils.TAG_BACKUP)) {
     1473                                // Delink backup tag if it is on the frame
     1474                                i.setLink(null);
     1475                        }
    14501476                }
    14511477
     
    15941620                        // reset the mouse cursor
    15951621                        updateCursor();
    1596                         FrameGraphics.Repaint();
    1597 
    15981622                        ItemUtils.EnclosedCheck(current.getItems());
    15991623                        FrameGraphics.Repaint();
     
    16041628
    16051629        private static void deleteItems(List<Item> itemList) {
    1606                 Frame current = DisplayIO.getCurrentFrame();
     1630                List<Frame> modifiedFrames = new LinkedList<Frame>();
     1631                // Get a list of all the modified frames
     1632                for (Item i : itemList) {
     1633                        Frame parent = i.getParent();
     1634                        if (parent != null)
     1635                                modifiedFrames.add(parent);
     1636                }
     1637
    16071638                List<Item> toUndo = new LinkedList<Item>();
    16081639                List<Item> seen = new LinkedList<Item>();
    1609 
    1610                 // Mike: Removed code that checked for rectangles and removed them
    1611                 // completely!!
    16121640
    16131641                // disconnect any connected items
     
    16231651                                        toUndo.addAll(copy(i));
    16241652                        }
    1625 
    16261653                        seen.add(i);
    16271654                }
    1628 
    1629                 // Mike: What is the point of the code below
    1630                 // It causes problems when deleting three items off the cursor which
    1631                 // include a non dot or line item
    1632                 /*
    1633                  * // check for rectangle deletion if (itemList.size() == 3) { boolean
    1634                  * rectangle = false; Dot dot = null; // check that this is indeed a
    1635                  * rectangle for (Item check : itemList) { if (dot == null && check
    1636                  * instanceof Dot) dot = (Dot) check; else if (check != dot &&
    1637                  * !dot.getLines().contains(check)) { rectangle = false; break; } else
    1638                  * rectangle = true; } // if this is a rectangle, remove the entire
    1639                  * rectangle if (rectangle) { // List<Item> copy =
    1640                  * copy(dot.getAllConnected());
    1641                  * current.addAllToUndo(dot.getAllConnected());
    1642                  * current.removeAllItems(dot.getAllConnected()); itemList.clear(); //
    1643                  * reset the mouse cursor updateCursor(); FrameGraphics.Repaint();
    1644                  * return; } }
    1645                  */
    1646 
    1647                 current.removeAllItems(itemList);
    1648                 current.addAllToUndo(itemList);
     1655                for (Frame f : modifiedFrames) {
     1656                        f.removeAllItems(itemList);
     1657                        ItemUtils.EnclosedCheck(f.getItems());
     1658                }
     1659                // TODO: How should undelete deal with undo when items are removed from
     1660                // the current frame as well as the overlay frame
     1661                DisplayIO.getCurrentFrame().addAllToUndo(itemList);
    16491662                itemList.clear();
    16501663        }
     
    19641977
    19651978                FrameGraphics.Repaint();
    1966                 ItemUtils.EnclosedCheck(toAnchor.getCurrentFrame().getItems());
     1979                ItemUtils.EnclosedCheck(toAnchor.getParentOrCurrentFrame().getItems());
    19671980        }
    19681981
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r50 r67  
    302302                return true;
    303303        }
    304 
     304       
    305305        /**
    306306         * Displays the given Frame on the display. If the current frame has changed
     
    318318                if (toDisplay == null)
    319319                        return;
    320 
     320               
    321321                Frame current = DisplayIO.getCurrentFrame();
    322322
     
    613613                        }
    614614                }
    615                 return new Color[]{Color.black, Color.white};
     615                return new Color[] { Color.black, Color.white };
    616616        }
    617617
     
    12571257                                for (File helpFrameset : helpFramesets) {
    12581258                                        String framesetName = helpFrameset.getName();
    1259                                         Frame indexFrame = FrameIO.LoadFrame(framesetName+ '1');
     1259                                        Frame indexFrame = FrameIO.LoadFrame(framesetName + '1');
    12601260                                        // Look through the folder for help index pages
    12611261                                        if (indexFrame != null
  • trunk/src/org/expeditee/gui/MouseEventRouter.java

    r41 r67  
    9595                                forwardToExpiditee = true;
    9696                        } else if (DisplayIO.getCurrentFrame() != null) { // is mouse over
    97                                                                                                                                 // a specific
    98                                                                                                                                 // expeditee
    99                                                                                                                                 // item?
     97                                // a specific
     98                                // expeditee
     99                                // item?
    100100                                // NOTE: Do not use FrameUtils.getCurrentItem() - thats relevent
    101101                                // for old mouse position only
     
    110110                                                .getCurrentFrame(), containerPoint.x, containerPoint.y) != null);
    111111                        }
    112                        
     112
    113113                        if (forwardToExpiditee) {
    114114
     
    125125                                MouseEvent expediteeEvent = SwingUtilities.convertMouseEvent(e
    126126                                                .getComponent(), e, _contentPane);
    127                                
     127
    128128                                switch (e.getID()) {
    129129                                case MouseEvent.MOUSE_MOVED:
     
    131131
    132132                                        // Ensure that expiditee has focus only if no popups exist
    133                                         if (!Browser._theBrowser.getContentPane().isFocusOwner()
    134                                                         && !isPopupVisible()) {
    135                                                 Browser._theBrowser.getContentPane().requestFocus();
     133                                        if (Browser._theBrowser.getContentPane() != null) {
     134                                                if (!Browser._theBrowser.getContentPane()
     135                                                                .isFocusOwner()
     136                                                                && !isPopupVisible()) {
     137                                                        Browser._theBrowser.getContentPane().requestFocus();
     138                                                }
    136139                                        }
    137140
  • trunk/src/org/expeditee/io/Conversion.java

    r4 r67  
    1010import java.util.StringTokenizer;
    1111
    12 import org.expeditee.gui.DisplayIO;
    1312import org.expeditee.items.Item;
    1413import org.expeditee.items.Text;
     
    4847                }
    4948
     49                // check if its a normal rgb code ie. 100 0 40
    5050                Color rgb = getRGBColor(colorCode, current);
    5151                if (rgb != null)
     
    5858                char c = colorCode.charAt(last);
    5959
    60                 while (c >= '0' && c <= '9') {
     60                while (Character.isDigit(c)) {
    6161                        num = c + num;
    6262                        if (last <= 0)
     
    6969                if (num.length() > 0)
    7070                        amount = Float.parseFloat(num);
     71               
     72                if(amount > 10)
     73                        amount = 10;
    7174
    7275                float color[] = { 0, 0, 0 };
     
    7477                if (colorCode.toLowerCase().startsWith("red"))
    7578                        color[0] = amount / 10;
    76 
    77                 if (colorCode.toLowerCase().startsWith("green"))
     79                else if (colorCode.toLowerCase().startsWith("green"))
    7880                        color[1] = amount / 10;
    79 
    80                 if (colorCode.toLowerCase().startsWith("blue"))
     81                else if (colorCode.toLowerCase().startsWith("blue"))
    8182                        color[2] = amount / 10;
     83                else
     84                        return current;
    8285
    8386                return new Color(color[0], color[1], color[2]);
     
    8891
    8992                try {
    90                         String r = colorCode.substring(0, colorCode.indexOf(" "));
    91                         colorCode = colorCode.substring(r.length() + 1);
    92 
    93                         String g = colorCode.substring(0, colorCode.indexOf(" "));
    94                         colorCode = colorCode.substring(g.length() + 1);
    95 
    96                         String b = colorCode.substring(0);
     93                        String[] values = colorCode.trim().split("\\s+");
     94                       
     95                        String r = values.length > 0 ? values[0] : "0";
     96                        String g = values.length > 1 ? values[1] : "0";
     97                        String b = values.length > 2 ? values[2] : "0";
    9798
    9899                        if (current != null && (r.startsWith("+") || r.startsWith("-"))) {
     
    125126                        return new Color(color[0], color[1], color[2]);
    126127                } catch (Exception e) {
    127                         return current;
     128                        return null;
    128129                }
    129130        }
     
    200201                String code = "t";
    201202                String fontName = font.getFamily().toLowerCase();
    202                
     203
    203204                for (int i = 0; i < Text.FONT_WHEEL.length; i++) {
    204                         if (Text.FONT_WHEEL[i].equals(fontName)){
     205                        if (Text.FONT_WHEEL[i].equals(fontName)) {
    205206                                code = "" + Text.FONT_CHARS[i];
    206207                                break;
    207208                        }
    208209                }
    209                
     210
    210211                switch (font.getStyle()) {
    211212                case Font.BOLD:
     
    297298         */
    298299        public static int getFrameNumber(String framename) {
    299                 String num = framename
    300                                 .replaceFirst("^\\w+([^\\d]+|\\d+[.][^\\d]+)", "");
     300                String num = null;
     301                // The framename must end in a digit
     302                assert (Character.isDigit(framename.charAt(framename.length() - 1)));
     303                // And start with a letter
     304                assert (Character.isLetter(framename.charAt(0)));
     305                // start at the end and find the first non digit char
     306                for (int i = framename.length() - 2; i >= 0; i--) {
     307                        if (!Character.isDigit(framename.charAt(i))) {
     308                                num = framename.substring(i + 1);
     309                                break;
     310                        }
     311                }
    301312
    302313                try {
     
    309320        /**
    310321         * Returns the frameset poriton of the given Frame name (frame number
    311          * removed)
     322         * removed) converted to lower case.
    312323         *
    313324         * @param frame
     
    319330        }
    320331
    321         public static String getFrameset(String frame, boolean convertToLower) {
    322                 String set = frame.replaceFirst("(\\d+|[.]\\d+)$", "");
    323 
    324                 // if there is no frameset given, then add the current frameset
    325                 if (set.length() == 0) {
    326                         set = DisplayIO.getCurrentFrame().getFramesetName();
     332        public static String getFrameset(String framename, boolean convertToLower) {
     333                String set = null;
     334                assert (Character.isDigit(framename.charAt(framename.length() - 1)));
     335                // And start with a letter
     336                assert (Character.isLetter(framename.charAt(0)));
     337                // start at the end and find the first non digit char
     338                for (int i = framename.length() - 2; i >= 0; i--) {
     339                        if (!Character.isDigit(framename.charAt(i))) {
     340                                set = framename.substring(0, i + 1);
     341                                break;
     342                        }
    327343                }
    328344
     
    343359         */
    344360        public static int getJustification(String justCode) {
     361                assert (justCode != null);
     362                justCode = justCode.trim().toLowerCase();
    345363                // as read from file
    346364                if (justCode.length() == 1) {
    347365                        switch (justCode.charAt(0)) {
    348                         case 'F':
     366                        case 'f':
    349367                                return Item.JUSTIFICATION_FULL;
    350                         case 'L':
     368                        case 'l':
    351369                                return Item.JUSTIFICATION_LEFT;
    352                         case 'R':
     370                        case 'r':
    353371                                return Item.JUSTIFICATION_RIGHT;
    354                         case 'C':
     372                        case 'c':
    355373                                return Item.JUSTIFICATION_CENTER;
    356374                        }
     
    358376
    359377                // from the user
    360                 justCode = justCode.trim().toLowerCase();
    361378                if (justCode.equals("center"))
    362379                        return Item.JUSTIFICATION_CENTER;
     
    395412        public static Object Convert(Class type, String value, Object orig) {
    396413                // System.out.println("Orig: " + orig);
     414                assert (value != null);
     415                value = value.trim();
    397416
    398417                if (type == String.class
     
    401420                else if (type == String.class)
    402421                        return value;
    403 
    404                 /*
    405                  * if(type == int.class || type == Integer.class){ return
    406                  * Integer.parseInt(value); }
    407                  *
    408                  * if(type == float.class || type == Float.class){ return
    409                  * Float.parseFloat(value); }
    410                  */
    411422
    412423                if (type == Font.class) {
     
    510521
    511522        public static Object[] Convert(Method method, String value, Object current) {
     523                value = value.trim();
    512524
    513525                String name = method.getName();
  • trunk/src/org/expeditee/io/DefaultFrameWriter.java

    r4 r67  
    44import java.io.FileWriter;
    55import java.io.IOException;
     6import java.lang.reflect.Method;
     7import java.util.LinkedHashMap;
    68
    79import org.expeditee.gui.Frame;
    810import org.expeditee.gui.FrameIO;
    911import org.expeditee.items.Item;
     12import org.expeditee.items.Text;
    1013
    1114public abstract class DefaultFrameWriter extends ItemWriter implements
     
    2326
    2427        protected boolean _stop = false;
     28
     29        // keep track of methods that are put on the same line
     30        protected static LinkedHashMap<String, Method> _ItemTags = null;
     31
     32        protected static LinkedHashMap<String, Method> _FrameTags = null;
     33
     34        public DefaultFrameWriter() {
     35                if (_ItemTags != null && _FrameTags != null)
     36                        return;
     37
     38                _ItemTags = new LinkedHashMap<String, Method>();
     39                _FrameTags = new LinkedHashMap<String, Method>();
     40
     41                Class[] param = {};
     42
     43                try {
     44                        _FrameTags.put("A", Frame.class.getMethod("getFrameName", param));
     45                        _FrameTags.put("V", Frame.class.getMethod("getVersion", param));
     46                        _FrameTags.put("p", Frame.class.getMethod("getProtection", param));
     47                        _FrameTags.put("U", Frame.class.getMethod("getOwner", param));
     48                        _FrameTags.put("D", Frame.class.getMethod("getDateCreated", param));
     49                        _FrameTags.put("M", Frame.class.getMethod("getLastModifyUser",
     50                                        param));
     51                        _FrameTags.put("d", Frame.class.getMethod("getLastModifyDate",
     52                                        param));
     53                        _FrameTags.put("F", Frame.class.getMethod("getFrozenDate", param));
     54
     55                        _FrameTags.put("O", Frame.class.getMethod("getForegroundColor",
     56                                        param));
     57                        _FrameTags.put("B", Frame.class.getMethod("getBackgroundColor",
     58                                        param));
     59                        _ItemTags.put("S", Item.class.getMethod("getTypeAndID", param));
     60                        _ItemTags.put("s", Item.class.getMethod("getDateCreated", param));
     61                        _ItemTags.put("d", Item.class.getMethod("getColor", param));
     62                        _ItemTags.put("G", Item.class
     63                                        .getMethod("getBackgroundColor", param));
     64                        _ItemTags.put("P", Item.class.getMethod("getPosition", param));
     65                        _ItemTags.put("F", Item.class.getMethod("getLink", param));
     66                        _ItemTags.put("X", Item.class.getMethod("getAction", param));
     67                        _ItemTags.put("x", Item.class.getMethod("getActionMark", param));
     68                        _ItemTags.put("U", Item.class.getMethod("getActionCursorEnter",
     69                                        param));
     70                        _ItemTags.put("V", Item.class.getMethod("getActionCursorLeave",
     71                                        param));
     72                        _ItemTags.put("W", Item.class.getMethod("getActionEnterFrame",
     73                                        param));
     74                        _ItemTags.put("Y", Item.class.getMethod("getActionLeaveFrame",
     75                                        param));
     76                        _ItemTags.put("D", Item.class.getMethod("getData", param));
     77                        _ItemTags.put("u", Item.class.getMethod("getHighlight", param));
     78                        _ItemTags.put("e", Item.class.getMethod("getFillColor", param));
     79                        _ItemTags.put("i", Item.class.getMethod("getFillPattern", param));
     80                        _ItemTags.put("o", Item.class.getMethod("getOwner", param));
     81                        _ItemTags.put("n", Item.class.getMethod("getLinkMark", param));
     82                        _ItemTags.put("q", Item.class.getMethod("getLinkFrameset", param));
     83                        _ItemTags.put("y", Item.class.getMethod("getLinkTemplate", param));
     84                        _ItemTags.put("g", Item.class.getMethod("getLinePattern", param));
     85
     86                        _ItemTags.put("j", Item.class.getMethod("getArrow", param));
     87
     88                        _ItemTags.put("f", Text.class.getMethod("getFont", param));
     89                        _ItemTags.put("t", Text.class.getMethod("getSpacing", param));
     90                        _ItemTags.put("T", Text.class.getMethod("getText", param));
     91
     92                        _ItemTags.put("a", Text.class.getMethod("getWordSpacing", param));
     93                        _ItemTags.put("b", Text.class.getMethod("getLetterSpacing", param));
     94                        _ItemTags
     95                                        .put("m", Text.class.getMethod("getInitialSpacing", param));
     96                        _ItemTags.put("w", Text.class.getMethod("getWidth", param));
     97                        _ItemTags.put("k", Text.class.getMethod("getJustification", param));
     98
     99                        _ItemTags.put("h", Item.class.getMethod("getThickness", param));
     100                        _ItemTags.put("l", Item.class.getMethod("getLineIDs", param));
     101                        _ItemTags.put("c", Item.class.getMethod("getConstraintIDs", param));
     102
     103                } catch (Exception e) {
     104                        e.printStackTrace();
     105                }
     106        }
    25107
    26108        public void setOutputLocation(String filename) {
     
    125207                return "Not Supported";
    126208        }
     209
    127210}
  • trunk/src/org/expeditee/io/ExpReader.java

    r50 r67  
    11package org.expeditee.io;
    22
    3 import java.awt.Color;
    4 import java.awt.Font;
    5 import java.awt.Point;
    63import java.io.BufferedReader;
    74import java.io.FileReader;
     
    96import java.lang.reflect.Method;
    107import java.util.HashMap;
    11 import java.util.LinkedHashMap;
    12 import java.util.List;
    138
    149import org.expeditee.gui.Frame;
     
    2621 *
    2722 */
    28 public class ExpReader implements FrameReader {
     23public class ExpReader extends FrameReader {
    2924
    3025        public static final String EXTENTION = ".exp";
     
    3227        private BufferedReader _reader = null;
    3328
    34         private static LinkedHashMap<Character, Method> _ItemTags = null;
    35 
    36         private static LinkedHashMap<Character, Method> _FrameTags = null;
    37 
    3829        private String _frameName;
    3930
     
    4233         */
    4334        public ExpReader(String frameName) {
     35                super();
     36
    4437                _frameName = frameName;
    45 
    46                 if (_ItemTags != null && _FrameTags != null)
    47                         return;
    48 
    49                 _ItemTags = new LinkedHashMap<Character, Method>();
    50                 _FrameTags = new LinkedHashMap<Character, Method>();
    51 
    52                 Class[] pString = { String.class };
    53                 Class[] pInt = { int.class };
    54                 Class[] pFloat = { float.class };
    55                 Class[] pColor = { Color.class };
    56                 Class[] pBool = { boolean.class };
    57                 Class[] pFont = { Font.class };
    58                 Class[] pPoint = { Point.class };
    59                 Class[] pArrow = { int.class, double.class };
    60                 Class[] pList = { List.class };
    61                 Class[] pIntArray = { int[].class };
    62                 Class[] pItem = { Item.class };
    63 
    64                 try {
    65                         _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt));
    66                         _FrameTags
    67                                         .put('p', Frame.class.getMethod("setProtection", pString));
    68                         _FrameTags.put('U', Frame.class.getMethod("setOwner", pString));
    69                         _FrameTags.put('D', Frame.class
    70                                         .getMethod("setDateCreated", pString));
    71                         _FrameTags.put('M', Frame.class.getMethod("setLastModifyUser",
    72                                         pString));
    73                         _FrameTags.put('d', Frame.class.getMethod("setLastModifyDate",
    74                                         pString));
    75                         _FrameTags
    76                                         .put('F', Frame.class.getMethod("setFrozenDate", pString));
    77 
    78                         _FrameTags.put('O', Frame.class.getMethod("setForegroundColor",
    79                                         pColor));
    80                         _FrameTags.put('B', Frame.class.getMethod("setBackgroundColor",
    81                                         pColor));
    82 
    83                         _ItemTags.put('S', Item.class.getMethod("setID", pInt));
    84                         _ItemTags.put('s', Item.class.getMethod("setDateCreated", pString));
    85                         _ItemTags.put('d', Item.class.getMethod("setColor", pColor));
    86                         _ItemTags.put('G', Item.class.getMethod("setBackgroundColor",
    87                                         pColor));
    88                         _ItemTags.put('P', Item.class.getMethod("setPosition", pPoint));
    89                         _ItemTags.put('F', Item.class.getMethod("setLink", pString));
    90                         _ItemTags.put('X', Item.class.getMethod("setAction", pList));
    91                         _ItemTags.put('x', Item.class.getMethod("setActionMark", pBool));
    92                         _ItemTags.put('U', Item.class.getMethod("setActionCursorEnter",
    93                                         pList));
    94                         _ItemTags.put('V', Item.class.getMethod("setActionCursorLeave",
    95                                         pList));
    96                         _ItemTags.put('W', Item.class.getMethod("setActionEnterFrame",
    97                                         pList));
    98                         _ItemTags.put('Y', Item.class.getMethod("setActionLeaveFrame",
    99                                         pList));
    100                         _ItemTags.put('D', Item.class.getMethod("setData", pString));
    101                         _ItemTags.put('u', Item.class.getMethod("setHighlight", pBool));
    102                         _ItemTags.put('e', Item.class.getMethod("setFillColor", pColor));
    103                         _ItemTags.put('i', Item.class.getMethod("setFillPattern", pString));
    104                         _ItemTags.put('o', Item.class.getMethod("setOwner", pString));
    105                         _ItemTags.put('n', Item.class.getMethod("setLinkMark", pBool));
    106                         _ItemTags
    107                                         .put('q', Item.class.getMethod("setLinkFrameset", pString));
    108                         _ItemTags
    109                                         .put('y', Item.class.getMethod("setLinkTemplate", pString));
    110                         _ItemTags.put('g', Item.class
    111                                         .getMethod("setLinePattern", pIntArray));
    112 
    113                         _ItemTags.put('j', Item.class.getMethod("setArrow", pArrow));
    114 
    115                         _ItemTags.put('f', Text.class.getMethod("setFont", pFont));
    116                         _ItemTags.put('t', Text.class.getMethod("setSpacing", pInt));
    117                         _ItemTags.put('T', Text.class.getMethod("appendLine", pString));
    118 
    119                         _ItemTags.put('a', Text.class.getMethod("setWordSpacing", pInt));
    120                         _ItemTags.put('b', Text.class.getMethod("setLetterSpacing", pInt));
    121                         _ItemTags.put('m', Text.class.getMethod("setInitialSpacing", pInt));
    122                         _ItemTags.put('w', Text.class.getMethod("setWidth", pInt));
    123                         _ItemTags.put('k', Text.class.getMethod("setJustification", pInt));
    124 
    125                         _ItemTags.put('h', Item.class.getMethod("setThickness", pFloat));
    126                         _ItemTags.put('l', Item.class.getMethod("setLineIDs", pString));
    127                         _ItemTags.put('c', Item.class
    128                                         .getMethod("setConstraintIDs", pString));
    129 
    130                         // Lines and constraints are created differently
    131                         _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem));
    132                         _ItemTags.put('C', Constraint.class.getMethod("getID",
    133                                         (Class[]) null));
    134                 } catch (Exception e) {
    135                         e.printStackTrace();
    136                 }
    13738        }
    13839
     
    14445         * @return true if s begins with a KMS tag
    14546         */
    146         private boolean isValidLine(String s) {
     47        private static boolean isValidLine(String s) {
    14748                return s.length() >= 2 && s.charAt(1) == ' '
    14849                                && Character.isLetter(s.charAt(0));
     
    280181        }
    281182
    282         private Character getTag(String line) {
     183        private static Character getTag(String line) {
    283184                assert (line.length() > 0);
    284185                return line.charAt(0);
    285186        }
    286187
    287         private String getValue(String line) {
     188        private static String getValue(String line) {
    288189                if (line.length() > 2)
    289190                        return line.substring(2);
     
    309210
    310211                if (toRun == null) {
    311                         System.out.println("Tag '" + tag + "' in '" + line
    312                                         + "' is not supported.");
     212                        if (tag != 'v') {
     213                                System.out.println("Tag '" + tag + "' in '" + line
     214                                                + "' is not supported.");
     215                        }
    313216                        return;
    314217                }
     
    331234                return new java.awt.Point(x, y);
    332235        }
     236
     237        public static int getVersion(String fullpath) {
     238                try {
     239                        BufferedReader reader = new BufferedReader(new FileReader(fullpath));
     240                        String next = "";
     241                        // First read the header lines until we get the version number
     242                        while (reader.ready() && !(next = reader.readLine()).equals("Z")) {
     243                                if (isValidLine(next)) {
     244                                        Character tag = getTag(next);
     245                                        String value = getValue(next);
     246                                        if (tag.equals('V'))
     247                                                return Integer.parseInt(value);
     248                                }
     249                        }
     250                } catch (Exception e) {
     251                }
     252                return 0;
     253        }
    333254}
  • trunk/src/org/expeditee/io/ExpWriter.java

    r58 r67  
    11package org.expeditee.io;
    22
    3 import java.awt.Rectangle;
    43import java.io.File;
    54import java.io.FileWriter;
     
    76import java.lang.reflect.Method;
    87import java.util.Iterator;
    9 import java.util.LinkedHashMap;
    108import java.util.LinkedList;
    119import java.util.List;
     
    1715import org.expeditee.items.Line;
    1816import org.expeditee.items.Picture;
    19 import org.expeditee.items.Text;
    2017import org.expeditee.items.WidgetCorner;
    2118import org.expeditee.items.WidgetEdge;
     
    3431        private StringBuilder _stringWriter = null;
    3532
    36         // keep track of methods that are put on the same line
    37         private static LinkedHashMap<String, Method> _ItemTags = null;
    38 
    39         private static LinkedHashMap<String, Method> _FrameTags = null;
    40 
    4133        private static final char TERMINATOR = 'Z';
    4234
    4335        public ExpWriter() {
    44                 if (_ItemTags != null && _FrameTags != null)
    45                         return;
    46 
    47                 _ItemTags = new LinkedHashMap<String, Method>();
    48                 _FrameTags = new LinkedHashMap<String, Method>();
    49 
    50                 Class[] param = {};
    51 
    52                 try {
    53                         _FrameTags.put("V", Frame.class.getMethod("getVersion", param));
    54                         _FrameTags.put("p", Frame.class.getMethod("getProtection", param));
    55                         _FrameTags.put("U", Frame.class.getMethod("getOwner", param));
    56                         _FrameTags.put("D", Frame.class.getMethod("getDateCreated", param));
    57                         _FrameTags.put("M", Frame.class.getMethod("getLastModifyUser",
    58                                         param));
    59                         _FrameTags.put("d", Frame.class.getMethod("getLastModifyDate",
    60                                         param));
    61                         _FrameTags.put("F", Frame.class.getMethod("getFrozenDate", param));
    62 
    63                         _FrameTags.put("O", Frame.class.getMethod("getForegroundColor",
    64                                         param));
    65                         _FrameTags.put("B", Frame.class.getMethod("getBackgroundColor",
    66                                         param));
    67 
    68                         _ItemTags.put("S", Item.class.getMethod("getTypeAndID", param));
    69                         _ItemTags.put("s", Item.class.getMethod("getDateCreated", param));
    70                         _ItemTags.put("d", Item.class.getMethod("getColor", param));
    71                         _ItemTags.put("G", Item.class
    72                                         .getMethod("getBackgroundColor", param));
    73                         _ItemTags.put("P", Item.class.getMethod("getPosition", param));
    74                         _ItemTags.put("F", Item.class.getMethod("getLink", param));
    75                         _ItemTags.put("X", Item.class.getMethod("getAction", param));
    76                         _ItemTags.put("x", Item.class.getMethod("getActionMark", param));
    77                         _ItemTags.put("U", Item.class.getMethod("getActionCursorEnter",
    78                                         param));
    79                         _ItemTags.put("V", Item.class.getMethod("getActionCursorLeave",
    80                                         param));
    81                         _ItemTags.put("W", Item.class.getMethod("getActionEnterFrame",
    82                                         param));
    83                         _ItemTags.put("Y", Item.class.getMethod("getActionLeaveFrame",
    84                                         param));
    85                         _ItemTags.put("D", Item.class.getMethod("getData", param));
    86                         _ItemTags.put("u", Item.class.getMethod("getHighlight", param));
    87                         _ItemTags.put("e", Item.class.getMethod("getFillColor", param));
    88                         _ItemTags.put("i", Item.class.getMethod("getFillPattern", param));
    89                         _ItemTags.put("o", Item.class.getMethod("getOwner", param));
    90                         _ItemTags.put("n", Item.class.getMethod("getLinkMark", param));
    91                         _ItemTags.put("q", Item.class.getMethod("getLinkFrameset", param));
    92                         _ItemTags.put("y", Item.class.getMethod("getLinkTemplate", param));
    93                         _ItemTags.put("g", Item.class.getMethod("getLinePattern", param));
    94 
    95                         _ItemTags.put("j", Item.class.getMethod("getArrow", param));
    96 
    97                         _ItemTags.put("f", Text.class.getMethod("getFont", param));
    98                         _ItemTags.put("t", Text.class.getMethod("getSpacing", param));
    99                         _ItemTags.put("T", Text.class.getMethod("getText", param));
    100 
    101                         _ItemTags.put("a", Text.class.getMethod("getWordSpacing", param));
    102                         _ItemTags.put("b", Text.class.getMethod("getLetterSpacing", param));
    103                         _ItemTags
    104                                         .put("m", Text.class.getMethod("getInitialSpacing", param));
    105                         _ItemTags.put("w", Text.class.getMethod("getWidth", param));
    106                         _ItemTags.put("k", Text.class.getMethod("getJustification", param));
    107 
    108                         _ItemTags.put("h", Item.class.getMethod("getThickness", param));
    109                         _ItemTags.put("l", Item.class.getMethod("getLineIDs", param));
    110                         _ItemTags.put("c", Item.class.getMethod("getConstraintIDs", param));
    111 
    112                 } catch (Exception e) {
    113                         e.printStackTrace();
    114                 }
     36                super();
    11537        }
    11638
     
    12850                } else
    12951                        _writer = new ProxyWriter(new FileWriter(_filename));
     52               
     53                try {
     54                        _ItemTags.put("S", Item.class.getMethod("getTypeAndID", new Class[] {}));
     55                } catch (Exception e) {
     56
     57                }
    13058        }
    13159
     
    225153                // Dont save the item if it is off the screen
    226154                if (item.offScreen()) {
    227                         System.out.println("item offscreen!");
     155                        //System.out.println("item offscreen!");
    228156                        return;
    229157                }
  • trunk/src/org/expeditee/io/FrameReader.java

    r4 r67  
    11package org.expeditee.io;
    22
     3import java.awt.Color;
     4import java.awt.Font;
     5import java.awt.Point;
    36import java.io.IOException;
     7import java.lang.reflect.Method;
     8import java.util.LinkedHashMap;
     9import java.util.List;
    410
    511import org.expeditee.gui.Frame;
     12import org.expeditee.items.Constraint;
     13import org.expeditee.items.Item;
     14import org.expeditee.items.Line;
     15import org.expeditee.items.Text;
    616
    7 public interface FrameReader {
     17public abstract class FrameReader {
     18        protected static LinkedHashMap<Character, Method> _ItemTags = null;
    819
    9         public abstract Frame readFrame(String fullPath)
    10                         throws IOException;
     20        protected static LinkedHashMap<Character, Method> _FrameTags = null;
     21       
     22        protected static Class[] pString = { String.class };
     23        protected static Class[] pInt = { int.class };
     24        protected static Class[] pFloat = { float.class };
     25        protected static Class[] pColor = { Color.class };
     26        protected static Class[] pBool = { boolean.class };
     27        protected static Class[] pFont = { Font.class };
     28        protected static Class[] pPoint = { Point.class };
     29        protected static Class[] pArrow = { int.class, double.class };
     30        protected static Class[] pList = { List.class };
     31        protected static Class[] pIntArray = { int[].class };
     32        protected static Class[] pItem = { Item.class };
     33       
     34        public FrameReader(){
     35                if (_ItemTags != null && _FrameTags != null)
     36                        return;
     37
     38                _ItemTags = new LinkedHashMap<Character, Method>();
     39                _FrameTags = new LinkedHashMap<Character, Method>();
     40
     41                try {
     42                        _FrameTags.put('A', Frame.class.getMethod("setFrameName", pString));
     43                        _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt));
     44                        _FrameTags
     45                                        .put('p', Frame.class.getMethod("setProtection", pString));
     46                        _FrameTags.put('U', Frame.class.getMethod("setOwner", pString));
     47                        _FrameTags.put('D', Frame.class
     48                                        .getMethod("setDateCreated", pString));
     49                        _FrameTags.put('M', Frame.class.getMethod("setLastModifyUser",
     50                                        pString));
     51                        _FrameTags.put('d', Frame.class.getMethod("setLastModifyDate",
     52                                        pString));
     53                        _FrameTags
     54                                        .put('F', Frame.class.getMethod("setFrozenDate", pString));
     55
     56                        _FrameTags.put('O', Frame.class.getMethod("setForegroundColor",
     57                                        pColor));
     58                        _FrameTags.put('B', Frame.class.getMethod("setBackgroundColor",
     59                                        pColor));
     60
     61                        _ItemTags.put('S', Item.class.getMethod("setID", pInt));
     62                        _ItemTags.put('s', Item.class.getMethod("setDateCreated", pString));
     63                        _ItemTags.put('d', Item.class.getMethod("setColor", pColor));
     64                        _ItemTags.put('G', Item.class.getMethod("setBackgroundColor",
     65                                        pColor));
     66                        _ItemTags.put('P', Item.class.getMethod("setPosition", pPoint));
     67                        _ItemTags.put('F', Item.class.getMethod("setLink", pString));
     68                        _ItemTags.put('X', Item.class.getMethod("setAction", pList));
     69                        _ItemTags.put('x', Item.class.getMethod("setActionMark", pBool));
     70                        _ItemTags.put('U', Item.class.getMethod("setActionCursorEnter",
     71                                        pList));
     72                        _ItemTags.put('V', Item.class.getMethod("setActionCursorLeave",
     73                                        pList));
     74                        _ItemTags.put('W', Item.class.getMethod("setActionEnterFrame",
     75                                        pList));
     76                        _ItemTags.put('Y', Item.class.getMethod("setActionLeaveFrame",
     77                                        pList));
     78                        _ItemTags.put('D', Item.class.getMethod("setData", pString));
     79                        _ItemTags.put('u', Item.class.getMethod("setHighlight", pBool));
     80                        _ItemTags.put('e', Item.class.getMethod("setFillColor", pColor));
     81                        _ItemTags.put('i', Item.class.getMethod("setFillPattern", pString));
     82                        _ItemTags.put('o', Item.class.getMethod("setOwner", pString));
     83                        _ItemTags.put('n', Item.class.getMethod("setLinkMark", pBool));
     84                        _ItemTags
     85                                        .put('q', Item.class.getMethod("setLinkFrameset", pString));
     86                        _ItemTags
     87                                        .put('y', Item.class.getMethod("setLinkTemplate", pString));
     88                        _ItemTags.put('g', Item.class
     89                                        .getMethod("setLinePattern", pIntArray));
     90
     91                        _ItemTags.put('j', Item.class.getMethod("setArrow", pArrow));
     92
     93                        _ItemTags.put('f', Text.class.getMethod("setFont", pFont));
     94                        _ItemTags.put('t', Text.class.getMethod("setSpacing", pInt));
     95                        _ItemTags.put('T', Text.class.getMethod("appendLine", pString));
     96
     97                        _ItemTags.put('a', Text.class.getMethod("setWordSpacing", pInt));
     98                        _ItemTags.put('b', Text.class.getMethod("setLetterSpacing", pInt));
     99                        _ItemTags.put('m', Text.class.getMethod("setInitialSpacing", pInt));
     100                        _ItemTags.put('w', Text.class.getMethod("setWidth", pInt));
     101                        _ItemTags.put('k', Text.class.getMethod("setJustification", pInt));
     102
     103                        _ItemTags.put('h', Item.class.getMethod("setThickness", pFloat));
     104                        _ItemTags.put('l', Item.class.getMethod("setLineIDs", pString));
     105                        _ItemTags.put('c', Item.class
     106                                        .getMethod("setConstraintIDs", pString));
     107                        // Lines and constraints are created differently
     108                        _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem));
     109                        _ItemTags.put('C', Constraint.class.getMethod("getID",
     110                                        (Class[]) null));
     111                } catch (Exception e) {
     112                        e.printStackTrace();
     113                }
     114               
     115        }
     116       
     117        public abstract Frame readFrame(String fullPath) throws IOException;
    11118}
  • trunk/src/org/expeditee/io/KMSReader.java

    r4 r67  
    11package org.expeditee.io;
    22
    3 import java.awt.Color;
    4 import java.awt.Font;
    5 import java.awt.Point;
    63import java.io.BufferedReader;
    74import java.io.FileReader;
     
    1310import java.util.Iterator;
    1411import java.util.LinkedHashMap;
    15 import java.util.List;
    1612
    1713import org.expeditee.gui.Frame;
     
    3026 *
    3127 */
    32 public class KMSReader implements FrameReader {
     28public class KMSReader extends FrameReader {
    3329
    3430        private BufferedReader _reader = null;
     
    4844                _FrameTags = new LinkedHashMap<String, Method>();
    4945
    50                 Class[] pString = { String.class };
    51                 Class[] pInt = { int.class };
    52                 Class[] pFloat = { float.class };
    53                 Class[] pColor = { Color.class };
    54                 Class[] pBool = { boolean.class };
    55                 Class[] pFont = { Font.class };
    56                 Class[] pPoint = { Point.class };
    57                 Class[] pArrow = { int.class, double.class };
    58                 Class[] pList = { List.class };
    59                 Class[] pIntArray = { int[].class };
    60                 Class[] pItem = { Item.class };
    61 
    6246                try {
    6347                        _FrameTags.put("A", Frame.class.getMethod("setFrameName", pString));
    6448                        _FrameTags.put("V", Frame.class.getMethod("setVersion", pInt));
    65                         _FrameTags
    66                                         .put("v", Frame.class.getMethod("setFormatVersion", pInt));
    6749                        _FrameTags
    6850                                        .put("p", Frame.class.getMethod("setProtection", pString));
     
    152134         * @return true if s begins with a KMS tag
    153135         */
    154         private boolean isValidLine(String s) {
     136        private static boolean isValidLine(String s) {
    155137                return s.length() >= 3 && s.charAt(0) == '+' && s.charAt(2) == '+'
    156138                                && Character.isLetter(s.charAt(1));
     
    332314        }
    333315
    334         private String getTag(String line) {
     316        private static String getTag(String line) {
    335317                assert (line.charAt(0) == '+');
    336318                assert (line.length() > 2);
     
    338320        }
    339321
    340         private String getValue(String line) {
     322        private static String getValue(String line) {
    341323                assert (line.charAt(0) == '+');
    342324                if (line.length() > 4)
     
    365347
    366348                if (_FrameTags.get(tag) == null) {
    367                         if (!tag.equals("t"))
     349                        if (!tag.equals("t") && !tag.equals("v") )
    368350                                FrameGraphics.ErrorMessage("Tag '" + tag + "' in '" + line
    369351                                                + "' is not supported.");
     
    530512                return toMake;
    531513        }
     514       
     515        public static int getVersion(String fullpath) {
     516                try {
     517                        BufferedReader reader = new BufferedReader(new FileReader(fullpath));
     518                        String next = "";
     519                        // First read the header lines until we get the version number
     520                        while (reader.ready() && (next = reader.readLine())!= null) {
     521                                if (isValidLine(next)) {
     522                                        char tag = getTag(next).charAt(0);
     523                                        String value = getValue(next);
     524                                        if (tag == 'V')
     525                                                return Integer.parseInt(value);
     526                                        else if(tag == 'Z')
     527                                                return 0;
     528                                }
     529                        }
     530                } catch (Exception e) {
     531                }
     532                return 0;
     533        }
    532534}
  • trunk/src/org/expeditee/io/KMSWriter.java

    r50 r67  
    77import java.lang.reflect.Method;
    88import java.util.Iterator;
    9 import java.util.LinkedHashMap;
    109import java.util.LinkedList;
    1110import java.util.List;
     
    1716import org.expeditee.items.Line;
    1817import org.expeditee.items.Picture;
    19 import org.expeditee.items.Text;
    2018import org.expeditee.stats.SessionStats;
    2119
     
    3230        private StringBuilder _stringWriter = null;
    3331
    34         // keep track of methods that are put on the same line
    35         private static LinkedHashMap<String, Method> _ItemTags = null;
    36 
    37         private static LinkedHashMap<String, Method> _FrameTags = null;
    38 
    39         private static LinkedHashMap<String, Method> _BodyTags = null;
    40 
    4132        private static final char TERMINATOR = 'Z';
    4233
     
    4435
    4536        public KMSWriter() {
    46                 if (_ItemTags != null && _FrameTags != null)
    47                         return;
    48 
    49                 _ItemTags = new LinkedHashMap<String, Method>();
    50                 _FrameTags = new LinkedHashMap<String, Method>();
    51                 _BodyTags = new LinkedHashMap<String, Method>();
    52 
    53                 Class[] param = {};
    54 
    55                 try {
    56                         _FrameTags.put("A", Frame.class.getMethod("getFrameName", param));
    57                         _FrameTags.put("V", Frame.class.getMethod("getVersion", param));
    58                         _FrameTags.put("v", Frame.class
    59                                         .getMethod("getFormatVersion", param));
    60                         _FrameTags.put("p", Frame.class.getMethod("getProtection", param));
    61                         _FrameTags.put("U", Frame.class.getMethod("getOwner", param));
    62                         _FrameTags.put("D", Frame.class.getMethod("getDateCreated", param));
    63                         _FrameTags.put("M", Frame.class.getMethod("getLastModifyUser",
    64                                         param));
    65                         _FrameTags.put("d", Frame.class.getMethod("getLastModifyDate",
    66                                         param));
    67                         _FrameTags.put("F", Frame.class.getMethod("getFrozenDate", param));
    68 
    69                         _BodyTags.put("O", Frame.class.getMethod("getForegroundColor",
    70                                         param));
    71                         _BodyTags.put("B", Frame.class.getMethod("getBackgroundColor",
    72                                         param));
    73                         _BodyTags
    74                                         .put("v", Frame.class.getMethod("getFormatVersion", param));
    75 
    76                         _ItemTags.put("S", Item.class.getMethod("getID", param));
    77                         _ItemTags.put("s", Item.class.getMethod("getDateCreated", param));
    78                         _ItemTags.put("d", Item.class.getMethod("getColor", param));
    79                         _ItemTags.put("G", Item.class
    80                                         .getMethod("getBackgroundColor", param));
    81                         _ItemTags.put("P", Item.class.getMethod("getPosition", param));
    82                         _ItemTags.put("F", Item.class.getMethod("getLink", param));
    83                         _ItemTags.put("X", Item.class.getMethod("getAction", param));
    84                         _ItemTags.put("x", Item.class.getMethod("getActionMark", param));
    85                         _ItemTags.put("U", Item.class.getMethod("getActionCursorEnter",
    86                                         param));
    87                         _ItemTags.put("V", Item.class.getMethod("getActionCursorLeave",
    88                                         param));
    89                         _ItemTags.put("W", Item.class.getMethod("getActionEnterFrame",
    90                                         param));
    91                         _ItemTags.put("Y", Item.class.getMethod("getActionLeaveFrame",
    92                                         param));
    93                         _ItemTags.put("D", Item.class.getMethod("getData", param));
    94                         _ItemTags.put("u", Item.class.getMethod("getHighlight", param));
    95                         _ItemTags.put("e", Item.class.getMethod("getFillColor", param));
    96                         _ItemTags.put("i", Item.class.getMethod("getFillPattern", param));
    97                         _ItemTags.put("o", Item.class.getMethod("getOwner", param));
    98                         _ItemTags.put("n", Item.class.getMethod("getLinkMark", param));
    99                         _ItemTags.put("q", Item.class.getMethod("getLinkFrameset", param));
    100                         _ItemTags.put("y", Item.class.getMethod("getLinkTemplate", param));
    101                         _ItemTags.put("g", Item.class.getMethod("getLinePattern", param));
    102 
    103                         _ItemTags.put("j", Item.class.getMethod("getArrow", param));
    104 
    105                         _ItemTags.put("f", Text.class.getMethod("getFont", param));
    106                         _ItemTags.put("t", Text.class.getMethod("getSpacing", param));
    107                         _ItemTags.put("T", Text.class.getMethod("getText", param));
    108 
    109                         _ItemTags.put("a", Text.class.getMethod("getWordSpacing", param));
    110                         _ItemTags.put("b", Text.class.getMethod("getLetterSpacing", param));
    111                         _ItemTags
    112                                         .put("m", Text.class.getMethod("getInitialSpacing", param));
    113                         _ItemTags.put("w", Text.class.getMethod("getWidth", param));
    114                         _ItemTags.put("k", Text.class.getMethod("getJustification", param));
    115 
    116                         _ItemTags.put("h", Dot.class.getMethod("getThickness", param));
    117                         _ItemTags.put("l", Dot.class.getMethod("getLineIDs", param));
    118                         _ItemTags.put("c", Dot.class.getMethod("getConstraintIDs", param));
    119 
    120                         // Lines and constraints are created differently
    121                         /*
    122                          * _LineTags.put("L", Line.class.getMethod("getID", param));
    123                          * _LineTags.put("s", Line.class.getMethod("getLineEnds", param));
    124                          * _LineTags.put("g", Line.class.getMethod("getLinePattern",
    125                          * param));
    126                          *
    127                          * _ConstraintTags.put("C", Constraint.class.getMethod("getID",
    128                          * (Class[]) null)); _ConstraintTags.put("s",
    129                          * Constraint.class.getMethod("getLineEnds", (Class[]) null));
    130                          */
    131                 } catch (SecurityException e) {
    132                         // TODO Auto-generated catch block
    133                         e.printStackTrace();
    134                 } catch (NoSuchMethodException e) {
    135                         // TODO Auto-generated catch block
    136                         e.printStackTrace();
    137                 }
     37                super();
    13838        }
    13939
     
    15252                        _writer = new ProxyWriter(new FileWriter(_filename));
    15353
     54                try {
     55                        _ItemTags.put("S", Item.class.getMethod("getID", new Class[] {}));
     56                } catch (Exception e) {
     57
     58                }
    15459                // _writer = new BufferedWriter(new FileWriter(filepath.toLowerCase() +
    15560                // filename.toLowerCase()));
     
    17176
    17277                writeHeader(frame);
    173                 // writeBody(frame);
    17478
    17579                // write out each Item in the Frame.
     
    19296                Iterator<String> it = _FrameTags.keySet().iterator();
    19397                Object[] param = {};
     98
     99                // Write the version tag
     100                writeLine("v", "22");
    194101
    195102                while (it.hasNext()) {
     
    212119                        }
    213120                }
    214 
    215                 writeTerminator();
    216                 it = _BodyTags.keySet().iterator();
    217 
    218                 while (it.hasNext()) {
    219                         String tag = it.next();
    220                         try {
    221                                 Object o = _BodyTags.get(tag).invoke(toWrite, param);
    222                                 o = Conversion.ConvertToKMS(_BodyTags.get(tag), o);
    223                                 if (o != null) {
    224                                         writeLine(tag, (String) o);
    225                                 }
    226                         } catch (IllegalArgumentException e) {
    227                                 // TODO Auto-generated catch block
    228                                 e.printStackTrace();
    229                         } catch (IllegalAccessException e) {
    230                                 // TODO Auto-generated catch block
    231                                 e.printStackTrace();
    232                         } catch (InvocationTargetException e) {
    233                                 // TODO Auto-generated catch block
    234                                 e.printStackTrace();
    235                         }
    236                 }
    237121        }
    238122
     
    267151                        item = ((Picture) item).getText();
    268152
    269                 /*
    270                  * if(item instanceof Text) writeClass(item); else if(item instanceof
    271                  * Dot) writeDot((Dot) item);
    272                  */
    273153                if (item.getLines().size() > 0)
    274154                        writePoint(item);
    275155                else if (!(item instanceof Line))
    276156                        writeClass(item);
    277                 // lines are saved at the end of the file
    278                 /*
    279                  * else if (item instanceof Line) ;
    280                  */
    281157                else
    282158                        System.out.println("Unknown Item: " + item.getID());
     
    338214                                                if (_points.contains(c.getStart())
    339215                                                                && _points.contains(c.getEnd())) {
    340                                                         writeLine("C", c.getID() + " "
    341                                                                         + c.getType());
     216                                                        writeLine("C", c.getID() + " " + c.getType());
    342217                                                        writeLine("s", c.getLineEnds());
    343218                                                }
     
    348223                        // remove the point from the list
    349224                        _points.remove(0);
    350 
    351225                }
    352226        }
     
    354228        @Override
    355229        protected String finaliseFrame() throws IOException {
    356                 writeLine("" + DELIMITER + TERMINATOR + DELIMITER);
     230                writeTerminator();
    357231
    358232                writeLine(SessionStats.getFrameEventList());
     
    399273                        }
    400274                }
    401 
    402                 /*
    403                  * Method[] methods = toWrite.getClass().getMethods(); ArrayList<String>
    404                  * meths = new ArrayList<String>();
    405                  *
    406                  * for(Method m : methods) meths.add(m.getName());
    407                  *
    408                  * String start = _Tags.get("DelimiterStart"); String end =
    409                  * _Tags.get("DelimiterEnd");
    410                  *
    411                  * Iterator<String> it = _Tags.keySet().iterator();
    412                  *
    413                  * String term = null; LinkedList<Method> seen = new LinkedList<Method>();
    414                  *
    415                  * while(it.hasNext()){ String name = it.next(); String cName =
    416                  * className;
    417                  *
    418                  * if(writeSuper && name.startsWith(superName)) cName = superName;
    419                  *
    420                  * if(name.startsWith(cName)){ String tag = start + _Tags.get(name) +
    421                  * end; String output = "";
    422                  *
    423                  * //check for other methods that go on this line LinkedList<String>
    424                  * shared = _SharedLine.get(name); LinkedList<String> runMethods = new
    425                  * LinkedList<String>();
    426                  *
    427                  * if(shared != null) runMethods.addAll(shared);
    428                  *
    429                  * name = name.substring((cName + ".").length());
    430                  * runMethods.addFirst(name);
    431                  *
    432                  * //loop through all methods and concat their output Iterator
    433                  * methodIterator = runMethods.iterator();
    434                  *
    435                  * while(methodIterator.hasNext()){ name = "get" +
    436                  * methodIterator.next();
    437                  *
    438                  * int ind = meths.indexOf(name);
    439                  *
    440                  * if(ind >= 0){ Method m = methods[ind];
    441                  *
    442                  * if(!seen.contains(m)){ try { if(m.getParameterTypes().length == 0){
    443                  * Object val = m.invoke(toWrite, (Object[]) null);
    444                  *
    445                  * if(val instanceof List){ int count = 0; for(Object o : (List) val){
    446                  * if(count == 0) output += " " +
    447                  * KMSConversion.ConvertToKMS(name.substring(3), o); else output += "\n" +
    448                  * tag + " " + KMSConversion.ConvertToKMS(name.substring(3), o);
    449                  *
    450                  * count++; } }else{ String res =
    451                  * KMSConversion.ConvertToKMS(name.substring(3), val);
    452                  *
    453                  * if(res != null) output += " " + res; } } } catch (Exception e) {
    454                  * Logger.Log(e); }
    455                  *
    456                  * seen.add(m); } }else if(name.equals("getTerminator")){ term = start +
    457                  * _Tags.get(cName + ".Terminator") + end; }else System.out.println("No
    458                  * method found: " + cName + "." + name); }
    459                  *
    460                  * if(output.length() > 0) writeLine(tag + output); } } if(term != null)
    461                  * writeLine(term);
    462                  */
    463         }
    464 
    465         /*
    466          * private void writeBody(Object toWrite) throws IOException{
    467          * writeClass(toWrite, "Body", " ", false); }
    468          */
     275        }
    469276
    470277        /**
  • trunk/src/org/expeditee/items/Dot.java

    r50 r67  
    302302        public void anchor() {
    303303                super.anchor();
    304                 Frame current = getCurrentFrame();
     304                Frame current = getParentOrCurrentFrame();
    305305                for (Line line : getLines()) {
    306306                        if (line.getID() < 0 && !current.getItems().contains(line)) {
  • trunk/src/org/expeditee/items/Item.java

    r58 r67  
    399399                // if its a relative link then return absolute
    400400                if (FrameIO.isPositiveInteger(link)) {
    401                         return _parent.getFramesetName() + Conversion.getFrameNumber(link);
     401                        return _parent.getFramesetName() + link;
    402402                }
    403403                return link;
     
    14571457
    14581458        public void anchor() {
    1459                 Frame current = getCurrentFrame();
     1459                Frame current = getParentOrCurrentFrame();
    14601460                setID(current.getNextItemID());
    14611461                setOffset(0, 0);
     
    14741474         * @return
    14751475         */
    1476         public Frame getCurrentFrame() {
     1476        public Frame getParentOrCurrentFrame() {
    14771477                // if the item is from an overlay the parent will NOT be null
    14781478                if (getParent() == null) {
Note: See TracChangeset for help on using the changeset viewer.