Changeset 108
- Timestamp:
- 06/27/08 16:44:21 (16 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 1 added
- 1 deleted
- 42 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Actions.java
r103 r108 1 1 package org.expeditee.actions; 2 2 3 import java.awt.GraphicsEnvironment; 3 4 import java.io.File; 4 5 import java.lang.reflect.Constructor; … … 54 55 private static HashMap<String, Method> _Actions = new HashMap<String, Method>(); 55 56 57 // map lower case fonts to capitalized fonts 58 protected static HashMap<String, String> _Fonts = new HashMap<String, String>(); 59 56 60 // maps lower case JAG class names to capitalized JAG names 57 61 private static HashMap<String, String> _JAGs = new HashMap<String, String>(); … … 179 183 */ 180 184 public static Collection<String> Init() { 185 181 186 Collection<String> warnings = new LinkedList<String>(); 182 187 Class[] classes; … … 489 494 public static void stopAgent() { 490 495 if (_Agent != null && _Agent.isRunning()) { 491 FrameGraphics. DisplayMessage("Stopping Agent...");496 FrameGraphics.ErrorMessage("Stopping Agent..."); 492 497 _Agent.stop(); 493 498 } … … 528 533 objects[0] = source; 529 534 ind = 1; 530 } else if ( paramTypes[0] == Item.class) {535 } else if (Item.class.isAssignableFrom(paramTypes[0])) { 531 536 objects[0] = launcher; 532 537 ind = 1; … … 539 544 objects[1] = source; 540 545 ind = 2; 541 } else if ( paramTypes[1] == Item.class) {546 } else if (Item.class.isAssignableFrom(paramTypes[1])) { 542 547 objects[1] = launcher; 543 548 ind = 2; … … 653 658 return command.substring(0, command.indexOf(" ")); 654 659 } 660 661 /** 662 * Gets an uncapitalized font name and returns the capitalized font name. 663 * The capitalized form can be used with the Font.decoded method to get a 664 * corresponding Font object. 665 * 666 * @param fontName 667 * a font name in mixed case 668 * @return the correct capitalized form of the font name 669 */ 670 public static String getCapitalizedFontName(String fontName) { 671 //Initialize the fonts if they have not already been loaded 672 if (_Fonts.size() == 0) { 673 String[] availableFonts = GraphicsEnvironment 674 .getLocalGraphicsEnvironment() 675 .getAvailableFontFamilyNames(); 676 for (String s : availableFonts) { 677 _Fonts.put(s.toLowerCase(), s); 678 } 679 } 680 return _Fonts.get(fontName.toLowerCase()); 681 } 655 682 } -
trunk/src/org/expeditee/actions/Misc.java
r107 r108 3 3 import java.awt.Color; 4 4 import java.awt.Dimension; 5 import java.awt.GraphicsEnvironment;6 5 import java.awt.Image; 7 6 import java.awt.image.BufferedImage; … … 12 11 import java.lang.reflect.Method; 13 12 import java.util.ArrayList; 13 import java.util.Collection; 14 14 import java.util.List; 15 15 … … 258 258 Frame current = DisplayIO.getCurrentFrame(); 259 259 Item text = current.getStatsTextItem(itemText); 260 text.setSelectedMode(Item.SelectedMode.Normal);261 text.setSelectedMode(Item.SelectedMode.None);262 260 FrameMouseActions.pickup(text); 263 261 FrameGraphics.Repaint(); … … 312 310 public static void GetAvailableFontFamilyNames() { 313 311 314 String[] availableFonts = GraphicsEnvironment 315 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); 312 Collection<String> availableFonts = Actions._Fonts.values(); 316 313 StringBuilder fontsList = new StringBuilder(); 317 314 for (String s : availableFonts) { -
trunk/src/org/expeditee/actions/NavigationActions.java
r105 r108 25 25 } 26 26 27 private static void Default() {28 System.out.println("Not Implemented");29 }30 31 27 /** 32 28 * Performs a back operation from the current Frame. If the back-stack is … … 35 31 public static void Back() { 36 32 DisplayIO.Back(); 37 }38 39 public static void ClearBack(Item i) {40 Default();41 }42 43 public static void DeleteBack() {44 Default();45 }46 47 public static void GetBack(String topFrame, int x, int y) {48 Default();49 }50 51 public static void GetBackList() {52 Default();53 33 } 54 34 … … 223 203 } 224 204 225 public static void OtherWindow() {226 Default();227 }228 229 205 /** 230 206 * Turns TwinFrames on if it is off, otherwise does nothing -
trunk/src/org/expeditee/actions/Simple.java
r107 r108 4 4 import java.awt.Point; 5 5 import java.awt.event.InputEvent; 6 import java.awt.geom.Point2D; 6 7 import java.io.BufferedReader; 7 8 import java.io.InputStreamReader; … … 188 189 private String _frameset; 189 190 190 private boolean _verbose;191 private static boolean _verbose = false; 191 192 192 193 public Simple(String frameset, boolean verbose) { … … 216 217 if (nextFrame == null) 217 218 continue; 218 ItemframeTitle = nextFrame.getTitleItem();219 Text frameTitle = nextFrame.getTitleItem(); 219 220 if (frameTitle == null) 220 221 continue; 221 222 // Run the frames with the RunFrame action on the title 222 Itemtitle = frameTitle.copy();223 Text title = frameTitle.copy(); 223 224 List<String> actions = title.getAction(); 224 225 if (actions == null || title.isAnnotation()) … … 235 236 _KeyStrokes.clear(); 236 237 _programsRunning++; 237 RunFrameAndReportError(title, new Context()); 238 Context context = new Context(); 239 RunFrameAndReportError(title, context); 238 240 _programsRunning--; 239 241 // if the throws exception annotation is on the frame then … … 306 308 } 307 309 308 private static void RunFrame( Itemcurrent, boolean acceptKeyboardInput,310 private static void RunFrame(Text current, boolean acceptKeyboardInput, 309 311 boolean step, int pause, Color color) { 310 312 try { … … 321 323 // an item without a link signals to run the current frame 322 324 if (current.getLink() == null) { 325 //Make a copy but hide it 323 326 current = current.copy(); 324 327 current.setLink(DisplayIO.getCurrentFrame().getName()); … … 334 337 } 335 338 336 public static void RunFrame( Itemcurrent, boolean acceptKeyboardInput) {339 public static void RunFrame(Text current, boolean acceptKeyboardInput) { 337 340 RunFrame(current, acceptKeyboardInput, false, 0, null); 338 341 } 339 342 340 public static void RunFrame( Itemcurrent) {343 public static void RunFrame(Text current) { 341 344 RunFrame(current, false); 342 345 } … … 348 351 * @param pause 349 352 */ 350 public static void DebugFrame(Item current, float pause, Color color) { 353 public static void DebugFrame(Text current, float pause, Color color) { 354 if(isProgramRunning()){ 355 stop(); 356 } 351 357 RunFrame(current, false, true, Math.round(pause * 1000), color); 352 358 } … … 359 365 * the time to pause between 360 366 */ 361 public static void DebugFrame( Itemcurrent, float pause) {367 public static void DebugFrame(Text current, float pause) { 362 368 DebugFrame(current, pause, null); 363 369 } 364 370 365 public static void DebugFrame( Itemcurrent) {371 public static void DebugFrame(Text current) { 366 372 DebugFrame(current, -1.0F, null); 367 373 } … … 391 397 Frame child = FrameIO.LoadFrame(current.getAbsoluteLink()); 392 398 399 // Create frame variables for each linked annotation item on the frame 400 // which has a single word of text corresponding to the variable name 401 for (Text text : child.getAnnotationItems()) { 402 String link = text.getAbsoluteLink(); 403 if (link == null) 404 continue; 405 Frame frame = FrameIO.LoadFrame(link); 406 if (frame == null) 407 continue; 408 // Now save the frame as a variable 409 String varName = text.getText().substring(1).trim(); 410 if (varName.indexOf(' ') > 0) 411 continue; 412 context.getPointers().setObject(SPointer.framePrefix + varName, 413 frame); 414 context.getPrimitives().add(SString.prefix + varName, 415 new SString(frame.getName())); 416 } 417 393 418 if (_step) { 394 419 if (child != DisplayIO.getCurrentFrame()) { … … 419 444 Color oldColor = item.getBackgroundColor(); 420 445 if (_step) { 421 if (item.getLink() != null) { 422 pause(item); 423 item.setSelectedMode(Item.SelectedMode.Normal, 424 _stepColor); 425 } else { 426 item.setBackgroundColor(_stepColor); 427 } 428 FrameGraphics.Repaint(); 446 pause(item); 429 447 } 430 448 lastItemStatus = RunItem(item, context, lastItemStatus); … … 432 450 if (item.getLink() == null) { 433 451 item.setBackgroundColor(oldColor); 434 pause(item);435 452 } else { 436 453 item.setSelectedMode(Item.SelectedMode.None); … … 464 481 if (_step) { 465 482 DisplayIO.removeFromBack(); 466 DisplayIO.setCurrentFrame(current.getParent()); 483 if(DisplayIO.getCurrentFrame() != current.getParent()) 484 DisplayIO.setCurrentFrame(current.getParent()); 467 485 } 468 486 … … 776 794 assertExactParametreCount(tokens, 3); 777 795 778 Map map = (Map) context.getPointers().getVariable(tokens[1])796 Map<String,String> map = (Map<String,String>) context.getPointers().getVariable(tokens[1]) 779 797 .getValue(); 780 798 String attribute = context.getPrimitives().getStringValue( … … 812 830 // attribute without the value in the same item 813 831 if (!found && attributeItem != null) { 814 Point endPoint = attributeItem.getEndParagraphPosition(); 832 Point2D.Float endPoint = attributeItem 833 .getEndParagraphPosition(); 815 834 816 835 for (Text text : targetFrame.getBodyTextItems(true)) { … … 1050 1069 // attribute without the value in the same item 1051 1070 if (!found && attributeItem != null) { 1052 Point endPoint = attributeItem1071 Point2D.Float endPoint = attributeItem 1053 1072 .getEndParagraphPosition(); 1054 1073 … … 1112 1131 .getValue(); 1113 1132 t.setText(log); 1133 } else if (tokens[0].equals("getframeitemcount")) { 1134 String frameVar = DEFAULT_FRAME; 1135 String countVar = DEFAULT_INTEGER; 1136 if (tokens.length > 1) { 1137 assertExactParametreCount(tokens, 2); 1138 assertVariableType(tokens[1], 1, SPointer.framePrefix); 1139 frameVar = tokens[1]; 1140 countVar = tokens[2]; 1141 } 1142 Frame frame = (Frame) context.getPointers().getVariable( 1143 frameVar).getValue(); 1144 Integer count = frame.getItems(true).size(); 1145 context.getPrimitives().setValue(countVar, 1146 new SInteger(count)); 1114 1147 } 1115 1148 } else if (tokens[0].equals("getassociation")) { … … 1189 1222 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1190 1223 // assertPrimitiveType(tokens[2], 2); 1191 Integer size = ( (Item) context.getPointers().getVariable(1192 tokens[1]).getValue()).getSize();1224 Integer size = (int) ((Item) context.getPointers() 1225 .getVariable(tokens[1]).getValue()).getSize(); 1193 1226 context.getPrimitives().setValue(tokens[2], 1194 1227 new SInteger(size)); … … 1402 1435 String codeText = getMessage(tokens, context, code.toString(), " ", 1403 1436 1); 1404 Text dynamicCode = new Text( 1,codeText);1437 Text dynamicCode = new Text(codeText); 1405 1438 RunItem(dynamicCode, context, Status.OK); 1406 1439 } else if (tokens[0].equals("runoscommand")) { … … 1682 1715 try { 1683 1716 success = FrameIO.DeleteFrame(frame); 1684 if (!success )1717 if (!success && _verbose) 1685 1718 FrameGraphics.WarningMessage(errorMessage); 1686 1719 } catch (Exception e) { 1687 1720 // If an exception is thrown then success is false 1688 FrameGraphics 1689 .WarningMessage(errorMessage 1690 + (e.getMessage() != null ? ". " 1691 + e.getMessage() : "")); 1721 if (_verbose) { 1722 FrameGraphics.WarningMessage(errorMessage 1723 + (e.getMessage() != null ? ". " + e.getMessage() 1724 : "")); 1725 } 1692 1726 } 1693 1727 if (tokens.length > 2) { … … 1700 1734 tokens[1]); 1701 1735 boolean success = FrameIO.DeleteFrameset(framesetName); 1702 if (!success )1736 if (!success && _verbose) { 1703 1737 FrameGraphics.WarningMessage("Error deleting " + framesetName); 1738 } 1704 1739 if (tokens.length > 2) { 1705 1740 context.getPrimitives().setValue(tokens[2], … … 1722 1757 boolean success = FrameIO.CopyFrameset(framesetToCopy, 1723 1758 copiedFrameset); 1724 if (!success )1759 if (!success && _verbose) 1725 1760 FrameGraphics.WarningMessage("Error copying " + framesetToCopy); 1726 1761 if (tokens.length > 3) { … … 1746 1781 context.getPointers().setObject(tokens[2], freshCopy); 1747 1782 String fileContents = FrameIO.ForceSaveFrame(freshCopy); 1783 FrameIO.ResumeCache(); 1784 // Need to add the new copy to the cache in case it is edited by 1785 // other simple statements 1786 FrameIO.addToCache(freshCopy); 1748 1787 boolean success = fileContents != null; 1749 if (!success )1788 if (!success && _verbose) 1750 1789 FrameGraphics.WarningMessage("Error copying " 1751 1790 + frameToCopy.getName()); 1752 FrameIO.ResumeCache();1753 1791 if (tokens.length > 4) { 1754 1792 context.getPrimitives().setValue(tokens[4], … … 2014 2052 count = countCharsInString(((Text) item).getText(), pattern); 2015 2053 context.getPrimitives().setValue(tokens[3], new SInteger(count)); 2054 } else if (tokens[0].equals("clearframe")) { 2055 String frameVar = DEFAULT_FRAME; 2056 if (tokens.length > 1) { 2057 assertMinParametreCount(tokens, 1); 2058 assertVariableType(tokens[1], 1, SPointer.framePrefix); 2059 frameVar = tokens[1]; 2060 } 2061 boolean success = true; 2062 try { 2063 Frame frameToClear = (Frame) context.getPointers().getVariable( 2064 frameVar).getValue(); 2065 frameToClear.clear(false); 2066 assert (frameToClear.getItems().size() <= 1); 2067 } catch (Exception e) { 2068 success = false; 2069 } 2070 if (tokens.length > 2) { 2071 assertExactParametreCount(tokens, 2); 2072 context.getPrimitives().setValue(tokens[2], 2073 new SBoolean(success)); 2074 } 2016 2075 } else if (tokens[0].equals("parseframename")) { 2017 2076 assertExactParametreCount(tokens, 4); … … 2026 2085 } catch (Exception e) { 2027 2086 success = false; 2028 FrameGraphics.WarningMessage("Error parsing " + frameName); 2087 if (_verbose) 2088 FrameGraphics.WarningMessage("Error parsing " + frameName); 2029 2089 } 2030 2090 // assertPrimitiveType(tokens[2], 2); … … 2491 2551 FrameGraphics.DisplayMessage("Running SimpleProgram...", Color.BLUE); 2492 2552 } 2553 2554 public static boolean isVerbose() { 2555 return _verbose; 2556 } 2493 2557 } -
trunk/src/org/expeditee/agents/ComputeTree.java
r97 r108 20 20 protected Frame process(Frame frame) { 21 21 _format.setMinimumFractionDigits(0); 22 if (computeFrame(frame) == null ) {22 if (computeFrame(frame) == null && !_stop) { 23 23 message("Nothing to compute!"); 24 24 } … … 38 38 String computeTag = null; 39 39 for (Item i : frame.getItems()) { 40 if(_stop) 41 return null; 40 42 if (i.isAnnotation()) { 41 43 String s = ((Text) i).getFirstLine().toLowerCase().trim(); … … 85 87 // operation 86 88 for (Item i : frame.getBodyTextItems(false)) { 89 if(_stop) 90 return null; 87 91 Double value = null; 88 92 // Process the frame that each item is linked to -
trunk/src/org/expeditee/agents/DefaultAgent.java
r86 r108 98 98 99 99 SessionStats.setEnabled(false); 100 100 _start.change(); 101 101 _end = process(_start); 102 102 -
trunk/src/org/expeditee/agents/DisplayTree.java
r86 r108 81 81 Item delay = ItemUtils.FindTag(toSearch.getItems(), 82 82 "@DisplayTreePause:"); 83 83 84 if (delay != null) { 84 85 try { -
trunk/src/org/expeditee/agents/SwitchyardTree.java
r80 r108 2 2 3 3 import java.awt.Color; 4 import java.awt. Point;4 import java.awt.geom.Point2D; 5 5 6 6 import org.expeditee.gui.Frame; … … 16 16 for (Text textItem : frame.getBodyTextItems(false)) { 17 17 // Delete all non-annotations with more that one letter 18 if (textItem.getText().length() > 1) 18 if (textItem.getText().length() > 1){ 19 19 frame.removeItem(textItem); 20 else { 20 if(_stop) 21 return null; 22 }else { 21 23 // goto child frame of any linked 1 letter items 22 24 String link = textItem.getAbsoluteLink(); … … 24 26 Frame childFrame = FrameIO.LoadFrame(link); 25 27 if (childFrame != null) { 26 Point lastItemEnd = textItem.getEndParagraphPosition();28 Point2D.Float lastItemEnd = textItem.getEndParagraphPosition(); 27 29 for (Text childItem : childFrame.getBodyTextItems(false)) { 28 30 // look for red items … … 31 33 Text itemCopy = childItem.copy(); 32 34 // add to the right of parent item 33 lastItemEnd. translate(20, 0);34 itemCopy.setPosition(lastItemEnd );35 lastItemEnd.setLocation(lastItemEnd.x + 20, lastItemEnd.y); 36 itemCopy.setPosition(lastItemEnd.x, lastItemEnd.y); 35 37 lastItemEnd = itemCopy 36 38 .getEndParagraphPosition(); … … 38 40 } 39 41 _itemCount++; 42 if(_stop) 43 return null; 40 44 } 41 45 } -
trunk/src/org/expeditee/gui/AttributeUtils.java
r102 r108 13 13 import org.expeditee.items.Item; 14 14 import org.expeditee.items.Justification; 15 import org.expeditee.items.Permission; 15 16 import org.expeditee.items.Text; 16 17 … … 127 128 128 129 _GetMethods.add(Frame.class.getMethod("getOwner", param)); 129 _GetMethods.add(Frame.class.getMethod("getP rotection", param));130 _GetMethods.add(Frame.class.getMethod("getPermission", param)); 130 131 _GetMethods.add(Frame.class.getMethod("getDateCreated", param)); 131 132 _GetMethods.add(Frame.class.getMethod("getLastModifyUser", param)); … … 140 141 Class[] pColor = { Color.class }; 141 142 Class[] pBool = { boolean.class }; 142 Class[] pArrow = { int.class, double.class };143 Class[] pArrow = { float.class, double.class }; 143 144 Class[] pList = { List.class }; 144 145 Class[] pIntArray = { int[].class }; 145 146 Class[] pJustification = { Justification.class }; 147 Class[] pPermission = { Permission.class }; 146 148 147 149 _SetMethods = new HashMap<String, Method>(); … … 228 230 "setJustification", pJustification)); 229 231 _SetMethods.put("width", Text.class.getMethod("setWidth", pInt)); 230 _SetMethods.put("size", Item.class.getMethod("setSize", p Int));231 _SetMethods.put("s", Item.class.getMethod("setSize", p Int));232 _SetMethods.put("size", Item.class.getMethod("setSize", pFloat)); 233 _SetMethods.put("s", Item.class.getMethod("setSize", pFloat)); 232 234 233 235 _SetMethods.put("foregroundcolor", Frame.class.getMethod( … … 239 241 _SetMethods.put("bgc0", Frame.class.getMethod("setBackgroundColor", 240 242 pColor)); 241 _SetMethods.put("p rotection", Frame.class.getMethod(242 "setP rotection", pString));243 _SetMethods.put("permission", Frame.class.getMethod( 244 "setPermission", pPermission)); 243 245 244 246 } catch (SecurityException e) { … … 626 628 */ 627 629 public static String getAttribute(String attributeValuePair) { 630 if(attributeValuePair.length() <= 1) 631 return null; 632 628 633 attributeValuePair = attributeValuePair.trim(); 629 634 -
trunk/src/org/expeditee/gui/Browser.java
r102 r108 65 65 66 66 public Browser() { 67 FrameGraphics.SupressMessages(true); 67 68 // Use the default values initially so we can load the profile frame 68 69 setSizes(new Dimension(UserSettings.InitialWidth, … … 93 94 } 94 95 } 96 //DisplayIO.setCurrentFrame(profile); 95 97 FrameUtils.ParseProfile(profile); 96 97 98 // Now reset the size of the windows to the size specified in the users 98 99 // profile … … 115 116 pack(); 116 117 try { 117 go(); 118 Collection<String> warningMessages = Actions.Init(); 119 120 DisplayIO.Init(this); 121 // Set visible must be just after DisplayIO.Init for the message box to 122 // be the right size 123 setVisible(true); 124 setVisible(false); 125 126 setupGraphics(); 127 128 // required to accept TAB key 129 setFocusTraversalKeysEnabled(false); 130 131 FrameUtils.loadFirstFrame(profile); 132 133 134 DisplayIO.UpdateTitle(); 135 136 FrameGraphics.SupressMessages(false); 137 //I think this can be moved back up to the top of the Go method now... 138 //It used to crash the program trying to print error messages up the top 139 for (String message : warningMessages) 140 FrameGraphics.WarningMessage(message); 141 142 FrameKeyboardActions keyboardListner = new FrameKeyboardActions(); 143 this.getContentPane().addKeyListener(keyboardListner); 144 this.addKeyListener(keyboardListner); 145 146 FrameKeyboardActions.Refresh(); 147 setVisible(true); 118 148 } catch (Exception e) { 119 149 e.printStackTrace(); 120 150 Logger.Log(e); 121 151 } 122 // FrameGraphics.ForceRepaint();123 152 } 124 153 125 154 Graphics2D g; 126 127 /**128 * Loads in the Menus and the first Frame.129 */130 public void go() {131 Collection<String> warningMessages = Actions.Init();132 133 DisplayIO.Init(this);134 // Set visible must be just after DisplayIO.Init for the message box to135 // be the right size136 setVisible(true);137 138 setupGraphics();139 140 // required to accept TAB key141 setFocusTraversalKeysEnabled(false);142 143 assert (UserSettings.FirstFrame != null);144 Frame firstFrame = FrameIO.LoadFrame(UserSettings.FirstFrame);145 146 DisplayIO.setCurrentFrame(firstFrame);147 DisplayIO.UpdateTitle();148 149 //I think this can be moved back up to the top of the Go method now...150 //It used to crash the program trying to print error messages up the top151 for (String message : warningMessages)152 FrameGraphics.WarningMessage(message);153 154 FrameKeyboardActions keyboardListner = new FrameKeyboardActions();155 this.getContentPane().addKeyListener(keyboardListner);156 this.addKeyListener(keyboardListner);157 }158 155 159 156 private void setupGraphics() { -
trunk/src/org/expeditee/gui/ColorUtils.java
r80 r108 5 5 public class ColorUtils { 6 6 7 public static Color getNextColor(Color color, Color[] wheel) { 7 /** 8 * Gets the next color in the specified color wheel. 9 * 10 * @param color 11 * the current color 12 * @param wheel 13 * the color wheel from which to find the next color 14 * @param skip 15 * a color to ignore, for example the current background color when getting the next foreground color or 16 * null if no colors should be skipped 17 * @return the next color on the color wheel 18 */ 19 public static Color getNextColor(Color color, Color[] wheel, Color skip) { 20 if (color == null) 21 return wheel[0]; 8 22 // search through the colour wheel to find the next colour 9 23 int pos = -1; 10 for (int i = 0; i < wheel.length; i++){ 11 if (color == null) { 12 break; 13 } else if (color.equals(wheel[i])) { 24 for (int i = 0; i < wheel.length; i++) { 25 if (color.equals(wheel[i])) { 14 26 pos = i; 15 27 break; … … 20 32 color = wheel[pos]; 21 33 34 if (skip != null && skip.equals(color)) 35 return getNextColor(color, wheel, skip); 36 22 37 return color; 23 38 } -
trunk/src/org/expeditee/gui/DisplayIO.java
r106 r108 8 8 import java.awt.Robot; 9 9 import java.awt.Toolkit; 10 import java.awt.geom.Point2D; 10 11 import java.awt.image.MemoryImageSource; 11 12 import java.util.LinkedList; … … 17 18 import org.expeditee.items.Item; 18 19 import org.expeditee.items.ItemParentStateChangedEvent; 20 import org.expeditee.items.Permission; 19 21 import org.expeditee.items.Picture; 20 22 import org.expeditee.items.Text; … … 58 60 * The title to display in the Title bar. 59 61 */ 60 public static final String TITLE = "Exp2 0Jun2008A";62 public static final String TITLE = "Exp26Jun2008B"; 61 63 62 64 private DisplayIO() { … … 88 90 boolean newSize) { 89 91 90 int size = text.getSize();91 Point newMouse = text.moveCursor(cursorMovement, DisplayIO.getMouseX(),92 FrameMouseActions. getY());92 int size = Math.round(text.getSize()); 93 Point2D.Float newMouse = text.moveCursor(cursorMovement, DisplayIO.getFloatMouseX(), 94 FrameMouseActions.MouseY); 93 95 94 96 if (!newSize && cursorType == Item.TEXT_CURSOR) { … … 230 232 * @param pos 231 233 */ 234 public static void setCursorPosition(Point2D.Float pos) { 235 setCursorPosition(pos.x, pos.y); 236 } 237 232 238 public static void setCursorPosition(Point pos) { 233 239 setCursorPosition(pos.x, pos.y); … … 235 241 236 242 public static void setCursorPosition(Point pos, boolean forceArrow) { 243 setCursorPosition(pos.x, pos.y, forceArrow); 244 } 245 246 public static void setCursorPosition(Point2D.Float pos, boolean forceArrow) { 237 247 setCursorPosition(pos.x, pos.y, forceArrow); 238 248 } … … 351 361 if (_CurrentFrames[getOppositeSide()] == frame 352 362 || _CurrentFrames[getOppositeSide()].getOverlays() 353 .contains(new Overlay(frame, 1))) {363 .contains(new Overlay(frame, Permission.followLinks))) { 354 364 FrameIO.SuspendCache(); 355 365 frame = FrameIO.LoadFrame(frame.getName()); … … 713 723 */ 714 724 public static void MoveCursorToEndOfItem(Item i) { 715 setTextCursor((Text) i, Text.END );725 setTextCursor((Text) i, Text.END, true); 716 726 } 717 727 } -
trunk/src/org/expeditee/gui/Frame.java
r105 r108 12 12 import java.util.Collections; 13 13 import java.util.HashMap; 14 import java.util.LinkedHashSet; 14 15 import java.util.LinkedList; 15 16 import java.util.List; … … 26 27 import org.expeditee.items.ItemUtils; 27 28 import org.expeditee.items.Line; 29 import org.expeditee.items.Permission; 28 30 import org.expeditee.items.Text; 29 31 import org.expeditee.items.WidgetCorner; 32 import org.expeditee.items.XRayable; 30 33 import org.expeditee.stats.SessionStats; 31 34 32 35 /** 33 * Represents a Expeditee Frame that is displayed on the screen. Also is a registered 34 * MouseListener on the Browser, and processes any MouseEvents directly. 36 * Represents a Expeditee Frame that is displayed on the screen. Also is a 37 * registered MouseListener on the Browser, and processes any MouseEvents 38 * directly. 35 39 * 36 40 * @author jdm18 … … 39 43 public class Frame implements ImageObserver { 40 44 41 public static Color[] COLOR_WHEEL = { 42 new Color(235, 235, 235), new Color(225, 225, 255), 43 new Color(195, 255, 255), new Color(225, 255, 225), 44 new Color(255, 255, 195), new Color(255, 225, 225), 45 new Color(255, 195, 255), Color.WHITE, 46 Color.GRAY, Color.DARK_GRAY,Color.BLACK, null }; 45 private boolean _protectionChanged = false; 46 47 public boolean isReadOnly() { 48 return !_frameName.hasPermission(Permission.full) 49 && !_protectionChanged; 50 } 51 52 public static Color[] COLOR_WHEEL = { new Color(235, 235, 235), 53 new Color(225, 225, 255), new Color(195, 255, 255), 54 new Color(225, 255, 225), new Color(255, 255, 195), 55 new Color(255, 225, 225), new Color(255, 195, 255), Color.WHITE, 56 Color.GRAY, Color.DARK_GRAY, Color.BLACK, null }; 47 57 48 58 // The various attributes of this Frame … … 53 63 private int _version = 0; 54 64 55 private String _protection = "" + Item.PERMISSION_FULL;65 private Permission _permission = null; 56 66 57 67 private String _owner = null; … … 184 194 */ 185 195 public void setChanged(boolean value) { 186 // System.out.println(getName() + " " + value);196 // System.out.println(getName() + " " + value); 187 197 _change = value; 188 198 … … 204 214 * @return The list of Item objects that are on this Frame. 205 215 */ 206 public List<Item> getItems( ) {216 public List<Item> getItems(boolean visible) { 207 217 208 218 if (!_sorted) { … … 211 221 } 212 222 213 List<Item> visibleItems = new ArrayList<Item>();223 List<Item> items = new ArrayList<Item>(); 214 224 215 225 for (Item i : _body) { 216 if (i.isVisible()) 217 visibleItems.add(i); 218 } 219 220 return visibleItems; 226 if (i == null) 227 continue; 228 if (i.isVisible() || (!visible && !i.isDeleted())) { 229 items.add(i); 230 } 231 } 232 233 return items; 234 } 235 236 public List<Item> getItems() { 237 return getItems(false); 221 238 } 222 239 … … 233 250 234 251 /** 252 * Gets a list of all the non annotation text items on the frame, excluding 253 * the title and frame name. 254 * 255 * @param includeAnnotations 256 * true if annotations should be included in the list 257 * @return list of text items 258 */ 259 public List<Text> getBodyTextItems(boolean includeAnnotations) { 260 return getBodyTextItems(includeAnnotations, false); 261 } 262 263 /** 235 264 * Returns a list of all the non annotation text items on the frame which 236 265 * are not the title or frame name. 237 266 * 267 * @param includeLineEnds 268 * true if text on the end of lines should be included in the 269 * list 238 270 * @return the list of body text items. 239 271 */ 240 public List<Text> getBodyTextItems(boolean includeAnnotations) { 272 public List<Text> getBodyTextItems(boolean includeAnnotations, 273 boolean includeLineEnds) { 241 274 List<Text> bodyTextItems = new ArrayList<Text>(); 242 275 for (Item i : getItems()) { 243 276 // only add up normal body text items 244 277 if ((i instanceof Text) 245 && (includeAnnotations || !i.isAnnotation())) { 278 && (includeAnnotations || !i.isAnnotation()) 279 && (includeLineEnds || !i.isLineEnd())) { 246 280 bodyTextItems.add((Text) i); 247 281 } … … 345 379 for (Item i : items) { 346 380 if (i instanceof Text && i.getX() < UserSettings.TitlePosition 347 && i.getY() < UserSettings.TitlePosition /* 348 * && i.getY() > 349 * 0 350 */) 381 && i.getY() < UserSettings.TitlePosition) 351 382 return (Text) i; 352 383 } … … 399 430 // We dont want the stats to wrap at all 400 431 t.setMaxSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); 432 t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY()); 433 // The next line is needed to make sure the item is removed from the 434 // frame when picked up 435 t.setParent(this); 401 436 t.setText(itemText); 402 t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());403 404 //The next line is needed to allow the link to be set properly when the item is picked up405 _body.add(t);406 //The next line is needed to make sure the item is removed from the frame when picked up407 t.setParent(this);408 437 return t; 409 438 } 410 411 439 412 440 public Text getCodeCommentTemplate() { … … 430 458 * Item.intersects(shape) return true. 431 459 */ 432 public List<Item> getItemsWithin(Polygon poly) { 433 List<Item> results = new ArrayList<Item>(); 434 435 for (Item i : _body) 436 if (i.isVisible() && i.intersects(poly)) { 437 if (!results.contains(i)) 460 public Collection<Item> getItemsWithin(Polygon poly) { 461 Collection<Item> results = new LinkedHashSet<Item>(); 462 for (Item i : getVisibleItems()) { 463 if (i.intersects(poly)) { 464 if (i instanceof XRayable) { 465 results.addAll(i.getConnected()); 466 } else { 438 467 results.add(i); 439 } 468 } 469 } 470 } 440 471 441 472 for (Overlay o : _overlays) … … 517 548 * The protection to use for this Frame. 518 549 */ 519 public void setProtection(String protection) { 520 _protection = protection; 550 public void setPermission(Permission permission) { 551 if (_permission != null && _permission.equals(permission)) 552 _protectionChanged = true; 553 554 _permission = permission; 521 555 522 556 if (_body.size() > 0) … … 593 627 */ 594 628 public void addItem(Item item) { 595 if (item != null) { 596 if (_body.contains(item)) { 597 // System.out.println("Item (" + item.getClass().getSimpleName() 598 // + ") with ID " + item.getID() + " already in body."); 599 return; 600 } 601 602 if (item instanceof Line) 603 _lineCount++; 604 605 _itemCount = Math.max(_itemCount, item.getID()); 606 607 _body.add(item); 608 item.setParent(this); 609 610 // If the item is a line end and has constraints with items already 611 // on the frame then make sure the constraints hold 612 if (item.isLineEnd()) { 613 item.setPosition(item.getPosition()); 614 } 615 616 _sorted = false; 617 618 item.setMaxSize(FrameGraphics.getMaxFrameSize()); 619 // add widget items to the list of widgets 620 if (item instanceof WidgetCorner) { 621 InteractiveWidget iw = ((WidgetCorner) item).getWidgetSource(); 622 if (!this._iWidgets.contains(iw)) { // A set would have been 623 // best 624 _iWidgets.add(iw); 625 } 626 } 627 628 item.onParentStateChanged(new ItemParentStateChangedEvent(this, 629 ItemParentStateChangedEvent.EVENT_TYPE_ADDED)); 630 631 change(); 632 } 629 if (item == null || item.equals(_frameName) || _body.contains(item)) 630 return; 631 632 if (item instanceof Line) 633 _lineCount++; 634 635 _itemCount = Math.max(_itemCount, item.getID()); 636 637 _body.add(item); 638 item.setParent(this); 639 640 // If the item is a line end and has constraints with items already 641 // on the frame then make sure the constraints hold 642 if (item.isLineEnd()) { 643 item.setPosition(item.getPosition()); 644 } 645 646 _sorted = false; 647 648 item.setMaxSize(FrameGraphics.getMaxFrameSize()); 649 // add widget items to the list of widgets 650 if (item instanceof WidgetCorner) { 651 InteractiveWidget iw = ((WidgetCorner) item).getWidgetSource(); 652 if (!this._iWidgets.contains(iw)) { // A set would have been 653 // best 654 _iWidgets.add(iw); 655 } 656 } 657 658 item.onParentStateChanged(new ItemParentStateChangedEvent(this, 659 ItemParentStateChangedEvent.EVENT_TYPE_ADDED)); 660 661 change(); 633 662 } 634 663 … … 637 666 return; 638 667 639 for (Item i : _body) 640 i.setMaxSize(max); 668 for (Item i : _body) { 669 if (i != null) 670 i.setMaxSize(max); 671 } 641 672 642 673 _frameName.resetFrameNamePosition(); … … 769 800 } 770 801 771 public String getProtection() { 772 return _protection; 802 public Permission getPermission() { 803 return getPermission(Permission.full); 804 } 805 806 public Permission getPermission(Permission defaultPermission) { 807 if (_permission == null) 808 return defaultPermission; 809 810 return _permission; 773 811 } 774 812 … … 847 885 s += "Name: " + _frameset + _number + "\n"; 848 886 s += "Version: " + _version + "\n"; 849 s += "Protection: " + _p rotection + "\n";887 s += "Protection: " + _permission + "\n"; 850 888 s += "Owner: " + _owner + "\n"; 851 889 s += "Date Created: " + _creationDate + "\n"; … … 863 901 864 902 public Item getItemAbove(Item current) { 903 // Make sure the items are sorted 904 Collections.sort(_body); 865 905 int ind = _body.indexOf(current); 866 906 if (ind == -1) … … 1263 1303 * items are added to the backup-stack. 1264 1304 */ 1265 public void clear( ) {1305 public void clear(boolean keepAnnotations) { 1266 1306 List<Item> newBody = new ArrayList<Item>(0); 1267 for (Item i : _body) 1268 if (i.isAnnotation() || i == getNameItem() || i == getTitleItem()) 1269 newBody.add(i); 1270 1307 Item title = getTitleItem(); 1308 if (title != null) { 1309 newBody.add(title); 1310 _body.remove(title); 1311 } 1312 if (keepAnnotations) { 1313 for (Item i : _body) { 1314 if (i.isAnnotation()) 1315 newBody.add(i); 1316 } 1317 } 1271 1318 _body.removeAll(newBody); 1272 1319 addAllToUndo(_body); 1273 1320 _body = newBody; 1321 change(); 1274 1322 } 1275 1323 … … 1307 1355 t.setText(""); 1308 1356 t.setParent(this); 1357 addItem(t); 1309 1358 return t; 1310 1359 } … … 1328 1377 1329 1378 private Text getTemplate(Text defaultTemplate, int templateTag) { 1330 Text t = defaultTemplate;1379 Text t = null; 1331 1380 1332 1381 // check for an updated template... … … 1338 1387 } 1339 1388 1340 if (t == null) 1341 return null; 1389 if (t == null) { 1390 if (defaultTemplate == null) { 1391 return null; 1392 } 1393 t = defaultTemplate; 1394 } 1342 1395 1343 1396 // If the item is linked apply any attribute pairs on the child frame … … 1378 1431 t.setPosition(x, y); 1379 1432 t.addAction(action); 1380 1381 addItem(t);1382 1433 return t; 1383 1434 } … … 1400 1451 1401 1452 public void setSaved() { 1402 // System.out.println(getName() + " saved");1453 // System.out.println(getName() + " saved"); 1403 1454 _saved = true; 1404 1455 _change = false; … … 1529 1580 public void toggleBackgroundColor() { 1530 1581 setBackgroundColor(ColorUtils.getNextColor(_background, 1531 Frame.COLOR_WHEEL ));1582 Frame.COLOR_WHEEL, null)); 1532 1583 } 1533 1584 … … 1542 1593 */ 1543 1594 public void refreshItemPermissions() { 1544 int permission = FrameUtils.getPermissionLevel(_protection, 1545 Item.PERMISSION_FULL); 1546 1547 _frameName.Permission = permission; 1595 Permission permission = getPermission(); 1596 _frameName.setPermission(permission); 1597 1548 1598 switch (permission) { 1549 case Item.PERMISSION_NONE:1599 case none: 1550 1600 _frameName.setBackgroundColor(new Color(255, 220, 220)); 1551 1601 break; 1552 case Item.PERMISSION_FOLLOW_LINKS:1602 case followLinks: 1553 1603 _frameName.setBackgroundColor(new Color(255, 230, 135)); 1554 1604 break; 1555 case Item.PERMISSION_COPY:1605 case copy: 1556 1606 _frameName.setBackgroundColor(new Color(255, 255, 155)); 1557 1607 break; 1558 case Item.PERMISSION_TDFC:1608 case createFrames: 1559 1609 _frameName.setBackgroundColor(new Color(220, 255, 220)); 1560 1610 break; 1561 case Item.PERMISSION_FULL:1611 case full: 1562 1612 _frameName.setBackgroundColor(null); 1563 1613 break; … … 1568 1618 1569 1619 for (Item i : _body) { 1570 i. Permission = permission;1620 i.setPermission(_permission); 1571 1621 } 1572 1622 } … … 1592 1642 } 1593 1643 } 1594 1595 public void setActiveTime(Time activeTime) {1644 1645 public void setActiveTime(Time activeTime) { 1596 1646 _activeTime = activeTime; 1597 1647 } 1598 1599 public void setDarkTime(Time darkTime) {1648 1649 public void setDarkTime(Time darkTime) { 1600 1650 _darkTime = darkTime; 1601 1651 } … … 1640 1690 return _darkTime; 1641 1691 } 1642 1692 1643 1693 public Time getActiveTime() { 1644 1694 return _activeTime; … … 1721 1771 _annotations.clear(); 1722 1772 } 1773 1774 public List<Item> getVisibleItems() { 1775 return getItems(true); 1776 } 1777 1778 public Collection<Text> getAnnotationItems() { 1779 return _annotations.values(); 1780 } 1781 1782 /** 1783 * Gets a list of items to be saved to file by text file writers. 1784 * 1785 * @return the list of items to be saved to a text file 1786 */ 1787 public List<Item> getItemsToSave() { 1788 1789 if (!_sorted) { 1790 Collections.sort(_body); 1791 _sorted = true; 1792 } 1793 1794 // iWidgets are handled specially since 8 items are written as one 1795 Collection<InteractiveWidget> seenWidgets = new LinkedHashSet<InteractiveWidget>(); 1796 1797 List<Item> toSave = new ArrayList<Item>(); 1798 1799 for (Item i : _body) { 1800 // TODO Mike says: checkout if the ID check is still needed- When 1801 // will ID still 1802 // be -1 when saving a frame? 1803 if (i == null || i instanceof Line || !i.isVisible() 1804 || i.getID() < 0 || i.offScreenTopOrLeft()) { 1805 continue; 1806 } 1807 1808 // Ensure only one of the WidgetCorners represent a single widget 1809 if (i instanceof WidgetCorner) { 1810 InteractiveWidget iw = ((WidgetCorner) i).getWidgetSource(); 1811 if (seenWidgets.contains(iw)) 1812 continue; 1813 seenWidgets.add(iw); 1814 toSave.add(iw.getSource()); 1815 } else if(i instanceof XRayable){ 1816 XRayable x = (XRayable)i; 1817 toSave.addAll(x.getItemsToSave()); 1818 }//Circle centers are items with attached enclosures 1819 else if (i.hasEnclosures()){ 1820 continue; 1821 }else{ 1822 toSave.add(i); 1823 } 1824 } 1825 1826 return toSave; 1827 } 1723 1828 } -
trunk/src/org/expeditee/gui/FrameCreator.java
r97 r108 22 22 private int _lastY = START_Y; 23 23 24 private Item _Mnext = new Text( -1,"@Next");24 private Item _Mnext = new Text("@Next"); 25 25 26 private Item _Mprev = new Text( -1,"@Previous");26 private Item _Mprev = new Text("@Previous"); 27 27 28 28 private Item _next; -
trunk/src/org/expeditee/gui/FrameGraphics.java
r106 r108 12 12 import java.awt.Point; 13 13 import java.awt.RenderingHints; 14 import java.awt. Stroke;14 import java.awt.geom.Point2D; 15 15 import java.awt.image.BufferedImage; 16 16 import java.awt.image.VolatileImage; … … 27 27 28 28 import org.expeditee.actions.Misc; 29 import org.expeditee.items.Circle; 29 30 import org.expeditee.items.InteractiveWidget; 30 31 import org.expeditee.items.Item; … … 34 35 import org.expeditee.items.Text; 35 36 import org.expeditee.items.WidgetEdge; 37 import org.expeditee.items.XRayable; 36 38 37 39 public class FrameGraphics { … … 114 116 public static void ToggleXRayMode() { 115 117 if (_Mode == MODE_XRAY) 116 _Mode = MODE_NORMAL;118 setMode(MODE_NORMAL, true); 117 119 else 118 _Mode = MODE_XRAY; 119 120 FrameUtils.Parse(DisplayIO.getCurrentFrame()); 120 setMode(MODE_XRAY, true); 121 121 DisplayIO.UpdateTitle(); 122 FrameMouseActions.getInstance().refreshHighlights(); 122 123 Repaint(); 124 } 125 126 public static void setMode(int mode, boolean parse) { 127 if (_Mode == mode) 128 return; 129 _Mode = mode; 130 if (parse) 131 FrameUtils.Parse(DisplayIO.getCurrentFrame()); 123 132 } 124 133 … … 222 231 AddAllOverlayItems(items, o.Frame, seenOverlays); 223 232 224 items.addAll(overlay.get Items());233 items.addAll(overlay.getVisibleItems()); 225 234 } 226 235 … … 242 251 */ 243 252 public static void AddAllVectorItems(List<Item> items, Frame vector, 244 Collection<Frame> seenVectors, Point origin, Float scale,253 Collection<Frame> seenVectors, Point2D.Float origin, Float scale, 245 254 Color defaultForeground, Color defaultBackground) { 246 255 … … 250 259 seenVectors.add(vector); 251 260 252 int originX = origin == null ? 0 : origin.x;253 int originY = origin == null ? 0 : origin.y;261 float originX = origin == null ? 0 : origin.x; 262 float originY = origin == null ? 0 : origin.y; 254 263 255 264 for (Vector o : vector.getVectors()) 256 265 AddAllVectorItems(items, o.Frame, new HashSet<Frame>(seenVectors), 257 new Point (originX + Math.round(o.Origin.x * scale), originY258 + Math.round(o.Origin.y * scale)), o.Scale * scale,266 new Point2D.Float(originX + o.Origin.x * scale, originY 267 + o.Origin.y * scale), o.Scale * scale, 259 268 o.Foreground, o.Background); 260 269 // if its the original frame then were done … … 264 273 } 265 274 // Put copies of the items shifted to the origin of the VectorTag 266 int dx = origin.x; 267 int dy = origin.y; 268 List<Item> copies = ItemUtils.CopyItems(vector.getItems()); 275 float dx = origin.x; 276 float dy = origin.y; 277 List<Item> copies = ItemUtils 278 .CopyItems(vector.getVisibleItems(), false); 269 279 // FrameMouseActions 270 Iterator<Item> iterator = copies.iterator();271 while (iterator.hasNext()) {272 Item i = iterator.next();280 while (!copies.isEmpty()) { 281 Iterator<Item> iterator = copies.iterator(); 282 Item item = iterator.next(); 273 283 // Dont paint annotation items for @v 274 if ( i.isAnnotation()) {284 if (!item.isVisible() || item.isAnnotation()) { 275 285 iterator.remove(); 276 286 continue; 277 287 } 278 i.setLinkMark(false); 279 i.setActionMark(false); 280 if (!(i instanceof Line)) { 281 i.setXY(Math.round(i.getX() * scale + dx), Math.round(i.getY() 282 * scale + dy)); 283 i.setThickness(Math.round(i.getThickness() * scale)); 284 i 285 .setArrowheadLength(Math.round(i.getArrowheadLength() 286 * scale)); 287 if (i.getColor() == null) { 288 i.setColor(defaultForeground); 288 item.setLinkMark(false); 289 item.setActionMark(false); 290 if (!(item instanceof Line)) { 291 item.setThickness(item.getThickness() * scale); 292 Collection<Item> connected = item.getAllConnected(); 293 for (Item i : connected) { 294 if (!(i instanceof Line)) { 295 i.setXY(i.getX() * scale + dx, i.getY() * scale + dy); 296 i.setArrowheadLength(i.getArrowheadLength() * scale); 297 if (i.getColor() == null) { 298 i.setColor(defaultForeground); 299 } 300 if (i.getBackgroundColor() == null) { 301 i.setBackgroundColor(defaultBackground); 302 } 303 if (i.getFillColor() == null) { 304 i.setFillColor(defaultBackground); 305 } 306 if (i instanceof Text) 307 i.setSize(i.getSize() * scale); 308 else if (i instanceof Picture) { 309 Picture p = (Picture) i; 310 p.setScale(p.getScale() * scale); 311 } 312 } 289 313 } 290 if (i.getBackgroundColor() == null) { 291 i.setBackgroundColor(defaultBackground); 292 } 293 if (i.getFillColor() == null) { 294 i.setFillColor(defaultBackground); 295 } 296 } 297 if (i instanceof Text) 298 i.setSize(Math.round(i.getSize() * scale)); 299 items.add(i); 314 items.addAll(connected); 315 copies.removeAll(connected); 316 } else { 317 items.add(item); 318 } 300 319 } 301 320 } … … 381 400 382 401 if (isActualFrame) { 402 // Add all the items for this frame and any other from other 403 // frames 383 404 AddAllOverlayItems(paintItems, toPaint, new LinkedList<Frame>()); 384 405 … … 388 409 389 410 } else { 390 paintItems.addAll(toPaint.get Items());411 paintItems.addAll(toPaint.getVisibleItems()); 391 412 paintWidgets = toPaint.getInteractiveWidgets(); 392 413 } … … 399 420 400 421 PaintPictures(bg, paintItems); 401 402 if (toPaint == DisplayIO.getCurrentFrame()) 422 PaintLines(bg, paintItems); 423 424 if (isActualFrame /* && toPaint == DisplayIO.getCurrentFrame() */) 403 425 PaintPictures(bg, Frame.FreeItems); 404 405 PaintLines(bg, paintItems);426 // TODO if we can get transparency with FreeItems... then text can 427 // be done before freeItems 406 428 PaintNonLinesNonPicture(bg, paintItems); 407 429 408 430 // toPaint.setBufferValid(true); 431 432 if (isActualFrame && !isAudienceMode()) { 433 PaintItem(bg, toPaint.getNameItem()); 434 } 409 435 410 436 if (DisplayIO.isTwinFramesOn()) { … … 442 468 } 443 469 } 444 PaintLines(bg, lines); 470 if (isActualFrame) 471 PaintLines(bg, lines); 445 472 } else { 446 // PaintPictures(bg, Frame.FreeItems);447 // PaintNonLinesNonPicture(bg, Frame.FreeItems);448 PaintLines(bg, Frame.FreeItems);449 } 450 451 if ( toPaint == DisplayIO.getCurrentFrame())473 // Dont paint the 474 if (isActualFrame) 475 PaintLines(bg, Frame.FreeItems); 476 } 477 478 if (isActualFrame /* && toPaint == DisplayIO.getCurrentFrame() */) 452 479 PaintNonLinesNonPicture(bg, Frame.FreeItems); 453 454 if (isActualFrame && !isAudienceMode()) {455 PaintItem(bg, toPaint.getNameItem());456 }457 480 458 481 // BROOK: Ensure popups are repainted … … 613 636 private static void PaintNonLinesNonPicture(Graphics2D g, List<Item> toPaint) { 614 637 for (Item i : toPaint) 615 if (!(i instanceof Line) && !(i instanceof Picture))638 if (!(i instanceof Line) && !(i instanceof XRayable)) 616 639 PaintItem(g, i); 617 640 } 618 641 642 /** 643 * Paint the lines that are not part of an enclosure. 644 * 645 * @param g 646 * @param toPaint 647 */ 619 648 private static void PaintLines(Graphics2D g, List<Item> toPaint) { 620 Stroke oldStroke = g.getStroke();621 649 // Use this set to keep track of the items that have been painted 622 650 Collection<Item> done = new HashSet<Item>(); 623 651 for (Item i : toPaint) 624 652 if (i instanceof Line) { 625 Line l = (Line) i;653 Line l = (Line) i; 626 654 if (done.contains(l)) { 627 655 l.paintArrows(g); … … 633 661 } 634 662 } 635 g.setStroke(oldStroke); 636 } 637 663 } 664 665 /** 666 * Paint filled areas and their surrounding lines as well as pictures. 667 * 668 * @param g 669 * @param toPaint 670 */ 638 671 private static void PaintPictures(Graphics2D g, List<Item> toPaint) { 639 672 // Use this set to keep track of the items that dont need to be … … 643 676 for (Item i : toPaint) { 644 677 // Ignore items that have already been done! 678 // Also ignore invisible items.. 679 // TODO possibly ignore invisible items before coming to this 680 // method? 645 681 if (done.contains(i)) 646 682 continue; 647 if (i instanceof Picture) { 648 PaintItem(g, i); 683 if (i instanceof XRayable) { 684 toFill.add(i); 685 done.addAll(i.getConnected()); 686 } else if (i.hasEnclosures()) { 687 for (Item enclosure : i.getEnclosures()) { 688 if (!toFill.contains(enclosure)) 689 toFill.add(enclosure); 690 } 691 done.addAll(i.getConnected()); 649 692 } else if (i.isLineEnd() 650 693 && (!isAudienceMode() || !i.isConnectedToAnnotation())) { … … 653 696 } 654 697 } 655 // Sort the items to fill698 // Sort the items to fill 656 699 Collections.sort(toFill, new Comparator<Item>() { 657 700 public int compare(Item a, Item b) { 658 IntegeraArea = a.getEnclosedArea();659 IntegerbArea = b.getEnclosedArea();701 Double aArea = a.getEnclosedArea(); 702 Double bArea = b.getEnclosedArea(); 660 703 return aArea.compareTo(bArea) * -1; 661 704 } 662 705 }); 663 for(Item i: toFill){ 664 i.paintFill(g); 665 PaintItem(g, i.getLines().get(0)); 706 for (Item i : toFill) { 707 if (i instanceof XRayable) { 708 PaintItem(g, i); 709 } else { 710 // Paint the fill and lines 711 i.paintFill(g); 712 PaintItem(g, i.getLines().get(0)); 713 } 666 714 } 667 715 } … … 705 753 } 706 754 } 755 } else if (i instanceof Circle) { 756 i.setSelectedMode(Item.SelectedMode.Connected); 707 757 } 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 } 714 i.setSelectedMode(Item.SelectedMode.Normal); 758 // FrameGraphics.ChangeSelectionMode(i, 759 // Item.SelectedMode.Normal); 760 // For polygons need to make sure all other endpoints are 761 // unHighlighted 762 ChangeSelectionMode(i, Item.SelectedMode.Normal, 763 Item.SelectedMode.None); 715 764 } 716 765 Repaint(); … … 719 768 720 769 public static void ChangeSelectionMode(Item item, Item.SelectedMode newMode) { 770 ChangeSelectionMode(item, newMode, newMode); 771 } 772 773 public static void ChangeSelectionMode(Item item, 774 Item.SelectedMode newMode, Item.SelectedMode connectedNewMode) { 721 775 if (item == null) 722 776 return; 723 724 for (Item i : item.getAllConnected()) 725 i.setSelectedMode(newMode); 777 boolean freeItem = Frame.FreeItems.contains(item); 778 for (Item i : item.getAllConnected()) { 779 // Mike: TODO comment on what the line below does!! 780 // I forgot already!!Opps 781 if (freeItem || !Frame.FreeItems.contains(i)) { 782 i.setSelectedMode(connectedNewMode); 783 } 784 } 785 if (newMode != connectedNewMode) 786 item.setSelectedMode(newMode); 726 787 Repaint(); 727 788 } … … 813 874 for (int i = 0; i < Messages.length; i++) { 814 875 if (Messages[i] == null) { 815 Messages[i] = new Text( -1,getMessagePrefix(true) + message);876 Messages[i] = new Text(getMessagePrefix(true) + message); 816 877 Messages[i].setPosition(20, pos); 817 878 Messages[i].setOffset(0, -_MaxSize.height); … … 938 999 for (Component c : parent.getComponents()) { 939 1000 if (c instanceof JPopupMenu && ((JPopupMenu) c).isVisible()) { 940 941 1001 Point p = SwingUtilities.convertPoint(c, c.getLocation(), 942 1002 Browser._theBrowser.getContentPane()); … … 951 1011 } 952 1012 } 1013 1014 public static int getMode() { 1015 return _Mode; 1016 } 953 1017 } -
trunk/src/org/expeditee/gui/FrameIO.java
r105 r108 23 23 import org.expeditee.items.Item; 24 24 import org.expeditee.items.ItemUtils; 25 import org.expeditee.items.Permission; 25 26 import org.expeditee.items.Text; 26 27 import org.expeditee.stats.SessionStats; … … 142 143 return null; 143 144 145 String frameNameLower = frameName.toLowerCase(); 144 146 // first try reading from cache 145 if (isCacheOn() && _Cache.containsKey(frameName .toLowerCase())) {147 if (isCacheOn() && _Cache.containsKey(frameNameLower)) { 146 148 Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName 147 149 + " from cache."); 148 return _Cache.get(frameName .toLowerCase());150 return _Cache.get(frameNameLower); 149 151 } 150 152 … … 289 291 _UseCache = cache; 290 292 if (_Cache.containsKey(fresh.getName().toLowerCase())) 291 _Cache.put(fresh.getName().toLowerCase(),fresh);293 addToCache(fresh); 292 294 DisplayIO.setCurrentFrame(fresh); 293 295 } … … 672 674 // Dont save if the frame is protected and it exists 673 675 if (checkBackup 674 && toSave. getNameItem().Permission < Item.PERMISSION_TDFC) {676 && toSave.isReadOnly()) { 675 677 _Cache.remove(toSave.getName().toLowerCase()); 676 678 SessionStats.NewFrameSession(); … … 709 711 ResumeCache(); 710 712 // Put the modified version in the cache 711 _Cache.put(toSave.getName().toLowerCase(),toSave);713 addToCache(toSave); 712 714 // Show the messages alerting the user 713 715 Text originalMessage = new Text(-1); … … 734 736 735 737 original.setFrameNumber(nextnum); 736 original.setP rotection("" + Item.PERMISSION_COPY);738 original.setPermission(Permission.copy); 737 739 original.change(); 738 740 SaveFrame(original, false, false); … … 756 758 toSave.setActiveTime(activeTime); 757 759 760 //int oldMode = FrameGraphics.getMode(); 761 //if (oldMode != FrameGraphics.MODE_XRAY) 762 // FrameGraphics.setMode(FrameGraphics.MODE_XRAY, true); 758 763 writer.writeFrame(toSave); 764 //FrameGraphics.setMode(oldMode, true); 759 765 toSave.setSaved(); 760 766 if (inc) { … … 764 770 // avoid out-of-sync frames (when in TwinFrames mode) 765 771 if (_Cache.containsKey(toSave.getName().toLowerCase())) 766 _Cache.put(toSave.getName().toLowerCase(),toSave);772 addToCache(toSave); 767 773 768 774 Logger.Log(Logger.SYSTEM, Logger.SAVE, "Saving " + toSave.getName() … … 790 796 791 797 return writer.getFileContents(); 798 } 799 800 /** 801 * @param toAdd 802 */ 803 public static void addToCache(Frame toAdd) { 804 _Cache.put(toAdd.getName().toLowerCase(), toAdd); 792 805 } 793 806 -
trunk/src/org/expeditee/gui/FrameKeyboardActions.java
r105 r108 2 2 3 3 import java.awt.Color; 4 import java.awt.Point;5 4 import java.awt.Toolkit; 6 5 import java.awt.datatransfer.DataFlavor; … … 8 7 import java.awt.event.KeyEvent; 9 8 import java.awt.event.KeyListener; 9 import java.awt.geom.Point2D; 10 10 import java.util.ArrayList; 11 11 import java.util.Collection; 12 import java.util.HashSet; 12 13 import java.util.LinkedList; 13 14 import java.util.List; … … 18 19 import org.expeditee.actions.Simple; 19 20 import org.expeditee.io.Logger; 21 import org.expeditee.items.Circle; 20 22 import org.expeditee.items.Dot; 21 23 import org.expeditee.items.Item; … … 23 25 import org.expeditee.items.Justification; 24 26 import org.expeditee.items.Line; 27 import org.expeditee.items.Permission; 25 28 import org.expeditee.items.Text; 29 import org.expeditee.items.XRayable; 26 30 import org.expeditee.stats.SessionStats; 27 31 … … 32 36 public synchronized void keyTyped(KeyEvent e) { 33 37 if (Simple.isProgramRunning()) { 34 if (e. getKeyChar() == KeyEvent.VK_ESCAPE35 || (e.isControlDown() &&e.getKeyChar() == KeyEvent.VK_C)) {38 if (e.isControlDown() 39 && (e.getKeyChar() == KeyEvent.VK_ESCAPE || e.getKeyChar() == KeyEvent.VK_C)) { 36 40 Simple.stop(); 41 return; 37 42 } else if (e.isControlDown() && e.getKeyChar() == KeyEvent.VK_SPACE) { 38 43 Simple.nextStatement(); 39 }40 41 Simple.KeyStroke(e.getKeyChar());42 44 return; 45 } else { 46 Simple.KeyStroke(e.getKeyChar()); 47 } 43 48 if (Simple.consumeKeyboardInput()) 44 49 return; … … 49 54 return; 50 55 } 51 // ingnore auto TDFC key sequence 52 if (e.getKeyChar() == KeyEvent.VK_ENTER && e.isControlDown()) 53 return; 54 55 if (FrameMouseActions.isWaitingForRobot()) { 56 // try{ 57 // Thread.sleep(10000); 58 // }catch(Exception ex){ 59 // 60 // } 61 // keyTyped(e); 62 // System.out.println("Waiting: " + e.getKeyChar()); 63 return; 64 } 56 57 // Deal with splitting text items when typing too fast 58 // Mike: thinks this problem may have been solved and was due to 59 // rounding errors in the text class... 60 // It may have been fixed by changing to the use of floats instead of 61 // ints for text positioning etc 62 // if (FrameMouseActions.isWaitingForRobot()) { 63 // System.out.println("Waiting: " + e.getKeyChar()); 64 // return; 65 // } 65 66 e.consume(); 66 67 char ch = e.getKeyChar(); … … 80 81 81 82 // permission check 82 if (on != null && on.Permission < Item.PERMISSION_FULL) {83 if (on != null && !on.hasPermission(Permission.full)) { 83 84 FrameGraphics 84 85 .DisplayMessage("Insufficient permission to edit this item"); … … 96 97 97 98 // ignore delete and backspace if in free space 98 if ( on == null99 if ((on == null || !(on instanceof Text)) 99 100 && (ch == KeyEvent.VK_BACK_SPACE || ch == KeyEvent.VK_TAB || ch == KeyEvent.VK_DELETE)) 100 101 return; … … 135 136 text = createText(ch); 136 137 FrameUtils.LastEdited = text; 137 DisplayIO.getCurrentFrame().addItem(text);138 138 DisplayIO.setTextCursor(text, Text.NONE); 139 139 return; … … 141 141 142 142 DisplayIO.setTextCursor(text, Text.NONE); 143 Point newMouse = null;143 Point2D.Float newMouse = null; 144 144 if (ch == '\t') { 145 145 if (isShiftDown) { 146 newMouse = text.removeTab(ch, DisplayIO.get MouseX(),147 FrameMouseActions. getY());146 newMouse = text.removeTab(ch, DisplayIO.getFloatMouseX(), 147 FrameMouseActions.MouseY); 148 148 } else { 149 newMouse = text.insertTab(ch, DisplayIO.get MouseX(),150 FrameMouseActions. getY());149 newMouse = text.insertTab(ch, DisplayIO.getFloatMouseX(), 150 FrameMouseActions.MouseY); 151 151 } 152 152 } else { 153 newMouse = text.insertChar(ch, DisplayIO.get MouseX(),154 FrameMouseActions. getY());153 newMouse = text.insertChar(ch, DisplayIO.getFloatMouseX(), 154 FrameMouseActions.MouseY); 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)158 // This repaint is needed for WINDOWS only?!?!? Mike is not sure why! 159 if (ch == KeyEvent.VK_DELETE) 160 160 FrameGraphics.Repaint(); 161 161 162 162 // a change has occured to the Frame 163 163 text.getParent().setChanged(true); … … 183 183 } 184 184 185 public static ItemreplaceDot(Item dot, char ch) {186 Itemtext = createText(ch);185 public static Text replaceDot(Item dot, char ch) { 186 Text text = createText(ch); 187 187 Item.DuplicateItem(dot, text); 188 188 FrameUtils.LastEdited = text; … … 194 194 Frame current = dot.getParentOrCurrentFrame(); 195 195 current.removeItem(dot); 196 current.addItem(text);197 196 ItemUtils.EnclosedCheck(current.getItems()); 198 197 return text; … … 233 232 Text t = DisplayIO.getCurrentFrame().createBlankText("" + start); 234 233 235 Point newMouse = t.insertChar(start, DisplayIO.getMouseX(),234 Point2D.Float newMouse = t.insertChar(start, DisplayIO.getMouseX(), 236 235 FrameMouseActions.getY()); 237 236 DisplayIO.setCursorPosition(newMouse.x, newMouse.y, false); … … 266 265 return; 267 266 } else { 268 FrameUtils.LastEdited = on;267 FrameUtils.LastEdited = (Text) on; 269 268 DisplayIO.setTextCursor((Text) on, direction); 270 269 } … … 313 312 } 314 313 315 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { 316 functionKey(FunctionKey.DropDown); 317 SessionStats.Escape(); 318 return; 319 } else if (e.getKeyCode() >= KeyEvent.VK_F1 314 if (e.getKeyCode() >= KeyEvent.VK_F1 320 315 && e.getKeyCode() <= KeyEvent.VK_F12) { 321 316 functionKey(FunctionKey.values()[e.getKeyCode() - KeyEvent.VK_F1 322 + 1]); 323 return; 324 } else if (e.isControlDown() && e.getKeyCode() != KeyEvent.VK_CONTROL) 325 controlChar(e, e.getKeyCode()); 317 + 1], e.isShiftDown()); 318 return; 319 } else if (e.isControlDown() && e.getKeyCode() != KeyEvent.VK_CONTROL) { 320 controlChar(e.getKeyCode(), e.isShiftDown()); 321 return; 322 } 323 324 // Do escape last so Ctl+Escape does not perform DropDown 325 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { 326 functionKey(FunctionKey.DropDown, false); 327 SessionStats.Escape(); 328 return; 329 } 326 330 327 331 switch (e.getKeyCode()) { 328 332 case KeyEvent.VK_CONTROL: 329 FrameMouseActions. shift(e);333 FrameMouseActions.control(e); 330 334 break; 331 335 case KeyEvent.VK_LEFT: … … 360 364 case KeyEvent.VK_HOME: 361 365 move(Text.HOME); 362 break;363 case KeyEvent.VK_ENTER:364 if (e.isControlDown()) {365 FrameMouseActions.leftButton(FrameUtils.getCurrentItem());366 FrameMouseActions.updateCursor();367 }368 366 break; 369 367 } … … 384 382 List<Text> textItems = current.getBodyTextItems(false); 385 383 if (textItems.size() == 0) { 384 //If there are no text items on the frame its a NoOp 385 if(title == null) 386 return; 386 387 DisplayIO.MoveCursorToEndOfItem(title); 387 388 FrameGraphics.Repaint(); … … 420 421 } 421 422 // If the user is on the title item 422 if (current .getTitleItem().equals(currentItem)) {423 if (current != null && title != null && title.equals(currentItem)) { 423 424 if (down) { 424 425 // Move to the first item … … 428 429 return; 429 430 } 431 430 432 // Find the current item... then move to the next item 431 433 for (int i = 0; i < textItems.size(); i++) { … … 437 439 .get(nextIndex)); 438 440 } 439 } else {441 } else if (title != null) { 440 442 DisplayIO.MoveCursorToEndOfItem(title); 441 443 } … … 452 454 public void keyReleased(KeyEvent e) { 453 455 if (e.getKeyCode() == KeyEvent.VK_CONTROL) { 454 FrameMouseActions. shift(e);456 FrameMouseActions.control(e); 455 457 } 456 458 } … … 473 475 } 474 476 475 private static void copyItemToClipboard(Item on) {477 private static void copyItemToClipboard(Item on) { 476 478 if (on == null || !(on instanceof Text)) 477 479 return; … … 487 489 // add the text of the item to the clipboard 488 490 StringSelection selection = new StringSelection(text); 489 Toolkit.getDefaultToolkit().getSystemClipboard().setContents( 490 selection,null);491 } 492 491 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, 492 null); 493 } 494 493 495 /** 494 496 * Processes all control character keystrokes. Currently Ctrl+C and Ctrl+V … … 498 500 * The character being pressed along with the control key 499 501 */ 500 private static void controlChar( KeyEvent e, int key) {502 private static void controlChar(int key, boolean isShiftDown) { 501 503 Logger.Log(Logger.USER, Logger.CONTROL_CHAR, "User pressing: Ctrl+" 502 504 + KeyEvent.getKeyText(key)); … … 570 572 if (clicked != null) { 571 573 // check permissions 572 if ( clicked.Permission < Item.PERMISSION_FULL574 if (!clicked.hasPermission(Permission.full) 573 575 && clicked.getParent() != null 574 576 && clicked.getParent().getNameItem() != clicked) { … … 612 614 // if this is a copy command 613 615 } else if (key == KeyEvent.VK_C) { 614 Item on = FrameUtils.getCurrentItem(); 615 if (on != null && on.Permission < Item.PERMISSION_COPY) { 616 if (current == null) 617 return; 618 619 if (current instanceof Text) { 620 if (current != null && !current.hasPermission(Permission.copy)) { 621 FrameGraphics 622 .DisplayMessage("Insufficient permission to copy that item"); 623 return; 624 } 625 copyItemToClipboard(current); 626 // FrameGraphics.DisplayMessage("Item copied to clipboard"); 627 return; 628 } 629 if (current != null && !current.hasPermission(Permission.full)) { 616 630 FrameGraphics 617 .DisplayMessage("Insufficient permission to copy that item" ); 618 return; 619 } 620 copyItemToClipboard(on); 621 //FrameGraphics.DisplayMessage("Item copied to clipboard"); 631 .DisplayMessage("Insufficient permission edit that item"); 632 return; 633 } 634 Text item = null; 635 // Check if its a line to be turned into a circle 636 if (current instanceof Dot && current.getLines().size() == 1) { 637 item = replaceDot(current, '@'); 638 } else if (current instanceof Line 639 && current.getAllConnected().size() == 3) { 640 Item end = ((Line) current).getEndItem(); 641 if (end instanceof Dot) { 642 item = replaceDot(end, '@'); 643 } else if (end instanceof Text) { 644 item = (Text) end; 645 } 646 } 647 item.setText("@c"); 648 DisplayIO.setCursorPosition(item.getX(), item.getY()); 649 FrameUtils.setLastEdited(null); 650 Refresh(); 622 651 return; 623 652 } else if (key == KeyEvent.VK_X) { 624 Item on = FrameUtils.getCurrentItem(); 625 if (on != null && on.Permission < Item.PERMISSION_FULL) { 653 if (current == null) 654 return; 655 if (current != null && !current.hasPermission(Permission.full)) { 626 656 FrameGraphics 627 .DisplayMessage("Insufficient permission to cut that item" 628 return; 629 } 630 copyItemToClipboard( on);657 .DisplayMessage("Insufficient permission to cut that item"); 658 return; 659 } 660 copyItemToClipboard(current); 631 661 FrameMouseActions.delete(current); 632 662 return; 633 }else if (key == KeyEvent.VK_D) { 663 } else if (key == KeyEvent.VK_M) { 664 if (current == null) 665 return; 666 if (current != null && !current.hasPermission(Permission.full)) { 667 FrameGraphics 668 .DisplayMessage("Insufficient permission toggle the items mark"); 669 return; 670 } 671 boolean newValue = !(current.getLinkMark() || current 672 .getActionMark()); 673 current.setLinkMark(newValue); 674 current.setActionMark(newValue); 675 } else if (key == KeyEvent.VK_Z) { 676 DisplayIO.getCurrentFrame().undo(); 677 return; 678 } else if (key == KeyEvent.VK_D) { 634 679 // perform a delete operation 635 processChar((char) KeyEvent.VK_DELETE, e.isShiftDown());680 processChar((char) KeyEvent.VK_DELETE, isShiftDown); 636 681 } else if (key == KeyEvent.VK_DELETE) { 637 682 // perform a delete operation … … 674 719 currentFrame.addItem(newText); 675 720 } 721 } else if (key == KeyEvent.VK_ENTER) { 722 Item currentItem = FrameUtils.getCurrentItem(); 723 FrameMouseActions.leftButton(currentItem, FrameUtils 724 .getCurrentItems(currentItem)); 725 FrameMouseActions.updateCursor(); 726 } else if (key == KeyEvent.VK_BACK_SPACE) { 727 DisplayIO.Back(); 676 728 } 677 729 FrameGraphics.Repaint(); … … 685 737 */ 686 738 private static Text getCurrentTextItem() { 687 Item i p= FrameUtils.getCurrentItem();688 689 if (i p != null && ip.Permission < Item.PERMISSION_FULL) {739 Item item = FrameUtils.getCurrentItem(); 740 741 if (item != null && !item.hasPermission(Permission.full)) { 690 742 FrameGraphics 691 743 .DisplayMessage("Insufficient permission to copy that item"); … … 694 746 695 747 Item on = null; 696 if (i p!= null)697 on = i p;748 if (item != null) 749 on = item; 698 750 699 751 if (on == null || !(on instanceof Text)) … … 703 755 } 704 756 705 public static void functionKey(FunctionKey key ) {706 functionKey(key, 1 );757 public static void functionKey(FunctionKey key, boolean isShiftDown) { 758 functionKey(key, 1, isShiftDown); 707 759 } 708 760 … … 711 763 * action based on the key. 712 764 */ 713 public static void functionKey(FunctionKey key, int repeat) { 765 public static void functionKey(FunctionKey key, int repeat, 766 boolean isShiftDown) { 714 767 // get whatever the user is pointing at 715 768 Item on = FrameUtils.getCurrentItem(); 716 717 769 // check for enclosed mode 718 770 if (on == null && key.ordinal() < FunctionKey.AudienceMode.ordinal()) { … … 721 773 if (enclosed != null && enclosed.size() > 0) { 722 774 // ensure only one dot\line is present in the list 723 Collection<Item> dots = FrameUtils.getEnclosingDots();724 Item firstConnected = dots.iterator().next();775 Collection<Item> lineEnds = FrameUtils.getEnclosingLineEnds(); 776 Item firstConnected = lineEnds.iterator().next(); 725 777 Collection<Item> connected = firstConnected.getAllConnected(); 726 778 727 779 // only resize lines if they are not surrounding some non line 728 780 // items 729 boolean resizeLines = true;730 for (Item ip : enclosed) {731 732 733 734 735 736 737 }781 // boolean resizeLines = true; 782 // for (Item ip : enclosed) { 783 // if (ip != null) { 784 // if (!(ip instanceof Line) && !(ip.isLineEnd())) { 785 // resizeLines = false; 786 // break; 787 // } 788 // } 789 // } 738 790 739 791 switch (key) { 740 792 case SizeUp: 741 if (resizeLines742 || (!(firstConnected instanceof Line) &&!(firstConnected instanceof Dot)))743 SetSize(firstConnected, repeat, false);793 // if ((!(firstConnected instanceof Line) && 794 // !(firstConnected instanceof Dot))) 795 SetSize(firstConnected, repeat, false, true); 744 796 break; 745 797 case SizeDown: 746 if (resizeLines747 || (!(firstConnected instanceof Line) &&!(firstConnected instanceof Dot)))748 SetSize(firstConnected, -repeat, false);798 // if ((!(firstConnected instanceof Line) && 799 // !(firstConnected instanceof Dot))) 800 SetSize(firstConnected, -repeat, false, true); 749 801 break; 750 802 case ChangeColor: 751 803 if (connected.size() > 0) { 752 for (Item d : dots) {753 SetFillColor(d );804 for (Item d : lineEnds) { 805 SetFillColor(d, isShiftDown); 754 806 break; 755 807 } … … 795 847 return; 796 848 case SizeUp: 797 SetSize(on, repeat, true );849 SetSize(on, repeat, true, false); 798 850 if (on instanceof Text) { 799 851 DisplayIO.setTextCursor((Text) on, Text.NONE, true); … … 801 853 break; 802 854 case SizeDown: 803 SetSize(on, -repeat, true );855 SetSize(on, -repeat, true, false); 804 856 if (on instanceof Text) { 805 857 DisplayIO.setTextCursor((Text) on, Text.NONE, true); … … 807 859 break; 808 860 case ChangeColor: 809 SetColor(on );861 SetColor(on, isShiftDown); 810 862 break; 811 863 case ToggleAnnotation: … … 825 877 break; 826 878 case XRayMode: 827 ToggleXRayMode(on);879 FrameGraphics.ToggleXRayMode(); 828 880 break; 829 881 case AudienceMode: 830 ToggleAudience(on);882 FrameGraphics.ToggleAudienceMode(); 831 883 break; 832 884 case Refresh: 833 Refresh(on); 834 break; 835 } 836 if (on == null) 885 Refresh(); 886 break; 887 } 888 on = FrameUtils.getCurrentItem(); 889 Collection<Item> enclosed = FrameUtils.getCurrentItems(on); 890 if (on == null && (enclosed == null || enclosed.size() == 0)) 837 891 FrameGraphics.DisplayMessage(displayMessage); 838 892 } … … 853 907 private static void Drop(Item ip) { 854 908 try { 909 FrameUtils.setLastEdited(null); 910 855 911 String newItemText = DEFAULT_NEW_ITEM_TEXT; 856 912 … … 922 978 923 979 // If the only item on the frame is the title and the frame name 924 // just 925 // drop a specified distance below the title 980 // just drop a specified distance below the title 926 981 if (column.size() == 0) { 927 982 Item itemTemplate = DisplayIO.getCurrentFrame() … … 960 1015 if (!mouseMoved) { 961 1016 Item moreTitle = moreFrame.getTitleItem(); 962 moreTitle. Permission = Item.PERMISSION_FULL;1017 moreTitle.setPermission(Permission.full); 963 1018 Drop(moreTitle); 964 1019 } … … 991 1046 } 992 1047 } else { 993 DisplayIO. setCursorPosition(dummyItem994 .getEndParagraphPosition().x, dummyItem.getY());995 996 }997 1048 DisplayIO.MoveCursorToEndOfItem(dummyItem); 1049 } 1050 } 1051 if(dummyItem.getText().length() == 0) 1052 dummyItem.getParentOrCurrentFrame().removeItem(dummyItem); 998 1053 DisplayIO.resetCursorOffset(); 999 1054 FrameGraphics.Repaint(); 1000 1055 } catch (RuntimeException e) { 1001 FrameGraphics.ErrorMessage(e.getMessage());1056 // FrameGraphics.ErrorMessage(e.getMessage()); 1002 1057 e.printStackTrace(); 1003 1058 } … … 1033 1088 String newItemText = DEFAULT_NEW_ITEM_TEXT; 1034 1089 1090 if (s == null) 1091 return newItemText; 1035 1092 /* 1036 1093 * Item i = ItemUtils.FindTag(DisplayIO.getCurrentFrame().getItems(), … … 1170 1227 * with resizing 1171 1228 */ 1172 private static void SetSize(Item item, int diff, boolean moveCursor) { 1173 List<Item> toSize = new ArrayList<Item>(); 1229 private static void SetSize(Item item, int diff, boolean moveCursor, 1230 boolean insideEnclosure) { 1231 Collection<Item> toSize = new HashSet<Item>(); 1174 1232 // the mouse is only moved when the Item is on the frame, not free 1175 1233 // boolean moveMouse = false; … … 1191 1249 } 1192 1250 // check permissions 1193 if ( item.Permission < Item.PERMISSION_FULL) {1251 if (!item.hasPermission(Permission.full)) { 1194 1252 FrameGraphics 1195 1253 .DisplayMessage("Insufficient permission to change the size of that item"); … … 1197 1255 } 1198 1256 toSet = item; 1199 1200 if (!(toSet instanceof Text) && toSet.isLineEnd()) { 1257 // For resizing enclosures pick up everything that is attached to 1258 // items partly in the enclosure 1259 //TODO make this only pick up stuff COMPLETELY enclosed... if we change copying to copy only the stuff completely enclosed 1260 if (insideEnclosure) { 1261 for (Item i : FrameUtils.getCurrentItems(toSet)) { 1262 if (!toSize.contains(i)) 1263 toSize.addAll(i.getAllConnected()); 1264 } 1265 } else if (!(toSet instanceof Text) && toSet.isLineEnd()) { 1201 1266 toSize.addAll(toSet.getLines()); 1202 1267 } else if (toSet instanceof Line) { … … 1212 1277 } 1213 1278 1214 int old_width = 0; 1215 int old_height = 0; 1216 1217 if (toSet != null) { 1218 old_width = toSet.getBoundsWidth(); 1219 old_height = toSet.getBoundsHeight(); 1279 Point2D origin = new Point2D.Float(FrameMouseActions.MouseX, 1280 FrameMouseActions.MouseY); 1281 // Inside enclosures increase the size of the enclosure 1282 if (insideEnclosure) { 1283 double ratio = (100.0 + diff * 2) / 100.0; 1284 Collection<Item> done = new HashSet<Item>(); 1285 // adjust the size of all the items 1286 for (Item i : toSize) { 1287 if (done.contains(i)) 1288 continue; 1289 if (i.isLineEnd()) { 1290 Collection<Item> allConnected = i.getAllConnected(); 1291 done.addAll(allConnected); 1292 for (Item it : allConnected) { 1293 it.translate(origin, ratio); 1294 it 1295 .setArrowheadLength((float) (it 1296 .getArrowheadLength() * ratio)); 1297 } 1298 i.setThickness((float) (i.getThickness() * ratio)); 1299 } else if (i instanceof XRayable) { 1300 i.translate(origin, ratio); 1301 i.setThickness((float) (i.getThickness() * ratio)); 1302 done.add(i); 1303 } else if (i instanceof Text) { 1304 i.translate(origin, ratio); 1305 i.setSize((float) (i.getSize() * ratio)); 1306 done.add(i); 1307 } 1308 } 1309 FrameGraphics.Repaint(); 1310 return; 1220 1311 } 1221 1312 … … 1223 1314 for (Item i : toSize) { 1224 1315 // Lines and dots use thickness, not size 1225 if (i instanceof Line) { 1226 Line line = (Line) i; 1227 float current = Math.abs(line.getThickness()); 1316 if (i instanceof Line || i instanceof Circle && !insideEnclosure) { 1317 float current = Math.abs(i.getThickness()); 1228 1318 current = Math.max(current + diff, 1); 1229 line.setThickness(current);1319 i.setThickness(current); 1230 1320 } else if (i instanceof Dot) { 1231 1321 Item dot = (Item) i; … … 1234 1324 dot.setThickness(current); 1235 1325 } else { 1236 int oldSize = Math.abs(i.getSize()); 1237 int newSize = Math.max(oldSize + diff, 1); 1326 float oldSize = Math.abs(i.getSize()); 1327 float newSize = Math.max(oldSize + diff, 1); 1328 float resizeRatio = newSize / oldSize; 1329 // Set size for Picture also translates 1238 1330 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 } 1254 } 1255 } 1256 1257 // center the mouse cursor on the item 1258 if (moveCursor && toSet != null) { 1259 if (!toSet 1260 .contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) { 1261 int x = DisplayIO.getMouseX(); 1262 int y = FrameMouseActions.getY(); 1263 1264 if (!toSet.contains(x, toSet.getY())) 1265 x = x - (old_width - toSet.getBoundsWidth()); 1266 1267 // text grows 'up', pictures grow 'down' 1268 int direction = -1; 1269 if (toSet instanceof Text) 1270 direction = 1; 1271 1272 if (!toSet.contains(toSet.getX(), y)) 1273 y = y 1274 + (direction * (old_height - toSet 1275 .getBoundsHeight())); 1276 1277 DisplayIO.setCursorPosition(x, y, false); 1278 } 1279 1280 // int x = toSet.getX() + toSet.getBoundsWidth() / 2; 1281 // int y = toSet.getY() + toSet.getBoundsHeight() / 2;; 1282 // DisplayIO.setCursorPosition(x, y); 1283 1331 if (i instanceof Text && i.getSize() != oldSize) { 1332 i.translate(origin, resizeRatio); 1333 } 1334 } 1284 1335 } 1285 1336 … … 1290 1341 } 1291 1342 1292 private static void SetFillColor(Item item ) {1343 private static void SetFillColor(Item item, boolean setTransparent) { 1293 1344 if (item == null) 1294 1345 return; 1295 1346 1296 Item toSet = item; // ;1347 Item toSet = item; 1297 1348 Color color = toSet.getFillColor(); 1298 1299 color = ColorUtils.getNextColor(color, Item.FILL_COLOR_WHEEL); 1300 1301 if (color == null) { 1302 FrameGraphics.DisplayMessage("FillColor is now transparent"); 1303 } 1349 if (setTransparent) 1350 color = null; 1351 else 1352 color = ColorUtils.getNextColor(color, Item.FILL_COLOR_WHEEL, null); 1353 1354 // if (color == null) { 1355 // FrameGraphics.DisplayMessage("FillColor is now transparent"); 1356 // } 1304 1357 1305 1358 toSet.setFillColor(color); … … 1316 1369 * The Item whose colour is to be changed 1317 1370 */ 1318 private static void SetColor(Item ip ) {1371 private static void SetColor(Item ip, boolean setTransparent) { 1319 1372 // first determine the next color 1320 1373 Color color = null; … … 1329 1382 // frame name 1330 1383 } else if (ip == currentFrame.getNameItem()) { 1331 currentFrame.toggleBackgroundColor(); 1384 // check permissions 1385 if (!ip.hasPermission(Permission.full)) { 1386 FrameGraphics 1387 .DisplayMessage("Insufficient permission to the frame's background color"); 1388 return; 1389 } 1390 if (setTransparent) 1391 currentFrame.setBackgroundColor(null); 1392 else 1393 currentFrame.toggleBackgroundColor(); 1332 1394 // Display a message if the color has changed to transparent 1333 if (currentFrame.getBackgroundColor() == null)1334 1335 1395 // if (currentFrame.getBackgroundColor() == null) 1396 // FrameGraphics 1397 // .DisplayMessage("Background color is now transparent"); 1336 1398 FrameGraphics.Repaint(); 1337 1399 return; 1338 1400 } else { 1339 1401 // check permissions 1340 if ( ip.Permission < Item.PERMISSION_FULL) {1402 if (!ip.hasPermission(Permission.full)) { 1341 1403 FrameGraphics 1342 1404 .DisplayMessage("Insufficient permission to change that item's color"); 1343 1405 return; 1344 1406 } 1345 color = ip.getColor(); 1346 } 1347 1348 color = ColorUtils.getNextColor(color, Item.COLOR_WHEEL); 1349 1350 // if we didnt find the color on the wheel 1351 if (color == null) { 1352 FrameGraphics.DisplayMessage("Color is set to default"); 1353 } 1354 1355 if (Frame.itemAttachedToCursor()) { 1407 color = ip.getPaintColor(); 1408 } 1409 if (setTransparent) 1410 color = null; 1411 else 1412 color = ColorUtils.getNextColor(color, Item.COLOR_WHEEL, 1413 currentFrame.getPaintBackgroundColor()); 1414 // if (currentFrame.getPaintForegroundColor().equals(color)) 1415 // color = null; 1416 1417 // if color is being set to default display a message to indicate that 1418 // if (color == null) { 1419 // FrameGraphics.DisplayMessage("Color is set to default"); 1420 // } 1421 1422 if (ip == null && Frame.itemAttachedToCursor()) { 1356 1423 for (Item i : Frame.FreeItems) 1357 1424 i.setColor(color); … … 1377 1444 1378 1445 // check permissions 1379 if ( toToggle.Permission < Item.PERMISSION_FULL) {1446 if (!toToggle.hasPermission(Permission.full)) { 1380 1447 FrameGraphics 1381 1448 .DisplayMessage("Insufficient permission to toggle that item's annotation"); … … 1401 1468 1402 1469 // check permissions 1403 if ( toToggle.Permission < Item.PERMISSION_FULL) {1470 if (!toToggle.hasPermission(Permission.full)) { 1404 1471 FrameGraphics 1405 1472 .DisplayMessage("Insufficient permission to toggle that item's annotation"); … … 1429 1496 1430 1497 // check permissions 1431 if ( toToggle.Permission < Item.PERMISSION_FULL) {1498 if (!toToggle.hasPermission(Permission.full)) { 1432 1499 FrameGraphics 1433 1500 .DisplayMessage("Insufficient permission to toggle that item's annotation"); … … 1466 1533 if (toAdd instanceof Text) { 1467 1534 // permission check 1468 if ( toAdd.Permission < Item.PERMISSION_FULL) {1535 if (!toAdd.hasPermission(Permission.full)) { 1469 1536 FrameGraphics 1470 1537 .DisplayMessage("Insufficicent permission to add the date to that item"); … … 1561 1628 1562 1629 // check permissions 1563 if ( item.Permission < Item.PERMISSION_FULL) {1630 if (!item.hasPermission(Permission.full)) { 1564 1631 FrameGraphics 1565 1632 .DisplayMessage("Insufficient permission to create a frameset from this item"); … … 1585 1652 1586 1653 /** 1587 * Toggles Audience mode on\off1588 *1589 * @param ignored1590 * This Item is currently ignored1591 */1592 private static void ToggleAudience(Item ignored) {1593 FrameGraphics.ToggleAudienceMode();1594 }1595 1596 private static void ToggleXRayMode(Item ignored) {1597 FrameGraphics.ToggleXRayMode();1598 }1599 1600 /**1601 * Runs the first Item on the first menu1602 *1603 * @param ignored1604 * This Item is currently ignored1605 */1606 /*1607 * private static void RunFirstMenuItem(Item ignored) {1608 * DisplayIO.activateMenuItem(0, 0); }1609 */1610 1611 /**1612 1654 * Forces a re-parse and repaint of the current Frame. 1613 * 1614 * @param ignored 1615 * This Item is currently ignored 1616 */ 1617 private static void Refresh(Item ignored) { 1655 */ 1656 public static void Refresh() { 1618 1657 Frame currentFrame = DisplayIO.getCurrentFrame(); 1619 1658 if (FrameIO.isProfileFrame(currentFrame)) { … … 1632 1671 // etc and the text cursor is showing 1633 1672 FrameMouseActions.updateCursor(); 1673 FrameMouseActions.getInstance().refreshHighlights(); 1634 1674 FrameGraphics.ForceRepaint(); 1635 1675 } -
trunk/src/org/expeditee/gui/FrameMouseActions.java
r106 r108 24 24 import org.expeditee.actions.Actions; 25 25 import org.expeditee.actions.NavigationActions; 26 import org.expeditee.items.Circle; 26 27 import org.expeditee.items.Constraint; 27 28 import org.expeditee.items.Dot; … … 31 32 import org.expeditee.items.ItemUtils; 32 33 import org.expeditee.items.Line; 34 import org.expeditee.items.Permission; 33 35 import org.expeditee.items.Picture; 34 36 import org.expeditee.items.Text; 35 37 import org.expeditee.items.WidgetCorner; 36 38 import org.expeditee.items.WidgetEdge; 39 import org.expeditee.items.XRayable; 40 import org.expeditee.items.Item.SelectedMode; 37 41 import org.expeditee.stats.SessionStats; 38 42 … … 151 155 private static Item _lastClickedOn = null; 152 156 153 private static List<Item> _lastClickedIn = null;157 private static Collection<Item> _lastClickedIn = null; 154 158 155 159 private static boolean _pulseOn = false; … … 315 319 _lastHighlightedItem = Frame.getItemAttachedToCursor(); 316 320 for (Item i : Frame.FreeItems) { 317 i. restoreLastMode(Item.DEPRESSED_HIGHLIGHT);321 i.setSelectionColor(Item.DEPRESSED_HIGHLIGHT); 318 322 } 319 323 FrameGraphics.Repaint(); … … 411 415 // get whatever the user was pointing at 412 416 Item clickedOn = _lastClickedOn; 413 List<Item> clickedIn = _lastClickedIn;417 Collection<Item> clickedIn = _lastClickedIn; 414 418 415 419 MouseX = e.getX(); … … 417 421 418 422 Item releasedOn = FrameUtils.getCurrentItem(); 419 List<Item> releasedIn = FrameUtils.getCurrentItems(releasedOn);423 Collection<Item> releasedIn = FrameUtils.getCurrentItems(releasedOn); 420 424 421 425 // TODO Simplify the login below … … 504 508 // Check if the user is trying to range an item for which they 505 509 // do not have permission to do so... or it is the frame name 506 if ( lastRanged.Permission < Item.PERMISSION_FULL510 if (!lastRanged.hasPermission(Permission.full) 507 511 || lastRanged.isFrameName()) { 508 512 FrameGraphics 509 .DisplayMessage("Insufficient permission to cut range");513 .DisplayMessage("Insufficient permission to cut text"); 510 514 lastRanged.clearSelection(); 511 515 FrameGraphics.Repaint(); … … 525 529 // Check if the user is trying to range an item for which they 526 530 // do not have permission to do so... or it is the frame name 527 if ( lastRanged.Permission < Item.PERMISSION_COPY) {531 if (!lastRanged.hasPermission(Permission.copy)) { 528 532 FrameGraphics 529 .DisplayMessage("Insufficient permission to copy range");533 .DisplayMessage("Insufficient permission to copy text"); 530 534 lastRanged.clearSelection(); 531 535 FrameGraphics.Repaint(); … … 558 562 // MIKE put the code below up here 559 563 _lastCropped.clearCropping(); 564 FrameGraphics.ChangeSelectionMode(_lastCropped, 565 SelectedMode.None); 560 566 _lastCropped = null; 561 567 FrameGraphics.Repaint(); … … 577 583 if (e.getButton() == MouseEvent.BUTTON1) { 578 584 SessionStats.AddFrameEvent("Lu"); 579 leftButton(clickedOn );585 leftButton(clickedOn, clickedIn); 580 586 return; 581 587 } … … 601 607 * This method handles all left-click actions 602 608 */ 603 public static void leftButton(Item clicked ) {609 public static void leftButton(Item clicked, Collection<Item> clickedIn) { 604 610 // if the user is pointing at something then either follow the link or 605 611 // do TDFC … … 627 633 && !(clicked instanceof Dot)) { 628 634 // check item permissions 629 if ( clicked.Permission < Item.PERMISSION_FOLLOW_LINKS) {635 if (!clicked.hasPermission(Permission.followLinks)) { 630 636 FrameGraphics 631 637 .DisplayMessage("Insufficient permissions to perform action on item"); … … 655 661 } else { 656 662 // check for TDFC permission 657 if ( clicked.Permission < Item.PERMISSION_TDFC) {663 if (!clicked.hasPermission(Permission.createFrames)) { 658 664 FrameGraphics 659 665 .DisplayMessage("Insufficient permission to TDFC from that item"); … … 722 728 * This method handles all middle-click actions 723 729 */ 724 private static void middleButton(Item clicked, List<Item> clickedIn) {730 private static void middleButton(Item clicked, Collection<Item> clickedIn) { 725 731 // if the cursor has Items attached 726 732 if (Frame.itemAttachedToCursor()) { … … 729 735 if (doMerging(clicked)) { 730 736 // check permissions 731 if ( clicked.Permission < Item.PERMISSION_FULL737 if (!clicked.hasPermission(Permission.full) 732 738 && clicked.getParent() != null 733 739 && clicked.getParent().getNameItem() != clicked) { … … 757 763 } else if (clicked != null) { 758 764 // check permissions 759 if ( clicked.Permission < Item.PERMISSION_FULL) {765 if (!clicked.hasPermission(Permission.full)) { 760 766 FrameGraphics 761 767 .DisplayMessage("Insufficient permission to pick up item"); … … 841 847 ArrayList<Item> toPickup = new ArrayList<Item>(clickedIn.size()); 842 848 for (Item ip : clickedIn) 843 if (ip. Permission >= Item.PERMISSION_FULL)849 if (ip.hasPermission(Permission.full)) 844 850 toPickup.add(ip); 845 851 pickup(toPickup); … … 850 856 // If we have permission to copy this item then pick it up 851 857 if (on != null && on.isLineEnd() 852 && on. Permission >= Item.PERMISSION_FULL) {858 && on.hasPermission(Permission.full)) { 853 859 on.removeAllConstraints(); 854 860 pickup(on); … … 858 864 // if its on a line then split the line and put a point on it and 859 865 // pick that point up 860 if (on instanceof Line && on. Permission >= Item.PERMISSION_FULL) {866 if (on instanceof Line && on.hasPermission(Permission.full)) { 861 867 Frame current = DisplayIO.getCurrentFrame(); 862 868 // create the two endpoints … … 932 938 * This method handles all right-click action 933 939 */ 934 private static void rightButton(Item clicked, List<Item> clickedIn) {940 private static void rightButton(Item clicked, Collection<Item> clickedIn) { 935 941 // if the cursor has Items attached, then anchor a copy of them 942 936 943 List<Item> copies = null; 937 944 if (Frame.itemAttachedToCursor()) { … … 943 950 || clicked instanceof Dot || clicked.isLineEnd())) { 944 951 // check permissions 945 if ( clicked.Permission < Item.PERMISSION_FULL952 if (!clicked.hasPermission(Permission.full) 946 953 && clicked.getParent().getNameItem() != clicked) { 947 954 FrameGraphics … … 949 956 return; 950 957 } 951 if (clicked instanceof Text || clicked instanceof Dot) { 958 if (clicked instanceof Text || clicked instanceof Dot 959 || clicked instanceof XRayable) { 952 960 if (isRubberBandingCorner()) { 953 961 // Move the cursor so that the copy is exactly the … … 978 986 979 987 for (Item ip : items) { 980 if (ip. Permission >= Item.PERMISSION_COPY)988 if (ip.hasPermission(Permission.copy)) 981 989 toCopy.add(ip); 982 990 } … … 990 998 pickup(copies); 991 999 // line onto something 992 } else if (Frame.FreeItems.size() == 2) { 1000 } else if (Frame.FreeItems.size() == 2 1001 && clicked instanceof XRayable) { 993 1002 copies = ItemUtils.UnreelLine(Frame.FreeItems, 994 _ shiftDown);1003 _controlDown); 995 1004 Collection<Item> leftOver = merge(Frame.FreeItems, 996 1005 clicked); … … 1016 1025 } 1017 1026 } else { 1018 copies = ItemUtils.UnreelLine(Frame.FreeItems, _shiftDown); 1027 copies = ItemUtils 1028 .UnreelLine(Frame.FreeItems, _controlDown); 1019 1029 if (copies == null) 1020 1030 copies = copy(Frame.FreeItems); … … 1036 1046 updateCursor(); 1037 1047 // pick up a copy of all enclosed items 1038 List<Item> enclosedItems = FrameUtils.getItemsEnclosedBy( 1039 DisplayIO.getCurrentFrame(), d.getEnclosedShape()); 1048 Collection<Item> enclosedItems = FrameUtils 1049 .getItemsEnclosedBy(DisplayIO.getCurrentFrame(), d 1050 .getEnclosedShape()); 1040 1051 if (enclosedItems != null) { 1041 1052 enclosedItems.removeAll(d.getAllConnected()); 1042 List<Item> toCopy = getFullyEnclosedItems(enclosedItems);1053 Collection<Item> toCopy = getFullyEnclosedItems(enclosedItems); 1043 1054 1044 1055 if (toCopy.size() > 0) { … … 1048 1059 Item closest = null; 1049 1060 double shortestDistance = Double.MAX_VALUE; 1050 for (int i = 0; i < toCopy.size(); i++) { 1051 Item next = toCopy.get(i); 1061 for (Item next : toCopy) { 1052 1062 if (next instanceof Line) 1053 1063 continue; … … 1074 1084 } 1075 1085 } else { 1076 if ( Frame.FreeItems.size() == 2) {1086 if (rubberBanding()) { 1077 1087 if (clicked != null) { 1078 1088 Collection<Item> leftOver = merge(Frame.FreeItems, … … 1083 1093 // endpoint and unreeling. ie. Normal unreeling 1084 1094 copies = ItemUtils.UnreelLine(Frame.FreeItems, 1085 _ shiftDown);1095 _controlDown); 1086 1096 1087 1097 if (copies == null) … … 1119 1129 if (clicked != null) { 1120 1130 // check permissions 1121 if ( clicked.Permission < Item.PERMISSION_COPY) {1131 if (!clicked.hasPermission(Permission.copy)) { 1122 1132 FrameGraphics 1123 1133 .DisplayMessage("Insufficient permission to copy item"); … … 1125 1135 } 1126 1136 1127 copies = ItemUtils.UnreelLine(clicked, _ shiftDown);1137 copies = ItemUtils.UnreelLine(clicked, _controlDown); 1128 1138 // Copies will NOT be null if the user right clicked on a point 1129 1139 if (copies == null) { … … 1143 1153 } 1144 1154 1155 FrameGraphics.ChangeSelectionMode(clicked, 1156 SelectedMode.None); 1157 1145 1158 if (!_extrude) 1146 1159 clearParent(copies); … … 1152 1165 if (clickedIn != null) { 1153 1166 // Set the selection mode for the items that were clicked in 1154 List<Item> enclosed = getFullyEnclosedItems(clickedIn);1167 Collection<Item> enclosed = getFullyEnclosedItems(clickedIn); 1155 1168 if (enclosed.size() == 0) { 1156 1169 FrameGraphics … … 1158 1171 } else { 1159 1172 copies = copy(enclosed); 1160 // TODO figure out how to get copies to be SELECTED when1161 // they are anchored1162 // for (Item i : copies) {1163 // if (i.isEnclosed()) {1164 // i.setSelectedMode(Item.SelectedMode.Enclosed);1165 // i.setSelectedMode(Item.SelectedMode.None);1166 // }1167 // }1168 1173 clearParent(copies); 1169 1174 pickup(copies); 1175 for (Item i : clickedIn) { 1176 i.setSelectedMode(SelectedMode.None); 1177 } 1170 1178 } 1171 1179 // otherwise, create a rectangle … … 1174 1182 MouseX, MouseY); 1175 1183 // if its on a line then create a line from that line 1176 if (on instanceof Line 1177 && on.Permission >= Item.PERMISSION_FULL) { 1184 if (on instanceof Line && on.hasPermission(Permission.full)) { 1178 1185 1179 1186 Line onLine = (Line) on; … … 1231 1238 anchor(new ArrayList<Item>(copies)); 1232 1239 pickup(d[3]); 1240 d[3].setSelectedMode(SelectedMode.Normal); 1241 d[3].setSelectedMode(SelectedMode.None); 1242 1233 1243 SessionStats.CreatedItems(copies); 1234 1244 copies.clear(); … … 1236 1246 } 1237 1247 } 1248 getInstance().refreshHighlights(); 1238 1249 SessionStats.CopiedItems(copies); 1239 1250 updateCursor(); … … 1252 1263 // and dragging 1253 1264 move(Frame.FreeItems); 1265 for (Item i : copies) { 1266 i.setSelectedMode(SelectedMode.None); 1267 } 1254 1268 anchor(copies); 1255 1269 } … … 1259 1273 * @return 1260 1274 */ 1261 private static List<Item> getFullyEnclosedItems(List<Item> enclosure) { 1275 private static Collection<Item> getFullyEnclosedItems( 1276 Collection<Item> enclosure) { 1262 1277 // copy the enclosedItems because the list will be modified 1263 List<Item> enclosedItems = new ArrayList<Item>(enclosure); 1264 List<Item> toCopy = new ArrayList<Item>(enclosedItems.size()); 1278 Collection<Item> enclosedItems = new LinkedHashSet<Item>(enclosure); 1279 Collection<Item> toCopy = new LinkedHashSet<Item>(enclosedItems.size()); 1280 1265 1281 while (enclosedItems.size() > 0) { 1266 Item i = enclosedItems. get(0);1267 if (i. Permission >= Item.PERMISSION_COPY) {1282 Item i = enclosedItems.iterator().next(); 1283 if (i.hasPermission(Permission.copy)) { 1268 1284 Collection<Item> items = i.getAllConnected(); 1269 1285 // Only copy if the entire shape is enclosed … … 1292 1308 */ 1293 1309 private static void clearParent(List<Item> items) { 1294 for (Item i : items) 1310 for (Item i : items) { 1311 // The next line is only necessary for circles... 1312 // Need to clean up/refactory some of this stuff 1313 i.getParentOrCurrentFrame().removeItem(i); 1295 1314 i.setParent(null); 1315 } 1296 1316 } 1297 1317 … … 1409 1429 }); 1410 1430 1411 private static boolean _ shiftDown;1431 private static boolean _controlDown; 1412 1432 1413 1433 public static void setLastRobotMove(float x, float y) { … … 1453 1473 MouseY = e.getY(); 1454 1474 1475 //Moving the mouse a certain distance removes the last edited text if it is empty 1476 Text lastEdited = FrameUtils.LastEdited; 1477 if(lastEdited != null && lastEdited.getPosition().distance(e.getPoint()) > 20){ 1478 FrameUtils.setLastEdited(null); 1479 } 1480 1455 1481 // If shift is down then the movement is constrained 1456 if (_ shiftDown && Frame.FreeItems.size() > 0) {1482 if (_controlDown && Frame.FreeItems.size() > 0) { 1457 1483 // Check if we are rubber banding a line 1458 1484 if (shiftStateChanged && rubberBanding()) { … … 1521 1547 Integer c2 = line2.getPossibleConstraint(); 1522 1548 1523 if (c1 != null ) {1549 if (c1 != null && c2 != null) { 1524 1550 // This is the case of a constrained rectangle 1525 1551 if ((c2 == Constraint.VERTICAL || c2 == Constraint.HORIZONTAL) … … 1548 1574 } 1549 1575 } 1550 } else if (c2 != null) { 1551 1552 } // Other wise it is a not constrained shape so constrain 1553 // the two lines lengths to be equal 1554 else { 1576 // } else if (c2 != null) { 1577 // 1578 // } // Other wise it is a not constrained shape so 1579 // constrain 1580 // the two lines lengths to be equal 1581 } else { 1555 1582 Item lineEnd1 = line1.getOppositeEnd(thisEnd); 1556 1583 Item lineEnd2 = line2.getOppositeEnd(thisEnd); … … 1588 1615 } 1589 1616 } 1590 } else if (shiftStateChanged && !_ shiftDown && rubberBanding()) {1617 } else if (shiftStateChanged && !_controlDown && rubberBanding()) { 1591 1618 // Get the line end that is being rubber banded 1592 1619 Item thisEnd = Frame.FreeItems.get(0).isLineEnd() ? Frame.FreeItems … … 1598 1625 _lastMouseMoved = e; 1599 1626 1600 /*1601 * int distance = (int) Math.sqrt(Math.pow(Math1602 * .abs(_lastMouseEvent.getX() - e.getX()), 2) +1603 * Math.pow(Math.abs(_lastMouseEvent.getY() - e.getY()), 2));1604 */1605 1606 // Just do the sum of the distance moved in x and y direction for1607 // speed!!1608 /*1609 * int distance = Math.abs(_lastMouseEvent.getX() - e.getX()) +1610 * Math.abs(_lastMouseEvent.getY() - e.getY());1611 */1612 1613 boolean checkHighlight = true;1614 1615 // Mike: This code checks if the mouse is moving above a1616 // threshold speed. If so it doesnt execute the code that checks if1617 // items underneath the cursor need to be highlighted.1618 /*1619 * if (Frame.itemAttachedToCursor()) { long time = e.getWhen() -1620 * _lastMouseEvent.getWhen(); // System.out.println(time + " D:" +1621 * distance); if (time > 0 && distance * 3 > time) { checkHighlight =1622 * false; // System.out.println("Dont check highlight!"); if1623 * (_lastHighlightedItem != null && !_lastHoldsHighlight) {1624 * if(_lastHighlightedItem instanceof Text) {1625 * FrameGraphics.ChangeSelectionMode(_lastHighlightedItem,1626 * Item.SelectedMode.None); } } } }1627 */1628 1629 1627 _lastMouseMoved = e; 1630 1628 1631 if (checkHighlight) { 1632 // ByMike: Get the item the mouse is hovering over 1633 Item click = FrameUtils.getCurrentItem(); 1634 Item on = null; 1635 // System.out.println(click); 1636 if (click != null) { 1637 on = click; 1638 // set the context 1639 if (on instanceof Line) 1640 _context = CONTEXT_AT_LINE; 1641 else if (on instanceof Dot) 1642 _context = CONTEXT_AT_DOT; 1643 else if (on instanceof Text) { 1644 // Checks that we are actually pointing on a character 1645 // not just space in the text box's bounding box 1646 if (((Item) on).contains(DisplayIO.getMouseX(), 1647 FrameMouseActions.getY())) { 1648 _context = CONTEXT_AT_TEXT; 1649 } else { 1650 // if we are pointing in space in the text box... it is 1651 // the same as pointing in freespace 1652 on = null; 1653 _context = CONTEXT_FREESPACE; 1654 } 1655 } 1656 1657 _alpha = 60; 1658 } else { 1659 _context = CONTEXT_FREESPACE; 1660 _alpha = -1; 1661 } 1662 1663 // if the user is pointing at an item, highlight it 1664 if (on != null && !Frame.FreeItems.contains(on)) { 1665 // if the user can spot-weld, show the virtual spot 1666 if (Frame.FreeItems.size() == 2 && on instanceof Line) { 1667 Line line = (Line) on; 1668 Item freeItem0 = Frame.FreeItems.get(0); 1669 Item freeItem1 = Frame.FreeItems.get(1); 1670 Item lineEnd = freeItem0.isLineEnd() ? freeItem0 1671 : (freeItem1.isLineEnd() ? freeItem1 : null); 1672 if (lineEnd != null) { 1673 line.showVirtualSpot(lineEnd, DisplayIO.getMouseX(), 1674 FrameMouseActions.getY()); 1675 } else 1676 // The user is pointing at another point or text item 1677 // etc 1678 FrameGraphics.ChangeSelectionMode(on, 1679 Item.SelectedMode.Normal); 1680 } else { 1681 // FrameGraphics.ChangeSelectionMode(on, 1682 // Item.SelectedMode.Connected); 1683 // TODO: The method below is for the most part redundant 1684 on = FrameGraphics.Highlight(on); 1685 } 1686 // if the last item highlighted is still highlighted, clear it 1687 if (_lastHoldsHighlight) { 1688 _lastHoldsHighlight = false; 1689 for (Item i : DisplayIO.getCurrentFrame().getItems()) 1690 if (i.isHighlighted() && i != on) 1691 FrameGraphics.ChangeSelectionMode(i, 1692 Item.SelectedMode.None); 1693 } 1694 1695 // if the user is not pointing at an item, check for enclosure 1696 // highlighting 1697 } else if (on == null) { 1698 Collection<Item> enclosure = FrameUtils.getEnclosingDots(); 1699 if (enclosure != null && enclosure.size() > 1) { 1700 Item firstLineEnd = enclosure.iterator().next(); 1701 if (firstLineEnd.getLines().size() > 1 && 1702 // check that the enclosure is not part of a point being 1703 // dragged in space 1704 !ContainsOneOf(enclosure, Frame.FreeItems)) { 1705 on = firstLineEnd.getLines().get(0); 1706 // System.out.println(on == null ? "Null" : 1707 // on.toString()); 1708 FrameGraphics.ChangeSelectionMode(on, 1709 Item.SelectedMode.Enclosed); 1710 } 1711 } else if (_lastHighlightedItem != null) { 1712 // System.out.println("LastHighlightedItem"); 1713 _lastHoldsHighlight = false; 1714 } 1715 } 1716 1717 // disable cursor changes when the cursor has items attached 1718 if (Frame.itemAttachedToCursor() 1719 && DisplayIO.getCursor() != Item.TEXT_CURSOR) 1720 _forceArrowCursor = false; 1721 1722 if (_lastHighlightedItem != null && _lastHighlightedItem != on 1723 && !_lastHoldsHighlight) { 1724 // Only want to turn off the highlighting only if 1725 // the last highlighted item is not connected to the currentItem 1726 // Otherwise we get flickering in transition from connected to 1727 // normal mode while moving the cursor along a line. 1728 if (on == null 1729 || !_lastHighlightedItem.getAllConnected().contains(on)) 1730 FrameGraphics.ChangeSelectionMode(_lastHighlightedItem, 1731 Item.SelectedMode.None); 1732 } 1733 1734 _lastHighlightedItem = on; 1735 1736 } 1629 refreshHighlights(); 1737 1630 1738 1631 if (Frame.itemAttachedToCursor()) { … … 1744 1637 updateCursor(); 1745 1638 1746 // if (_lastItem == null)1747 // DisplayIO.UpdateTitle();1748 1749 1639 _forceArrowCursor = true; 1640 } 1641 1642 public void refreshHighlights() { 1643 // ByMike: Get the item the mouse is hovering over 1644 Item click = FrameUtils.getCurrentItem(); 1645 Item on = null; 1646 // System.out.println(click); 1647 if (click != null) { 1648 on = click; 1649 // set the context 1650 if (on instanceof Line) 1651 _context = CONTEXT_AT_LINE; 1652 else if (on instanceof Dot) 1653 _context = CONTEXT_AT_DOT; 1654 else if (on instanceof Text) { 1655 // Checks that we are actually pointing on a character 1656 // not just space in the text box's bounding box 1657 if (((Item) on).contains(DisplayIO.getMouseX(), 1658 FrameMouseActions.getY())) { 1659 _context = CONTEXT_AT_TEXT; 1660 } else { 1661 // if we are pointing in space in the text box... it is 1662 // the same as pointing in freespace 1663 on = null; 1664 _context = CONTEXT_FREESPACE; 1665 } 1666 } 1667 if (Frame.FreeItems.size() > 0) 1668 _alpha = 60; 1669 else 1670 _alpha = -1; 1671 } else { 1672 _context = CONTEXT_FREESPACE; 1673 _alpha = -1; 1674 } 1675 1676 // if the user is pointing at an item, highlight it 1677 if (on != null && !Frame.FreeItems.contains(on)) { 1678 // if the user can spot-weld, show the virtual spot 1679 if (Frame.FreeItems.size() == 2 && on instanceof Line) { 1680 Line line = (Line) on; 1681 Item freeItem0 = Frame.FreeItems.get(0); 1682 Item freeItem1 = Frame.FreeItems.get(1); 1683 Item lineEnd = freeItem0.isLineEnd() ? freeItem0 : (freeItem1 1684 .isLineEnd() ? freeItem1 : null); 1685 if (lineEnd != null) { 1686 line.showVirtualSpot(lineEnd, DisplayIO.getMouseX(), 1687 FrameMouseActions.getY()); 1688 } else 1689 // The user is pointing at another point or text item 1690 // etc 1691 FrameGraphics.ChangeSelectionMode(on, 1692 Item.SelectedMode.Normal); 1693 } else { 1694 // FrameGraphics.ChangeSelectionMode(on, 1695 // Item.SelectedMode.Connected); 1696 // TODO: The method below is for the most part redundant 1697 on = FrameGraphics.Highlight(on); 1698 } 1699 // if the last item highlighted is still highlighted, clear it 1700 if (_lastHoldsHighlight) { 1701 _lastHoldsHighlight = false; 1702 for (Item i : DisplayIO.getCurrentFrame().getItems()) 1703 if (i.isHighlighted() && i != on) 1704 FrameGraphics.ChangeSelectionMode(i, 1705 Item.SelectedMode.None); 1706 } 1707 1708 // if the user is not pointing at an item, check for enclosure 1709 // highlighting 1710 } else if (on == null) { 1711 Collection<Item> enclosure = FrameUtils.getEnclosingLineEnds(); 1712 if (enclosure != null && enclosure.size() > 0) { 1713 Item firstLineEnd = enclosure.iterator().next(); 1714 if (firstLineEnd.getLines().size() > 1 && 1715 // check that the enclosure is not part of a point being 1716 // dragged in space 1717 !ContainsOneOf(enclosure, Frame.FreeItems)) { 1718 on = firstLineEnd.getLines().get(0); 1719 // System.out.println(on == null ? "Null" : 1720 // on.toString()); 1721 FrameGraphics.ChangeSelectionMode(on, 1722 Item.SelectedMode.Enclosed); 1723 } else if (firstLineEnd instanceof XRayable) { 1724 on = firstLineEnd; 1725 FrameGraphics.ChangeSelectionMode(firstLineEnd, 1726 Item.SelectedMode.Enclosed); 1727 } 1728 } else if (_lastHighlightedItem != null) { 1729 // System.out.println("LastHighlightedItem"); 1730 _lastHoldsHighlight = false; 1731 } 1732 } 1733 1734 // disable cursor changes when the cursor has items attached 1735 if (Frame.itemAttachedToCursor() 1736 && DisplayIO.getCursor() != Item.TEXT_CURSOR) 1737 _forceArrowCursor = false; 1738 1739 // setLastHighlightedItem(on); 1740 1741 if (_lastHighlightedItem != null && _lastHighlightedItem != on 1742 && !_lastHoldsHighlight) { 1743 // Turn off the highlighting only if 1744 // the last highlighted item is not connected to the currentItem 1745 // Otherwise we get flickering in transition from connected to 1746 // normal mode while moving the cursor along a line. 1747 if (on == null 1748 || (!on.getAllConnected().contains(_lastHighlightedItem))) { 1749 FrameGraphics.ChangeSelectionMode(_lastHighlightedItem, 1750 Item.SelectedMode.None); 1751 } 1752 } 1753 1754 _lastHighlightedItem = on; 1755 1750 1756 } 1751 1757 … … 1779 1785 } 1780 1786 foundLineEnd = true; 1781 } else if (!(i instanceof Line) ) {1787 } else if (!(i instanceof Line) || !i.isVisible()) { 1782 1788 return false; 1783 1789 } … … 1791 1797 */ 1792 1798 public static void updateCursor() { 1793 if (rubberBanding() /* && !_shiftDown */) {1799 if (rubberBanding()) { 1794 1800 DisplayIO.setCursor(Item.HIDDEN_CURSOR); 1795 1801 return; … … 1828 1834 1829 1835 for (Item move : toMove) { 1830 if (!(move instanceof Line)) 1831 move.setPosition(move.getX() - deltax, move.getY() - deltay); 1836 move.setPosition(move.getX() - deltax, move.getY() - deltay); 1832 1837 1833 1838 if (move instanceof Text) { … … 1921 1926 Item item = toExtract; 1922 1927 // Extract the frames attributes when the user clicks on the frame name 1928 FrameGraphics.ChangeSelectionMode(item, SelectedMode.None); 1923 1929 if (item.isFrameName()) 1924 1930 attribs = AttributeUtils.extractAttributes(item.getParent()); 1925 else 1931 else { 1926 1932 attribs = AttributeUtils.extractAttributes(item); 1933 } 1927 1934 1928 1935 if (attribs == null) … … 1944 1951 if (toDelete != null 1945 1952 && toDelete == DisplayIO.getCurrentFrame().getNameItem()) { 1946 DisplayIO.getCurrentFrame().clear( );1953 DisplayIO.getCurrentFrame().clear(false); 1947 1954 FrameGraphics.Repaint(); 1948 1955 return; … … 1957 1964 1958 1965 // check permissions 1959 if ( toDelete.Permission < Item.PERMISSION_FULL) {1966 if (!toDelete.hasPermission(Permission.full)) { 1960 1967 FrameGraphics 1961 1968 .DisplayMessage("Insufficient permission to swap Item text"); … … 1989 1996 // if the user is pointing inside a closed shape, delete all 1990 1997 // items inside it 1991 List<Item> items = FrameUtils.getCurrentItems(null);1998 Collection<Item> items = FrameUtils.getCurrentItems(null); 1992 1999 1993 2000 if (items != null) { … … 1995 2002 .size()); 1996 2003 for (Item ip : items) { 1997 if (ip. Permission >= Item.PERMISSION_FULL) {2004 if (ip.hasPermission(Permission.full)) { 1998 2005 // Only include lines if one of their enpoints are also 1999 2006 // being removed 2000 2007 if (ip instanceof Line) { 2001 2008 Line l = (Line) ip; 2002 if (!items.contains(l.getEndItem()) 2003 && !items.contains(l.getStartItem())) 2009 Item end = l.getEndItem(); 2010 Item start = l.getStartItem(); 2011 2012 // If one end of a line is being delted, remove the 2013 // other end if all its connecting lines are being 2014 // delted 2015 if (items.contains(end)) { 2016 if (!items.contains(start) 2017 && items.containsAll(start.getLines())) { 2018 toRemove.add(start); 2019 } 2020 } else if (items.contains(start)) { 2021 if (items.containsAll(end.getLines())) { 2022 toRemove.add(end); 2023 } 2024 } else { 2004 2025 continue; 2026 } 2005 2027 } 2006 2028 toRemove.add(ip); … … 2022 2044 } else { 2023 2045 // check permissions 2024 if ( toDelete.Permission < Item.PERMISSION_FULL) {2046 if (!toDelete.hasPermission(Permission.full)) { 2025 2047 FrameGraphics 2026 2048 .DisplayMessage("Insufficient permission to delete item"); … … 2085 2107 // disconnect any connected items 2086 2108 for (Item i : itemList) { 2109 // Make sure text items attached to cursor are reset back to the 2110 // transparency they should have. 2111 if (i instanceof Text) { 2112 ((Text) i).setAlpha(-1); 2113 } 2114 2087 2115 if (i.getLines().size() > 0) { 2088 2116 Collection<Item> toDelete = deleteLineEnd(i); … … 2194 2222 } 2195 2223 2224 // if(mergee instanceof XRayable) 2225 // return merger; 2226 2196 2227 // check for rectangle merging 2197 2228 if (merger.size() == 3 && mergee.getLines().size() == 2) { … … 2246 2277 2247 2278 for (Item i : merger) { 2279 if (!i.isVisible()) 2280 continue; 2248 2281 // check for link merging 2249 2282 if (i instanceof Text … … 2305 2338 mergee.getParent().setChanged(true); 2306 2339 ItemUtils.EnclosedCheck(mergee.getParent().getItems()); 2340 //Mike: Why does parse frame have to be called?!? 2307 2341 FrameUtils.Parse(mergee.getParent()); 2308 2342 … … 2322 2356 return; 2323 2357 2324 if ( toGrab.Permission < Item.PERMISSION_FULL) {2358 if (!toGrab.hasPermission(Permission.full)) { 2325 2359 FrameGraphics 2326 2360 .DisplayMessage("Insufficient permission pickup the item"); 2327 2361 return; 2328 2362 } 2363 2364 if (toGrab instanceof Circle) 2365 toGrab.setSelectedMode(SelectedMode.Connected); 2366 else 2367 toGrab.setSelectedMode(SelectedMode.Normal); 2368 2329 2369 // Brook: If the widget corner is being picked up. Instead refer to 2330 2370 // picking up the edge for fixed-sized widgets so it is not so confusing … … 2349 2389 while (iter.hasNext()) { 2350 2390 Item i = iter.next(); 2351 if ( i.Permission < Item.PERMISSION_FULL) {2391 if (!i.hasPermission(Permission.full)) { 2352 2392 iter.remove(); 2353 2393 continue; 2354 2394 } 2355 2395 if (i.equals(_lastHighlightedItem)) 2396 _lastHighlightedItem = null; 2397 // i.setSelectedMode(SelectedMode.None); 2356 2398 // Check if it has a relative link if so make it absolute 2357 2399 i.setAbsoluteLink(); … … 2365 2407 i.setFloating(true); 2366 2408 } 2367 2409 _lastHighlightedItem = null; 2368 2410 updateCursor(); 2369 2411 … … 2372 2414 if (toGrab.size() > 1) { 2373 2415 for (Item i : toGrab) { 2374 // MIKE: Why cant we use a line for the offset calculations?!? 2375 if (!(i instanceof Line)) { 2416 // MIKE: Movement goes haywire if these are removed because Line 2417 // class returns 0 for getX 2418 if (!(i instanceof Line) && !(i instanceof XRayable)) { 2376 2419 _offX = DisplayIO.getMouseX() - i.getX() + i.getOffset().x; 2377 2420 _offY = getY() - i.getY() + i.getOffset().y; … … 2419 2462 // attach the line to the cursor 2420 2463 pickup(end); 2464 _lastHighlightedItem = null; 2465 2466 // TODO figure out how to get the end to highlight 2467 // end.setSelectedMode(SelectedMode.Normal); 2468 // end.setSelectedMode(SelectedMode.None); 2421 2469 2422 2470 return line; … … 2474 2522 int clicks = arg0.getClickCount(); 2475 2523 2476 // if a line is being rubber-banded, check for auto straightening2477 2524 if (Frame.FreeItems.size() == 2) { 2478 if ((Frame.FreeItems.get(0) instanceof Dot && Frame.FreeItems 2479 .get(1) instanceof Line) 2480 || (Frame.FreeItems.get(1) instanceof Dot && Frame.FreeItems 2525 if ((Frame.FreeItems.get(0).isLineEnd() && Frame.FreeItems.get(1) instanceof Line) 2526 || (Frame.FreeItems.get(1).isLineEnd() && Frame.FreeItems 2481 2527 .get(0) instanceof Line)) { 2482 2528 … … 2507 2553 if (ip != null && clicks > 1) { 2508 2554 float size = ip.getSize(); 2509 if (ip instanceof Dot || ip instanceof Line) 2555 if (ip instanceof Dot || ip instanceof Line 2556 || ip instanceof Circle) { 2510 2557 size = ip.getThickness(); 2558 } 2511 2559 // base the number of clicks on the size of the object 2512 2560 clicks = (int) Math.ceil(size / 20.0 * clicks); 2513 2561 } 2514 FrameKeyboardActions.functionKey(rotationType, clicks); 2562 FrameKeyboardActions.functionKey(rotationType, clicks, arg0 2563 .isShiftDown()); 2515 2564 2516 2565 } else if (clicks == MOUSE_WHEEL_THRESHOLD) { … … 2524 2573 } 2525 2574 2526 if (item instanceof Line ) {2575 if (item instanceof Line || item instanceof Circle) { 2527 2576 // check permissions 2528 if ( item.Permission < Item.PERMISSION_FULL) {2577 if (!item.hasPermission(Permission.full)) { 2529 2578 FrameGraphics 2530 2579 .DisplayMessage("Insufficient permission to edit the Line"); 2531 2580 return; 2532 2581 } 2533 Line line = (Line) item; 2534 line.toggleDashed(arg0.getWheelRotation()); 2535 line.getParent().change(); 2582 item.toggleDashed(arg0.getWheelRotation()); 2583 item.getParent().change(); 2536 2584 FrameGraphics.Repaint(); 2537 2585 return; … … 2579 2627 } 2580 2628 2581 public static void shift(KeyEvent ke) {2582 _ shiftDown = ke.isControlDown();2583 2584 if (_ shiftDown) {2629 public static void control(KeyEvent ke) { 2630 _controlDown = ke.isControlDown(); 2631 2632 if (_controlDown) { 2585 2633 _offX = 0; 2586 2634 _offY = 0; -
trunk/src/org/expeditee/gui/FrameUtils.java
r107 r108 8 8 import java.util.Collections; 9 9 import java.util.Comparator; 10 import java.util.LinkedHashSet; 10 11 import java.util.LinkedList; 11 12 import java.util.List; 12 13 13 14 import org.expeditee.io.Logger; 15 import org.expeditee.items.Circle; 14 16 import org.expeditee.items.Dot; 17 import org.expeditee.items.FrameBitmap; 18 import org.expeditee.items.FrameImage; 15 19 import org.expeditee.items.InteractiveWidget; 16 20 import org.expeditee.items.InteractiveWidgetInitialisationFailedException; … … 19 23 import org.expeditee.items.ItemUtils; 20 24 import org.expeditee.items.Line; 25 import org.expeditee.items.Permission; 21 26 import org.expeditee.items.Picture; 22 27 import org.expeditee.items.Text; 23 28 import org.expeditee.items.WidgetCorner; 24 29 import org.expeditee.items.WidgetEdge; 30 import org.expeditee.items.XRayable; 25 31 import org.expeditee.stats.SessionStats; 26 32 … … 39 45 private static float _LastResponse = 0; 40 46 41 public static ItemLastEdited = null;47 public static Text LastEdited = null; 42 48 43 49 public static int MINIMUM_INTERITEM_SPACING = -6; … … 281 287 } else 282 288 return false; 283 } else if (opposite.getOverlays().contains(new Overlay(toSave, 1))) { 289 } else if (opposite.getOverlays().contains( 290 new Overlay(toSave, Permission.followLinks))) { 284 291 if (opposite.getOverlays().get( 285 opposite.getOverlays().indexOf(new Overlay(toSave, 1))).Frame 292 opposite.getOverlays().indexOf( 293 new Overlay(toSave, Permission.followLinks))).Frame 286 294 .hasChanged()) 287 295 if (DisplayIO.DisplayConfirmDialog( … … 384 392 DisplayIO.setCurrentFrame(toDisplay); 385 393 FrameMouseActions.updateCursor(); 394 // FrameMouseActions.getInstance().refreshHighlights(); 386 395 // update response timer 387 396 _LastResponse = ResponseTimer.getElapsedSeconds(); … … 464 473 return false; 465 474 } 466 467 // replace the Text source with the new Picture468 frame.removeItem(txt);469 frame.addItem(pic);470 471 return true;472 }473 474 private static boolean createFramePicture(Frame frame, Text txt) {475 if (txt.getLink() == null)476 return false;477 478 // attempt to create the picture479 Picture pic = ItemUtils.CreateFrameImage(txt, frame);480 481 // if the picture could not be created successfully482 if (pic == null) {483 FrameGraphics.ErrorMessage("Error loading frame image");484 return false;485 }486 487 // replace the Text source with the new Picture488 frame.removeItem(txt);489 frame.addItem(pic);490 491 return true;492 }493 494 private static boolean createFrameBitmap(Frame frame, Text txt) {495 if (txt.getLink() == null)496 return false;497 498 // attempt to create the picture499 Picture pic = ItemUtils.CreateFrameBitmap(txt, frame);500 501 // if the picture could not be created successfully502 if (pic == null) {503 FrameGraphics.ErrorMessage("Error loading frame image");504 return false;505 }506 507 // replace the Text source with the new Picture508 frame.removeItem(txt);509 475 frame.addItem(pic); 510 476 … … 573 539 UserSettings.TitleTemplate = profile.getTitleItem(); 574 540 575 List<Text> items = profile.getBodyTextItems(true );541 List<Text> items = profile.getBodyTextItems(true, true); 576 542 577 543 // check for all tags setting user values … … 670 636 } 671 637 } 672 638 } 639 640 public static void loadFirstFrame(Frame profile) { 673 641 if (UserSettings.FirstFrame == null) 674 642 UserSettings.FirstFrame = profile.getName(); 675 643 else { 676 if (FrameIO.LoadFrame(UserSettings.FirstFrame) == null) { 644 Frame firstFrame = FrameIO.LoadFrame(UserSettings.FirstFrame); 645 if ( firstFrame == null) { 677 646 FrameGraphics.WarningMessage("Home frame not found: " 678 647 + UserSettings.FirstFrame); 679 648 UserSettings.FirstFrame = profile.getName(); 680 } 681 } 682 649 DisplayIO.setCurrentFrame(profile); 650 }else{ 651 DisplayIO.setCurrentFrame(firstFrame); 652 } 653 } 683 654 } 684 655 … … 821 792 */ 822 793 public static void Parse(Frame toParse, boolean firstParse) { 794 // TODO check why we are getting toParse == null... when profile frame 795 // is being created and change the lines below 796 if (toParse == null) 797 return; 823 798 // System.out.println(firstParse); 824 799 if (firstParse) … … 833 808 834 809 for (Item i : items) { 835 if (i instanceof Picture) {810 if (i instanceof XRayable) { 836 811 toParse.removeItem(i); 837 toParse.addItem(((Picture) i).getText()); 812 // Show the items 813 for (Item item : ((XRayable) i).getConnected()) { 814 item.setHidden(false); 815 item.removeEnclosure(i); 816 } 838 817 } else if (i instanceof WidgetCorner) { 839 818 toParse.removeItem(i); … … 861 840 boolean filledPoints = true; 862 841 863 int permissionLevel = getPermissionLevel(toParse.getProtection(), 864 Item.PERMISSION_FULL); 842 Permission permission = toParse.getPermission(); 865 843 toParse.clearAnnotations(); 866 844 … … 868 846 for (Item i : toParse.getItems()) { 869 847 try { 870 i. Permission = permissionLevel;848 i.setPermission(permission); 871 849 if (i instanceof Text && i.isAnnotation()) { 872 850 if (ItemUtils.startsWithTag(i, ItemUtils.TAG_POINTTYPE)) { … … 898 876 // frame contains an @ao which leads to a frame with an 899 877 // @v which points back to the frame with the @ao 900 901 878 Frame vector = FrameIO.LoadFrame(i.getAbsoluteLink()); 902 879 if (vector != null) { … … 908 885 } catch (Exception e) { 909 886 } 910 vectors.add(new Vector(vector, i.getPosition(), 911 scale, i.getColor(), i.getBackgroundColor())); 887 vectors 888 .add(new Vector(vector, i.getPosition(), 889 scale, i.getColor(), i 890 .getBackgroundColor())); 912 891 } 913 892 } … … 928 907 // Parse(overlay); 929 908 if (overlay != null && !overlays.contains(overlay)) 930 overlays.add(new Overlay(overlay, 931 Item.PERMISSION_NONE)); 909 overlays.add(new Overlay(overlay, Permission.none)); 932 910 } 933 911 // check for ACTIVE_OVERLAY items … … 949 927 .getFirstLine()); 950 928 // default permission (if none is specified) 951 int permission = getPermissionLevel(level,952 Item.PERMISSION_FOLLOW_LINKS);929 Permission permissionLevel = Permission.getPermission( 930 level, Permission.followLinks); 953 931 954 932 if (overlay != null) { … … 959 937 for (Overlay o : overlays) { 960 938 if (o.Frame.equals(overlay)) { 961 o. Level = permission;939 o.Frame.setPermission(permissionLevel); 962 940 found = true; 963 941 break; … … 966 944 // If it wasnt in the list create it and add it. 967 945 if (!found) { 968 overlays.add(new Overlay(overlay, permission)); 946 overlays.add(new Overlay(overlay, 947 permissionLevel)); 969 948 } 970 949 } … … 974 953 if (!FrameGraphics.isXRayMode()) { 975 954 if (ItemUtils.startsWithTag(i, ItemUtils.TAG_IMAGE, 976 true)) 955 true)) { 977 956 createPicture(toParse, (Text) i); 978 // check for frame images 979 else if (i.getLink() != null 957 // check for frame images 958 } else if (ItemUtils.startsWithTag(i, 959 ItemUtils.TAG_FRAME_IMAGE) 960 && i.getLink() != null 980 961 && !i.getAbsoluteLink().equalsIgnoreCase( 981 962 toParse.getName())) { 982 if (ItemUtils.startsWithTag(i, 983 ItemUtils.TAG_FRAME_IMAGE)) { 984 createFramePicture(toParse, (Text) i); 985 } else if (ItemUtils.startsWithTag(i, 986 ItemUtils.TAG_BITMAP_IMAGE)) { 987 createFrameBitmap(toParse, (Text) i); 963 XRayable image = null; 964 if (i.getEnclosures().size() > 0) { 965 i.setHidden(true); 966 image = i.getEnclosures().iterator().next(); 967 image.refresh(); 968 } else { 969 image = new FrameImage((Text) i, toParse, null); 988 970 } 989 } 990 // Check for interactive widgets 991 else if (ItemUtils.startsWithTag(i, 971 //TODO Add the image when creating new FrameImage 972 toParse.addItem(image); 973 } else if (ItemUtils.startsWithTag(i, 974 ItemUtils.TAG_BITMAP_IMAGE) 975 && i.getLink() != null 976 && !i.getAbsoluteLink().equalsIgnoreCase( 977 toParse.getName())) { 978 XRayable image = null; 979 if (i.getEnclosures().size() > 0) { 980 image = i.getEnclosures().iterator().next(); 981 image.refresh(); 982 i.setHidden(true); 983 } else { 984 // If a new bitmap is created for a 985 // frame which already has a bitmap dont 986 // recreate the bitmap 987 image = new FrameBitmap((Text) i, toParse, null); 988 } 989 toParse.addItem(image); 990 } else if (ItemUtils.startsWithTag(i, "@c")) { 991 // Can only have a @c 992 if (i.getLines().size() == 1) { 993 toParse.addItem(new Circle((Text) i)); 994 } 995 // Check for interactive widgets 996 } else if (ItemUtils.startsWithTag(i, 992 997 ItemUtils.TAG_IWIDGET)) { 993 998 createWidget(toParse, (Text) i); … … 1001 1006 // only remove items on first parse 1002 1007 if (firstParse) { 1008 // TODO refactor so thta this code is not needed 1009 // Remove when the file is being saved 1003 1010 // remove dots of size 1 1004 1011 if (i instanceof Dot) { … … 1057 1064 1058 1065 /** 1059 * Converts a string containing the permission level into its integer1060 * equivalent.1061 *1062 * @param level1063 * @param defaultPermission1064 * @return1065 */1066 public static int getPermissionLevel(String level, int defaultPermission) {1067 level = level.trim().toLowerCase();1068 if (level.length() == 0)1069 return defaultPermission;1070 1071 try {1072 return Integer.parseInt(level);1073 } catch (Exception e) {1074 // if this is a text permission level, parse it1075 1076 if (level.equals("none"))1077 return Item.PERMISSION_NONE;1078 else if (level.equals("links") || level.equals("link"))1079 return Item.PERMISSION_FOLLOW_LINKS;1080 else if (level.equals("copy"))1081 return Item.PERMISSION_COPY;1082 else if (level.equals("tdfc"))1083 return Item.PERMISSION_TDFC;1084 else if (level.equals("full") || level.equals("all"))1085 return Item.PERMISSION_FULL;1086 }1087 return defaultPermission;1088 }1089 1090 /**1091 1066 * Searches through the list of items on this frame to find one at the given 1092 1067 * x,y coordinates. … … 1099 1074 */ 1100 1075 public static Item onItem(Frame toCheck, float floatX, float floatY) { 1101 // System.out.println("MouseX: " + floatX + " MouseY: " + floatY);1102 1076 // System.out.println("MouseX: " + floatX + " MouseY: " + floatY); 1077 1103 1078 int x = Math.round(floatX); 1104 1079 int y = Math.round(floatY); … … 1114 1089 if (message != null) { 1115 1090 if (message.contains(x, y)) { 1116 message. Permission = Item.PERMISSION_COPY;1091 message.setPermission(Permission.copy); 1117 1092 possibles.add(message); 1118 } else 1093 } else{ 1119 1094 // Not sure why but if the line below is removed then 1120 1095 // several items can be highlighted at once 1121 1096 message.setSelectedMode(Item.SelectedMode.None); 1097 } 1122 1098 } 1123 1099 } … … 1126 1102 if (FrameGraphics.MessageLink != null) { 1127 1103 if (FrameGraphics.MessageLink.contains(x, y)) { 1128 FrameGraphics.MessageLink. Permission = Item.PERMISSION_COPY;1104 FrameGraphics.MessageLink.setPermission(Permission.copy); 1129 1105 possibles.add(FrameGraphics.MessageLink); 1130 1106 } … … 1135 1111 // otherwise, the mouse is on the frame 1136 1112 } else { 1137 1138 if (LastEdited != null &&LastEdited.contains(x, y)1113 if (LastEdited != null && /*LastEdited.isVisible() 1114 &&*/ LastEdited.contains(x, y) 1139 1115 && !Frame.FreeItems.contains(LastEdited) 1140 1116 && LastEdited.getParent() == DisplayIO.getCurrentFrame() 1141 1117 && LastEdited.getParent().getItems().contains(LastEdited)) { 1142 LastEdited. Permission = Item.PERMISSION_FULL;1118 LastEdited.setPermission(Permission.full); 1143 1119 return LastEdited; 1144 1120 } else … … 1146 1122 1147 1123 ArrayList<Item> checkList = new ArrayList<Item>(); 1148 checkList.addAll(toCheck.get Items());1124 checkList.addAll(toCheck.getVisibleItems()); 1149 1125 checkList.add(toCheck.getNameItem()); 1150 1126 for (Item i : checkList) { … … 1156 1132 } 1157 1133 } 1158 int framePermission = getPermissionLevel(toCheck.getProtection(), 1159 Item.PERMISSION_FULL); 1134 Permission framePermission = toCheck.getPermission(); 1160 1135 for (Overlay o : toCheck.getOverlays()) { 1161 if (o.Level > Item.PERMISSION_NONE) {1136 if (o.Level.ordinal() > Permission.none.ordinal()) { 1162 1137 Item i = onItem(o.Frame, x, y); 1163 1138 … … 1165 1140 // it should be ignored here 1166 1141 if (i != null && i.getID() > 0) { 1167 i.Permission = Math.min(o.Level, framePermission); 1142 i.setPermission(Permission 1143 .min(o.Level, framePermission)); 1168 1144 possibles.add(i); 1169 1145 } … … 1214 1190 } 1215 1191 1216 public static List<Item> getCurrentItems(Item currentItem) {1217 1218 Collection<Item> enclosure = getEnclosing Dots();1192 public static Collection<Item> getCurrentItems(Item currentItem) { 1193 1194 Collection<Item> enclosure = getEnclosingLineEnds(); 1219 1195 if (enclosure == null || enclosure.size() == 0) 1220 1196 return null; … … 1222 1198 Item firstItem = enclosure.iterator().next(); 1223 1199 1224 List<Item> enclosed = getItemsEnclosedBy(DisplayIO.getCurrentFrame(),1225 firstItem.getEnclosedShape());1200 Collection<Item> enclosed = getItemsEnclosedBy(DisplayIO 1201 .getCurrentFrame(), firstItem.getEnclosedShape()); 1226 1202 1227 1203 // Brook: enclosed widgets are to be fully enclosed, never partially … … 1249 1225 } 1250 1226 1251 public static Collection<Item> getEnclosing Dots() {1227 public static Collection<Item> getEnclosingLineEnds() { 1252 1228 // update enclosed shapes 1253 1229 Frame current = DisplayIO.getCurrentFrame(); … … 1268 1244 Item i = items.get(0); 1269 1245 items.remove(i); 1270 if (i.is LineEnd() && i.isEnclosed()) {1246 if (i.isEnclosed()) { 1271 1247 Polygon p = i.getEnclosedShape(); 1272 1248 if (p.contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) { … … 1336 1312 } 1337 1313 1338 public static List<Item> getItemsEnclosedBy(Frame frame, Polygon poly) { 1339 List<Item> contained = frame.getItemsWithin(poly); 1340 1341 ArrayList<Item> results = new ArrayList<Item>(contained.size()); 1314 //TODO Remove this method!! 1315 //We should be able to get by with just getItemsWithin 1316 public static Collection<Item> getItemsEnclosedBy(Frame frame, Polygon poly) { 1317 Collection<Item> contained = frame.getItemsWithin(poly); 1318 1319 Collection<Item> results = new LinkedHashSet<Item>(contained.size()); 1342 1320 1343 1321 // check for correct permissions … … 1345 1323 // if the item is on the frame 1346 1324 if (item.getParent() == frame || item.getParent() == null) { 1347 // item.Permission = Item.PERMISSION_FULL;1325 // item.Permission = Permission.full; 1348 1326 results.add(item); 1349 1327 // otherwise, it must be on an overlay frame … … 1351 1329 for (Overlay overlay : frame.getOverlays()) 1352 1330 if (overlay.Frame == item.getParent()) { 1353 item. Permission = overlay.Level;1331 item.setPermission(overlay.Level); 1354 1332 results.add(item); 1355 1333 break; … … 1397 1375 1398 1376 Text t = profile.addText(xPos, yPos, "@ItemTemplate", null); 1399 t.setColor( Color.black);1377 t.setColor(null); 1400 1378 1401 1379 yPos += spacing; … … 1483 1461 1484 1462 private static Item _tdfcItem = null; 1463 1464 public static void setLastEdited(Text lastEdited) { 1465 if(LastEdited != null && LastEdited.getText().length() == 0){ 1466 LastEdited.getParentOrCurrentFrame().removeItem(LastEdited); 1467 } 1468 LastEdited = lastEdited; 1469 } 1485 1470 } -
trunk/src/org/expeditee/gui/Overlay.java
r4 r108 1 1 package org.expeditee.gui; 2 3 import org.expeditee.items.Permission; 2 4 3 5 public class Overlay { 4 6 public Frame Frame; 5 7 6 public intLevel;8 public Permission Level; 7 9 8 public Overlay(Frame overlay, intlevel) {10 public Overlay(Frame overlay, Permission level) { 9 11 Frame = overlay; 10 12 Level = level; -
trunk/src/org/expeditee/gui/UserSettings.java
r80 r108 49 49 public static boolean Threading = true; 50 50 51 public static Text ItemTemplate = new Text( -1,"@ItemTemplate");51 public static Text ItemTemplate = new Text("@ItemTemplate"); 52 52 53 public static Text LineTemplate = new Text( -1,"@LineTemplate");53 public static Text LineTemplate = new Text("@LineTemplate"); 54 54 55 55 public static Text AnnotationTemplate = null; -
trunk/src/org/expeditee/io/Conversion.java
r97 r108 10 10 import java.util.StringTokenizer; 11 11 12 import org.expeditee.actions.Actions; 12 13 import org.expeditee.items.Item; 13 14 import org.expeditee.items.Justification; 15 import org.expeditee.items.Permission; 14 16 import org.expeditee.items.Text; 15 17 … … 73 75 74 76 float color[] = { 0, 0, 0 }; 75 // Assert.assertTrue(color.length == 3);77 // Assert.assertTrue(color.length == 3); 76 78 77 79 if (colorCode.startsWith("red")) … … 89 91 private static Color getRGBColor(String colorCode, Color current) { 90 92 int color[] = new int[3]; 91 // Assert.assertTrue(color.length == 3);93 // Assert.assertTrue(color.length == 3); 92 94 93 95 try { … … 171 173 */ 172 174 public static String getExpediteeFontCode(Font font) { 173 String code = "t";174 String fontName = font.getFamily().toLowerCase();175 String fontName = font.getFamily(); 176 String code = font.getFamily() + '_'; 175 177 176 178 for (int i = 0; i < Text.FONT_WHEEL.length; i++) { 177 if (Text.FONT_WHEEL[i].equals (fontName)) {179 if (Text.FONT_WHEEL[i].equalsIgnoreCase(fontName)) { 178 180 code = "" + Text.FONT_CHARS[i]; 179 181 break; … … 212 214 assert (fontCode != null); 213 215 216 int separator = fontCode.indexOf('_'); 214 217 String code = Text.FONT_WHEEL[0]; 215 216 char c = fontCode.charAt(0); 217 for (int i = 0; i < Text.FONT_CHARS.length; i++) { 218 if (c == Text.FONT_CHARS[i]) { 219 code = Text.FONT_WHEEL[i] + '-'; 220 break; 218 if (separator > 0) { 219 code = Actions.getCapitalizedFontName(fontCode.substring(0,separator)) + '-'; 220 fontCode = fontCode.substring(separator); 221 } else { 222 char c = fontCode.charAt(0); 223 for (int i = 0; i < Text.FONT_CHARS.length; i++) { 224 if (c == Text.FONT_CHARS[i]) { 225 code = Text.FONT_WHEEL[i] + '-'; 226 break; 227 } 221 228 } 222 229 } … … 293 300 } 294 301 295 public static String getFramesetName(String framename, boolean convertToLower) { 302 public static String getFramesetName(String framename, 303 boolean convertToLower) { 296 304 String set = null; 297 305 assert (Character.isDigit(framename.charAt(framename.length() - 1))); … … 337 345 try { 338 346 // Find the field and value of colorName 339 Field[] fields = Class.forName("java.awt.Color").getFields();347 Field[] fields = java.awt.Color.class.getFields(); 340 348 Field field = null; 341 349 for (int i = 0; i < fields.length; i++) { … … 458 466 String name = method.getName(); 459 467 Class[] types = method.getParameterTypes(); 460 468 461 469 String fullValue = value; 462 470 value = value.trim(); … … 466 474 just[0] = Justification.getJustification(value); 467 475 return just; 476 }else if (name.endsWith("Permission")) { 477 Permission[] permission = new Permission[1]; 478 permission[0] = Permission.getPermission(value); 479 return permission; 468 480 } 469 481 … … 472 484 return null; 473 485 474 Integerlength = null;486 Float length = null; 475 487 Double ratio = null; 476 488 … … 480 492 } else { 481 493 assert (current instanceof String); 482 int oldLength = getArrowLength(current.toString());494 float oldLength = getArrowLength(current.toString()); 483 495 double oldRatio = getArrowRatio(current.toString()); 484 length = ( Integer) Convert(int.class, value.substring(0, value496 length = (Float) Convert(float.class, value.substring(0, value 485 497 .indexOf(" ")), oldLength); 486 498 ratio = (Double) Convert(double.class, value.substring( … … 512 524 } 513 525 514 private static int getArrowLength(String s) {515 return Integer.parseInt(s.substring(0, s.indexOf(" ")));526 private static float getArrowLength(String s) { 527 return Float.parseFloat(s.substring(0, s.indexOf(" "))); 516 528 } 517 529 … … 532 544 533 545 if (name.endsWith("Justification")) 534 return ((Justification)output).getCode(); 546 return ((Justification) output).getCode(); 547 548 if (name.endsWith("Permission")) 549 return ((Permission) output).getCode(); 535 550 536 551 // strings can be returned immediately -
trunk/src/org/expeditee/io/DefaultFrameWriter.java
r86 r108 44 44 try { 45 45 _FrameTags.put("V", Frame.class.getMethod("getVersion", param)); 46 _FrameTags.put("p", Frame.class.getMethod("getP rotection", param));46 _FrameTags.put("p", Frame.class.getMethod("getPermission", param)); 47 47 _FrameTags.put("U", Frame.class.getMethod("getOwner", param)); 48 48 _FrameTags.put("D", Frame.class.getMethod("getDateCreated", param)); -
trunk/src/org/expeditee/io/ExpWriter.java
r105 r108 12 12 import org.expeditee.gui.Frame; 13 13 import org.expeditee.items.Constraint; 14 import org.expeditee.items.InteractiveWidget;15 14 import org.expeditee.items.Item; 16 15 import org.expeditee.items.Line; 17 import org.expeditee.items.Picture;18 import org.expeditee.items.WidgetCorner;19 16 import org.expeditee.items.WidgetEdge; 20 17 import org.expeditee.stats.SessionStats; … … 76 73 writeHeader(frame); 77 74 78 // write out each Item in the Frame. 79 List<Item> items = frame.getItems(); 80 81 // iWidgets are handled specially since 8 items are written as one 82 List<InteractiveWidget> seenWidgets = new LinkedList<InteractiveWidget>(); 83 84 // do not write items with ID -1, also skip any lines 85 for (Item i : items) { 86 87 // Ensure only one of the WidgetCorners represent a single widget 88 if (i instanceof WidgetCorner) { 89 InteractiveWidget iw = ((WidgetCorner) i).getWidgetSource(); 90 if (seenWidgets.contains(iw)) 91 continue; 92 seenWidgets.add(iw); 93 } 94 95 if (i.getID() >= 0 && !(i instanceof Line)) { 96 writeItem(i); 97 } 75 76 // write each item in the frame 77 for (Item i : frame.getItemsToSave()) { 78 assert(!(i instanceof Line)); 79 writeItem(i); 98 80 } 99 81 … … 119 101 o = Conversion.ConvertToExpeditee(_FrameTags.get(tag), o); 120 102 if (o != null) { 121 writeLine(tag, (String) o);103 writeLine(tag, o.toString()); 122 104 } 123 105 } catch (Exception e) { … … 155 137 return; 156 138 157 // Dont save the item if it is off the screen158 if (item.offScreenTopOrLeft()) {159 //System.out.println("item offscreen!");160 return;161 }162 163 // Pictures are saved as the corresponding text items that created them164 if (item instanceof Picture)165 item = ((Picture) item).getText();166 else if (item instanceof WidgetCorner)167 item = ((WidgetCorner) item).getWidgetSource().getSource();168 169 139 if (item.isLineEnd()) 170 write Point(item);140 writeLineEnd(item); 171 141 else if (!(item instanceof Line)) 172 142 writeClass(item); … … 179 149 } 180 150 181 private List<Item> _ points = new LinkedList<Item>();182 183 // Writes out a Dotto the file184 protected void write Point(Item point) throws IOException {185 _ points.add(point);151 private List<Item> _lineEnds = new LinkedList<Item>(); 152 153 // Writes out a LineEnd to the file 154 protected void writeLineEnd(Item point) throws IOException { 155 _lineEnds.add(point); 186 156 writeClass(point); 187 157 } … … 192 162 193 163 // loop through all points stored 194 for (int i = 0; i < _ points.size(); i++) {195 List<Line> lines = _ points.get(i).getLines();164 for (int i = 0; i < _lineEnds.size(); i++) { 165 List<Line> lines = _lineEnds.get(i).getLines(); 196 166 197 167 // if this point is part of one or more lines … … 225 195 226 196 // loop through all the points 227 while (_ points.size() > 0) {228 Item i = _ points.get(0);197 while (_lineEnds.size() > 0) { 198 Item i = _lineEnds.get(0); 229 199 230 200 // if there are any constraints to write … … 235 205 // written 236 206 for (Constraint c : constraints) { 237 if (_ points.contains(c.getStart())238 && _ points.contains(c.getEnd())) {207 if (_lineEnds.contains(c.getStart()) 208 && _lineEnds.contains(c.getEnd())) { 239 209 writeLine("C", c.getID() + " " + c.getType()); 240 210 writeLine("s", c.getLineEnds()); … … 245 215 } 246 216 // remove the point from the list 247 _ points.remove(0);217 _lineEnds.remove(0); 248 218 } 249 219 } … … 265 235 String tag = it.next(); 266 236 Method toRun = _ItemTags.get(tag); 267 Class declarer = toRun.getDeclaringClass();237 Class<?> declarer = toRun.getDeclaringClass(); 268 238 if (declarer.isAssignableFrom(toWrite.getClass())) { 269 239 try { -
trunk/src/org/expeditee/io/FrameReader.java
r97 r108 14 14 import org.expeditee.items.Justification; 15 15 import org.expeditee.items.Line; 16 import org.expeditee.items.Permission; 16 17 import org.expeditee.items.Text; 17 18 … … 28 29 protected static Class[] pFont = { Font.class }; 29 30 protected static Class[] pPoint = { Point.class }; 30 protected static Class[] pArrow = { int.class, double.class };31 protected static Class[] pArrow = { float.class, double.class }; 31 32 protected static Class[] pList = { List.class }; 32 33 protected static Class[] pIntArray = { int[].class }; 33 34 protected static Class[] pItem = { Item.class }; 34 35 protected static Class[] pJustification = { Justification.class }; 36 protected static Class[] pPermission = { Permission.class }; 35 37 36 38 public FrameReader(){ … … 45 47 _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt)); 46 48 _FrameTags 47 .put('p', Frame.class.getMethod("setP rotection", pString));49 .put('p', Frame.class.getMethod("setPermission", pPermission)); 48 50 _FrameTags.put('U', Frame.class.getMethod("setOwner", pString)); 49 51 _FrameTags.put('D', Frame.class -
trunk/src/org/expeditee/io/HTMLBWriter.java
r80 r108 47 47 + filesFolder, fileName); 48 48 } else {//It is a normal Image stored somewhere 49 Text source = pic.get Text();49 Text source = pic.getSource(); 50 50 51 51 fileName = source.getFirstLine(); -
trunk/src/org/expeditee/io/HTMLWriter.java
r80 r108 108 108 @Override 109 109 protected void writePicture(Picture pic) throws IOException { 110 Text source = pic.get Text();110 Text source = pic.getSource(); 111 111 112 112 String line = source.getFirstLine(); -
trunk/src/org/expeditee/io/KMSReader.java
r97 r108 49 49 _FrameTags.put("V", Frame.class.getMethod("setVersion", pInt)); 50 50 _FrameTags 51 .put("p", Frame.class.getMethod("setP rotection", pString));51 .put("p", Frame.class.getMethod("setPermission", pPermission)); 52 52 _FrameTags.put("U", Frame.class.getMethod("setOwner", pString)); 53 53 _FrameTags.put("D", Frame.class -
trunk/src/org/expeditee/io/KMSWriter.java
r97 r108 16 16 import org.expeditee.items.Item; 17 17 import org.expeditee.items.Line; 18 import org.expeditee.items.Picture;19 18 import org.expeditee.stats.SessionStats; 20 19 … … 80 79 81 80 // write out each Item in the Frame. 82 List<Item> items = frame.getItems ();81 List<Item> items = frame.getItemsToSave(); 83 82 84 83 // do not write items with ID -1, also skip any lines 85 84 for (Item i : items) { 86 if (i.getID() >= 0 && !(i instanceof Line)) 87 writeItem(i); 85 writeItem(i); 88 86 } 89 87 … … 108 106 o = Conversion.ConvertToExpeditee(_FrameTags.get(tag), o); 109 107 if (o != null) { 110 writeLine(tag, (String) o);108 writeLine(tag, o.toString()); 111 109 } 112 110 } catch (IllegalArgumentException e) { … … 147 145 if (_writer == null) 148 146 return; 149 150 if (item.offScreenTopOrLeft()) {151 //System.out.println("item offscreen!");152 return;153 }154 147 155 148 writeLine(""); 156 // Pictures are saved as the corresponding text items that created them157 if (item instanceof Picture)158 item = ((Picture) item).getText();159 160 149 if (item.getLines().size() > 0) 161 150 writePoint(item); 162 else if (!(item instanceof Line))151 else 163 152 writeClass(item); 164 else165 System.out.println("Unknown Item: " + item.getID());166 153 } 167 154 … … 253 240 String tag = it.next(); 254 241 Method toRun = _ItemTags.get(tag); 255 Class declarer = toRun.getDeclaringClass();242 Class<?> declarer = toRun.getDeclaringClass(); 256 243 if (declarer.isAssignableFrom(toWrite.getClass())) { 257 244 try { -
trunk/src/org/expeditee/items/Dot.java
r97 r108 26 26 27 27 private static final int _MINIMUM_DOT_SIZE = 6; 28 29 // the polygon surrounding this point, used for 'gravity'30 private Polygon _poly = null;31 28 32 29 private int _pointType = Item.POINTTYPE_SQUARE; … … 92 89 public void paint(Graphics2D g) { 93 90 if (isHighlighted() /* && !Frame.FreeItems.contains(this) */) { 94 g.setColor(getHighlightColor()); 91 Color backgroundColor = g.getBackground(); 92 Color highlightColor = getHighlightColor(); 93 if (highlightColor.equals(backgroundColor)){ 94 highlightColor = ALTERNATE_HIGHLIGHT; 95 } 96 g.setColor(highlightColor); 97 g.setStroke(HIGHLIGHT_STROKE); 98 //g.setStroke() 95 99 // Draw the highlighting rectangle surrounding the dot 96 100 // this is drawn even if its part of a rectangle … … 150 154 */ 151 155 protected void updatePolygon() { 152 int thick = (int) Math.ceil(getThickness());156 int thick = Math.round(getThickness()); 153 157 // Sets a minimum size for the dot 154 158 thick = Math.max(thick, _MINIMUM_DOT_SIZE); … … 165 169 166 170 @Override 167 public Polygon getPolygon() {168 if (_poly == null)169 updatePolygon();170 171 Polygon external = new Polygon(_poly.xpoints, _poly.ypoints,172 _poly.npoints);173 174 return external;175 }176 177 @Override178 171 public Item copy() { 179 172 Dot copy = new Dot(getX(), getY(), getID()); … … 205 198 // if the item being merged with is another Dot 206 199 if (merger instanceof Dot) { 200 if(merger.hasEnclosures() || hasEnclosures()) 201 return merger; 202 207 203 Item dot = (Item) merger; 208 204 merger.setPosition(this.getPosition()); -
trunk/src/org/expeditee/items/FrameBitmap.java
r106 r108 2 2 3 3 import java.awt.Color; 4 import java.awt.Image; 4 5 import java.awt.image.BufferedImage; 5 6 import java.awt.image.ImageObserver; … … 9 10 import org.expeditee.gui.FrameIO; 10 11 12 //TODO tidy up the mess I caused with refresh during the period where I was going into XRay mode before saving 13 11 14 public class FrameBitmap extends FramePicture { 12 public FrameBitmap(Text source, String size, ImageObserver observer) 13 throws IllegalArgumentException { 14 super(); 15 _source = source; 16 _imageObserver = observer; 17 18 refresh(); 19 20 if (_image == null) 21 throw new IllegalArgumentException(); 22 23 parseSize(size); 15 public FrameBitmap(Text source, ImageObserver observer, Image image){ 16 super(source, observer, image); 24 17 } 25 18 … … 77 70 @Override 78 71 protected Picture createPicture() { 79 return ItemUtils.CreateFrameBitmap((Text) _source.copy(),80 _imageObserver );72 return new FrameBitmap((Text) _source.copy(), 73 _imageObserver, _image); 81 74 } 82 75 -
trunk/src/org/expeditee/items/FrameImage.java
r80 r108 1 1 package org.expeditee.items; 2 2 3 import java.awt.Image; 3 4 import java.awt.image.ImageObserver; 4 5 … … 22 23 * screen. 23 24 */ 24 public FrameImage(Text source, String size, ImageObserver observer) 25 throws IllegalArgumentException { 26 super(); 27 _source = source; 28 _imageObserver = observer; 29 30 refresh(); 31 32 if (_image == null) 33 throw new IllegalArgumentException(); 34 35 parseSize(size); 36 25 public FrameImage(Text source, ImageObserver observer, Image image) { 26 super(source, observer, image); 37 27 } 38 28 39 29 @Override 40 30 protected Picture createPicture() { 41 return ItemUtils 42 .CreateFrameImage((Text) _source.copy(), _imageObserver); 31 return new FrameImage(_source.copy(), _imageObserver, _image); 43 32 } 44 33 45 34 @Override 46 35 public boolean refresh() { 36 // Need to parse the first time the frame is being displayed 37 // parseSize(); 47 38 assert (_source.getLink() != null); 48 39 Frame frame = FrameIO.LoadFrame(_source.getAbsoluteLink()); … … 54 45 _image = frame.getBuffer(); 55 46 47 // TODO tidy this up, need to call parse size only when the frame has 48 // been created to begin with 49 parseSize(); 50 updatePolygon(); 56 51 return true; 57 52 } 58 53 59 54 @Override 60 55 protected String getTagText() { -
trunk/src/org/expeditee/items/FramePicture.java
r80 r108 1 1 package org.expeditee.items; 2 3 import java.awt.Color; 4 import java.awt.Image; 5 import java.awt.image.ImageObserver; 2 6 3 7 import org.expeditee.gui.Frame; 4 8 5 9 public class FramePicture extends Picture { 6 protected FramePicture( ) {7 super( );10 protected FramePicture(Text source, ImageObserver observer, Image image) { 11 super(source, observer, image); 8 12 } 9 13 14 @Override 15 public void setColor(Color c) { 16 super.setColor(c); 17 refresh(); 18 } 19 10 20 @Override 11 21 public void setLink(String frameName) { … … 14 24 else { 15 25 _source.setLink(frameName); 16 26 //remove the picture if the link is being removed 17 27 if (_source.getLink() == null) { 18 28 Frame parent = getParent(); 19 29 if (parent != null) { 20 30 parent.removeItem(this); 21 parent.addItem(_source); 31 _source.setHidden(false); 32 _source.removeEnclosure(this); 22 33 } 23 34 } else { -
trunk/src/org/expeditee/items/InteractiveWidget.java
r85 r108 748 748 if ((e.getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY || e 749 749 .getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY) 750 && e.getOverlayLevel() == Item.PERMISSION_NONE) {750 && e.getOverlayLevel().equals(Permission.none)) { 751 751 return; // item belongs to a non-active overlay 752 752 } -
trunk/src/org/expeditee/items/Item.java
r107 r108 9 9 import java.awt.Polygon; 10 10 import java.awt.Rectangle; 11 import java.awt.Stroke; 11 12 import java.awt.geom.AffineTransform; 12 13 import java.awt.geom.Area; 14 import java.awt.geom.Point2D; 15 import java.awt.geom.Rectangle2D; 13 16 import java.util.ArrayList; 14 17 import java.util.Collection; 15 18 import java.util.ConcurrentModificationException; 19 import java.util.HashSet; 16 20 import java.util.LinkedHashSet; 17 21 import java.util.LinkedList; … … 39 43 public abstract class Item implements Comparable<Item>, Runnable { 40 44 45 public static final Float DEFAULT_THICKNESS = 2f; 46 47 public static final Float MINIMUM_THICKNESS = 1f; 48 41 49 protected final int JOIN = BasicStroke.JOIN_ROUND; 42 50 43 51 protected final int CAP = BasicStroke.CAP_BUTT; 44 52 53 protected final Stroke HIGHLIGHT_STROKE = new BasicStroke( 54 MINIMUM_THICKNESS, CAP, JOIN, 4.0F); 55 45 56 // contains all dots (including this one) that form an enclosure 46 57 // if this dot is part of an enclosing shape … … 49 60 public static final int LEFT_MARGIN = 13; 50 61 62 // indicates which end the arrowhead should be drawn at 63 protected Polygon _poly = null; 64 51 65 protected boolean _connectedToAnnotation = false; 52 53 public static final int PERMISSION_NONE = 0;54 55 public static final int PERMISSION_FOLLOW_LINKS = 1;56 57 public static final int PERMISSION_COPY = 2;58 59 public static final int PERMISSION_TDFC = 3;60 61 public static final int PERMISSION_FULL = 4;62 66 63 67 public static final int NEAR_DISTANCE = 15; … … 103 107 * this Item. 104 108 */ 105 public static Color[] COLOR_WHEEL = { Color. RED, Color.BLUE, Item.GREEN,106 Color.MAGENTA, Color.YELLOW.darker(), Color.BLACK, Color.DARK_GRAY,107 Color.GRAY, Color.WHITE, null }; 108 109 public static Color[] COLOR_WHEEL = { Color.BLACK, Color.RED, Color.BLUE, 110 Item.GREEN, Color.MAGENTA, Color.YELLOW.darker(), Color.WHITE }; 111 112 // TODO Have shift toggle through a black and white color wheel? 109 113 public static Color[] FILL_COLOR_WHEEL = { new Color(255, 150, 150), 110 114 new Color(150, 150, 255), new Color(150, 255, 150), 111 115 new Color(255, 150, 255), new Color(255, 255, 100), Color.WHITE, 112 Color.GRAY, Color.DARK_GRAY, Color.BLACK, null }; 116 Color.BLACK}; 117 /* Color.GRAY, 118 * Color.DARK_GRAY, 119 */ 113 120 114 121 public static final int UNCHANGED_CURSOR = -100; … … 167 174 168 175 dest.setParent(source.getParent()); 169 dest._mode = SelectedMode.None; 170 dest._lastMode = source._mode; 171 176 dest._mode = source._mode;// SelectedMode.None; 177 dest._visible = source._visible; 172 178 Frame parent = source.getParentOrCurrentFrame(); 173 179 // TODO MIKE says maybe we could tighten up and only give items ID's if … … 199 205 private Point _offset = new Point(0, 0); 200 206 201 pr ivatefloat _x;202 203 pr ivatefloat _y;207 protected float _x; 208 209 protected float _y; 204 210 205 211 private int _id; … … 229 235 private List<String> _actionLeaveFrame = null; 230 236 231 public int Permission = PERMISSION_FULL; 237 public Permission _permission = Permission.full; 238 239 public void setPermission(Permission permission){ 240 _permission = permission; 241 } 242 243 public boolean hasPermission(Permission permission){ 244 return _permission.ordinal() >= permission.ordinal(); 245 } 232 246 233 247 // A fill color of null represents transparent … … 256 270 257 271 // arrowhead parameters 258 private int _arrowheadLength = 0;272 private float _arrowheadLength = 0; 259 273 260 274 private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO; … … 283 297 284 298 private boolean _visible = true; 285 286 private SelectedMode _lastMode = SelectedMode.None;287 299 288 300 private float _thickness = -1.0F; … … 303 315 } 304 316 305 if (_actions == null) 317 if (_actions == null){ 318 _poly = null; 306 319 _actions = new LinkedList<String>(); 320 } 307 321 _actions.add(action); 308 322 } … … 312 326 connected.add(this); 313 327 314 for ( Line line : getLines()) {315 if (!connected.contains( line))316 line.addAllConnected(connected);328 for (Item item : getConnected()) { 329 if (!connected.contains(item)) 330 item.addAllConnected(connected); 317 331 } 318 332 } … … 383 397 384 398 public void delete() { 385 setVisible(false); 386 } 387 399 _deleted = true; 400 } 401 402 @Override 388 403 public boolean equals(Object o) { 389 if (o instanceof Item) { 404 if (o == null) 405 return false; 406 if (getClass().equals(o.getClass())) { 390 407 Item i = (Item) o; 391 408 return i.getID() == getID() 392 409 && ((i.getParent() == _parent) || (i.getParent() != null && i 393 410 .getParent().equals(_parent))); 394 395 411 } else 396 412 return false; … … 463 479 } 464 480 465 public int getArrowheadLength() {481 public float getArrowheadLength() { 466 482 return _arrowheadLength; 467 483 } … … 559 575 List<Item> conn = new LinkedList<Item>(); 560 576 conn.add(this); 561 577 conn.addAll(getEnclosures()); 562 578 conn.addAll(getLines()); 563 579 return conn; … … 698 714 699 715 public Color getPaintBackgroundColor() { 700 if (_colorBackground == null) { 716 Color colorBackground = getBackgroundColor(); 717 if (colorBackground == null) { 701 718 if (getParent() != null && getParent().getBackgroundColor() != null) 702 719 return getParent().getBackgroundColor(); … … 705 722 } 706 723 707 return _colorBackground;724 return colorBackground; 708 725 } 709 726 … … 713 730 * @return The Color of this item (foreground) 714 731 */ 715 public Color getPaintColor() {732 public final Color getPaintColor() { 716 733 // If color is null then get the paint foregroundColor for the frame the 717 734 // item is on which is a color adjusted to suit the background 718 if (_color == null) { 735 Color color = getColor(); 736 737 if (color == null) { 719 738 if (getParent() != null) 720 739 return getParent().getPaintForegroundColor(); … … 727 746 } 728 747 729 return _color;748 return color; 730 749 } 731 750 … … 739 758 } 740 759 741 public Frame getParent() {760 public final Frame getParent() { 742 761 return _parent; 743 762 } 744 763 745 /** 746 * Returns the Shape that surrounds this Item representing this Item's 747 * 'gravity'. 748 * 749 * @return The Shape (rectangle) surrounding this Item, which represents 750 * this Items 'gravity'. 751 */ 752 public abstract Polygon getPolygon(); 753 754 public Point getPosition() { 764 public final Point getPosition() { 755 765 return new Point(getX(), getY()); 756 766 } … … 762 772 * @return The size of this Item. 763 773 */ 764 public int getSize() {765 return -1 ;774 public float getSize() { 775 return -1.0F; 766 776 } 767 777 … … 809 819 /** 810 820 * Checks if the given Shape intersects with the Shape around this Item. 811 * Note: Both Shape objects should be rectangles for this to work properly.812 821 * 813 822 * @param s … … 819 828 return false; 820 829 821 // return p.getBounds().intersects(getArea().getBounds());822 830 Area a = new Area(p); 823 824 831 a.intersect(this.getArea()); 832 825 833 return !a.isEmpty(); 826 834 } … … 859 867 */ 860 868 public boolean isHighlighted() { 869 if (isFloating()) 870 return false; 861 871 return _mode != SelectedMode.None; 862 872 } … … 917 927 918 928 public void paintFill(Graphics2D g) { 919 if (getFillColor() != null && getEnclosingDots() != null) { 920 g.setColor(getFillColor()); 929 Color fillColor = getFillColor(); 930 if (fillColor != null && getEnclosingDots() != null) { 931 if(isFloating()){ 932 //TODO experiment with adding alpha when picking up filled items... 933 //Slows things down quite alot!! 934 fillColor = new Color(fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue()); 935 } 936 g.setColor(fillColor); 921 937 // The painting is not efficient enough for gradients... 922 938 // Shape s = getEnclosedShape(); … … 1021 1037 // Check if all the characters are digits and hence it is a relative 1022 1038 // link 1023 for (int i = 0; i < link.length(); i++) { 1024 if (!Character.isDigit(link.charAt(i))) 1025 return; 1026 } 1039 if(!FrameIO.isPositiveInteger(link)) 1040 return; 1027 1041 1028 1042 // Make it an absolute link … … 1038 1052 1039 1053 /** 1040 * Sets any action code (KMS action language)that should be associated with1054 * Sets any action code that should be associated with 1041 1055 * this Item Each entry in the list is one line of code 1042 1056 * … … 1045 1059 */ 1046 1060 public void setActions(List<String> actions) { 1061 //Want to resize the highlight box for text items if actions have been added 1062 _poly = null; 1047 1063 if (actions == null || actions.size() == 0) 1048 1064 _actions = null; … … 1075 1091 1076 1092 public void setActionMark(boolean val) { 1093 _poly = null; 1077 1094 _actionMark = val; 1078 1095 } … … 1096 1113 * The ratio of the arrow's length to its width. 1097 1114 */ 1098 public void setArrow( int length, double ratio) {1115 public void setArrow(float length, double ratio) { 1099 1116 _arrowheadLength = length; 1100 1117 _arrowheadRatio = ratio; … … 1106 1123 } 1107 1124 1108 public void setArrowheadLength( int length) {1125 public void setArrowheadLength(float length) { 1109 1126 _arrowheadLength = length; 1110 1127 updateArrowPolygon(); … … 1250 1267 1251 1268 public void setLinkMark(boolean val) { 1269 _poly = null; 1252 1270 _linkMark = val; 1253 1271 } … … 1307 1325 _y = y; 1308 1326 1327 for (Item i : getEnclosures()) { 1328 i.updatePolygon(); 1329 } 1309 1330 updatePolygon(); 1310 1331 … … 1400 1421 return; 1401 1422 assert (_parent != null); 1423 1424 if(FrameIO.isPositiveInteger(link)) 1425 return; 1426 1402 1427 // Check if the link is for the current frameset 1403 1428 if (_parent.getFramesetName().equalsIgnoreCase( … … 1411 1436 * Dots this is the thickness. 1412 1437 */ 1413 public void setSize( int size) {1438 public void setSize(float size) { 1414 1439 } 1415 1440 … … 1500 1525 else { 1501 1526 _arrowhead = new Polygon(); 1502 _arrowhead.addPoint((int) getX(), (int) getY()); 1527 _arrowhead.addPoint(Math.round(getX()), Math.round(getY())); 1528 _arrowhead.addPoint((Math.round(getX() - getArrowheadLength())), 1529 ((int) Math.round(getY() 1530 - (getArrowheadLength() * getArrowheadRatio())))); 1531 _arrowhead.addPoint(Math.round(getX()), (int) getY()); 1503 1532 _arrowhead 1504 1533 .addPoint( 1505 (int) getX() - getArrowheadLength(), 1506 (int) (getY() - (getArrowheadLength() * getArrowheadRatio()))); 1507 _arrowhead.addPoint((int) getX(), (int) getY()); 1508 _arrowhead 1509 .addPoint( 1510 (int) getX() - getArrowheadLength(), 1511 (int) (getY() + (getArrowheadLength() * getArrowheadRatio()))); 1534 (int) Math.round(getX() - getArrowheadLength()), 1535 (int) Math 1536 .round((getY() + (getArrowheadLength() * getArrowheadRatio())))); 1512 1537 } 1513 1538 } 1514 1539 1515 1540 protected abstract void updatePolygon(); 1541 1542 public void setHidden(boolean state) { 1543 this._visible = !state; 1544 } 1545 1516 1546 1517 1547 public void setVisible(boolean state) { … … 1520 1550 1521 1551 public boolean isVisible() { 1522 return _visible ;1552 return _visible && !_deleted; 1523 1553 } 1524 1554 … … 1540 1570 } 1541 1571 setSelectionColor(color); 1542 _lastMode = _mode;1543 1572 _mode = mode; 1544 }1545 1546 public void restoreLastMode(Color selectionColor) {1547 setSelectionColor(selectionColor);1548 if (_mode != SelectedMode.None)1549 return;1550 _mode = _lastMode;1551 _lastMode = SelectedMode.None;1552 1573 } 1553 1574 … … 1659 1680 } 1660 1681 1682 /** 1683 * True if this item is the end of a line. 1684 * 1685 * @return 1686 */ 1661 1687 public boolean isLineEnd() { 1688 // TODO this will need to be redone when enclosure class is added... 1689 // At the moment enclosures are only circles...we dont want circle 1690 // centers to be lineEnds 1662 1691 return _lines.size() > 0; 1692 } 1693 1694 public boolean hasEnclosures(){ 1695 return _enclosures.size() > 0; 1663 1696 } 1664 1697 … … 1717 1750 1718 1751 public void setAction(String string) { 1752 //Want to resize the highlight box for text items if actions are been added 1753 if(_actions == null || _actions.size() == 0){ 1754 _poly = null; 1755 } 1719 1756 _actions = new LinkedList<String>(); 1720 1757 _actions.add(string); … … 1732 1769 protected void paintLink(Graphics2D g) { 1733 1770 if (getLink() != null || getAction() != null) { 1771 g.setStroke(HIGHLIGHT_STROKE); 1734 1772 if (getLink() != null && getAction() != null) { 1735 1773 g.setColor(LINK_ACTION_COLOR); … … 1806 1844 return null; 1807 1845 // assert (_parent!= null); 1846 Frame parent = getParentOrCurrentFrame(); 1808 1847 if (_parent == null) { 1809 1848 // if parent is null it is an item on the message box 1810 1849 // so it must already be absolute 1811 assert (!FrameIO.isPositiveInteger(link)); 1812 return link; 1850 //assert (!FrameIO.isPositiveInteger(link)); 1851 //return link; 1852 1813 1853 } 1814 1854 1815 1855 // if its a relative link then return absolute 1816 1856 if (FrameIO.isPositiveInteger(link)) { 1817 return _parent.getFramesetName() + link;1857 return parent.getFramesetName() + link; 1818 1858 } 1819 1859 return link; … … 1828 1868 * new y position 1829 1869 */ 1830 public void setXY( int x, int y) {1870 public void setXY(float x, float y) { 1831 1871 _x = x; 1832 1872 _y = y; … … 1877 1917 1878 1918 /** 1879 * Gets the size of the enclosure that this item is part of. 1880 * @return the area of the box surrounding the enclosed shape that this item is part of 1881 */ 1882 public Integer getEnclosedArea() { 1919 * Gets the size of the enclosure that this item is part of. Used to 1920 * determine the paint order of items, with smaller items being painted 1921 * first. 1922 * 1923 * @return the area of the box surrounding the enclosed shape that this item 1924 * is part of 1925 */ 1926 public double getEnclosedArea() { 1883 1927 if (_enclosure == null) 1884 return 0; 1885 Rectangle box = getEnclosedShape().getBounds(); 1886 Integer area = box.width * box.height; 1887 1888 if (getFillColor() == null) 1889 return -area; 1890 1891 return area; 1928 return 0.0; 1929 Rectangle2D box = getEnclosedShape().getBounds2D(); 1930 return box.getWidth() * box.getHeight(); 1931 } 1932 1933 /** 1934 * Returns the Shape that surrounds this Item representing this Item's 1935 * 'gravity'. 1936 * 1937 * @return The Shape (rectangle) surrounding this Item, which represents 1938 * this Items 'gravity'. 1939 */ 1940 public final Polygon getPolygon() { 1941 if (_poly == null) 1942 updatePolygon(); 1943 1944 return new Polygon(_poly.xpoints, _poly.ypoints, _poly.npoints); 1945 } 1946 1947 /** 1948 * Shifts the position of the item along the line between this items 1949 * location and a specified point. 1950 * 1951 * @param origin 1952 * @param ratio 1953 */ 1954 public void translate(Point2D origin, double ratio) { 1955 _x = (float) (origin.getX() + ratio * (_x - origin.getX())); 1956 _y = (float) (origin.getY() + ratio * (_y - origin.getY())); 1957 updatePolygon(); 1958 for (Line line : getLines()) 1959 line.updatePolygon(); 1960 } 1961 1962 private static int[] LinePatterns = new int[] { 0, 10, 20 }; 1963 1964 /** 1965 * The rotates through a wheel of dashed lines. 1966 * 1967 * @param amount 1968 * number of rotations around the wheel to toggle by. 1969 */ 1970 public void toggleDashed(int amount) { 1971 // find the index of the current line pattern 1972 int[] currentPattern = getLinePattern(); 1973 1974 // Find the current pattern and move to the next pattern in the wheel 1975 for (int i = 0; i < LinePatterns.length; i++) { 1976 if (currentPattern == null || currentPattern[0] == LinePatterns[i]) { 1977 i += LinePatterns.length + amount; 1978 i %= LinePatterns.length; 1979 1980 // if we are at the start of the wheel make it 'null' (solid 1981 // line) 1982 if (i == 0) { 1983 setLinePattern(null); 1984 } else { 1985 setLinePattern(new int[] { LinePatterns[i], LinePatterns[i] }); 1986 } 1987 return; 1988 } 1989 } 1990 } 1991 1992 Collection<XRayable> _enclosures = new HashSet<XRayable>(); 1993 1994 private boolean _deleted = false; 1995 1996 /** 1997 * For now there can only be one enclosure per item 1998 * @param enclosure 1999 */ 2000 public void addEnclosure(XRayable enclosure) { 2001 _enclosures.clear(); 2002 _enclosures.add(enclosure); 2003 } 2004 2005 public Collection<? extends XRayable> getEnclosures() { 2006 return _enclosures; 2007 } 2008 2009 public void removeEnclosure(Item i) { 2010 _enclosures.remove(i); 2011 2012 } 2013 2014 public boolean isDeleted() { 2015 return _deleted; 1892 2016 } 1893 2017 } -
trunk/src/org/expeditee/items/ItemParentStateChangedEvent.java
r55 r108 12 12 13 13 private Frame _src; 14 private int_overlayLevel;14 private Permission _overlayLevel; 15 15 private int _eventType; 16 16 … … 24 24 25 25 public ItemParentStateChangedEvent(Frame src, int eventType) { 26 this(src, eventType, 0);26 this(src, eventType, Permission.none); 27 27 } 28 28 29 public ItemParentStateChangedEvent(Frame src, int eventType, intoverlayLevel) {29 public ItemParentStateChangedEvent(Frame src, int eventType, Permission overlayLevel) { 30 30 _src = src; 31 31 _overlayLevel = overlayLevel; … … 37 37 * @return 38 38 */ 39 public intgetOverlayLevel() {39 public Permission getOverlayLevel() { 40 40 return _overlayLevel; 41 41 } -
trunk/src/org/expeditee/items/ItemUtils.java
r97 r108 14 14 import java.util.Map; 15 15 16 import org.expeditee.gui.AttributeUtils;17 16 import org.expeditee.gui.DisplayIO; 18 17 import org.expeditee.gui.Frame; 18 import org.expeditee.items.Item.SelectedMode; 19 19 20 20 //Static methods that provide functions for the objects\ … … 132 132 return (Text) i; 133 133 } 134 135 134 return null; 136 135 } … … 406 405 } 407 406 408 public static Picture CreateFrameImage(Text source, ImageObserver observer) {409 String size = source.getFirstLine();410 411 // remove @f tag412 size = AttributeUtils.getValue(size);413 414 try {415 Picture pic = new FrameImage(source, size, observer);416 return pic;417 } catch (Exception e) {418 // e.printStackTrace();419 return null;420 }421 }422 423 public static Picture CreateFrameBitmap(Text source, ImageObserver observer) {424 String size = source.getFirstLine();425 426 // remove @b tag427 size = AttributeUtils.getValue(size);428 429 try {430 Picture pic = new FrameBitmap(source, size, observer);431 return pic;432 } catch (Exception e) {433 // e.printStackTrace();434 return null;435 }436 }437 438 407 /** 439 408 * Creates a deep copy of the given List of Items. … … 454 423 Collection<Item> lineEnds = new LinkedHashSet<Item>(); 455 424 Collection<Line> lines = new LinkedHashSet<Line>(); 425 Collection<XRayable> xrayables = new LinkedHashSet<XRayable>(); 456 426 Collection<Constraint> constraints = new LinkedHashSet<Constraint>(); 457 427 … … 467 437 // BROOK 468 438 if (i instanceof WidgetCorner) { // dont add these 469 470 439 if (!widgets.contains(((WidgetCorner) i).getWidgetSource())) 471 440 widgets.add(((WidgetCorner) i).getWidgetSource()); 472 473 441 // BROOK 474 442 } else if (i instanceof WidgetEdge) { // dont add these 475 476 443 // lines are recreated later 477 444 } else if (i instanceof Line) { 478 445 lines.add((Line) i); 446 } else if (i instanceof XRayable) { 447 xrayables.add((XRayable)i); 479 448 } else { 480 449 if (i.isLineEnd()) { … … 486 455 } 487 456 } 488 457 458 //Dont copy the other items that are part of the circle 459 for(XRayable x : xrayables){ 460 Collection<Item> connected = x.getConnected(); 461 singles.removeAll(connected); 462 lineEnds.removeAll(connected); 463 lines.removeAll(connected); 464 copies.addAll(x.copy().getConnected()); 465 } 466 489 467 // copy all single items 490 468 for (Item i : singles) { … … 608 586 for (Item item : toUnreel) { 609 587 // we dont want to unreel anything other than lines 610 if ( !(item.isLineEnd() || item instanceof Line)) {588 if (item.hasEnclosures() || !(item.isLineEnd() || item instanceof Line)) { 611 589 return null; 612 590 } … … 623 601 // copy the original endpoint 624 602 Item copy = origEnd.copy(); 603 origEnd.setSelectedMode(SelectedMode.None); 625 604 copy.removeAllLines(); 626 605 copy.removeAllConstraints(); … … 631 610 // if the previous line was constrained then make the new line 632 611 // constrained if it was a single line 633 // TODO add later a diagonal constraint if getLines() == 3 or 4612 // TODO add later a diagonal constraint if getLines() == 3 or 4 634 613 Collection<Constraint> constraints = origEnd.getConstraints(); 635 if (constrain && constraints.size() > 0 && origEnd.getLines().size() == 2) { 614 if (constrain && constraints.size() > 0 615 && origEnd.getLines().size() == 2) { 636 616 Integer type = null; 637 617 for (Constraint c : constraints) { … … 640 620 } else if (c.getType() == Constraint.VERTICAL) { 641 621 type = Constraint.HORIZONTAL; 642 } if (c.getType() == Constraint.DIAGONAL_NEG) { 622 } 623 if (c.getType() == Constraint.DIAGONAL_NEG) { 643 624 type = Constraint.DIAGONAL_POS; 644 625 } else if (c.getType() == Constraint.DIAGONAL_POS) { -
trunk/src/org/expeditee/items/Line.java
r107 r108 38 38 private static final int MAXIMUM_ARROW_HEAD_LENGTH = 60; 39 39 40 public static final Float DEFAULT_THICKNESS = 2f;41 42 public static final Float MINIMUM_THICKNESS = 1f;43 44 40 private Item _start; 45 41 … … 51 47 private Point _endOffset = new Point(0, 0); 52 48 53 // indicates which end the arrowhead should be drawn at54 private Polygon _poly = null;55 56 49 private float _thickness = -1; 57 58 private boolean _isCircle = false; 59 50 60 51 // brush strokes used for painting this line and highlighting 61 52 private Stroke _lineStroke = new BasicStroke(DEFAULT_THICKNESS, CAP, JOIN, 62 53 4.0F); 54 55 Stroke getStroke() { 56 return _lineStroke; 57 } 63 58 64 59 // private Stroke _highlightStroke = new BasicStroke (1f + /*GRAVITY + … … 91 86 if (thick < 0) 92 87 thick = 1; 93 /* 94 * if (_start instanceof Dot && _end instanceof Dot) thick = (((Dot) 95 * _start).getThickness() + ((Dot) _end) .getThickness()) / 2.0f; else 96 * if (_start instanceof Dot) thick = ((Dot) _start).getThickness(); 97 * else if (_end instanceof Dot) thick = ((Dot) _end).getThickness(); 98 * else thick = 1; 99 */ 100 88 101 89 setThickness(thick); 102 90 } … … 253 241 } 254 242 255 private void paintCircle(Graphics2D g, Item end) { 256 int distance = (int) Math.sqrt(Math.pow(Math.abs(_start.getX() 257 - _end.getX()), 2) 258 + Math.pow(Math.abs(_start.getY() - _end.getY()), 2)); 259 260 // Approximation of circle for mouse interaction 261 int points = 20; 262 263 double radians = 0.0; 264 int xPoints[] = new int[points]; 265 int yPoints[] = new int[xPoints.length]; 266 267 for (int i = 0; i < xPoints.length; i++) { 268 xPoints[i] = (int) (distance * Math.cos(radians)); 269 yPoints[i] = (int) (distance * Math.sin(radians)); 270 radians += (2.0 * Math.PI) / xPoints.length; 271 } 272 273 _poly = new Polygon(xPoints, yPoints, xPoints.length); 274 _poly.translate(end.getX(), end.getY()); 275 276 distance *= 2; 277 278 g.drawOval(end.getX() - (distance / 2), end.getY() - (distance / 2), 279 distance, distance); 280 // Arc version, same result but allows for portions of the circle to be 281 // drawn 282 // g.drawArc(end.getX() - (distance / 2), end.getY() - (distance / 2), 283 // distance, distance, 0, 360); 284 } 285 243 @Override 286 244 public void setLinePattern(int[] pattern) { 287 245 super.setLinePattern(pattern); … … 311 269 @Override 312 270 public void paint(Graphics2D g) { 271 if(!isVisible()) 272 return; 313 273 g.setColor(getPaintColor()); 314 274 315 275 // if (this._mode == Item.SelectedMode.Disconnect) 316 276 // System.out.println("Disconnect mode!"); 317 318 if (_start instanceof Text && ((Text) _start).startsWith("@c")) { 319 g.setStroke(_lineStroke); 320 paintCircle(g, _end); 321 _isCircle = true; 322 } else if (_end instanceof Text && ((Text) _end).startsWith("@c")) { 323 g.setStroke(_lineStroke); 324 paintCircle(g, _start); 325 _isCircle = true; 326 } else { 327 // Get a path of points 328 int[][][] paths = getPaths(); 329 g.setStroke(_lineStroke); 330 for (int i = 0; i < paths.length; i++) { 331 int[][] path = paths[i]; 332 int last = path[0].length - 1; 333 if (path[0][0] == path[0][last] && path[1][0] == path[1][last]) { 334 g.drawPolygon(path[0], path[1], last); 335 } else { 336 g.drawPolyline(path[0], path[1], last + 1); 337 } 338 } 339 // paint the arrowhead (if necessary) 340 paintArrows(g); 341 // g.drawLine(_start.getX() + _startOffset.x, _start.getY() 342 // + _startOffset.y, _end.getX() + _endOffset.x, _end.getY() 343 // + _endOffset.y); 344 // TODO deal with the offset 345 _isCircle = false; 346 } 347 348 // update the highlight shape 349 // java.awt.geom.Line2D.Float shape = new 350 // java.awt.geom.Line2D.Float(_startx, _starty, _endx, _endy); 351 // _shape = _highlightStroke.createStrokedShape(shape); 352 353 // g.setStroke(norm); 277 g.setStroke(_lineStroke); 278 // Get a path of points 279 int[][][] paths = getPaths(); 280 for (int i = 0; i < paths.length; i++) { 281 int[][] path = paths[i]; 282 int last = path[0].length - 1; 283 if (path[0][0] == path[0][last] && path[1][0] == path[1][last]) { 284 g.drawPolygon(path[0], path[1], last); 285 } else { 286 g.drawPolyline(path[0], path[1], last + 1); 287 } 288 } 289 // paint the arrowhead (if necessary) 290 paintArrows(g); 354 291 355 292 if (showLineHighlight() && isHighlighted()) { 356 293 g.setColor(getHighlightColor()); 357 g.setStroke( new BasicStroke(MINIMUM_THICKNESS, CAP, JOIN));294 g.setStroke(HIGHLIGHT_STROKE); 358 295 ((Graphics2D) g).draw(this.getArea()); 359 296 } … … 398 335 visited.add(this); 399 336 400 start.appendPath(visited, points, 401 true, toExplore); 402 end.appendPath(visited, points, false, 403 toExplore); 337 start.appendPath(visited, points, true, toExplore); 338 end.appendPath(visited, points, false, toExplore); 404 339 return points; 405 340 } … … 437 372 y0 = getOppositeEnd(withArrow).getY() + endOffset.y; 438 373 439 int arrowLength = withArrow.getArrowheadLength();374 float arrowLength = withArrow.getArrowheadLength(); 440 375 double arrowRatio = withArrow.getArrowheadRatio(); 441 376 … … 474 409 arrowhead = new Polygon(); 475 410 arrowhead.addPoint((int) x0, (int) y0); 476 arrowhead.addPoint((int) x0 - arrowLength,477 (int) (y0 - (arrowLength * arrowRatio)));411 arrowhead.addPoint((int)Math.round(x0 - arrowLength), 412 (int)Math.round((y0 - (arrowLength * arrowRatio)))); 478 413 arrowhead.addPoint((int) x0, (int) y0); 479 arrowhead.addPoint((int) x0 - arrowLength,480 (int) (y0 + (arrowLength * arrowRatio)));414 arrowhead.addPoint((int)Math.round( x0 - arrowLength), 415 (int)Math.round( (y0 + (arrowLength * arrowRatio)))); 481 416 if (!disconnectMode) 482 417 withArrow.setArrowhead(arrowhead); … … 523 458 524 459 return rad; 525 }526 527 @Override528 public Polygon getPolygon() {529 if (_poly == null)530 updatePolygon();531 532 return _poly;533 460 } 534 461 … … 696 623 int length = (int) Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); 697 624 length /= ARROW_HEAD_TO_LENGTH_RATIO; 698 arrow.setArrowheadLength(Math.min(MAXIMUM_ARROW_HEAD_LENGTH,Math.max(MINIMUM_ARROW_HEAD_LENGTH, length))); 625 arrow.setArrowheadLength(Math.min(MAXIMUM_ARROW_HEAD_LENGTH, Math.max( 626 MINIMUM_ARROW_HEAD_LENGTH, length))); 699 627 } 700 628 … … 723 651 } 724 652 725 private static int[] LinePatterns = new int[] { 0, 10, 20 };726 727 /**728 * The rotates through a wheel of dashed lines.729 *730 * @param amount731 * number of rotations around the wheel to toggle by.732 */733 public void toggleDashed(int amount) {734 // find the index of the current line pattern735 int[] currentPattern = getLinePattern();736 737 // Find the current pattern and move to the next pattern in the wheel738 for (int i = 0; i < LinePatterns.length; i++) {739 if (currentPattern == null || currentPattern[0] == LinePatterns[i]) {740 i += LinePatterns.length + amount;741 i %= LinePatterns.length;742 743 // if we are at the start of the wheel make it 'null' (solid744 // line)745 if (i == 0) {746 setLinePattern(null);747 } else {748 setLinePattern(new int[] { LinePatterns[i], LinePatterns[i] });749 }750 return;751 }752 }753 }754 755 653 private static double[] ArrowHeadRatios = new double[] { 0.25, 0.5, 1.0 }; 756 654 … … 803 701 804 702 // find the index of the current line pattern 805 int currentLength = arrow.getArrowheadLength();703 float currentLength = arrow.getArrowheadLength(); 806 704 807 705 // Find the current pattern and move to the next pattern in the wheel … … 1036 934 @Override 1037 935 protected void updatePolygon() { 1038 if (_isCircle) {1039 1040 }1041 1042 936 _poly = new Polygon(); 1043 937 -
trunk/src/org/expeditee/items/Picture.java
r106 r108 2 2 3 3 import java.awt.AlphaComposite; 4 import java.awt.Color;5 4 import java.awt.Dimension; 6 5 import java.awt.Graphics2D; … … 10 9 import java.awt.Rectangle; 11 10 import java.awt.Shape; 11 import java.awt.geom.Point2D; 12 12 import java.awt.image.ImageObserver; 13 13 import java.io.File; 14 14 import java.io.IOException; 15 15 import java.text.DecimalFormat; 16 import java.util.List;17 16 18 17 import javax.imageio.ImageIO; 19 18 import javax.swing.ImageIcon; 20 19 20 import org.expeditee.gui.AttributeUtils; 21 21 import org.expeditee.gui.FrameGraphics; 22 import org.expeditee.gui.FrameMouseActions; 22 23 import org.expeditee.io.Logger; 23 24 … … 39 40 * 40 41 */ 41 public class Picture extends Item{42 43 private static final int MINIMUM_WIDTH = 10;42 public class Picture extends XRayable { 43 44 private static final int MINIMUM_WIDTH = 20; 44 45 45 46 public static final int WIDTH = 0; … … 48 49 49 50 protected Image _image = null; 50 51 private Polygon _poly = null;52 53 // private Polygon _circle = null;54 protected Text _source = null;55 51 56 52 private int _scaleType = RATIO; … … 77 73 protected ImageObserver _imageObserver = null; 78 74 79 protected Picture() { 80 super(); 75 protected Picture(Text source, ImageObserver observer, Image image) { 76 super(source); 77 78 _imageObserver = observer; 79 _image = image; 80 81 refresh(); 82 83 if (_image != null) 84 parseSize(); 81 85 } 82 86 … … 99 103 */ 100 104 public Picture(Text source, String fileName, String path, String size, 101 ImageObserver observer) throws IllegalArgumentException{102 super();105 ImageObserver observer) { 106 this(source, observer, null); 103 107 _fileName = fileName; 104 108 _path = path; 105 _source = source; 106 _imageObserver = observer; 107 108 refresh(); 109 109 } 110 111 protected void parseSize() { 112 String size = _source.getFirstLine(); 113 size = AttributeUtils.getValue(size); 114 115 if(_end.x != 0 || _end.y != 0) 116 return; 117 118 // set the default values for start and end 119 _start.setLocation(0, 0); 110 120 if (_image == null) 111 throw new IllegalArgumentException(); 112 113 parseSize(size); 114 } 115 116 protected void parseSize(String size) { 117 // set the default values for start and end 118 _start = new Point(0, 0); 119 _end = new Point(_image.getWidth(null), _image.getHeight(null)); 121 _end.setLocation(0, 0); 122 else 123 _end.setLocation(_image.getWidth(null), _image.getHeight(null)); 120 124 size = size.trim(); 121 125 String[] values = size.split("\\s+"); … … 197 201 198 202 protected void updatePolygon() { 199 if (_image == null) 200 return; 201 203 if (_image == null) { 204 refresh(); 205 parseSize(); 206 } 202 207 _poly = new Polygon(); 203 208 … … 206 211 int height = getHeight(); 207 212 208 int xdiff = - getLeftMargin();213 int xdiff = -MARGIN_RIGHT; // -getLeftMargin(); 209 214 210 215 // extra pixel around the image so the highlighting is visible … … 227 232 } 228 233 229 /** 230 * Returns the Text Item that was used to create this Picture object. This 231 * is required when saving the Frame. 232 * 233 * @return The Text Item used to create this Picture. 234 */ 235 public Text getText() { 236 return _source; 237 } 238 239 @Override 240 public int getID() { 241 return _source.getID(); 242 } 243 244 @Override 245 public void setID(int newID) { 246 _source.setID(newID); 247 } 248 249 @Override 250 public int getY() { 251 return _source.getY(); 252 } 253 254 @Override 255 public int getX() { 256 return _source.getX(); 257 } 258 259 @Override 260 public void setPosition(float x, float y) { 261 _source.setPosition(x, y); 262 263 updatePolygon(); 264 } 265 266 @Override 267 public String getLink() { 268 if (_source == null) 269 return null; 270 else 271 return _source.getLink(); 272 } 273 274 @Override 275 public void setLink(String frameName) { 276 if (_source == null) { 277 return; 278 } else { 279 _source.setLink(frameName); 280 } 281 282 updatePolygon(); 283 } 284 285 @Override 286 public void setActions(List<String> action) { 287 if (_source == null) 288 return; 289 else 290 _source.setActions(action); 291 292 updatePolygon(); 293 } 294 295 @Override 296 public List<String> getAction() { 297 if (_source == null) 298 return null; 299 else 300 return _source.getAction(); 234 @Override 235 public double getEnclosedArea() { 236 return getWidth() * getHeight(); 301 237 } 302 238 … … 325 261 */ 326 262 @Override 327 protected void paintLink(Graphics2D g) {263 protected void paintLink(Graphics2D g) { 328 264 if (FrameGraphics.isAudienceMode()) 329 265 return; 330 266 super.paintLink(g); 331 267 } 332 268 333 269 @Override 334 270 public void paint(Graphics2D g) { … … 383 319 384 320 @Override 385 public Polygon getPolygon() {386 if (_poly == null)387 updatePolygon();388 389 Polygon external = new Polygon(_poly.xpoints, _poly.ypoints,390 _poly.npoints);391 return external;392 }393 394 @Override395 321 public int setSelectionColor() { 396 322 super.setSelectionColor(); … … 407 333 Picture p = createPicture(); 408 334 p._image = _image; 409 p._imageObserver = _imageObserver; 410 p._source = _source.copy(); 411 Item.DuplicateItem(this, p); 335 p._mode = _mode; 336 // Doing Duplicate item duplicates link mark which we dont want to do 337 // when in audience mode because the linkMark will be copied incorrectly 338 // Get all properties from the source 412 339 413 340 if (!isCropTooSmall() && _cropStart != null && _cropEnd != null) { … … 439 366 p._start = new Point(startX, startY); 440 367 p._end = new Point(endX, endY); 441 p.setPosition(topLeft.x + _source.getX(), topLeft.y + _source.getY()); 368 p._source.setPosition(topLeft.x + _source.getX(), topLeft.y 369 + _source.getY()); 442 370 } else { 443 371 p._start = _start; … … 460 388 } 461 389 462 @Override 463 public Color getColor() { 464 return _source.getColor(); 465 } 466 467 @Override 468 public void setColor(Color c) { 469 _source.setColor(c); 470 } 471 472 @Override 473 public int getSize() { 390 public float getScale() { 391 return _scale; 392 } 393 394 public void setScale(float scale){ 395 _scale = scale; 396 } 397 398 @Override 399 public float getSize() { 474 400 return _source.getSize(); 475 401 } 476 402 477 403 @Override 478 public void setSize( int size) {479 int diff = size - _source.getSize();404 public void setSize(float size) { 405 float diff = size - _source.getSize(); 480 406 float oldScale = _scale; 481 407 482 int multiplier = 1000 + (diff) * 40; 483 _scale = (Math.round(_scale * multiplier)) / 1000F; 484 485 //If the above formula didnt change stuff due to rounding 486 //change it manually 487 if (_scale == oldScale){ 488 _scale += 0.01 * diff; 489 } 490 408 float multiplier = (1000F + diff * 40F) / 1000F; 409 _scale = _scale * multiplier; 410 491 411 // picture must still be at least XX pixels wide 492 if (getWidth() < MINIMUM_WIDTH) { 412 if (getWidth() < MINIMUM_WIDTH) { 493 413 _scale = oldScale; 494 } 495 414 } else { 415 _source.translate(new Point2D.Float(FrameMouseActions.MouseX, 416 FrameMouseActions.MouseY), multiplier); 417 } 496 418 updateSource(); 497 419 updatePolygon(); … … 513 435 514 436 @Override 515 public Item merge(Item merger, int mouseX, int mouseY) {516 return merger;517 }518 519 437 public boolean refresh() { 520 438 // ImageIcon is faster, but cannot handle some formats … … 556 474 @Override 557 475 public boolean getLinkMark() { 558 return _source.getLinkMark();476 return !FrameGraphics.isAudienceMode() && _source.getLinkMark(); 559 477 } 560 478 … … 601 519 _source.setText(newText.toString()); 602 520 } 521 522 @Override 523 public void translate(Point2D origin, double ratio){ 524 _scale *= ratio; 525 updateSource(); 526 super.translate(origin, ratio); 527 } 603 528 } -
trunk/src/org/expeditee/items/Text.java
r107 r108 17 17 import java.awt.font.TextLayout; 18 18 import java.awt.geom.AffineTransform; 19 import java.awt.geom.Point2D; 19 20 import java.awt.geom.Rectangle2D; 20 21 import java.text.AttributedString; … … 91 92 92 93 private int _selectionEnd = -1; 93 94 94 95 // text is broken up into lines 95 96 private StringBuffer _text = new StringBuffer(); … … 103 104 // The font to display this text in 104 105 private Font _font; 105 106 // the rectangle surrounding this text item107 private Polygon _poly = null;108 106 109 107 /** … … 121 119 122 120 setID(id); 121 } 122 123 /** 124 * Creates a text item which is not added to the frame. 125 * @param text 126 */ 127 public Text(String text) { 128 super(); 129 _text.append(text); 130 rebuild(false); 131 setID(-1); 123 132 } 124 133 … … 323 332 * The Y position to insert the Strings at. 324 333 */ 325 public Point insertChar(char ch, int mouseX, int mouseY) {334 public Point2D.Float insertChar(char ch, float mouseX, float mouseY) { 326 335 if (ch != '\t') 327 336 return insertText("" + ch, mouseX, mouseY); … … 362 371 } 363 372 364 public Point getEndPosition(int mouseY) {373 public Point2D.Float getEndPosition(int mouseY) { 365 374 return getEdgePosition(getLinePosition(mouseY), false); 366 375 } 367 376 368 public Point getStartPosition(int mouseY) {377 public Point2D.Float getStartPosition(int mouseY) { 369 378 return getEdgePosition(getLinePosition(mouseY), true); 370 379 } 371 380 372 public Point getEndParagraphPosition() {381 public Point2D.Float getEndParagraphPosition() { 373 382 return getEdgePosition(_textLayouts.size() - 1, false); 374 383 } 375 384 376 public Point getStartParagraphPosition() {385 public Point2D.Float getStartParagraphPosition() { 377 386 return getEdgePosition(0, true); 378 387 } 379 388 380 private Point getEdgePosition(int line, boolean start) {389 private Point2D.Float getEdgePosition(int line, boolean start) { 381 390 // if there is no text yet, or the line is invalid 382 391 if (_text == null || _text.length() == 0 || line < 0 383 392 || line > _textLayouts.size() - 1) 384 return new Point (getX(), getY());393 return new Point2D.Float(getX(), getY()); 385 394 386 395 TextLayout last = _textLayouts.get(line); … … 400 409 x, 401 410 (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth())); 402 return new Point (Math.round(x), Math.round(getY() + y + caret[1]));411 return new Point2D.Float(x, getY() + y + caret[1]); 403 412 } 404 413 … … 483 492 * @return The new location that the mouse cursor should be moved to 484 493 */ 485 public java.awt.Point insertText(String text, int mouseX, int mouseY) { 494 public Point2D.Float insertText(String text, float mouseX, float mouseY) { 495 return insertText(text, mouseX, mouseY, -1); 496 } 497 498 public Point2D.Float insertText(String text, float mouseX, float mouseY, 499 int insertPos) { 486 500 TextHitInfo hit; 487 501 TextLayout current = null; … … 490 504 // check for empty string 491 505 if (text == null || text.length() == 0) 492 return new Point (mouseX, mouseY);506 return new Point2D.Float(mouseX, mouseY); 493 507 494 508 // if there is no text yet … … 516 530 pos++; 517 531 532 if (insertPos < 0) 533 insertPos = pos; 534 518 535 // if this is a backspace key 519 536 if (text.charAt(0) == KeyEvent.VK_BACK_SPACE) { 520 if ( pos > 0) {521 deleteChar( pos - 1, false);522 523 pos--;537 if (insertPos > 0) { 538 deleteChar(insertPos - 1); 539 if (pos > 0) 540 pos--; 524 541 } 525 542 // if this is a delete key 526 543 } else if (text.charAt(0) == KeyEvent.VK_DELETE) { 527 if ( pos < _text.length()) {528 deleteChar( pos, false);544 if (insertPos < _text.length()) { 545 deleteChar(insertPos); 529 546 } 530 547 // this is a tab … … 549 566 if (_text.length() > 0 550 567 && Character.isSpaceChar(_text.charAt(0))) { 551 deleteChar(0 , false);568 deleteChar(0); 552 569 pos--; 553 570 } else … … 575 592 // this is a normal insert 576 593 } else { 577 insertString(text, pos);594 insertString(text, insertPos); 578 595 pos += text.length(); 596 } 597 598 if (_text.length() == 0){ 599 rebuild(false); 600 return new Point2D.Float(this._x, this._y); 579 601 } 580 602 … … 621 643 x, 622 644 (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth())); 623 return new Point(Math.round(x), Math.round(getY() + y + caret[1])); 624 } 625 626 public Point moveCursor(int direction, int mouseX, int mouseY) { 645 return new Point2D.Float(Math.round(x), Math.round(getY() + y 646 + caret[1])); 647 } 648 649 public Point2D.Float moveCursor(int direction, float mouseX, float mouseY) { 627 650 // check for home or end keys 628 651 if (direction == HOME) … … 638 661 // if there is no text yet 639 662 if (_text == null || _text.length() == 0) { 640 return new Point (mouseX, mouseY);663 return new Point2D.Float(mouseX, mouseY); 641 664 // otherwise, move the cursor 642 665 } else { … … 700 723 float y = getLineDrop(current) * line; 701 724 702 return new Point( 703 Math.round(getX() + caret[0]) + getJustOffset(current), Math 704 .round(getY() + y + caret[1])); 725 return new Point2D.Float(getX() + caret[0] + getJustOffset(current), 726 getY() + y + caret[1]); 705 727 } 706 728 … … 715 737 * @return The position in the string of the character being pointed at. 716 738 */ 717 public TextHitInfo getCharPosition(int line, int mouseX) {739 public TextHitInfo getCharPosition(int line, float mouseX) { 718 740 if (line < 0 || line >= _textLayouts.size()) 719 741 return null; … … 726 748 } 727 749 728 public int getLinePosition( int mouseY) {750 public int getLinePosition(float mouseY) { 729 751 mouseY += getOffset().y; 730 752 … … 737 759 738 760 if (bounds.getWidth() < 1) 739 bounds.setRect(bounds.getMinX(), bounds 740 .get MinY(), 10, bounds.getHeight());761 bounds.setRect(bounds.getMinX(), bounds.getMinY(), 10, bounds 762 .getHeight()); 741 763 742 764 double x = bounds.getCenterX(); … … 791 813 792 814 public void setFamily(String newFamily) { 793 String toDecode = newFamily + "-" + getFontStyle() + "-" + getSize(); 815 String toDecode = newFamily + "-" + getFontStyle() + "-" 816 + Math.round(getSize()); 794 817 setFont(Font.decode(toDecode)); 795 818 } … … 1075 1098 _poly.addPoint(maxX + getGravity(), maxY + getGravity()); 1076 1099 _poly.addPoint(minX - getGravity(), maxY + getGravity()); 1100 1101 _poly.translate(getX(), getY()); 1077 1102 } 1078 1103 … … 1082 1107 private void rebuild(boolean limitWidth) { 1083 1108 // if there is no text, there is nothing to do 1084 if (_text == null || _text.length() == 0) 1109 if (_text == null || _text.length() == 0){ 1110 // Frame parent = getParent(); 1111 // if(parent != null) 1112 // parent.removeItem(this); 1085 1113 return; 1114 } 1086 1115 1087 1116 AttributedString paragraphText = new AttributedString(_text.toString()); … … 1246 1275 @Override 1247 1276 public void paint(Graphics2D g) { 1277 if (!isVisible()) 1278 return; 1279 1248 1280 // if there is no text to paint, do nothing. 1249 1281 if (_text == null || _text.length() == 0 || getMaxSize() == null)// || 1250 // _textLayouts.size()1251 // < 1)1252 1282 return; 1253 1283 … … 1257 1287 return; 1258 1288 } 1259 1289 1260 1290 // the background is only cleared if required 1261 1291 if (getBackgroundColor() != null) { … … 1266 1296 g.setColor(bgc); 1267 1297 g.fill(getPolygon()); 1298 } 1299 1300 if (isHighlighted()) { 1301 g.setColor(getPaintHighlightColor()); 1302 Stroke _highlightStroke = new BasicStroke( 1303 (float) _highlightThickness, CAP, JOIN); 1304 g.setStroke(_highlightStroke); 1305 if (SelectedMode.Enclosed.equals(getSelectedMode())) 1306 g.fillPolygon(getPolygon()); 1307 else 1308 g.drawPolygon(getPolygon()); 1268 1309 } 1269 1310 … … 1349 1390 1350 1391 paintLink(g); 1351 1352 if (isHighlighted()) {1353 g.setColor(getPaintHighlightColor());1354 Stroke _highlightStroke = new BasicStroke(1355 (float) _highlightThickness, CAP, JOIN);1356 g.setStroke(_highlightStroke);1357 g.drawPolygon(getPolygon());1358 }1359 1392 } 1360 1393 … … 1372 1405 1373 1406 @Override 1374 public Polygon getPolygon() {1375 updatePolygon();1376 1377 Polygon external = new Polygon(_poly.xpoints, _poly.ypoints,1378 _poly.npoints);1379 external.translate(getX(), getY());1380 1381 return external;1382 }1383 1384 @Override1385 1407 public Text copy() { 1386 1408 Text copy = new Text(getID()); 1387 1388 1409 // copy standard item values 1389 1410 Item.DuplicateItem(this, copy); … … 1398 1419 copy.setFont(getFont()); 1399 1420 copy.setText(_text.toString()); 1421 copy.setHidden(!isVisible()); 1400 1422 // copy._poly = new Polygon(_poly.xpoints,_poly.ypoints, _poly.npoints); 1401 1423 … … 1404 1426 1405 1427 @Override 1406 public int getSize() {1407 return getPaintFont().getSize ();1428 public float getSize() { 1429 return getPaintFont().getSize2D(); 1408 1430 } 1409 1431 … … 1418 1440 1419 1441 @Override 1420 public void setSize( int size) {1442 public void setSize(float size) { 1421 1443 // Dont want to have size set when duplicating a point which has size 0 1422 1444 if (size < 0) … … 1425 1447 if (size < MINIMUM_FONT_SIZE) 1426 1448 size = MINIMUM_FONT_SIZE; 1427 setFont(getPaintFont().deriveFont( (float)size));1449 setFont(getPaintFont().deriveFont(size)); 1428 1450 } 1429 1451 1430 1452 @Override 1431 1453 public void setAnnotation(boolean val) { 1454 float mouseX = DisplayIO.getFloatMouseX(); 1455 float mouseY = FrameMouseActions.MouseY; 1456 Point2D.Float newPoint = new Point2D.Float(); 1432 1457 if (val) { 1433 1458 // if this is already an annotation, do nothing 1434 1459 if (isAnnotation()) 1435 1460 return; 1436 if (_text.charAt(0) == '*') { 1437 deleteChar(0, true); 1461 if (!isLineEnd() && _text.length() > 0 && _text.charAt(0) == '*') { 1462 newPoint.setLocation(insertText("" 1463 + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1)); 1438 1464 if (_text.length() > 0 && _text.charAt(0) == ' ') 1439 deleteChar(0, true); 1465 newPoint.setLocation(insertText("" 1466 + (char) KeyEvent.VK_BACK_SPACE, newPoint.x, 1467 newPoint.y, 1)); 1440 1468 } else { 1441 insertString("@", 0);1469 newPoint.setLocation(insertText("@", mouseX, mouseY, 0)); 1442 1470 } 1443 1471 } else { … … 1445 1473 if (!isAnnotation()) 1446 1474 return; 1447 1448 if (_text.charAt(0) == '@') { 1449 _text.setCharAt(0, ' '); 1450 insertString("*", 0); 1475 if (!isLineEnd() && _text.charAt(0) == '@') { 1476 newPoint.setLocation(insertText("" 1477 + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1)); 1478 newPoint 1479 .setLocation(insertText("* ", newPoint.x, newPoint.y, 0)); 1451 1480 } else { 1452 deleteChar(0, true); 1481 newPoint.setLocation(insertText("" 1482 + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1)); 1453 1483 } 1454 1484 } 1455 1485 rebuild(false); 1486 DisplayIO.setCursorPosition(newPoint.x, newPoint.y, false); 1456 1487 } 1457 1488 … … 1475 1506 } 1476 1507 1477 private void deleteChar(int pos , boolean replaceWithDot) {1508 private void deleteChar(int pos) { 1478 1509 _text.deleteCharAt(pos); 1479 1510 1480 1511 if (_text.length() == 0) { 1481 if ( replaceWithDot) {1512 if (this.isLineEnd()) { 1482 1513 // Remove and replace with a dot 1483 1514 FrameKeyboardActions.replaceText(this); 1484 DisplayIO.setCursorPosition(this. getPosition());1515 DisplayIO.setCursorPosition(this._x, this._y); 1485 1516 } 1486 1517 return; … … 1642 1673 1643 1674 @Override 1644 public void delete() {1645 setVisible(false);1646 }1647 1648 @Override1649 1675 public void anchor() { 1650 1676 super.anchor(); … … 1674 1700 public static final String TAB_STRING = " "; 1675 1701 1676 public Point insertTab(char ch, int mouseX, int mouseY) {1702 public Point2D.Float insertTab(char ch, float mouseX, float mouseY) { 1677 1703 return insertText("" + ch, mouseX, mouseY); 1678 1704 } 1679 1705 1680 public Point removeTab(char ch, int mouseX, int mouseY) {1706 public Point2D.Float removeTab(char ch, float mouseX, float mouseY) { 1681 1707 // Insert a space as a flag that it is a backwards tab 1682 1708 return insertText(ch + " ", mouseX, mouseY); 1683 1709 } 1710 1711 @Override 1712 public void setLink(String frame) { 1713 // If a link is being removed or set then need to reset poly so the 1714 // highlighting is drawn with the correct width 1715 if (frame == null || getLink() == null) 1716 _poly = null; 1717 super.setLink(frame); 1718 } 1684 1719 } -
trunk/src/org/expeditee/simple/Context.java
r97 r108 7 7 import java.io.FileWriter; 8 8 9 import org.expeditee.actions.Simple; 9 10 import org.expeditee.gui.Frame; 10 11 import org.expeditee.gui.FrameGraphics; … … 236 237 success = false; 237 238 } 238 if (!success )239 if (!success && Simple.isVerbose()) 239 240 FrameGraphics.WarningMessage("Error creating " + framesetName); 240 241 if (successVar != null) { -
trunk/src/org/expeditee/simple/Primitives.java
r87 r108 180 180 } 181 181 182 /** 183 * Adds two variables to gether returning the value in the first. 184 * @param toSet 185 * @param amount 186 * @throws Exception 187 */ 182 188 public void add(String toSet, String amount) throws Exception { 183 189 setValue(toSet, new SReal(getVariable(toSet).doubleValue()
Note:
See TracChangeset
for help on using the changeset viewer.