Changeset 67
- Timestamp:
- 05/19/08 12:03:18 (16 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/.classpath
r62 r67 2 2 <classpath> 3 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="src" path="tests"/> 4 5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 5 6 <classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/> -
trunk/src/org/expeditee/actions/NavigationActions.java
r65 r67 117 117 118 118 public static void NextFrame(boolean addToBack) { 119 addToBack = adjustAddToBack(addToBack); 119 120 Frame next = FrameIO.LoadNext(); 120 FrameUtils.DisplayFrame(next, true);121 FrameUtils.DisplayFrame(next, addToBack); 121 122 } 122 123 … … 145 146 146 147 public static void PreviousFrame(boolean addToBack) { 148 addToBack = adjustAddToBack(addToBack); 147 149 Frame prev = FrameIO.LoadPrevious(); 148 150 FrameUtils.DisplayFrame(prev, addToBack); … … 213 215 // ByMike: Find the first occurence of a ParentItem linked to the source 214 216 while (parentItemLinkedToSource < items.size() 215 && (items.get(parentItemLinkedToSource).get Link() == null || !items216 .get(parentItemLinkedToSource).get Link().toLowerCase()217 && (items.get(parentItemLinkedToSource).getAbsoluteLink() == null || !items 218 .get(parentItemLinkedToSource).getAbsoluteLink().toLowerCase() 217 219 .equals(sourceName))) { 218 220 parentItemLinkedToSource++; // ByRob: this increments to the next … … 224 226 if (items.get(i).isLinkValid() 225 227 && !items.get(i).isAnnotation() 226 && !items.get(i).get Link().toLowerCase().equals(228 && !items.get(i).getAbsoluteLink().toLowerCase().equals( 227 229 source.getFrameName().toLowerCase())) { 228 230 _LastItemUsed = items.get(i); … … 250 252 DisplayIO.ToggleTwinFrames(); 251 253 } 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 } 252 279 } -
trunk/src/org/expeditee/actions/Simple.java
r64 r67 1977 1977 1978 1978 item.setPosition(newX, newY); 1979 DisplayIO.repaint();1979 FrameGraphics.Repaint(); 1980 1980 } 1981 1981 // Thread.yield(); … … 2037 2037 return Status.OK; 2038 2038 } else if (tokens[0].equals("repaint")) { 2039 DisplayIO.repaint();2039 FrameGraphics.Repaint(); 2040 2040 return Status.OK; 2041 2041 } -
trunk/src/org/expeditee/gui/AttributeUtils.java
r50 r67 587 587 * The String to strip 588 588 * @return The part of the String that is after a colon if there is one, or 589 * nullif there is no colon589 * the entire string if there is no colon 590 590 */ 591 591 public static String stripValue(String toStrip) { 592 592 int ind = toStrip.lastIndexOf(SEPARATOR_CHAR); 593 593 if (ind < 0) 594 return null;594 return toStrip; 595 595 596 596 toStrip = toStrip.substring(ind + 1); -
trunk/src/org/expeditee/gui/Browser.java
r50 r67 31 31 public class Browser extends JFrame implements ComponentListener, 32 32 WindowListener, WindowStateListener { 33 33 34 34 /** 35 35 * Default version - just to stop eclipse from complaining about it. … … 40 40 41 41 public static Browser _theBrowser; 42 42 43 43 /** 44 44 * Constructs a new Browser object, then launches it … … 49 49 _theBrowser = new Browser(); 50 50 // Why do we want to ignore repaint? 51 // b.setIgnoreRepaint(true);51 //_theBrowser.setIgnoreRepaint(true); 52 52 _theBrowser.requestFocus(); 53 53 // FrameGraphics.ForceRepaint(); 54 54 } 55 55 56 56 public void setSizes(Dimension size) { 57 57 setSize(size); 58 58 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)); 62 67 // center the frame on the screen 63 68 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 64 69 double xpos = screen.getWidth() / 2; 65 70 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); 76 76 77 77 UserSettings.Init(); 78 UserSettings.Username = FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")); 78 UserSettings.Username = FrameIO.ConvertToValidFramesetName(System 79 .getProperty("user.name")); 79 80 String userName = UserSettings.Username; 80 81 Frame profile = FrameIO.LoadProfile(userName); … … 83 84 profile = FrameIO.CreateNewProfile(userName); 84 85 } 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 86 88 e.printStackTrace(); 87 assert (false);89 assert (false); 88 90 } 89 91 } … … 95 97 UserSettings.InitialHeight)); 96 98 97 // set the layout to absolute layout for widgets99 // set the layout to absolute layout for widgets 98 100 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())); 101 105 this.getGlassPane().setVisible(true); 102 106 this.getContentPane().setBackground(Color.white); 103 107 this.getContentPane().setFocusTraversalKeysEnabled(false); 104 108 105 109 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 106 110 … … 147 151 private void setupGraphics() { 148 152 g = (Graphics2D) this.getContentPane().getGraphics(); 149 assert g != null;153 assert (g != null); 150 154 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 151 155 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); … … 154 158 } 155 159 160 // private int count = 0; 156 161 @Override 157 162 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 158 166 super.paint(g); 159 167 FrameGraphics.Repaint(); 168 //System.out.println("Paint " + count++); 160 169 } 161 170 … … 166 175 setSizes(this.getSize()); 167 176 setupGraphics(); 168 repaint(); 177 FrameIO.RefreshCasheImages(); 178 FrameGraphics.Repaint(); 169 179 } 170 180 … … 211 221 } 212 222 213 /*214 * public void windowGainedFocus(WindowEvent e) { FrameGraphics.Repaint(); }215 *216 * public void windowLostFocus(WindowEvent e) { //FrameGraphics.Repaint(); }217 */218 223 public void windowStateChanged(WindowEvent e) { 219 // FrameGraphics.Repaint();220 // System.out.println('C');224 // FrameGraphics.Repaint(); 225 // System.out.println('C'); 221 226 } 222 227 -
trunk/src/org/expeditee/gui/DisplayIO.java
r58 r67 15 15 import javax.swing.JOptionPane; 16 16 17 import org.expeditee.actions.NavigationActions; 17 18 import org.expeditee.items.Item; 18 19 import org.expeditee.items.ItemParentStateChangedEvent; … … 54 55 private static Robot _Robot; 55 56 56 // public static JMenuBar _MenuBar = new JMenuBar();57 58 57 private static boolean _TwinFrames = false; 59 58 … … 61 60 * The title to display in the Title bar. 62 61 */ 63 public static final String TITLE = "Exp1 6May2008A";62 public static final String TITLE = "Exp17May2008A"; 64 63 65 64 private DisplayIO() { … … 114 113 } 115 114 116 /*117 * System.out.println("hs: " + hotspotPos + " start: " + start + " font: " +118 * size + " cursor: " + (cursorSize - start));119 */120 121 115 int[] pixels = new int[cursorSize * cursorSize]; 122 116 … … 229 223 230 224 /** 231 * Forces a complete repaint of the GUI and Frame232 */233 public static void repaint() {234 _Browser.repaint();235 }236 237 /**238 225 * Returns the top item (last added) of the Back-Stack (which is popped off) 239 226 * … … 519 506 520 507 /** 521 * Adds the given JMenu to the JMenuBar of the GUI522 *523 * @param menu524 * The menu to add525 */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 at535 * the given index in the Menu at the given index.536 *537 * @param menu538 * The index of the menu (starts from 0)539 * @param index540 * The index of the Item to simulate a click on (starts from 0)541 */542 /*543 * public static void activateMenuItem(int menu, int index) { if544 * (_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) return553 * 21;554 *555 * return _MenuBar.getHeight() - 5; }556 */557 558 /**559 508 * Returns the current mouse X coordinate. This coordinate is relative to 560 509 * the left edge of the frame the mouse is in. It takes into account the … … 589 538 590 539 public static void Back() { 540 NavigationActions.ResetLastAddToBack(); 541 591 542 int side = getCurrentSide(); 592 543 -
trunk/src/org/expeditee/gui/Frame.java
r56 r67 41 41 42 42 // The various attributes of this Frame 43 /**44 * TODO: Change these to non-string attributes (where applicable). All45 * processing to\from Java types should be done in KMSReader and KMSWriter.46 */47 43 private String _frameset = null; 48 44 49 45 private int _number = -1; 50 46 51 private int _version = 1; 52 53 private int _fversion = -1; 47 private int _version = 0; 54 48 55 49 private String _protection = null; … … 90 84 91 85 public static List<Item> FreeItems = new ArrayList<Item>(); 92 86 93 87 // for drawing purposes 94 88 private List<InteractiveWidget> _iWidgets = new ArrayList<InteractiveWidget>(); … … 101 95 private Text _frameName = null; 102 96 103 // private Text _template = UserSettings.ItemTemplate.copy();104 105 97 private List<Overlay> _overlays = new ArrayList<Overlay>(); 106 98 … … 122 114 public void setBuffer(VolatileImage newBuffer) { 123 115 _buffer = newBuffer; 124 // setBufferValid(true);125 116 } 126 117 127 118 public boolean isBufferValid() { 128 if (_buffer != null &&_buffer.contentsLost())119 if (_buffer == null || _buffer.contentsLost()) 129 120 return false; 130 121 … … 132 123 } 133 124 134 p ublicvoid setBufferValid(boolean newValue) {125 private void setBufferValid(boolean newValue) { 135 126 _validBuffer = newValue; 136 127 } … … 147 138 i.setID(++_lineCount); 148 139 } 149 140 150 141 /** 151 142 * 152 143 * @return The interactive widgets that are currently ancored in this frame. 153 * Hence it exlcudes free-widgets. Returns a copy144 * Hence it exlcudes free-widgets. Returns a copy 154 145 */ 155 146 public List<InteractiveWidget> getInteractiveWidgets() { … … 181 172 _change = value; 182 173 183 if (_change) {174 if (_change) { 184 175 setBufferValid(false); 185 176 _saved = false; … … 204 195 _sorted = true; 205 196 } 206 197 207 198 List<Item> visibleItems = new ArrayList<Item>(); 208 209 for (Item i: _body) {199 200 for (Item i : _body) { 210 201 if (i.isVisible()) 211 202 visibleItems.add(i); 212 203 } 213 204 214 205 return visibleItems; 215 206 } 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 219 211 * @return True if this frame contains i. 220 212 */ 221 213 public boolean containsItem(Item i) { 222 if (i == null) throw new NullPointerException("i"); 214 if (i == null) 215 throw new NullPointerException("i"); 223 216 return _body.contains(i); 224 217 } … … 234 227 for (Item i : getItems()) { 235 228 // 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())) { 238 231 bodyTextItems.add((Text) i); 239 232 } … … 241 234 bodyTextItems.remove(getTitle()); 242 235 243 return bodyTextItems; 236 return bodyTextItems; 244 237 } 245 238 … … 316 309 frameTitle.stripFirstWord(); 317 310 } 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))) { 321 316 frameTitle.stripFirstWord(); 322 317 } … … 425 420 426 421 for (Item i : _body) 427 if (i.isVisible() /* && i != _frameName*/&& i.intersects(poly)) {422 if (i.isVisible() /* && i != _frameName */&& i.intersects(poly)) { 428 423 if (!results.contains(i)) 429 424 results.add(i); … … 462 457 */ 463 458 public void setFrameNumber(int number) { 459 assert (number >= 0); 460 461 if (_number == number) 462 return; 463 464 464 _number = number; 465 465 boolean oldchange = _change; … … 469 469 if (_frameName != null) { 470 470 id = _frameName.getID(); 471 } else {471 } else { 472 472 id = -1 * getNextItemID(); 473 473 } … … 493 493 494 494 /** 495 * Sets the version of this Frame to the given String.495 * Increments the version of this Frame to the given String. 496 496 * 497 497 * @param version … … 500 500 public void setVersion(int version) { 501 501 _version = version; 502 }503 504 /**505 * Sets the format version of this Frame to the given String.506 *507 * @param version508 * The format version to use for this Frame.509 */510 public void setFormatVersion(int version) {511 _fversion = version;512 502 } 513 503 … … 593 583 if (item != null) { 594 584 if (_body.contains(item)) { 595 // System.out.println("Item (" + item.getClass().getSimpleName()596 // 585 // System.out.println("Item (" + item.getClass().getSimpleName() 586 // + ") with ID " + item.getID() + " already in body."); 597 587 return; 598 588 } … … 600 590 if (item instanceof Line) 601 591 _lineCount++; 602 592 603 593 _itemCount = Math.max(_itemCount, item.getID()); 604 594 … … 609 599 610 600 item.setMaxSize(FrameGraphics.getMaxFrameSize()); 611 // add widget items to the list of widgets601 // add widget items to the list of widgets 612 602 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); 616 607 } 617 608 } 618 619 item.onParentStateChanged(new ItemParentStateChangedEvent( 620 this,ItemParentStateChangedEvent.EVENT_TYPE_ADDED));609 610 item.onParentStateChanged(new ItemParentStateChangedEvent(this, 611 ItemParentStateChangedEvent.EVENT_TYPE_ADDED)); 621 612 622 613 change(); … … 648 639 649 640 public void removeItem(Item item) { 650 if (_body.remove(item)) 641 if (_body.remove(item)) { 651 642 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 } 662 652 } 663 653 … … 760 750 * @return The version of this Frame. 761 751 */ 752 public int getVersion(boolean increment) { 753 // System.out.println("Version: " + _version); 754 if (increment) 755 _version++; 756 return _version; 757 } 758 762 759 public int getVersion() { 763 return _version; 764 } 765 766 public int getFormatVersion() { 767 return _fversion; 760 return getVersion(true); 768 761 } 769 762 … … 843 836 s += "Name: " + _frameset + _number + "\n"; 844 837 s += "Version: " + _version + "\n"; 845 s += "Format Version: " + _fversion + "\n";846 838 s += "Protection: " + _protection + "\n"; 847 839 s += "Owner: " + _owner + "\n"; … … 935 927 * @param overlay 936 928 * The Frame to add 937 * 929 * 938 930 * @throws NullPointerException 939 * If overlay is null.931 * If overlay is null. 940 932 */ 941 933 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 945 943 _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... 948 947 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>()); 950 950 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, 954 953 overlay.Level)); 955 954 } … … 957 956 958 957 /** 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. 960 960 * 961 961 * @param overlay 962 962 * The overlay to remove 963 * 963 * 964 964 * @throws NullPointerException 965 * If overlay is null.965 * If overlay is null. 966 966 */ 967 967 public void removeOverlay(Overlay overlay) { 968 if (overlay == null) throw new NullPointerException("overlay"); 969 968 if (overlay == null) 969 throw new NullPointerException("overlay"); 970 970 971 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... 973 975 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>()); 975 978 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, 979 981 overlay.Level)); 980 982 } 981 983 } 982 983 /** 984 * Removes the given Frame from the list of overlayed Frames being drawn with985 * this Frame.984 985 /** 986 * Removes the given Frame from the list of overlayed Frames being drawn 987 * with this Frame. 986 988 * 987 989 * @param overlayedFrame 988 990 * The Frame to remove 989 * 991 * 990 992 * @throws NullPointerException 991 * If overlayedFrame is null.993 * If overlayedFrame is null. 992 994 */ 993 995 public void removeOverlay(Frame overlayedFrame) { 994 if (overlayedFrame == null) throw new NullPointerException("overlay"); 995 996 if (overlayedFrame == null) 997 throw new NullPointerException("overlay"); 998 996 999 // Locate the oveylay(s) that match this 997 1000 List<Overlay> overlaysToRemove = new LinkedList<Overlay>(); 998 1001 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... 1002 1007 removeOverlay(o); 1003 1008 } 1004 1009 1005 1010 } 1006 1011 … … 1010 1015 return l; 1011 1016 } 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). 1015 1021 */ 1016 1022 public List<Overlay> getOverlaysDeep() { … … 1019 1025 return l; 1020 1026 } 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 1038 1045 /** 1039 1046 * 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. 1042 1052 */ 1043 1053 public Overlay getOverlayOwner(Item item) { 1044 if (item == null) throw new NullPointerException("item"); 1054 if (item == null) 1055 throw new NullPointerException("item"); 1045 1056 List<Overlay> overlays = getOverlaysDeep(); 1046 1057 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 1051 1063 return null; 1052 1064 } … … 1089 1101 List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems()); 1090 1102 copies.remove(toMergeWith.getFrameNameItem()); 1091 1103 1092 1104 for (Item i : copies) { 1093 1105 if (i.getID() >= 0) { … … 1143 1155 /** 1144 1156 * Creates a new text item with the given text. 1157 * 1145 1158 * @param text 1146 1159 * @return -
trunk/src/org/expeditee/gui/FrameGraphics.java
r48 r67 59 59 public static final int MODE_XRAY = 2; 60 60 61 public static final Color ERROR_COLOR = Color.red; 62 61 63 private static int _Mode = MODE_NORMAL; 62 64 … … 64 66 private static boolean _SupressErrors = false; 65 67 68 public static String MESSAGES_FRAMESET_NAME = "Messages"; 66 69 // 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); 74 71 75 72 // creator for creating the message frames 76 73 private static FrameCreator _creator; 77 78 /**79 * Returns the Graphics2D object currently being used to draw with, this may80 * 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 }87 74 88 75 /** … … 154 141 MESSAGE_LINK_X); 155 142 156 Repaint();143 //Repaint(); 157 144 } 158 145 … … 471 458 */ 472 459 public static void Repaint() { 460 //Thread.dumpStack(); 473 461 if (_DisplayGraphics == null) 474 462 return; … … 627 615 // if the creator needs to be initialised (happens on first message) 628 616 if (_creator == null) { 629 _creator = new FrameCreator( "Messages", true);617 _creator = new FrameCreator(MESSAGES_FRAMESET_NAME, true); 630 618 631 619 // set up 'Messages' link on the right hand side … … 699 687 if (tokens.length > 1) 700 688 link = tokens[tokens.length - 1]; 701 displayMessage(message, link, Color.RED);689 displayMessage(message, link, ERROR_COLOR); 702 690 } 703 691 … … 706 694 return; 707 695 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); 744 697 } 745 698 -
trunk/src/org/expeditee/gui/FrameIO.java
r64 r67 548 548 } 549 549 550 public static void RefreshCasheImages() { 551 SuspendCache(); 552 for (Frame f : _Cache.values()) 553 f.setBuffer(null); 554 ResumeCache(); 555 } 556 550 557 /** 551 558 * Creates a new frameset using the given name. This includes creating a new … … 603 610 } 604 611 612 public static String SaveFrame(Frame toSave, boolean inc) { 613 return SaveFrame(toSave, inc, true); 614 } 615 605 616 /** 606 617 * Saves the given Frame to disk in the corresponding frameset directory, if … … 613 624 * True if the saved frames counter should be incremented, false 614 625 * 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) { 617 631 618 632 if (toSave == null) … … 630 644 .getFrameName()); 631 645 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 632 653 FrameWriter writer = null; 654 int savedVersion; 633 655 try { 634 656 // if its a new frame or an existing Exp frame... 635 657 if (fullPath == null || fullPath.endsWith(ExpReader.EXTENTION)) { 636 658 writer = new ExpWriter(); 659 savedVersion = ExpReader.getVersion(fullPath); 637 660 } else { 638 661 writer = new KMSWriter(); 662 savedVersion = KMSReader.getVersion(fullPath); 639 663 } 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 642 692 && ItemUtils.ContainsTag(toSave.getItems(), 643 693 ItemUtils.TAG_BACKUP)) { … … 649 699 int nextnum = ReadINF(toSave.path, toSave.getFramesetName()) + 1; 650 700 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); 653 706 654 707 Item i = ItemUtils.FindTag(toSave.getItems(), … … 657 710 toSave.setFrameNumber(orignum); 658 711 ResumeCache(); 659 } else if (toSave.getFrameNumber() < 0) {660 toSave.setFrameNumber(-toSave.getFrameNumber());661 712 } 662 713 … … 1000 1051 int copyNumber = 1; 1001 1052 File dest = new File(destPath + File.separator); 1002 // Create the trash folder if it doesnt already exist1053 // Create the trash folder if it doesnt already exist 1003 1054 if (!dest.getParentFile().exists()) 1004 1055 dest.mkdirs(); … … 1006 1057 // a number to the end 1007 1058 while (dest.exists()) { 1008 dest = new File(destPath + ++copyNumber + File.separator 1059 dest = new File(destPath + ++copyNumber + File.separator); 1009 1060 } 1010 1061 return framesetDirectory.renameTo(dest); -
trunk/src/org/expeditee/gui/FrameKeyboardActions.java
r65 r67 17 17 import org.expeditee.actions.Simple; 18 18 import org.expeditee.io.Logger; 19 import org.expeditee.items.Constraint;20 19 import org.expeditee.items.Dot; 21 20 import org.expeditee.items.Item; -
trunk/src/org/expeditee/gui/FrameMouseActions.java
r58 r67 1 1 package org.expeditee.gui; 2 2 3 import java.awt.Point; 3 4 import java.awt.event.ActionEvent; 4 5 import java.awt.event.ActionListener; … … 261 262 // pre-cache the frame if it is linked 262 263 if (on != null && on.getLink() != null && on.isLinkValid()) { 263 FrameIO.Precache(on.get Link());264 FrameIO.Precache(on.getAbsoluteLink()); 264 265 } 265 266 … … 739 740 .getPosition(), false); 740 741 pickup(newPoint); 741 ItemUtils.EnclosedCheck(toDisconnect.getCurrentFrame().getItems()); 742 ItemUtils.EnclosedCheck(toDisconnect 743 .getParentOrCurrentFrame().getItems()); 742 744 return; 743 745 } … … 913 915 914 916 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 915 935 pickup(copy(toCopy)); 936 //Remove the rectangle 916 937 DisplayIO.getCurrentFrame().removeAllItems( 917 938 d.getAllConnected()); 918 939 } else { 940 //Pick up a copy of the rectangle 919 941 pickup(copy(d.getAllConnected())); 920 942 } … … 1443 1465 setTdfcItem(linker); 1444 1466 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 } 1450 1476 } 1451 1477 … … 1594 1620 // reset the mouse cursor 1595 1621 updateCursor(); 1596 FrameGraphics.Repaint();1597 1598 1622 ItemUtils.EnclosedCheck(current.getItems()); 1599 1623 FrameGraphics.Repaint(); … … 1604 1628 1605 1629 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 1607 1638 List<Item> toUndo = new LinkedList<Item>(); 1608 1639 List<Item> seen = new LinkedList<Item>(); 1609 1610 // Mike: Removed code that checked for rectangles and removed them1611 // completely!!1612 1640 1613 1641 // disconnect any connected items … … 1623 1651 toUndo.addAll(copy(i)); 1624 1652 } 1625 1626 1653 seen.add(i); 1627 1654 } 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); 1649 1662 itemList.clear(); 1650 1663 } … … 1964 1977 1965 1978 FrameGraphics.Repaint(); 1966 ItemUtils.EnclosedCheck(toAnchor.get CurrentFrame().getItems());1979 ItemUtils.EnclosedCheck(toAnchor.getParentOrCurrentFrame().getItems()); 1967 1980 } 1968 1981 -
trunk/src/org/expeditee/gui/FrameUtils.java
r50 r67 302 302 return true; 303 303 } 304 304 305 305 /** 306 306 * Displays the given Frame on the display. If the current frame has changed … … 318 318 if (toDisplay == null) 319 319 return; 320 320 321 321 Frame current = DisplayIO.getCurrentFrame(); 322 322 … … 613 613 } 614 614 } 615 return new Color[] {Color.black, Color.white};615 return new Color[] { Color.black, Color.white }; 616 616 } 617 617 … … 1257 1257 for (File helpFrameset : helpFramesets) { 1258 1258 String framesetName = helpFrameset.getName(); 1259 Frame indexFrame = FrameIO.LoadFrame(framesetName + '1');1259 Frame indexFrame = FrameIO.LoadFrame(framesetName + '1'); 1260 1260 // Look through the folder for help index pages 1261 1261 if (indexFrame != null -
trunk/src/org/expeditee/gui/MouseEventRouter.java
r41 r67 95 95 forwardToExpiditee = true; 96 96 } else if (DisplayIO.getCurrentFrame() != null) { // is mouse over 97 98 99 97 // a specific 98 // expeditee 99 // item? 100 100 // NOTE: Do not use FrameUtils.getCurrentItem() - thats relevent 101 101 // for old mouse position only … … 110 110 .getCurrentFrame(), containerPoint.x, containerPoint.y) != null); 111 111 } 112 112 113 113 if (forwardToExpiditee) { 114 114 … … 125 125 MouseEvent expediteeEvent = SwingUtilities.convertMouseEvent(e 126 126 .getComponent(), e, _contentPane); 127 127 128 128 switch (e.getID()) { 129 129 case MouseEvent.MOUSE_MOVED: … … 131 131 132 132 // 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 } 136 139 } 137 140 -
trunk/src/org/expeditee/io/Conversion.java
r4 r67 10 10 import java.util.StringTokenizer; 11 11 12 import org.expeditee.gui.DisplayIO;13 12 import org.expeditee.items.Item; 14 13 import org.expeditee.items.Text; … … 48 47 } 49 48 49 // check if its a normal rgb code ie. 100 0 40 50 50 Color rgb = getRGBColor(colorCode, current); 51 51 if (rgb != null) … … 58 58 char c = colorCode.charAt(last); 59 59 60 while ( c >= '0' && c <= '9') {60 while (Character.isDigit(c)) { 61 61 num = c + num; 62 62 if (last <= 0) … … 69 69 if (num.length() > 0) 70 70 amount = Float.parseFloat(num); 71 72 if(amount > 10) 73 amount = 10; 71 74 72 75 float color[] = { 0, 0, 0 }; … … 74 77 if (colorCode.toLowerCase().startsWith("red")) 75 78 color[0] = amount / 10; 76 77 if (colorCode.toLowerCase().startsWith("green")) 79 else if (colorCode.toLowerCase().startsWith("green")) 78 80 color[1] = amount / 10; 79 80 if (colorCode.toLowerCase().startsWith("blue")) 81 else if (colorCode.toLowerCase().startsWith("blue")) 81 82 color[2] = amount / 10; 83 else 84 return current; 82 85 83 86 return new Color(color[0], color[1], color[2]); … … 88 91 89 92 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"; 97 98 98 99 if (current != null && (r.startsWith("+") || r.startsWith("-"))) { … … 125 126 return new Color(color[0], color[1], color[2]); 126 127 } catch (Exception e) { 127 return current;128 return null; 128 129 } 129 130 } … … 200 201 String code = "t"; 201 202 String fontName = font.getFamily().toLowerCase(); 202 203 203 204 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)) { 205 206 code = "" + Text.FONT_CHARS[i]; 206 207 break; 207 208 } 208 209 } 209 210 210 211 switch (font.getStyle()) { 211 212 case Font.BOLD: … … 297 298 */ 298 299 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 } 301 312 302 313 try { … … 309 320 /** 310 321 * Returns the frameset poriton of the given Frame name (frame number 311 * removed) 322 * removed) converted to lower case. 312 323 * 313 324 * @param frame … … 319 330 } 320 331 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 } 327 343 } 328 344 … … 343 359 */ 344 360 public static int getJustification(String justCode) { 361 assert (justCode != null); 362 justCode = justCode.trim().toLowerCase(); 345 363 // as read from file 346 364 if (justCode.length() == 1) { 347 365 switch (justCode.charAt(0)) { 348 case ' F':366 case 'f': 349 367 return Item.JUSTIFICATION_FULL; 350 case ' L':368 case 'l': 351 369 return Item.JUSTIFICATION_LEFT; 352 case ' R':370 case 'r': 353 371 return Item.JUSTIFICATION_RIGHT; 354 case ' C':372 case 'c': 355 373 return Item.JUSTIFICATION_CENTER; 356 374 } … … 358 376 359 377 // from the user 360 justCode = justCode.trim().toLowerCase();361 378 if (justCode.equals("center")) 362 379 return Item.JUSTIFICATION_CENTER; … … 395 412 public static Object Convert(Class type, String value, Object orig) { 396 413 // System.out.println("Orig: " + orig); 414 assert (value != null); 415 value = value.trim(); 397 416 398 417 if (type == String.class … … 401 420 else if (type == String.class) 402 421 return value; 403 404 /*405 * if(type == int.class || type == Integer.class){ return406 * Integer.parseInt(value); }407 *408 * if(type == float.class || type == Float.class){ return409 * Float.parseFloat(value); }410 */411 422 412 423 if (type == Font.class) { … … 510 521 511 522 public static Object[] Convert(Method method, String value, Object current) { 523 value = value.trim(); 512 524 513 525 String name = method.getName(); -
trunk/src/org/expeditee/io/DefaultFrameWriter.java
r4 r67 4 4 import java.io.FileWriter; 5 5 import java.io.IOException; 6 import java.lang.reflect.Method; 7 import java.util.LinkedHashMap; 6 8 7 9 import org.expeditee.gui.Frame; 8 10 import org.expeditee.gui.FrameIO; 9 11 import org.expeditee.items.Item; 12 import org.expeditee.items.Text; 10 13 11 14 public abstract class DefaultFrameWriter extends ItemWriter implements … … 23 26 24 27 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 } 25 107 26 108 public void setOutputLocation(String filename) { … … 125 207 return "Not Supported"; 126 208 } 209 127 210 } -
trunk/src/org/expeditee/io/ExpReader.java
r50 r67 1 1 package org.expeditee.io; 2 2 3 import java.awt.Color;4 import java.awt.Font;5 import java.awt.Point;6 3 import java.io.BufferedReader; 7 4 import java.io.FileReader; … … 9 6 import java.lang.reflect.Method; 10 7 import java.util.HashMap; 11 import java.util.LinkedHashMap;12 import java.util.List;13 8 14 9 import org.expeditee.gui.Frame; … … 26 21 * 27 22 */ 28 public class ExpReader implements FrameReader {23 public class ExpReader extends FrameReader { 29 24 30 25 public static final String EXTENTION = ".exp"; … … 32 27 private BufferedReader _reader = null; 33 28 34 private static LinkedHashMap<Character, Method> _ItemTags = null;35 36 private static LinkedHashMap<Character, Method> _FrameTags = null;37 38 29 private String _frameName; 39 30 … … 42 33 */ 43 34 public ExpReader(String frameName) { 35 super(); 36 44 37 _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 _FrameTags67 .put('p', Frame.class.getMethod("setProtection", pString));68 _FrameTags.put('U', Frame.class.getMethod("setOwner", pString));69 _FrameTags.put('D', Frame.class70 .getMethod("setDateCreated", pString));71 _FrameTags.put('M', Frame.class.getMethod("setLastModifyUser",72 pString));73 _FrameTags.put('d', Frame.class.getMethod("setLastModifyDate",74 pString));75 _FrameTags76 .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 _ItemTags107 .put('q', Item.class.getMethod("setLinkFrameset", pString));108 _ItemTags109 .put('y', Item.class.getMethod("setLinkTemplate", pString));110 _ItemTags.put('g', Item.class111 .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.class128 .getMethod("setConstraintIDs", pString));129 130 // Lines and constraints are created differently131 _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 }137 38 } 138 39 … … 144 45 * @return true if s begins with a KMS tag 145 46 */ 146 private boolean isValidLine(String s) {47 private static boolean isValidLine(String s) { 147 48 return s.length() >= 2 && s.charAt(1) == ' ' 148 49 && Character.isLetter(s.charAt(0)); … … 280 181 } 281 182 282 private Character getTag(String line) {183 private static Character getTag(String line) { 283 184 assert (line.length() > 0); 284 185 return line.charAt(0); 285 186 } 286 187 287 private String getValue(String line) {188 private static String getValue(String line) { 288 189 if (line.length() > 2) 289 190 return line.substring(2); … … 309 210 310 211 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 } 313 216 return; 314 217 } … … 331 234 return new java.awt.Point(x, y); 332 235 } 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 } 333 254 } -
trunk/src/org/expeditee/io/ExpWriter.java
r58 r67 1 1 package org.expeditee.io; 2 2 3 import java.awt.Rectangle;4 3 import java.io.File; 5 4 import java.io.FileWriter; … … 7 6 import java.lang.reflect.Method; 8 7 import java.util.Iterator; 9 import java.util.LinkedHashMap;10 8 import java.util.LinkedList; 11 9 import java.util.List; … … 17 15 import org.expeditee.items.Line; 18 16 import org.expeditee.items.Picture; 19 import org.expeditee.items.Text;20 17 import org.expeditee.items.WidgetCorner; 21 18 import org.expeditee.items.WidgetEdge; … … 34 31 private StringBuilder _stringWriter = null; 35 32 36 // keep track of methods that are put on the same line37 private static LinkedHashMap<String, Method> _ItemTags = null;38 39 private static LinkedHashMap<String, Method> _FrameTags = null;40 41 33 private static final char TERMINATOR = 'Z'; 42 34 43 35 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(); 115 37 } 116 38 … … 128 50 } else 129 51 _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 } 130 58 } 131 59 … … 225 153 // Dont save the item if it is off the screen 226 154 if (item.offScreen()) { 227 System.out.println("item offscreen!");155 //System.out.println("item offscreen!"); 228 156 return; 229 157 } -
trunk/src/org/expeditee/io/FrameReader.java
r4 r67 1 1 package org.expeditee.io; 2 2 3 import java.awt.Color; 4 import java.awt.Font; 5 import java.awt.Point; 3 6 import java.io.IOException; 7 import java.lang.reflect.Method; 8 import java.util.LinkedHashMap; 9 import java.util.List; 4 10 5 11 import org.expeditee.gui.Frame; 12 import org.expeditee.items.Constraint; 13 import org.expeditee.items.Item; 14 import org.expeditee.items.Line; 15 import org.expeditee.items.Text; 6 16 7 public interface FrameReader { 17 public abstract class FrameReader { 18 protected static LinkedHashMap<Character, Method> _ItemTags = null; 8 19 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; 11 118 } -
trunk/src/org/expeditee/io/KMSReader.java
r4 r67 1 1 package org.expeditee.io; 2 2 3 import java.awt.Color;4 import java.awt.Font;5 import java.awt.Point;6 3 import java.io.BufferedReader; 7 4 import java.io.FileReader; … … 13 10 import java.util.Iterator; 14 11 import java.util.LinkedHashMap; 15 import java.util.List;16 12 17 13 import org.expeditee.gui.Frame; … … 30 26 * 31 27 */ 32 public class KMSReader implements FrameReader {28 public class KMSReader extends FrameReader { 33 29 34 30 private BufferedReader _reader = null; … … 48 44 _FrameTags = new LinkedHashMap<String, Method>(); 49 45 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 62 46 try { 63 47 _FrameTags.put("A", Frame.class.getMethod("setFrameName", pString)); 64 48 _FrameTags.put("V", Frame.class.getMethod("setVersion", pInt)); 65 _FrameTags66 .put("v", Frame.class.getMethod("setFormatVersion", pInt));67 49 _FrameTags 68 50 .put("p", Frame.class.getMethod("setProtection", pString)); … … 152 134 * @return true if s begins with a KMS tag 153 135 */ 154 private boolean isValidLine(String s) {136 private static boolean isValidLine(String s) { 155 137 return s.length() >= 3 && s.charAt(0) == '+' && s.charAt(2) == '+' 156 138 && Character.isLetter(s.charAt(1)); … … 332 314 } 333 315 334 private String getTag(String line) {316 private static String getTag(String line) { 335 317 assert (line.charAt(0) == '+'); 336 318 assert (line.length() > 2); … … 338 320 } 339 321 340 private String getValue(String line) {322 private static String getValue(String line) { 341 323 assert (line.charAt(0) == '+'); 342 324 if (line.length() > 4) … … 365 347 366 348 if (_FrameTags.get(tag) == null) { 367 if (!tag.equals("t") )349 if (!tag.equals("t") && !tag.equals("v") ) 368 350 FrameGraphics.ErrorMessage("Tag '" + tag + "' in '" + line 369 351 + "' is not supported."); … … 530 512 return toMake; 531 513 } 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 } 532 534 } -
trunk/src/org/expeditee/io/KMSWriter.java
r50 r67 7 7 import java.lang.reflect.Method; 8 8 import java.util.Iterator; 9 import java.util.LinkedHashMap;10 9 import java.util.LinkedList; 11 10 import java.util.List; … … 17 16 import org.expeditee.items.Line; 18 17 import org.expeditee.items.Picture; 19 import org.expeditee.items.Text;20 18 import org.expeditee.stats.SessionStats; 21 19 … … 32 30 private StringBuilder _stringWriter = null; 33 31 34 // keep track of methods that are put on the same line35 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 41 32 private static final char TERMINATOR = 'Z'; 42 33 … … 44 35 45 36 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(); 138 38 } 139 39 … … 152 52 _writer = new ProxyWriter(new FileWriter(_filename)); 153 53 54 try { 55 _ItemTags.put("S", Item.class.getMethod("getID", new Class[] {})); 56 } catch (Exception e) { 57 58 } 154 59 // _writer = new BufferedWriter(new FileWriter(filepath.toLowerCase() + 155 60 // filename.toLowerCase())); … … 171 76 172 77 writeHeader(frame); 173 // writeBody(frame);174 78 175 79 // write out each Item in the Frame. … … 192 96 Iterator<String> it = _FrameTags.keySet().iterator(); 193 97 Object[] param = {}; 98 99 // Write the version tag 100 writeLine("v", "22"); 194 101 195 102 while (it.hasNext()) { … … 212 119 } 213 120 } 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 block228 e.printStackTrace();229 } catch (IllegalAccessException e) {230 // TODO Auto-generated catch block231 e.printStackTrace();232 } catch (InvocationTargetException e) {233 // TODO Auto-generated catch block234 e.printStackTrace();235 }236 }237 121 } 238 122 … … 267 151 item = ((Picture) item).getText(); 268 152 269 /*270 * if(item instanceof Text) writeClass(item); else if(item instanceof271 * Dot) writeDot((Dot) item);272 */273 153 if (item.getLines().size() > 0) 274 154 writePoint(item); 275 155 else if (!(item instanceof Line)) 276 156 writeClass(item); 277 // lines are saved at the end of the file278 /*279 * else if (item instanceof Line) ;280 */281 157 else 282 158 System.out.println("Unknown Item: " + item.getID()); … … 338 214 if (_points.contains(c.getStart()) 339 215 && _points.contains(c.getEnd())) { 340 writeLine("C", c.getID() + " " 341 + c.getType()); 216 writeLine("C", c.getID() + " " + c.getType()); 342 217 writeLine("s", c.getLineEnds()); 343 218 } … … 348 223 // remove the point from the list 349 224 _points.remove(0); 350 351 225 } 352 226 } … … 354 228 @Override 355 229 protected String finaliseFrame() throws IOException { 356 write Line("" + DELIMITER + TERMINATOR + DELIMITER);230 writeTerminator(); 357 231 358 232 writeLine(SessionStats.getFrameEventList()); … … 399 273 } 400 274 } 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 } 469 276 470 277 /** -
trunk/src/org/expeditee/items/Dot.java
r50 r67 302 302 public void anchor() { 303 303 super.anchor(); 304 Frame current = get CurrentFrame();304 Frame current = getParentOrCurrentFrame(); 305 305 for (Line line : getLines()) { 306 306 if (line.getID() < 0 && !current.getItems().contains(line)) { -
trunk/src/org/expeditee/items/Item.java
r58 r67 399 399 // if its a relative link then return absolute 400 400 if (FrameIO.isPositiveInteger(link)) { 401 return _parent.getFramesetName() + Conversion.getFrameNumber(link);401 return _parent.getFramesetName() + link; 402 402 } 403 403 return link; … … 1457 1457 1458 1458 public void anchor() { 1459 Frame current = get CurrentFrame();1459 Frame current = getParentOrCurrentFrame(); 1460 1460 setID(current.getNextItemID()); 1461 1461 setOffset(0, 0); … … 1474 1474 * @return 1475 1475 */ 1476 public Frame get CurrentFrame() {1476 public Frame getParentOrCurrentFrame() { 1477 1477 // if the item is from an overlay the parent will NOT be null 1478 1478 if (getParent() == null) {
Note:
See TracChangeset
for help on using the changeset viewer.