Changeset 105
- Timestamp:
- 06/20/08 12:55:35 (16 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Misc.java
r97 r105 30 30 31 31 /** 32 * A list of miscellaneous KMSActions and Actions specific to Expeditee32 * A list of miscellaneous Actions and Actions specific to Expeditee 33 33 * 34 34 */ … … 181 181 // copy the item and switch 182 182 item = item.copy(); 183 item.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());183 item.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY()); 184 184 item.setParent(null); 185 185 … … 238 238 FrameGraphics.DisplayMessage("Computing comet stats..."); 239 239 240 CometStats cometStats = new CometStats(frame , true);240 CometStats cometStats = new CometStats(frame); 241 241 CreateTextItem(cometStats.toString()); 242 242 FrameGraphics.OverwriteMessage("Comet stats time: " … … 248 248 FrameGraphics.DisplayMessage("Computing tree stats..."); 249 249 250 TreeStats treeStats = new TreeStats(frame , true);250 TreeStats treeStats = new TreeStats(frame); 251 251 CreateTextItem(treeStats.toString()); 252 252 FrameGraphics.OverwriteMessage("Tree stats time: " … … 299 299 text.setText(fileContents); 300 300 301 text.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());301 text.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY()); 302 302 text.setSize(FRAME_FILE_FONT_SIZE); 303 303 … … 324 324 text.setText(fontsList.toString()); 325 325 326 text.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());326 text.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY()); 327 327 text.setSize(FRAME_FILE_FONT_SIZE); 328 328 -
trunk/src/org/expeditee/actions/NavigationActions.java
r80 r105 11 11 12 12 /** 13 * Provides the Navigation related KMSaction procedures13 * Provides the Navigation related action procedures 14 14 * 15 15 * @author jdm18 -
trunk/src/org/expeditee/actions/Simple.java
r97 r105 2109 2109 2110 2110 int initialX = DisplayIO.getMouseX(); 2111 int initialY = DisplayIO.getMouseY();2111 int initialY = FrameMouseActions.getY(); 2112 2112 2113 2113 final int timeInterval = 40; -
trunk/src/org/expeditee/gui/DisplayIO.java
r104 r105 58 58 * The title to display in the Title bar. 59 59 */ 60 public static final String TITLE = "Exp 16Jun2008A";60 public static final String TITLE = "Exp20Jun2008A"; 61 61 62 62 private DisplayIO() { … … 81 81 } 82 82 83 public static void setTextCursor(int size) { 84 setTextCursor(size, false); 85 } 86 87 public static void setTextCursor(int size, boolean newSize) { 88 if (!newSize && cursorType == Item.TEXT_CURSOR) 83 public static void setTextCursor(Text text, int cursorMovement) { 84 setTextCursor(text, cursorMovement, false); 85 } 86 87 public static void setTextCursor(Text text, int cursorMovement, 88 boolean newSize) { 89 90 int size = text.getSize(); 91 Point newMouse = text.moveCursor(cursorMovement, DisplayIO.getMouseX(), 92 FrameMouseActions.getY()); 93 94 if (!newSize && cursorType == Item.TEXT_CURSOR) { 95 if (cursorMovement != 0) 96 DisplayIO.setCursorPosition(newMouse, false); 89 97 return; 98 } 90 99 91 100 cursorType = Item.TEXT_CURSOR; … … 126 135 image, new Point(0, hotspotPos), "textcursor"); 127 136 _Browser.setCursor(textCursor); 137 DisplayIO.setCursorPosition(newMouse, false); 128 138 } 129 139 … … 169 179 * The y coordinate 170 180 */ 171 public static void setCursorPosition( int x, int y) {181 public static void setCursorPosition(float x, float y) { 172 182 setCursorPosition(x, y, true); 173 183 } 174 184 175 public static void setCursorPosition( int x, int y, boolean forceArrow) {185 public static void setCursorPosition(float x, float y, boolean forceArrow) { 176 186 // Adjust the position to move the mouse to to account for being in 177 187 // TwinFramesMode … … 183 193 } 184 194 185 int deltax = x - FrameMouseActions.MouseX;186 int deltay = y - FrameMouseActions.MouseY;195 float deltax = x - FrameMouseActions.MouseX; 196 float deltay = y - FrameMouseActions.MouseY; 187 197 188 198 // When the Robot moves the cursor... a short time later a mouseMoved … … 203 213 int mouseX = (int) _Browser.getContentPane().getLocationOnScreen() 204 214 .getX() 205 + x;215 + (int) (x + 0.5); 206 216 int mouseY = (int) _Browser.getContentPane().getLocationOnScreen() 207 217 .getY() 208 + y;218 + (int) (y + 0.5); 209 219 _Robot.mouseMove(mouseX, mouseY); 210 220 // System.out.println("MouseMoved: " + x + "," + y); … … 261 271 int side = getCurrentSide(); 262 272 263 //// do not allow duplicate frames264 //if (_VisitedFrames[side].size() > 0)265 //if (_VisitedFrames[side].peek().equals(toAdd.getName())) {266 //return;267 //}273 // // do not allow duplicate frames 274 // if (_VisitedFrames[side].size() > 0) 275 // if (_VisitedFrames[side].peek().equals(toAdd.getName())) { 276 // return; 277 // } 268 278 269 279 Item ip = FrameUtils.getCurrentItem(); … … 272 282 else 273 283 _VisitedFrames[side].push(toAdd.getName()); 274 275 // System.out.println("Added: " + _VisitedFrames[side].size());284 285 // System.out.println("Added: " + _VisitedFrames[side].size()); 276 286 } 277 287 … … 283 293 _VisitedFrames[side].pop(); 284 294 } 285 // System.out.println("Removed: " + _VisitedFrames[side].size());295 // System.out.println("Removed: " + _VisitedFrames[side].size()); 286 296 } 287 297 … … 543 553 * @return The X coordinate of the mouse. 544 554 */ 555 public static float getFloatMouseX() { 556 if (_TwinFrames 557 && FrameMouseActions.MouseY < FrameGraphics.getMaxSize().height) 558 return FrameMouseActions.MouseX % (_Browser.getWidth() / 2); 559 560 return FrameMouseActions.MouseX; 561 } 562 563 /** 564 * Returns the current mouse X coordinate. This coordinate is relative to 565 * the left edge of the frame the mouse is in. It takes into account the 566 * user being in twin frames mode. 567 * 568 * @return The X coordinate of the mouse. 569 */ 545 570 public static int getMouseX() { 546 if (_TwinFrames && getMouseY() < FrameGraphics.getMaxSize().height) 547 return FrameMouseActions.MouseX % (_Browser.getWidth() / 2); 548 549 return FrameMouseActions.MouseX; 550 } 551 552 /** 553 * Returns the current mouse Y coordinate. This is relative to the top of 554 * the frame. 555 * 556 * @return The Y coordinate of the mouse. 557 */ 558 public static int getMouseY() { 559 return FrameMouseActions.MouseY; 560 } 561 562 public static int getRealMouseX() { 563 return FrameMouseActions.MouseX; 564 } 565 566 public static int getRealMouseY() { 567 return FrameMouseActions.MouseY; 571 return Math.round(getFloatMouseX()); 568 572 } 569 573 … … 589 593 FrameIO.SuspendCache(); 590 594 Frame frame = FrameIO.LoadFrame(_VisitedFrames[side].pop()); 591 //If the top frame on the backup stack is the current frame go back again... 592 if(frame.equals(getCurrentFrame())){ 595 // If the top frame on the backup stack is the current frame go back 596 // again... 597 if (frame.equals(getCurrentFrame())) { 593 598 Back(); 594 599 return; … … 708 713 */ 709 714 public static void MoveCursorToEndOfItem(Item i) { 710 setCursorPosition(i.getPosition()); 711 Point newMouse = ((Text) i).moveCursor(Text.END, getMouseX(), 712 getMouseY()); 713 setTextCursor(((Item) i).getSize()); 714 setCursorPosition(newMouse, false); 715 setTextCursor((Text) i, Text.END); 715 716 } 716 717 } -
trunk/src/org/expeditee/gui/Frame.java
r104 r105 31 31 32 32 /** 33 * Represents a KMSFrame that is displayed on the screen. Also is a registered33 * Represents a Expeditee Frame that is displayed on the screen. Also is a registered 34 34 * MouseListener on the Browser, and processes any MouseEvents directly. 35 35 * … … 400 400 t.setMaxSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); 401 401 t.setText(itemText); 402 t.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());402 t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY()); 403 403 404 404 //The next line is needed to allow the link to be set properly when the item is picked up … … 765 765 * @return The version of this Frame. 766 766 */ 767 public int getVersion(boolean increment) { 768 // System.out.println("Version: " + _version); 769 if (increment) 770 _version++; 767 public int getVersion() { 771 768 return _version; 772 }773 774 public int getVersion() {775 return getVersion(true);776 769 } 777 770 … … 1311 1304 t.setID(getNextItemID()); 1312 1305 t.setMaxSize(FrameGraphics.getMaxFrameSize()); 1313 t.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());1306 t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY()); 1314 1307 t.setText(""); 1315 1308 t.setParent(this); … … 1318 1311 1319 1312 public Item createDot() { 1320 Item dot = new Dot(DisplayIO.getMouseX(), DisplayIO.getMouseY(),1313 Item dot = new Dot(DisplayIO.getMouseX(), FrameMouseActions.getY(), 1321 1314 getNextItemID()); 1322 1315 -
trunk/src/org/expeditee/gui/FrameGraphics.java
r102 r105 12 12 import java.awt.Point; 13 13 import java.awt.RenderingHints; 14 import java.awt.Stroke; 14 15 import java.awt.image.BufferedImage; 15 16 import java.awt.image.VolatileImage; 16 17 import java.util.Collection; 18 import java.util.Collections; 19 import java.util.Comparator; 17 20 import java.util.HashSet; 18 21 import java.util.Iterator; … … 74 77 75 78 // The link to the message frameset 76 public static Item MessageLink= new Text(-2, "@" + MESSAGES_FRAMESET_NAME,Color.black, Color.white); 79 public static Item MessageLink = new Text(-2, "@" + MESSAGES_FRAMESET_NAME, 80 Color.black, Color.white); 77 81 78 82 // creator for creating the message frames 79 83 private static FrameCreator _creator; 80 84 81 85 /** 82 86 * If Audience Mode is on this method will toggle it to be off, or … … 140 144 int newMaxHeight = max.height 141 145 - (isAudienceMode() ? 0 : MESSAGE_BUFFER_HEIGHT); 142 if (newMaxHeight > 0) 146 if (newMaxHeight > 0) { 143 147 _MaxSize.setSize(max.width, newMaxHeight); 148 } 144 149 145 150 if (DisplayIO.getCurrentFrame() != null) { … … 237 242 */ 238 243 public static void AddAllVectorItems(List<Item> items, Frame vector, 239 Collection<Frame> seenVectors, Point origin, Float scale) { 244 Collection<Frame> seenVectors, Point origin, Float scale, 245 Color defaultForeground, Color defaultBackground) { 240 246 241 247 // Check all the vector items and add the items on the vectors 242 243 248 if (seenVectors.contains(vector)) 244 249 return; … … 251 256 AddAllVectorItems(items, o.Frame, new HashSet<Frame>(seenVectors), 252 257 new Point(originX + Math.round(o.Origin.x * scale), originY 253 + Math.round(o.Origin.y * scale)), o.Scale * scale); 258 + Math.round(o.Origin.y * scale)), o.Scale * scale, 259 o.Foreground, o.Background); 254 260 // if its the original frame then were done 255 261 if (origin == null) { … … 273 279 i.setActionMark(false); 274 280 if (!(i instanceof Line)) { 275 i.setPosition((int) (i.getX() * scale + dx + 0.5), (int) (i 276 .getY() 281 i.setXY((int) (i.getX() * scale + dx + 0.5), (int) (i.getY() 277 282 * scale + dy + 0.5)); 278 283 i.setThickness((int) (i.getThickness() * scale + 0.5)); … … 280 285 .setArrowheadLength((int) (i.getArrowheadLength() 281 286 * scale + 0.5)); 287 if (i.getColor() == null) { 288 i.setColor(defaultForeground); 289 } 290 if (i.getBackgroundColor() == null) { 291 i.setBackgroundColor(defaultBackground); 292 } 293 if (i.getFillColor() == null) { 294 i.setFillColor(defaultBackground); 295 } 282 296 } 283 297 if (i instanceof Text) … … 364 378 365 379 AddAllVectorItems(paintItems, toPaint, new LinkedList<Frame>(), 366 null, 1F );380 null, 1F, null, null); 367 381 368 382 if (isActualFrame) { … … 404 418 ^ line.getStartItem().isFloating()) { 405 419 lines.add(TransposeLine(line, 406 line.getEndItem(), toPaint, DisplayIO407 .getRealMouseX(), -DisplayIO420 line.getEndItem(), toPaint, 421 FrameMouseActions.getY(), -DisplayIO 408 422 .getMiddle())); 409 423 lines.add(TransposeLine(line, line 410 .getStartItem(), toPaint, DisplayIO411 .getRealMouseX(), -DisplayIO412 .getMiddle()));424 .getStartItem(), toPaint, 425 FrameMouseActions.getY(), -DisplayIO 426 .getMiddle())); 413 427 } 414 428 } else { … … 604 618 605 619 private static void PaintLines(Graphics2D g, List<Item> toPaint) { 620 Stroke oldStroke = g.getStroke(); 621 // Use this set to keep track of the items that have been painted 622 Collection<Item> done = new HashSet<Item>(); 606 623 for (Item i : toPaint) 607 if (i instanceof Line) 608 PaintItem(g, i); 624 if (i instanceof Line) { 625 Line l = (Line)i; 626 if (done.contains(l)) { 627 l.paintArrows(g); 628 } else { 629 // When painting a line all connected lines are painted too 630 done.addAll(l.getAllConnected()); 631 if (l.getStartItem().getEnclosedArea() == 0) 632 PaintItem(g, i); 633 } 634 } 635 g.setStroke(oldStroke); 609 636 } 610 637 611 638 private static void PaintPictures(Graphics2D g, List<Item> toPaint) { 639 // Use this set to keep track of the items that dont need to be 640 // repainted 641 Collection<Item> done = new HashSet<Item>(); 642 List<Item> toFill = new LinkedList<Item>(); 612 643 for (Item i : toPaint) { 644 // Ignore items that have already been done! 645 if (done.contains(i)) 646 continue; 613 647 if (i instanceof Picture) { 614 648 PaintItem(g, i); 615 649 } else if (i.isLineEnd() 616 650 && (!isAudienceMode() || !i.isConnectedToAnnotation())) { 617 i.paintFill(g); 618 } 651 toFill.add(i); 652 done.addAll(i.getAllConnected()); 653 } 654 } 655 //Sort the items to fill 656 Collections.sort(toFill, new Comparator<Item>() { 657 public int compare(Item a, Item b) { 658 Integer aArea = a.getEnclosedArea(); 659 Integer bArea = b.getEnclosedArea(); 660 return aArea.compareTo(bArea) * -1; 661 } 662 }); 663 for(Item i: toFill){ 664 i.paintFill(g); 665 PaintItem(g, i.getLines().get(0)); 619 666 } 620 667 } … … 635 682 // Check if within 20% of the end of the line 636 683 Line l = (Line) i; 637 Item toDisconnect = l.getEndPointToDisconnect( 638 FrameMouseActions.MouseX, FrameMouseActions.MouseY); 684 Item toDisconnect = l.getEndPointToDisconnect(Math 685 .round(FrameMouseActions.MouseX), Math 686 .round(FrameMouseActions.MouseY)); 639 687 640 688 // Brook: Widget Edges do not have such a context … … 658 706 } 659 707 } else { 708 //FrameGraphics.ChangeSelectionMode(i, 709 // Item.SelectedMode.Normal); 710 //For polygons need to make sure all other endpoints are unHighlighted 711 for (Item conn : i.getAllConnected()) { 712 conn.setSelectedMode(Item.SelectedMode.None); 713 } 660 714 i.setSelectedMode(Item.SelectedMode.Normal); 661 715 } … … 785 839 Text last = Messages[Messages.length - 1]; 786 840 last.setColor(color); 787 // Make set the text for the new message841 // Make set the text for the new message 788 842 last.setText(getMessagePrefix(true) + message); 789 843 last.setLink(link); -
trunk/src/org/expeditee/gui/FrameIO.java
r104 r105 9 9 import java.io.FileWriter; 10 10 import java.io.IOException; 11 import java.sql.Time; 11 12 import java.util.HashMap; 12 13 … … 629 630 * 630 631 * @param toSave 631 * The Frame to save to disk in KMS format.632 * The Frame to save to disk 632 633 */ 633 634 public static String SaveFrame(Frame toSave) { … … 645 646 * 646 647 * @param toSave 647 * The Frame to save to disk in KMS format.648 * The Frame to save to disk 648 649 * @param inc 649 650 * True if the saved frames counter should be incremented, false … … 655 656 boolean checkBackup) { 656 657 657 if (toSave == null) 658 // TODO When loading a frame maybe append onto the event history too- with a 659 // break to indicate the end of a session 660 661 if (toSave == null ||!toSave.hasChanged() || toSave.isSaved()){ 662 SessionStats.NewFrameSession(); 658 663 return ""; 659 660 if (!toSave.hasChanged() || toSave.isSaved()) 661 return ""; 662 664 } 663 665 // Get the full path only to determine which format to use for saving 664 666 // the frame … … 672 674 && toSave.getNameItem().Permission < Item.PERMISSION_TDFC) { 673 675 _Cache.remove(toSave.getName().toLowerCase()); 676 SessionStats.NewFrameSession(); 674 677 return ""; 675 678 } … … 694 697 } 695 698 // Check if we are trying to save an out of date version 696 if (savedVersion > toSave.getVersion( false)699 if (savedVersion > toSave.getVersion() 697 700 && !toSave.getFramesetName().equalsIgnoreCase( 698 701 FrameGraphics.MESSAGES_FRAMESET_NAME)) { … … 741 744 ResumeCache(); 742 745 } 743 toSave.setActiveTime(SessionStats.getFrameActiveTime()); 744 toSave.setDarkTime(SessionStats.getFrameDarkTime()); 746 // Update general stuff about frame 745 747 toSave.setLastModifyDate(Logger.EasyDateFormat("ddMMMyyyy:HHmm")); 746 748 toSave.setLastModifyUser(UserSettings.Username); 749 toSave.setVersion(toSave.getVersion() + 1); 750 Time darkTime = new Time(SessionStats.getFrameDarkTime().getTime() 751 + toSave.getDarkTime().getTime()); 752 Time activeTime = new Time(SessionStats.getFrameActiveTime() 753 .getTime() 754 + toSave.getActiveTime().getTime()); 755 toSave.setDarkTime(darkTime); 756 toSave.setActiveTime(activeTime); 757 747 758 writer.writeFrame(toSave); 748 759 toSave.setSaved(); 749 if (inc) 760 if (inc) { 750 761 SessionStats.SavedFrame(toSave.getName()); 762 } 751 763 752 764 // avoid out-of-sync frames (when in TwinFrames mode) -
trunk/src/org/expeditee/gui/FrameKeyboardActions.java
r97 r105 136 136 FrameUtils.LastEdited = text; 137 137 DisplayIO.getCurrentFrame().addItem(text); 138 DisplayIO.setTextCursor(text .getSize());139 return; 140 } 141 142 DisplayIO.setTextCursor(text .getSize());138 DisplayIO.setTextCursor(text, Text.NONE); 139 return; 140 } 141 142 DisplayIO.setTextCursor(text, Text.NONE); 143 143 Point newMouse = null; 144 144 if (ch == '\t') { 145 145 if (isShiftDown) { 146 newMouse = text.removeTab(ch, DisplayIO.getMouseX(), DisplayIO147 .getMouseY());146 newMouse = text.removeTab(ch, DisplayIO.getMouseX(), 147 FrameMouseActions.getY()); 148 148 } else { 149 newMouse = text.insertTab(ch, DisplayIO.getMouseX(), DisplayIO150 .getMouseY());149 newMouse = text.insertTab(ch, DisplayIO.getMouseX(), 150 FrameMouseActions.getY()); 151 151 } 152 152 } else { 153 newMouse = text.insertChar(ch, DisplayIO.getMouseX(), DisplayIO154 .getMouseY());153 newMouse = text.insertChar(ch, DisplayIO.getMouseX(), 154 FrameMouseActions.getY()); 155 155 } 156 156 DisplayIO.setCursorPosition(newMouse.x, newMouse.y, false); 157 157 158 //This repaint is needed for WINDOWS only?!?!? Mike is not sure why! 159 if(ch == KeyEvent.VK_DELETE) 160 FrameGraphics.Repaint(); 161 158 162 // a change has occured to the Frame 159 163 text.getParent().setChanged(true); … … 229 233 Text t = DisplayIO.getCurrentFrame().createBlankText("" + start); 230 234 231 Point newMouse = t.insertChar(start, DisplayIO.getMouseX(), DisplayIO232 .getMouseY());235 Point newMouse = t.insertChar(start, DisplayIO.getMouseX(), 236 FrameMouseActions.getY()); 233 237 DisplayIO.setCursorPosition(newMouse.x, newMouse.y, false); 234 238 … … 248 252 249 253 private void move(int direction) { 250 Item ip= FrameUtils.getCurrentItem();251 252 if ( ip== null) {254 Item on = FrameUtils.getCurrentItem(); 255 256 if (on == null) { 253 257 navigateFrame(direction); 254 258 return; 255 259 } 256 260 257 Item on = ip;258 261 if (on instanceof Text) { 259 262 // When the user hits the left and right button with mouse … … 264 267 } else { 265 268 FrameUtils.LastEdited = on; 266 Point newMouse = ((Text) on).moveCursor(direction, DisplayIO 267 .getMouseX(), DisplayIO.getMouseY()); 268 DisplayIO.setTextCursor(((Item) on).getSize()); 269 DisplayIO.setCursorPosition(newMouse, false); 269 DisplayIO.setTextCursor((Text) on, direction); 270 270 } 271 271 } … … 323 323 return; 324 324 } else if (e.isControlDown() && e.getKeyCode() != KeyEvent.VK_CONTROL) 325 controlChar(e, KeyEvent.getKeyText(e.getKeyCode()));325 controlChar(e, e.getKeyCode()); 326 326 327 327 switch (e.getKeyCode()) { … … 392 392 if (currentItem == null) { 393 393 // find the nearest item in the correct direction 394 int currY = DisplayIO.getMouseY();394 int currY = FrameMouseActions.getY(); 395 395 for (int i = 0; i < textItems.size(); i++) { 396 396 Item t = textItems.get(i); … … 473 473 } 474 474 475 private static void copyItemToClipboard(Item on){ 476 if (on == null || !(on instanceof Text)) 477 return; 478 479 String text = ""; 480 481 List<String> lines = ((Text) on).getTextList(); 482 for (String s : lines) 483 text += s + "\n"; 484 // remove the last '\n' 485 text = text.substring(0, text.length() - 1); 486 487 // add the text of the item to the clipboard 488 StringSelection selection = new StringSelection(text); 489 Toolkit.getDefaultToolkit().getSystemClipboard().setContents( 490 selection, null); 491 } 492 475 493 /** 476 494 * Processes all control character keystrokes. Currently Ctrl+C and Ctrl+V … … 480 498 * The character being pressed along with the control key 481 499 */ 482 private static void controlChar(KeyEvent e, String ch) { 483 if (ch.length() > 1) 484 return; 500 private static void controlChar(KeyEvent e, int key) { 485 501 Logger.Log(Logger.USER, Logger.CONTROL_CHAR, "User pressing: Ctrl+" 486 + ch);502 + KeyEvent.getKeyText(key)); 487 503 // 488 504 // if (FrameUtils.getCurrentItem() == null … … 495 511 Frame currentFrame = DisplayIO.getCurrentFrame(); 496 512 // Link or delink an item 497 if ( ch.charAt(0)== KeyEvent.VK_L) {513 if (key == KeyEvent.VK_L) { 498 514 // If its not linked then link it to its self 499 515 if (current instanceof Text && current.getLink() == null) { … … 508 524 current.setLink(null); 509 525 } 510 } else if ( ch.charAt(0)== KeyEvent.VK_G) {526 } else if (key == KeyEvent.VK_G) { 511 527 // If its not linked then link it to its self 512 528 if (current instanceof Text) { … … 522 538 return; 523 539 } 524 } else if ( ch.charAt(0)== KeyEvent.VK_A) {540 } else if (key == KeyEvent.VK_A) { 525 541 // If its not linked then link it to its self 526 542 if (current instanceof Text && current.getAction() == null) { … … 543 559 current.setActions(null); 544 560 } 545 } else if ( ch.charAt(0)== KeyEvent.VK_V) {561 } else if (key == KeyEvent.VK_V) { 546 562 try { 547 563 // read in the data from the clipboard … … 573 589 574 590 String temp = ""; 575 int y = DisplayIO.getMouseY();591 int y = FrameMouseActions.getY(); 576 592 577 593 // separate the clipboard content into items based on … … 595 611 } 596 612 // if this is a copy command 597 } else if (ch.charAt(0) == KeyEvent.VK_C) { 598 Item ip = FrameUtils.getCurrentItem(); 599 600 if (ip != null && ip.Permission < Item.PERMISSION_COPY) { 613 } else if (key == KeyEvent.VK_C) { 614 Item on = FrameUtils.getCurrentItem(); 615 if (on != null && on.Permission < Item.PERMISSION_COPY) { 601 616 FrameGraphics 602 .DisplayMessage("Insufficient permission to copy that item"); 603 return; 604 } 605 606 Item on = null; 607 if (ip != null) 608 on = ip; 609 610 if (on == null || !(on instanceof Text)) 611 return; 612 613 String text = ""; 614 615 List<String> lines = ((Text) on).getTextList(); 616 for (String s : lines) 617 text += s + "\n"; 618 // remove the last '\n' 619 text = text.substring(0, text.length() - 1); 620 621 // add the text of the item to the clipboard 622 StringSelection selection = new StringSelection(text); 623 Toolkit.getDefaultToolkit().getSystemClipboard().setContents( 624 selection, null); 625 FrameGraphics.DisplayMessage("Item copied to clipboard"); 626 return; 627 } else if (ch.charAt(0) == KeyEvent.VK_D) { 617 .DisplayMessage("Insufficient permission to copy that item" ); 618 return; 619 } 620 copyItemToClipboard(on); 621 //FrameGraphics.DisplayMessage("Item copied to clipboard"); 622 return; 623 } else if (key == KeyEvent.VK_X) { 624 Item on = FrameUtils.getCurrentItem(); 625 if (on != null && on.Permission < Item.PERMISSION_FULL) { 626 FrameGraphics 627 .DisplayMessage("Insufficient permission to cut that item" ); 628 return; 629 } 630 copyItemToClipboard(on); 631 FrameMouseActions.delete(current); 632 return; 633 }else if (key == KeyEvent.VK_D) { 628 634 // perform a delete operation 629 635 processChar((char) KeyEvent.VK_DELETE, e.isShiftDown()); 636 } else if (key == KeyEvent.VK_DELETE) { 637 // perform a delete operation 630 638 FrameMouseActions.delete(current); 631 } else if ( ch.charAt(0)== KeyEvent.VK_F) {639 } else if (key == KeyEvent.VK_F) { 632 640 // perform a delete operation 633 641 Actions.PerformAction(currentFrame, null, "Format"); 634 642 return; 635 } else if ( ch.charAt(0)== KeyEvent.VK_J) {643 } else if (key == KeyEvent.VK_J) { 636 644 637 645 Text text = getCurrentTextItem(); … … 644 652 645 653 text.setJustification(Justification.left); 646 } else if ( ch.charAt(0)== KeyEvent.VK_S) {654 } else if (key == KeyEvent.VK_S) { 647 655 // split the current text item 648 656 Text text = getCurrentTextItem(); … … 788 796 case SizeUp: 789 797 SetSize(on, repeat, true); 790 DisplayIO.setTextCursor(on.getSize(), true); 798 if (on instanceof Text) { 799 DisplayIO.setTextCursor((Text) on, Text.NONE, true); 800 } 791 801 break; 792 802 case SizeDown: 793 803 SetSize(on, -repeat, true); 794 DisplayIO.setTextCursor(on.getSize(), true); 804 if (on instanceof Text) { 805 DisplayIO.setTextCursor((Text) on, Text.NONE, true); 806 } 795 807 break; 796 808 case ChangeColor: … … 952 964 } 953 965 // Add the bullet text to the item 954 dummyItem.setPosition(DisplayIO.getMouseX(), DisplayIO955 .getMouseY());966 dummyItem.setPosition(DisplayIO.getMouseX(), 967 FrameMouseActions.getY()); 956 968 } else { 957 969 FrameGraphics … … 959 971 // ensures correct repainting when items don't move 960 972 DisplayIO.setCursorPosition(DisplayIO.getMouseX(), 961 DisplayIO.getMouseY());973 FrameMouseActions.getY()); 962 974 return; 963 975 } … … 1222 1234 dot.setThickness(current); 1223 1235 } else { 1224 int current = Math.abs(i.getSize()); 1225 current = Math.max(current + diff, 1); 1226 i.setSize(current); 1236 int oldSize = Math.abs(i.getSize()); 1237 int newSize = Math.max(oldSize + diff, 1); 1238 i.setSize(newSize); 1239 if (i instanceof Text) { 1240 // Move the cursor as close as we can to where it should be 1241 int itemX = i.getX(); 1242 int itemY = i.getY(); 1243 float resizeRatio = (float) newSize / oldSize; 1244 float fromOriginX = DisplayIO.getFloatMouseX() - itemX; 1245 float fromOriginY = FrameMouseActions.MouseY - itemY; 1246 float newX = itemX + fromOriginX * resizeRatio; 1247 float newY = itemY + fromOriginY * resizeRatio; 1248 if (i instanceof Text) 1249 newY--; 1250 DisplayIO.setCursorPosition(newX, newY, false); 1251 toSet.getParent().setChanged(true); 1252 return; 1253 } 1227 1254 } 1228 1255 } … … 1230 1257 // center the mouse cursor on the item 1231 1258 if (moveCursor && toSet != null) { 1232 if (!toSet.contains(DisplayIO.getMouseX(), DisplayIO.getMouseY())) { 1259 if (!toSet 1260 .contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) { 1233 1261 int x = DisplayIO.getMouseX(); 1234 int y = DisplayIO.getMouseY();1262 int y = FrameMouseActions.getY(); 1235 1263 1236 1264 if (!toSet.contains(x, toSet.getY())) … … 1247 1275 .getBoundsHeight())); 1248 1276 1249 DisplayIO.setCursorPosition(x, y );1277 DisplayIO.setCursorPosition(x, y, false); 1250 1278 } 1251 1279 -
trunk/src/org/expeditee/gui/FrameMouseActions.java
r102 r105 87 87 * The last known mouse X coordinate 88 88 */ 89 public static int MouseX;89 public static float MouseX; 90 90 91 91 /** … … 93 93 * application. 94 94 */ 95 public static int MouseY;95 public static float MouseY; 96 96 97 97 // Distance of mouse cursor from the origin of the item that was picked up … … 335 335 _lastRanged = (Text) on; 336 336 // set start-drag point 337 _lastRanged.setSelectionStart(DisplayIO.getMouseX(), DisplayIO 338 .getMouseY()); 337 _lastRanged.setSelectionStart(DisplayIO.getMouseX(), FrameMouseActions.getY()); 339 338 } 340 339 … … 343 342 _lastCropped = (Picture) on; 344 343 // set start crop point 345 _lastCropped.setStartCrop(DisplayIO.getMouseX(), DisplayIO 346 .getMouseY()); 344 _lastCropped.setStartCrop(DisplayIO.getMouseX(), FrameMouseActions.getY()); 347 345 _lastCropped.setShowCrop(true); 348 346 } … … 537 535 ranged.setLink(null); 538 536 ranged.setParent(null); 539 ranged.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY());537 ranged.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY()); 540 538 pickup(ranged); 541 539 … … 607 605 // Check if the user is nearby another item... 608 606 int mouseX = DisplayIO.getMouseX(); 609 int mouseY = DisplayIO.getMouseY();607 int mouseY = FrameMouseActions.getY(); 610 608 // System.out.println(mouseX + "," + mouseY); 611 609 for (Item i : DisplayIO.getCurrentFrame().getItems()) { … … 636 634 637 635 // actions take priority 638 if (_lastMouseClick != null && !_lastMouseClick.is ShiftDown()636 if (_lastMouseClick != null && !_lastMouseClick.isControlDown() 639 637 && clickedOn.getAction() != null) { 640 638 clickedOn.performActions(); … … 846 844 // otherwise the user is creating a line 847 845 } else { 848 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), M ouseX,849 M ouseY);846 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), Math.round(MouseX), 847 Math.round(MouseY)); 850 848 // If we have permission to copy this item then pick it up 851 849 if (on != null && on.isLineEnd() … … 861 859 Frame current = DisplayIO.getCurrentFrame(); 862 860 // create the two endpoints 863 Item newPoint = DisplayIO.getCurrentFrame().createDot();864 865 861 Line oldLine = (Line) on; 862 Item newPoint = oldLine.getStartItem().copy(); 863 newPoint.setPosition(MouseX, MouseY); 864 866 865 Item end = oldLine.getEndItem(); 867 866 // create the Line … … 1044 1043 // Find the closest item to the mouse cursor 1045 1044 double currentX = DisplayIO.getMouseX(); 1046 double currentY = DisplayIO.getMouseY();1045 double currentY = FrameMouseActions.getY(); 1047 1046 Item closest = null; 1048 1047 double shortestDistance = Double.MAX_VALUE; … … 1176 1175 && on.Permission >= Item.PERMISSION_FULL) { 1177 1176 1178 Line newLine = createLine(); 1177 Line onLine = (Line)on; 1178 Line newLine = onLine.copy(); 1179 Item end = newLine.getEndItem(); 1180 Item start = newLine.getStartItem(); 1181 end.setPosition(MouseX, MouseY); 1182 start.setPosition(MouseX, MouseY); 1183 onLine.autoArrowheadLength(); 1184 // anchor the start 1185 anchor(start); 1186 // attach the line to the cursor 1187 pickup(end); 1188 1179 1189 List<Item> toMerge = new LinkedList<Item>(); 1180 1190 toMerge.add(newLine.getStartItem()); 1181 1191 toMerge.add(newLine); 1182 Item end = newLine.getEndItem(); 1183 //Make sure the highlighting is shown when the end is anchored 1192 1193 // Make sure the highlighting is shown when the end is 1194 // anchored 1184 1195 end.setSelectedMode(Item.SelectedMode.Normal); 1185 1196 end.setSelectedMode(Item.SelectedMode.None); 1186 1197 merge(toMerge, on); 1187 // anchor(left);1188 // Frame.FreeItems.clear();1198 // anchor(left); 1199 // Frame.FreeItems.clear(); 1189 1200 FrameGraphics.Repaint(); 1190 1201 updateCursor(); … … 1300 1311 MouseY = e.getY(); 1301 1312 1302 int distance = _lastRanged.getY() - DisplayIO.getMouseY();1313 int distance = _lastRanged.getY() - FrameMouseActions.getY(); 1303 1314 if (distance <= 0) 1304 distance = DisplayIO.getMouseY() - _lastRanged.getY()1315 distance = FrameMouseActions.getY() - _lastRanged.getY() 1305 1316 - _lastRanged.getBoundsHeight(); 1306 1317 … … 1310 1321 } else { 1311 1322 // update the ranged section 1312 _lastRanged.setSelectionEnd(DisplayIO.getMouseX(), DisplayIO 1313 .getMouseY()); 1323 _lastRanged.setSelectionEnd(DisplayIO.getMouseX(), FrameMouseActions.getY()); 1314 1324 _isNoOp = false; 1315 1325 } 1316 1326 1317 DisplayIO.setTextCursor(_lastRanged .getSize());1327 DisplayIO.setTextCursor(_lastRanged, Text.NONE); 1318 1328 FrameGraphics.Repaint(); 1319 1329 return; … … 1339 1349 } 1340 1350 // update the ranged section 1341 _lastCropped.setEndCrop(DisplayIO.getMouseX(), DisplayIO 1342 .getMouseY()); 1351 _lastCropped.setEndCrop(DisplayIO.getMouseX(), FrameMouseActions.getY()); 1343 1352 1344 1353 FrameGraphics.Repaint(); … … 1398 1407 private static boolean _shiftDown; 1399 1408 1400 public static void setLastRobotMove( int x, int y) {1409 public static void setLastRobotMove(float x, float y) { 1401 1410 // Make sure the system is in the right state while waiting for the 1402 1411 // Robots event to arrive. … … 1405 1414 // System.out.println("MouseMoved: " + MouseX + "," + MouseY + " " + 1406 1415 // System.currentTimeMillis()); 1407 LastRobotX = x;1408 LastRobotY = y;1416 LastRobotX = (int) (x + 0.5); 1417 LastRobotY = (int) (y + 0.5); 1409 1418 _RobotTimer.start(); 1410 1419 } … … 1629 1638 // Checks that we are actually pointing on a character 1630 1639 // not just space in the text box's bounding box 1631 if (((Item) on).contains(DisplayIO.getMouseX(), DisplayIO 1632 .getMouseY())) { 1640 if (((Item) on).contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) { 1633 1641 _context = CONTEXT_AT_TEXT; 1634 1642 } else { … … 1657 1665 if (lineEnd != null) { 1658 1666 line.showVirtualSpot(lineEnd, DisplayIO.getMouseX(), 1659 DisplayIO.getMouseY());1667 FrameMouseActions.getY()); 1660 1668 } else 1661 1669 // The user is pointing at another point or text item … … 1780 1788 return; 1781 1789 } 1790 //This is to make sure the TEXT_CURSOR doesnt get inadvertantly turned off! 1791 Item on = FrameUtils.getCurrentItem(); 1792 if(on != null && on instanceof Text){ 1793 return; 1794 } 1782 1795 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 1783 1796 } … … 1791 1804 _offX = DisplayIO.getMouseX() - Frame.FreeItems.get(0).getX() 1792 1805 + Frame.FreeItems.get(0).getOffset().x; 1793 _offY = MouseY- Frame.FreeItems.get(0).getY()1806 _offY = getY() - Frame.FreeItems.get(0).getY() 1794 1807 + Frame.FreeItems.get(0).getOffset().y; 1795 1808 } … … 1804 1817 1805 1818 int deltax = firstDot.getX() - xPos; 1806 int deltay = firstDot.getY() - ( MouseY- _offY);1819 int deltay = firstDot.getY() - (getY() - _offY); 1807 1820 1808 1821 for (Item move : toMove) { … … 1954 1967 _offX = DisplayIO.getMouseX() - anchored.getX() 1955 1968 + anchored.getOffset().x; 1956 _offY = MouseY- anchored.getY() + anchored.getOffset().y;1969 _offY = getY() - anchored.getY() + anchored.getOffset().y; 1957 1970 } else { 1958 1971 deleteItems(Frame.FreeItems); … … 2167 2180 2168 2181 public static Collection<Item> merge(List<Item> merger, Item mergee) { 2169 assert (mergee != null);2182 assert (mergee != null); 2170 2183 if (mergee.isFrameName()) { 2171 2184 return mergee.getParent().merge(merger); … … 2242 2255 if (mergee instanceof Text) 2243 2256 ((Text) mergee).insertText(txt.getText(), DisplayIO 2244 .getMouseX(), DisplayIO.getMouseY());2257 .getMouseX(), FrameMouseActions.getY()); 2245 2258 2246 2259 else if (mergee instanceof Dot) { … … 2263 2276 // Dot override doesnt use the x and y coords 2264 2277 // Text does... but could be removed 2265 res = mergee.merge(i, DisplayIO.getMouseX(), MouseY);2278 res = mergee.merge(i, DisplayIO.getMouseX(), getY()); 2266 2279 if (res != null) { 2267 2280 remain.add(res); … … 2273 2286 } 2274 2287 // Moving the cursor ensures shapes are anchored correctly 2275 res = mergee.merge(i, DisplayIO.getMouseX(), MouseY);2288 res = mergee.merge(i, DisplayIO.getMouseX(), getY()); 2276 2289 if (res != null) 2277 2290 remain.addAll(res.getConnected()); … … 2353 2366 if (!(i instanceof Line)) { 2354 2367 _offX = DisplayIO.getMouseX() - i.getX() + i.getOffset().x; 2355 _offY = MouseY- i.getY() + i.getOffset().y;2368 _offY = getY() - i.getY() + i.getOffset().y; 2356 2369 2357 2370 // make the offset item the first item in the list (so … … 2371 2384 _offX = DisplayIO.getMouseX() - soleItem.getX() 2372 2385 + soleItem.getOffset().x; 2373 _offY = MouseY- soleItem.getY() + soleItem.getOffset().y;2386 _offY = getY() - soleItem.getY() + soleItem.getOffset().y; 2374 2387 // Now call move so that if we are on a message in the message box 2375 2388 // It doesnt appear up the top of the scree!! … … 2379 2392 .DisplayMessage("Insufficient permission pickup the items"); 2380 2393 } 2394 FrameGraphics.Repaint(); 2381 2395 } 2382 2396 … … 2415 2429 2416 2430 if (checkEnclosure) { 2417 FrameGraphics.Repaint();2418 2431 ItemUtils.EnclosedCheck(toAnchor.getParentOrCurrentFrame() 2419 2432 .getItems()); 2433 FrameGraphics.Repaint(); 2420 2434 } 2421 2435 } … … 2433 2447 } 2434 2448 toAnchor.clear(); 2435 FrameGraphics.Repaint();2436 2449 // Check enclosure for all the frames of the items that were anchored 2437 2450 for (Frame f : checkEnclosure) { 2438 2451 ItemUtils.EnclosedCheck(f.getItems()); 2439 2452 } 2453 FrameGraphics.Repaint(); 2440 2454 } 2441 2455 … … 2581 2595 updateCursor(); 2582 2596 } 2597 2598 public static int getX() { 2599 return (int)(MouseX + 0.5); 2600 } 2601 2602 public static int getY() { 2603 return (int)(MouseY + 0.5); 2604 } 2583 2605 } -
trunk/src/org/expeditee/gui/FrameUtils.java
r103 r105 909 909 } 910 910 vectors.add(new Vector(vector, i.getPosition(), 911 scale ));911 scale, i.getColor(), i.getBackgroundColor())); 912 912 } 913 913 } … … 1098 1098 * @return The Item at the given coordinates, or NULL if none is found. 1099 1099 */ 1100 public static Item onItem(Frame toCheck, int x, int y) { 1100 public static Item onItem(Frame toCheck, float floatX, float floatY) { 1101 int x = Math.round(floatX); 1102 int y = Math.round(floatY); 1101 1103 if (toCheck == null) 1102 1104 return null; … … 1214 1216 public static Item getCurrentItem() { 1215 1217 return onItem(DisplayIO.getCurrentFrame(), DisplayIO.getMouseX(), 1216 DisplayIO.getMouseY());1218 FrameMouseActions.getY()); 1217 1219 } 1218 1220 … … 1273 1275 if (i.isLineEnd() && i.isEnclosed()) { 1274 1276 Polygon p = i.getEnclosedShape(); 1275 if (p.contains(DisplayIO.getMouseX(), DisplayIO.getMouseY())) {1277 if (p.contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) { 1276 1278 used.add(i); 1277 1279 items.removeAll(i.getEnclosingDots()); … … 1297 1299 1298 1300 int mouseX = DisplayIO.getMouseX(); 1299 int mouseY = DisplayIO.getMouseY();1301 int mouseY = FrameMouseActions.getY(); 1300 1302 1301 1303 for (int i = 0; i < p1.npoints; i++) { -
trunk/src/org/expeditee/gui/Vector.java
r79 r105 1 1 package org.expeditee.gui; 2 2 3 import java.awt.Color; 3 4 import java.awt.Point; 4 5 … … 10 11 public float Scale; 11 12 12 public Vector(Frame overlay, Point origin, Float scale) { 13 public Color Foreground; 14 public Color Background; 15 16 public Vector(Frame overlay, Point origin, Float scale, Color color, Color background) { 13 17 Frame = overlay; 14 18 Origin = origin; 15 19 Scale = scale; 20 Foreground = color; 21 Background = background; 16 22 } 17 23 -
trunk/src/org/expeditee/io/ExpReader.java
r97 r105 40 40 41 41 /** 42 * Determines whether a string begins with a KMStag.42 * Determines whether a string begins with tag. 43 43 * 44 44 * @param s 45 45 * a line of text 46 * @return true if s begins with a KMStag46 * @return true if s begins with a tag 47 47 */ 48 48 private static boolean isValidLine(String s) { … … 52 52 53 53 /** 54 * Reads a KMSfile with the given name from disk.54 * Reads a file with the given name from disk. 55 55 * 56 56 * @param frameName -
trunk/src/org/expeditee/io/ExpWriter.java
r97 r105 103 103 writeTerminator(); 104 104 writeConstraintData(); 105 105 writeTerminator(); 106 writeLine(SessionStats.getFrameEventList(frame)); 107 106 108 return; 107 109 } … … 249 251 @Override 250 252 protected String finaliseFrame() throws IOException { 251 writeTerminator();252 253 writeLine(SessionStats.getFrameEventList());254 255 253 _writer.flush(); 256 254 _writer.close(); -
trunk/src/org/expeditee/items/Item.java
r97 r105 67 67 public static final Color DEPRESSED_HIGHLIGHT = Color.GREEN; 68 68 69 public static final Color DISCONNECT_HIGHLIGHT = Color.BLUE;69 public static final Color ALTERNATE_HIGHLIGHT = Color.BLUE; 70 70 71 71 public static final Color LINK_COLOR = Color.BLACK; … … 291 291 * 292 292 * @param action 293 * The KMS action languageto add to this Item293 * The action to add to this Item 294 294 */ 295 295 public void addAction(String action) { … … 393 393 394 394 /** 395 * Returns a list of any action code (KMS action language) that is currently396 * associated with thisItem395 * Returns a list of any action code that is currently associated with this 396 * Item 397 397 * 398 398 * @return A List of action code associated with this Item, or null if none … … 785 785 */ 786 786 public int getX() { 787 return (int) (_x + 0.5);787 return (int) (_x + 0.5); 788 788 } 789 789 … … 794 794 */ 795 795 public int getY() { 796 return (int) (_y + 0.5);796 return (int) (_y + 0.5); 797 797 } 798 798 … … 883 883 + getBoundsHeight() + NEAR_DISTANCE); 884 884 } 885 886 /**887 * Checks if this item is a frame title.888 *889 * @return true if the item is a frame title890 */891 /*892 * public boolean isTitle() { // check if the title has been assigned if893 * (getID() >= 0 && this instanceof Text) if (getX() < 200 && getY() <894 * getSize() + system.io.KMSConversion.Y_ADJUST) return true; return false; }895 */896 885 897 886 public boolean isOldTag() { … … 925 914 if (getFillColor() != null && getEnclosingDots() != null) { 926 915 g.setColor(getFillColor()); 916 // The painting is not efficient enough for gradients... 927 917 // Shape s = getEnclosedShape(); 928 918 // Rectangle b = s.getBounds(); … … 1330 1320 } 1331 1321 } else if (c.isDiagonal()) { 1332 if (Math.abs(other._x - x) != Math 1333 .abs(other._y - y)) { 1334 1322 if (Math.abs(other._x - x) != Math.abs(other._y - y)) { 1323 1335 1324 float m1 = c.getGradient(); 1336 1325 float c1 = y - m1 * x; … … 1341 1330 // If there is only one line... 1342 1331 if (lines.size() == 1) { 1343 if (m1 != 0) {1344 if (Math.abs(deltaX) > Math.abs(deltaY)){1332 if (m1 != 0) { 1333 if (Math.abs(deltaX) > Math.abs(deltaY)) { 1345 1334 other.setX((other._y - c1) / m1); 1346 } else {1335 } else { 1347 1336 other.setY(m1 * other._x + c1); 1348 1337 } … … 1362 1351 other.setY(m1 * other._x + c1); 1363 1352 } else if (Math.abs(xDiff) == Math.abs(yDiff) 1364 && !this.isFloating() && deltaX == 0 && deltaY == 0){ 1353 && !this.isFloating() && deltaX == 0 1354 && deltaY == 0) { 1365 1355 if (deltaX == 0) { 1366 _x = (_y - other._y) * m1 1367 + other._x; 1356 _x = (_y - other._y) * m1 + other._x; 1368 1357 } else { 1369 _y = (_x - other._x) * m1 1370 + other._y; 1358 _y = (_x - other._x) * m1 + other._y; 1371 1359 } 1372 1360 } else { … … 1543 1531 1544 1532 public void setSelectedMode(SelectedMode mode, Color color) { 1533 if (color != null && color.equals(getPaintColor())) { 1534 color = ALTERNATE_HIGHLIGHT; 1535 } 1545 1536 setSelectionColor(color); 1546 1537 _lastMode = _mode; … … 1823 1814 return link; 1824 1815 } 1816 1817 /** 1818 * Sets the x and y values of this item ignoring constraints. 1819 * 1820 * @param x 1821 * new x position 1822 * @param y 1823 * new y position 1824 */ 1825 public void setXY(int x, int y) { 1826 _x = x; 1827 _y = y; 1828 } 1829 1830 /** 1831 * Recursive function for getting the path around a shape. This is used to 1832 * get the path that is painted on the screen. 1833 * 1834 * @param visited 1835 * @param points 1836 * @param addToEnd 1837 * @param toExplore 1838 */ 1839 public void appendPath(Collection<Line> visited, LinkedList<Point> points, 1840 boolean addToEnd, Collection<Line> toExplore) { 1841 1842 if (addToEnd) { 1843 // put the start item points into our list 1844 points.addLast(getPosition()); 1845 } else { 1846 points.addFirst(getPosition()); 1847 } 1848 1849 // Find the line that has not been added yet 1850 LinkedList<Line> lines = new LinkedList<Line>(); 1851 lines.addAll(getLines()); 1852 1853 while (!lines.isEmpty()) { 1854 Line l = lines.remove(); 1855 // if we havnt visited the line yet visit it 1856 if (!visited.contains(l)) { 1857 visited.add(l); 1858 Item otherEnd = l.getOppositeEnd(this); 1859 // Add all the enexplored lines to our list 1860 while (!lines.isEmpty()) { 1861 l = lines.remove(); 1862 // Get the paths for the rest of the lines to be explored 1863 // later 1864 if (!toExplore.contains(l) && !visited.contains(l)) { 1865 toExplore.add(l); 1866 } 1867 } 1868 otherEnd.appendPath(visited, points, addToEnd, toExplore); 1869 } 1870 } 1871 } 1872 1873 /** 1874 * Gets the size of the enclosure that this item is part of. 1875 * @return the area of the box surrounding the enclosed shape that this item is part of 1876 */ 1877 public Integer getEnclosedArea() { 1878 if (_enclosure == null) 1879 return 0; 1880 Rectangle box = getEnclosedShape().getBounds(); 1881 Integer area = box.width * box.height; 1882 1883 if (getFillColor() == null) 1884 return -area; 1885 1886 return area; 1887 } 1825 1888 } -
trunk/src/org/expeditee/items/Line.java
r102 r105 13 13 import java.util.ArrayList; 14 14 import java.util.Collection; 15 import java.util.HashSet; 16 import java.util.Iterator; 17 import java.util.LinkedList; 15 18 import java.util.List; 16 19 … … 33 36 private static final int MINIMUM_ARROW_HEAD_LENGTH = 8; 34 37 38 private static final int MAXIMUM_ARROW_HEAD_LENGTH = 60; 39 35 40 public static final Float DEFAULT_THICKNESS = 2f; 36 41 … … 53 58 private boolean _isCircle = false; 54 59 60 // TODO find out why bevel is not working 61 private final int JOIN = BasicStroke.JOIN_ROUND; 62 63 private final int CAP = BasicStroke.CAP_BUTT; 64 55 65 // brush strokes used for painting this line and highlighting 56 private Stroke _lineStroke = new BasicStroke(DEFAULT_THICKNESS, 57 BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);66 private Stroke _lineStroke = new BasicStroke(DEFAULT_THICKNESS, CAP, JOIN, 67 4.0F); 58 68 59 69 // private Stroke _highlightStroke = new BasicStroke (1f + /*GRAVITY + … … 292 302 dash[i] = (float) pattern[i]; 293 303 _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS), 294 BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, dash, 295 0.0f); 304 CAP, JOIN, 10f, dash, 0.0f); 296 305 } else 297 306 _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS), 298 BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);307 CAP, JOIN); 299 308 300 309 if (_start.getLinePattern() != pattern) … … 321 330 _isCircle = true; 322 331 } else { 332 // Get a path of points 333 int[][][] paths = getPaths(); 334 g.setStroke(_lineStroke); 335 for (int i = 0; i < paths.length; i++) { 336 int[][] path = paths[i]; 337 int last = path[0].length - 1; 338 if (path[0][0] == path[0][last] && path[1][0] == path[1][last]) { 339 g.drawPolygon(path[0], path[1], last); 340 } else { 341 g.drawPolyline(path[0], path[1], last + 1); 342 } 343 } 323 344 // paint the arrowhead (if necessary) 324 g.setStroke(new BasicStroke(getThickness(), BasicStroke.CAP_BUTT, 325 BasicStroke.JOIN_MITER)); 326 327 paintArrow(g, _start, _startOffset, _endOffset); 328 paintArrow(g, _end, _endOffset, _startOffset); 329 330 g.setStroke(_lineStroke); 331 g.drawLine(_start.getX() + _startOffset.x, _start.getY() 332 + _startOffset.y, _end.getX() + _endOffset.x, _end.getY() 333 + _endOffset.y); 334 345 paintArrows(g); 346 // g.drawLine(_start.getX() + _startOffset.x, _start.getY() 347 // + _startOffset.y, _end.getX() + _endOffset.x, _end.getY() 348 // + _endOffset.y); 349 // TODO deal with the offset 335 350 _isCircle = false; 336 351 } … … 345 360 if (showLineHighlight() && isHighlighted()) { 346 361 g.setColor(getHighlightColor()); 347 g.setStroke(new BasicStroke(MINIMUM_THICKNESS, 348 BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); 362 g.setStroke(new BasicStroke(MINIMUM_THICKNESS, CAP, JOIN)); 349 363 ((Graphics2D) g).draw(this.getArea()); 350 364 } 365 } 366 367 protected int[][][] getPaths() { 368 List<List<Point>> pointPaths = new LinkedList<List<Point>>(); 369 Collection<Line> visited = new HashSet<Line>(); 370 LinkedList<Line> toExplore = new LinkedList<Line>(); 371 toExplore.add(this); 372 while (toExplore.size() > 0) { 373 Line nextLine = toExplore.remove(0); 374 // Start at the item we have already explored... unless both have 375 // been explored 376 if (!visited.contains(nextLine)) { 377 pointPaths.add(nextLine.getPath(visited, toExplore)); 378 } 379 } 380 // Put the paths into int arrays 381 int[][][] paths = new int[pointPaths.size()][][]; 382 Iterator<List<Point>> iter = pointPaths.iterator(); 383 384 for (int i = 0; i < paths.length; i++) { 385 List<Point> pointPath = iter.next(); 386 int[][] path = new int[2][pointPath.size()]; 387 paths[i] = path; 388 // Add all the x and y's to the array 389 for (int j = 0; j < path[0].length; j++) { 390 path[0][j] = pointPath.get(j).x; 391 path[1][j] = pointPath.get(j).y; 392 } 393 } 394 return paths; 395 } 396 397 protected List<Point> getPath(Collection<Line> visited, 398 LinkedList<Line> toExplore) { 399 LinkedList<Point> points = new LinkedList<Point>(); 400 // put the start item points into our list 401 Item start = getStartItem(); 402 Item end = getEndItem(); 403 visited.add(this); 404 405 start.appendPath(visited, points, 406 true, toExplore); 407 end.appendPath(visited, points, false, 408 toExplore); 409 return points; 410 } 411 412 public void paintArrows(Graphics2D g) { 413 g.setColor(getPaintColor()); 414 g 415 .setStroke(new BasicStroke(getThickness(), CAP, 416 BasicStroke.JOIN_MITER)); 417 paintArrow(g, _start, _startOffset, _endOffset); 418 paintArrow(g, _end, _endOffset, _startOffset); 351 419 352 420 if (_virtualSpot != null) { … … 393 461 int length = (int) Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); 394 462 395 if (arrowLength < 0 && length > MINIMUM_ARROW_HEAD_LENGTH) { 463 // The length of the line must at least be as long as the arrow or we 464 // wont show the arrow 465 if (length <= MINIMUM_ARROW_HEAD_LENGTH) 466 return; 467 if (arrowLength == AUTO_ARROWHEAD_LENGTH) { 396 468 arrowLength = length / ARROW_HEAD_TO_LENGTH_RATIO; 397 469 arrowLength = Math.max(MINIMUM_ARROW_HEAD_LENGTH, arrowLength); 470 arrowLength = Math.min(MAXIMUM_ARROW_HEAD_LENGTH, arrowLength); 398 471 withArrow.setArrowhead(null); 399 472 if (arrowRatio < 0) … … 571 644 dash[i] = (float) pattern[i]; 572 645 _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS), 573 BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, dash, 574 0.0f); 646 CAP, JOIN, 10f, dash, 0.0f); 575 647 } else 576 648 _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS), 577 BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);649 CAP, JOIN); 578 650 } 579 651 … … 629 701 int length = (int) Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); 630 702 length /= ARROW_HEAD_TO_LENGTH_RATIO; 631 arrow.setArrowheadLength(Math.m ax(MINIMUM_ARROW_HEAD_LENGTH, length));703 arrow.setArrowheadLength(Math.min(MAXIMUM_ARROW_HEAD_LENGTH,Math.max(MINIMUM_ARROW_HEAD_LENGTH, length))); 632 704 } 633 705 … … 718 790 719 791 private static int[] ArrowHeadLength = new int[] { /* AUTO_ARROWHEAD_LENGTH, */ 720 0, 20, 40, 80};792 0, 20, 40, MAXIMUM_ARROW_HEAD_LENGTH }; 721 793 722 794 /** … … 805 877 Item spot = new Dot(mouseX, mouseY, -1); 806 878 spot.setThickness(Math.max(this.getThickness(), 5)); 807 if ( this.getColor() != Color.RED)808 spot.setColor( Color.RED);879 if (DEFAULT_HIGHLIGHT.equals(this.getColor())) 880 spot.setColor(ALTERNATE_HIGHLIGHT); 809 881 else 810 spot.setColor( Color.BLUE);882 spot.setColor(DEFAULT_HIGHLIGHT); 811 883 812 884 // calculate nearest point on line from spot … … 913 985 914 986 // lines that are in 'connected' mode, also cannot be attached 915 if (spot.isFloating() && spot.getLines().get(0).getOppositeEnd(spot).isFloating()) 987 if (spot.isFloating() 988 && spot.getLines().get(0).getOppositeEnd(spot).isFloating()) 916 989 return merger; 917 990 … … 1074 1147 1075 1148 public Integer getPossibleConstraint() { 1076 if (_start.getY() == _end.getY() 1077 && _start.getX() != _end.getX()) 1149 if (_start.getY() == _end.getY() && _start.getX() != _end.getX()) 1078 1150 return Constraint.HORIZONTAL; 1079 else if (_start.getX() == _end.getX() && _start.getY() != _end.getY())1151 else if (_start.getX() == _end.getX() && _start.getY() != _end.getY()) 1080 1152 return Constraint.VERTICAL; 1081 1153 return null; -
trunk/src/org/expeditee/items/Picture.java
r97 r105 229 229 /** 230 230 * Returns the Text Item that was used to create this Picture object. This 231 * is required by KMSWriter forsaving the Frame.231 * is required when saving the Frame. 232 232 * 233 233 * @return The Text Item used to create this Picture. -
trunk/src/org/expeditee/items/Text.java
r98 r105 58 58 public static final int MINIMUM_RANGED_CHARS = 2; 59 59 60 public static final int UP = 0; 61 62 public static final int DOWN = 1; 63 64 public static final int LEFT = 2; 65 66 public static final int RIGHT = 3; 67 68 public static final int HOME = 4; 69 70 public static final int END = 5; 71 72 public static final int PAGE_DOWN = 6; 73 74 public static final int PAGE_UP = 7; 60 public static final int NONE = 0; 61 62 public static final int UP = 1; 63 64 public static final int DOWN = 2; 65 66 public static final int LEFT = 3; 67 68 public static final int RIGHT = 4; 69 70 public static final int HOME = 5; 71 72 public static final int END = 6; 73 74 public static final int PAGE_DOWN = 7; 75 76 public static final int PAGE_UP = 8; 75 77 76 78 private int _maxWidth = -1; … … 392 394 // move the cursor to the new location 393 395 float[] caret = last.getCaretInfo(hit); 394 int y = getLineDrop(last) * line;395 396 int x = ((int) (getX() + caret[0] ) + getJustOffset(last));396 float y = getLineDrop(last) * line; 397 398 int x = ((int) (getX() + caret[0] + 0.5) + getJustOffset(last)); 397 399 x = Math 398 400 .min( 399 401 x, 400 402 (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth())); 401 return new Point(x, getY() + /* DisplayIO.getOffset() + */y 402 + (int) caret[1]); 403 return new Point(x, (int) (getY() + y + caret[1] + 0.5)); 403 404 } 404 405 … … 614 615 // move the cursor to the new location 615 616 float[] caret = current.getCaretInfo(hit); 616 int y = getLineDrop(current) * line;617 618 int x = ( (int) (getX() + caret[0]) + getJustOffset(current));617 float y = getLineDrop(current) * line; 618 619 int x = (int) (getX() + caret[0] + 0.5) + getJustOffset(current); 619 620 x = Math 620 621 .min( 621 622 x, 622 623 (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth())); 623 return new Point(x, getY() + y + (int) caret[1]);624 return new Point(x, (int) (getY() + y + caret[1] + 0.5)); 624 625 } 625 626 … … 698 699 // move the cursor to the new location 699 700 float[] caret = current.getCaretInfo(hit); 700 int y = getLineDrop(current) * line;701 702 return new Point((int) (getX() + caret[0] ) + getJustOffset(current),703 getY() + y + (int) caret[1]);701 float y = getLineDrop(current) * line; 702 703 return new Point((int) (getX() + caret[0] + 0.5) 704 + getJustOffset(current), (int) (getY() + y + caret[1] + 0.5)); 704 705 } 705 706 … … 937 938 } 938 939 939 private int getLineDrop(TextLayout layout) {940 private float getLineDrop(TextLayout layout) { 940 941 if (getSpacing() < 0) 941 return (int) (layout.getAscent() + layout.getDescent() + layout942 .getLeading());943 944 return (int) (layout.getAscent() + layout.getDescent() + getSpacing());942 return layout.getAscent() + layout.getDescent() 943 + layout.getLeading(); 944 945 return layout.getAscent() + layout.getDescent() + getSpacing(); 945 946 } 946 947 -
trunk/src/org/expeditee/stats/CometStats.java
r103 r105 4 4 5 5 import org.expeditee.gui.Frame; 6 import org.expeditee.gui.FrameGraphics;7 6 import org.expeditee.io.Logger; 8 7 9 8 public class CometStats { 10 protectedstatic String COLUMN_SEPARATOR = " | ";11 9 static String COLUMN_SEPARATOR = " | "; 10 12 11 protected int _sessions = 0; 13 12 … … 18 17 protected long _dark = 0; 19 18 19 /* 20 * public CometStats(Frame topFrame) { this(topFrame, false); } 21 * 22 * public CometStats(Frame topFrame, boolean includeCurrentSession) { _name = 23 * topFrame.getName(); Frame backupFrame = topFrame; if 24 * (includeCurrentSession) { _active = 25 * SessionStats.getFrameActiveTime().getTime(); if (_active > 0) { _sessions = 26 * 1; _dark = SessionStats.getFrameDarkTime().getTime(); } } 27 * // Keep going back until we have reached the end of the comet tail while 28 * (backupFrame != null) { long backupActive = 29 * backupFrame.getActiveTime().getTime(); // Update the time if user spent 30 * time editing the frame // backupActive will be zero if the frame has not 31 * been saved yet if (backupActive > 0) { _sessions++; _active += 32 * backupActive; _dark += backupFrame.getDarkTime().getTime(); } 33 * FrameGraphics.OverwriteMessage("Computed: " + backupFrame.getName()); // 34 * Get the backup of the backup; backupFrame = backupFrame.getBackupFrame(); } 35 * _sessions = topFrame.getVersion() + 1; } 36 */ 37 20 38 public CometStats(Frame topFrame) { 21 this(topFrame, false); 22 } 39 _name = topFrame.getName(); 23 40 24 public CometStats(Frame topFrame, boolean includeCurrentSession) { 25 _name = topFrame.getName(); 26 Frame backupFrame = topFrame; 27 if (includeCurrentSession) { 28 _active = SessionStats.getFrameActiveTime().getTime(); 29 if (_active > 0) { 30 _sessions = 1; 31 _dark = SessionStats.getFrameDarkTime().getTime(); 32 } 33 } 34 35 // Keep going back until we have reached the end of the comet tail 36 while (backupFrame != null) { 37 long backupActive = backupFrame.getActiveTime().getTime(); 38 // Update the time if user spent time editing the frame 39 // backupActive will be zero if the frame has not been saved yet 40 if (backupActive > 0) { 41 _sessions++; 42 _active += backupActive; 43 _dark += backupFrame.getDarkTime().getTime(); 44 } 45 FrameGraphics.OverwriteMessage("Computed: " + backupFrame.getName()); 46 // Get the backup of the backup; 47 backupFrame = backupFrame.getBackupFrame(); 48 } 41 _active = SessionStats.getFrameActiveTime().getTime() 42 + topFrame.getActiveTime().getTime(); 43 _dark = SessionStats.getFrameDarkTime().getTime() 44 + topFrame.getDarkTime().getTime(); 45 _sessions = topFrame.getVersion() + 1; 49 46 } 50 47 … … 57 54 StringBuffer sb = new StringBuffer(); 58 55 sb.append(SessionStats.getDate()); 59 sb.append("Comet Name: ").append(_name).append('\n');56 sb.append("CometStats: ").append(_name).append('\n'); 60 57 sb.append("Versions: ").append(_sessions).append('\n'); 61 sb.append(" Current | Average | Total").append('\n'); 58 sb.append(" | Current | Average | Total").append('\n'); 59 sb.append("-----------|----------|----------|---------").append('\n'); 62 60 Time averageActive = new Time((long) (0.5 + active.getTime() 63 61 / (1.0 * _sessions))); … … 70 68 Time currentTotal = SessionStats.getFrameTotalTime(); 71 69 72 sb.append("ActiveTime: ").append(Logger.EasyTimeFormat(currentActive)) 73 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageActive)) 74 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(active)).append('\n'); 75 sb.append(" DarkTime: ").append(Logger.EasyTimeFormat(currentDark)) 76 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageDark)).append( 77 COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(dark)).append('\n'); 78 sb.append(" TotalTime: ").append(Logger.EasyTimeFormat(currentTotal)) 79 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageTotal)) 80 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(total)); 70 sb.append("ActiveTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(currentActive)) 71 .append(COLUMN_SEPARATOR).append( 72 Logger.EasyTimeFormat(averageActive)).append( 73 COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(active)) 74 .append('\n'); 75 sb.append(" DarkTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(currentDark)) 76 .append(COLUMN_SEPARATOR).append( 77 Logger.EasyTimeFormat(averageDark)).append( 78 COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(dark)) 79 .append('\n'); 80 sb.append(" TotalTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(currentTotal)) 81 .append(COLUMN_SEPARATOR).append( 82 Logger.EasyTimeFormat(averageTotal)).append( 83 COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(total)); 81 84 return sb.toString(); 82 85 } -
trunk/src/org/expeditee/stats/SessionStats.java
r104 r105 10 10 11 11 import org.expeditee.gui.DisplayIO; 12 import org.expeditee.gui.Frame; 13 import org.expeditee.gui.FrameMouseActions; 12 14 import org.expeditee.gui.FrameUtils; 13 15 import org.expeditee.gui.TimeKeeper; … … 21 23 public class SessionStats { 22 24 25 public static final String COLUMN_SEPARATOR = CometStats.COLUMN_SEPARATOR; 26 27 public static final String COLUMN_SEPARATOR2 = "-|-"; 28 23 29 public static final String DARK_TIME_ATTRIBUTE = "DarkTime:"; 24 30 … … 30 36 31 37 public enum ItemType { 32 Text, Dot, Picture, Line;38 Text, Dot, Line, Picture, Total; 33 39 } 34 40 … … 37 43 } 38 44 39 private static final int STAT_TYPES = 4;40 41 private static final int ITEM_TYPES = 4;45 private static final int STAT_TYPES = StatType.values().length; 46 47 private static final int ITEM_TYPES = ItemType.values().length; 42 48 43 49 private static int[][] _ItemStats = new int[ITEM_TYPES][STAT_TYPES]; … … 108 114 Date currentTime = new Date(); 109 115 long elapsedTime = currentTime.getTime() - _StartTime.getTime(); 110 String time = "" + (int) ((double)elapsedTime / MILLISECONDS_PER_MINUTE + 0.5); // (new 116 String time = "" 117 + (int) ((double) elapsedTime / MILLISECONDS_PER_MINUTE + 0.5); // (new 111 118 // SimpleDateFormat("m").format(elapsedTime)); 112 119 … … 222 229 } 223 230 231 private static StringBuffer getCompactStat(String name, int value, 232 int minValueWidth, int minTotalWidth) { 233 StringBuffer stats = new StringBuffer(); 234 // prevent divide by zero errors 235 if (value > 0) { 236 String perHour = getRate(value); 237 String valueString = "" + value; 238 while (valueString.length() < minValueWidth) 239 valueString = " " + valueString; 240 stats.append(valueString).append("@").append(perHour.toString()) 241 .append("/h"); 242 } 243 while (stats.length() < minTotalWidth) { 244 stats.append(' '); 245 } 246 return stats.append(COLUMN_SEPARATOR); 247 } 248 224 249 private static String getRate(int value) { 225 250 return "" + Math.round(value * 60 / getMinutesUsed()); … … 262 287 FrameEdited(frameName); 263 288 _SavedFrames++; 264 265 _FrameEvents.clear(); 266 _FrameAccessTime = new Date(); 267 _FrameAccessDarkTime = (Time) _DarkTime.clone(); 289 290 NewFrameSession(); 268 291 } 269 292 … … 302 325 303 326 _FrameEvents.add(Logger.EasyDateFormat("mm:ss:SSS", elapsedTime) + " " 304 + DisplayIO.getMouseX() + " " + DisplayIO.getMouseY() + " "327 + DisplayIO.getMouseX() + " " + FrameMouseActions.getY() + " " 305 328 + description); 306 329 } 307 330 308 331 public static Time getFrameDarkTime() { 309 return new Time(_DarkTime.getTime() 310 - _FrameAccessDarkTime.getTime()); 311 } 312 332 return new Time(_DarkTime.getTime() - _FrameAccessDarkTime.getTime()); 333 } 313 334 314 335 public static Time getFrameActiveTime() { 315 return new Time(getFrameTotalTime().getTime() - getFrameDarkTime().getTime()); 336 return new Time(getFrameTotalTime().getTime() 337 - getFrameDarkTime().getTime()); 316 338 } 317 339 318 340 public static Time getFrameTotalTime() { 319 return new Time((new Date()).getTime() 320 - _FrameAccessTime.getTime()); 321 } 322 323 public static String getFrameEventList() { 341 return new Time((new Date()).getTime() - _FrameAccessTime.getTime()); 342 } 343 344 public static String getFrameEventList(Frame currentFrame) { 324 345 StringBuilder eventList = new StringBuilder(); 325 346 // First put on the session and darkTime 326 Time darkTime = getFrameDarkTime(); 327 Time activeTime = getFrameActiveTime(); 347 Time darkTime = currentFrame == null ? getFrameDarkTime() 348 : currentFrame.getDarkTime(); 349 Time activeTime = currentFrame == null ? getFrameActiveTime() 350 : currentFrame.getActiveTime(); 328 351 eventList.append(ACTIVE_TIME_ATTRIBUTE).append( 329 352 Logger.EasyTimeFormat(activeTime)).append('\n'); … … 335 358 eventList.deleteCharAt(eventList.length() - 1); 336 359 return eventList.toString(); 360 } 361 362 public static String getFrameEventList() { 363 return getFrameEventList(null); 337 364 } 338 365 … … 399 426 400 427 public static String getItemStats() { 401 StringBuffer stats = getLength(); 428 429 StringBuffer sb = getLength(); 430 402 431 int max = 0; 432 final int TOTAL_INDEX = ITEM_TYPES - 1; 403 433 for (int i = 0; i < STAT_TYPES; i++) { 404 for (int j = 0; j < ITEM_TYPES; j++) {405 if (_ItemStats[j][i] > max)406 max= _ItemStats[j][i];434 _ItemStats[TOTAL_INDEX][i] = 0; 435 for (int j = 0; j < TOTAL_INDEX; j++) { 436 _ItemStats[TOTAL_INDEX][i] += _ItemStats[j][i]; 407 437 } 438 } 439 for (int i = 0; i < STAT_TYPES; i++) { 440 max = Math.max(_ItemStats[TOTAL_INDEX][i], max); 408 441 } 409 442 int maxWidthValue = ("" + max).length(); 410 443 int maxWidthRate = (getRate(max)).length(); 411 444 445 int maxNameWidth = 0; 446 int maxColumnWidth = 0; 447 ItemType[] itemTypes = ItemType.values(); 448 StatType[] statTypes = StatType.values(); 449 // Get the width of the longest itemType 450 for (int i = 0; i < ITEM_TYPES; i++) { 451 maxNameWidth = Math.max(maxNameWidth, itemTypes[i].toString() 452 .length()); 453 } 454 412 455 for (int i = 0; i < STAT_TYPES; i++) { 413 int total = 0; 414 int nonZeroItems = 0; 415 String statName = StatType.values()[i].toString(); 416 for (int j = 0; j < ITEM_TYPES; j++) { 456 maxNameWidth = Math.max(maxColumnWidth, statTypes[i].toString() 457 .length()); 458 } 459 maxColumnWidth = Math.max(maxWidthRate + maxWidthValue + 3, 460 maxNameWidth); 461 462 sb.append(getBufferedString("", maxNameWidth)).append(COLUMN_SEPARATOR); 463 464 StringBuffer lineSeparator = getBufferedString("", maxNameWidth, '-'); 465 lineSeparator.append(COLUMN_SEPARATOR2); 466 467 for (int i = 0; i < STAT_TYPES; i++) { 468 sb.append( 469 getBufferedString(statTypes[i].toString(), maxColumnWidth)) 470 .append(COLUMN_SEPARATOR); 471 lineSeparator.append(getBufferedString("", maxColumnWidth, '-') 472 .append(COLUMN_SEPARATOR2)); 473 } 474 //Remove the last column separator 475 lineSeparator.delete(lineSeparator.length() 476 - COLUMN_SEPARATOR2.length(), lineSeparator.length() - 1); 477 sb.delete(sb.length() - COLUMN_SEPARATOR.length(), sb.length() - 1); 478 sb.append('\n'); 479 sb.append(lineSeparator).append('\n'); 480 481 for (int j = 0; j < ITEM_TYPES; j++) { 482 sb.append(getBufferedString(itemTypes[j].toString(), maxNameWidth)) 483 .append(COLUMN_SEPARATOR); 484 for (int i = 0; i < STAT_TYPES; i++) { 485 int total = 0; 486 int nonZeroItems = 0; 487 String statName = StatType.values()[i].toString(); 488 417 489 int value = _ItemStats[j][i]; 418 490 if (value > 0) 419 491 nonZeroItems++; 420 492 total += value; 421 appendStat(stats, ItemType.values()[j].toString() + statName,422 value);493 sb.append(getCompactStat(ItemType.values()[j].toString() 494 + statName, value, maxWidthValue, maxColumnWidth)); 423 495 } 424 // Only display a total if the number of items to be counted for the 425 // statType > 1 426 if (nonZeroItems > 1) 427 appendStat(stats, "Total" + statName, total, true, false, 428 maxWidthValue, maxWidthRate); 429 } 430 stats.deleteCharAt(stats.length() - 1); 431 return stats.toString(); 496 sb.delete(sb.length() - COLUMN_SEPARATOR.length(), sb.length() - 1); 497 sb.append('\n'); 498 } 499 // Remove the last newline character 500 sb.deleteCharAt(sb.length() - 1); 501 return sb.toString(); 502 } 503 504 private static StringBuffer getBufferedString(String string, int width) { 505 return getBufferedString(string, width, ' '); 506 } 507 508 private static StringBuffer getBufferedString(String string, int width, 509 char bufferChar) { 510 StringBuffer sb = new StringBuffer(string); 511 while (sb.length() < width) { 512 sb.append(bufferChar); 513 } 514 return sb; 432 515 } 433 516 … … 487 570 return stats; 488 571 } 489 572 490 573 public static StringBuffer getDate() { 491 574 StringBuffer stats = new StringBuffer("Date: "); … … 510 593 DeletedItems(items); 511 594 } 595 596 public static void NewFrameSession() { 597 _FrameEvents.clear(); 598 _FrameAccessTime = new Date(); 599 _FrameAccessDarkTime = (Time) _DarkTime.clone(); 600 } 512 601 } -
trunk/src/org/expeditee/stats/TreeStats.java
r103 r105 20 20 protected long _treeDark = 0; 21 21 22 public TreeStats(Frame topFrame, Set<String> visited) { 23 this(topFrame, false, visited); 22 23 public TreeStats(Frame topFrame) { 24 this(topFrame, new HashSet<String>()); 24 25 } 25 26 26 public TreeStats(Frame topFrame, boolean includeCurrentSession) { 27 this(topFrame, includeCurrentSession, new HashSet<String>()); 28 } 29 30 public TreeStats(Frame topFrame, boolean includeCurrentSession, Set<String> visited) { 31 super(topFrame, includeCurrentSession); 27 public TreeStats(Frame topFrame, Set<String> visited) { 28 super(topFrame); 32 29 visited.add(_name.toLowerCase()); 33 30 FrameGraphics.OverwriteMessage("Computed: " + _name); … … 69 66 StringBuffer sb = new StringBuffer(); 70 67 sb.append(SessionStats.getDate()); 71 sb.append("T opFrame: ").append(_name).append('\n');68 sb.append("TreeStats: ").append(_name).append('\n'); 72 69 sb.append("Frames: ").append(_treeFrames).append('\n'); 73 70 sb.append("Versions: ").append(_treeSessions).append('\n'); 74 sb.append(" VersionAve| FrameAve | Total").append('\n'); 71 sb.append(" |VersionAve| FrameAve | Total").append('\n'); 72 sb.append("-----------|----------|----------|---------").append('\n'); 75 73 Time averageActive = new Time((long) (0.5 + active.getTime() 76 74 / (1.0 * _treeFrames))); … … 86 84 / (1.0 * _treeSessions))); 87 85 88 sb.append("ActiveTime : ").append(Logger.EasyTimeFormat(averageActiveEdit))86 sb.append("ActiveTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageActiveEdit)) 89 87 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageActive)) 90 88 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(active)).append('\n'); 91 sb.append(" DarkTime : ").append(Logger.EasyTimeFormat(averageDarkEdit))89 sb.append(" DarkTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageDarkEdit)) 92 90 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageDark)).append( 93 91 COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(dark)).append('\n'); 94 sb.append(" TotalTime : ").append(Logger.EasyTimeFormat(averageTotalEdit))92 sb.append(" TotalTime").append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageTotalEdit)) 95 93 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(averageTotal)) 96 94 .append(COLUMN_SEPARATOR).append(Logger.EasyTimeFormat(total));
Note:
See TracChangeset
for help on using the changeset viewer.