Changeset 72
- Timestamp:
- 05/23/08 09:02:59 (16 years ago)
- Location:
- trunk
- Files:
-
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Actions.java
r41 r72 45 45 46 46 public static final String ROOT_PACKAGE = "org.expeditee."; 47 47 48 48 // Package and class file locations 49 49 private static final String ACTIONS_PACKAGE = ROOT_PACKAGE + "actions."; 50 50 51 51 private static final String AGENTS_PACKAGE = ROOT_PACKAGE + "agents."; 52 53 private static final String NAVIGATIONS_CLASS = ROOT_PACKAGE + "actions.NavigationActions"; 54 52 53 private static final String NAVIGATIONS_CLASS = ROOT_PACKAGE 54 + "actions.NavigationActions"; 55 55 56 public static Class[] getClasses(String pckgname) 56 57 throws ClassNotFoundException { … … 232 233 233 234 /** 234 * Performs the given KMS action command. The source Frame and Item are235 * given because they are required by some actions. Note that the source236 * framedoes not have to be the Item's parent Frame.235 * Performs the given action command. The source Frame and Item are given 236 * because they are required by some actions. Note that the source frame 237 * does not have to be the Item's parent Frame. 237 238 * 238 239 * @param source … … 246 247 if (!command.equalsIgnoreCase("Restore")) 247 248 FrameIO.SaveFrame(source, false); 248 249 249 250 // separate method name and parameter names 250 251 String mname = getName(command); … … 278 279 // Need to save the frame if we are navigating away from it so we dont 279 280 // loose changes 280 if (toRun.getDeclaringClass().getName().equals( 281 NAVIGATIONS_CLASS)) { 281 if (toRun.getDeclaringClass().getName().equals(NAVIGATIONS_CLASS)) { 282 282 FrameIO.SaveFrame(DisplayIO.getCurrentFrame()); 283 283 } … … 363 363 if (con == null) { 364 364 FrameGraphics.DisplayMessage("Invalid parametres for agent."); 365 // System.out.println("Constructor not found...");365 // System.out.println("Constructor not found..."); 366 366 return; 367 367 } … … 482 482 } 483 483 484 String param ;484 String param = values; 485 485 // convert the rest of the objects 486 486 for (; ind < objects.length; ind++) { 487 // strip off the next value488 param = ParseValue(values);489 values = RemainingParams(values);490 491 487 // check if its the last param and combine 492 if (values.length() > 0 && ind == objects.length - 1) 493 param = param.trim() + ' ' + values.trim(); 494 488 if (values.length() > 0 && ind == objects.length - 1) { 489 param = values.trim(); 490 // check if its a string 491 if (param.length() > 0 && param.charAt(0) == '"'){ 492 int endOfString = param.indexOf('"', 1); 493 if (endOfString > 0){ 494 param = param.substring(0,endOfString); 495 } 496 } 497 } else {// strip off the next value 498 param = ParseValue(values); 499 values = RemainingParams(values); 500 } 495 501 // convert the value to an object 496 502 Object o = Conversion.Convert(paramTypes[ind], param); … … 509 515 * @return the remaining N - 1 parameters 510 516 */ 511 p rivatestatic String RemainingParams(String params) {517 public static String RemainingParams(String params) { 512 518 if (params.length() == 0) 513 519 return null; … … 523 529 // Check if we have a string parameter 524 530 if (params.charAt(0) == '"') { 525 return params.substring(params.indexOf('"', 1) + 1); 526 } 527 528 return params.substring(params.indexOf(" ")); 531 int endOfString = params.indexOf('"', 1); 532 if (endOfString > 0){ 533 if (endOfString > params.length()) 534 return ""; 535 return params.substring(endOfString + 1).trim(); 536 } 537 } 538 539 return params.substring(params.indexOf(" ")).trim(); 529 540 } 530 541 … … 537 548 * @return The first value in the String 538 549 */ 539 p rivatestatic String ParseValue(String params) {550 public static String ParseValue(String params) { 540 551 if (params.length() == 0) 541 552 return null; … … 543 554 // remove leading and trailing spaces 544 555 String param = params.trim(); 556 557 // Check if we have a string parameter 558 if (param.charAt(0) == '"') { 559 int endOfString = param.indexOf('"', 1); 560 if (endOfString > 0) 561 return param.substring(1, endOfString); 562 } 545 563 546 564 // if there are no more parameters, we are done … … 549 567 } 550 568 551 // Check if we have a string parameter552 if (param.charAt(0) == '"') {553 return param.substring(1, param.indexOf('"', 1));554 }555 556 569 return param.substring(0, param.indexOf(" ")); 557 570 } -
trunk/src/org/expeditee/actions/Debug.java
r4 r72 5 5 import org.expeditee.gui.DisplayIO; 6 6 import org.expeditee.items.Constraint; 7 import org.expeditee.items.Dot;8 7 import org.expeditee.items.Item; 9 8 … … 24 23 25 24 for (Item i : items) 26 if (i instanceof Dot) {25 if (i.isLineEnd()) { 27 26 System.out.println(i.getID()); 28 27 29 for (Constraint c : ((Dot) i).getConstraints())30 if (c.getOppositeEnd( (Dot)i) != null)28 for (Constraint c : i.getConstraints()) 29 if (c.getOppositeEnd(i) != null) 31 30 System.out.println("\t" 32 + c.getOppositeEnd( (Dot)i).getID());31 + c.getOppositeEnd(i).getID()); 33 32 else 34 33 System.out.println("\tNULL"); -
trunk/src/org/expeditee/actions/Misc.java
r70 r72 8 8 import java.io.FileNotFoundException; 9 9 import java.io.IOException; 10 import java.lang.reflect.Method; 10 11 import java.util.ArrayList; 11 12 import java.util.List; … … 18 19 import org.expeditee.gui.FrameIO; 19 20 import org.expeditee.gui.FrameMouseActions; 21 import org.expeditee.gui.TimeKeeper; 20 22 import org.expeditee.items.Item; 21 23 import org.expeditee.items.Text; … … 28 30 */ 29 31 public class Misc { 30 private static final int STATS_FONT_SIZE = 18;31 32 32 private static final int FRAME_FILE_FONT_SIZE = 10; 33 33 … … 152 152 getFromChildFrame(current, false); 153 153 } 154 155 /** 156 * Loads the Frame linked to by the given Item. The first Text Item on the Frame157 * that is not the title or name is then placed on the cursor. If the given158 * Item has no link, or no item is found then this is a no-op.154 155 /** 156 * Loads the Frame linked to by the given Item. The first Text Item on the 157 * Frame that is not the title or name is then placed on the cursor. If the 158 * given Item has no link, or no item is found then this is a no-op. 159 159 * 160 160 * @param current … … 165 165 getFromChildFrame(current, true); 166 166 } 167 168 private static void getFromChildFrame(Item current, boolean textOnly) {167 168 private static void getFromChildFrame(Item current, boolean textOnly) { 169 169 Item item = getFirstBodyItemOnChildFrame(current, textOnly); 170 170 // if no item was found … … 226 226 227 227 public static void CreateTextItem(String itemText) { 228 Text text = DisplayIO.getCurrentFrame().createNewText(); 229 // We dont want the stats to wrap at all 230 text.setMaxSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); 231 232 text.setText(itemText); 233 234 text.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY()); 235 text.setSize(STATS_FONT_SIZE); 236 228 SessionStats.CreatedText(); 229 Frame current = DisplayIO.getCurrentFrame(); 230 Text text = current.getStatsTextItem(itemText); 237 231 FrameMouseActions.pickup(text); 238 239 232 FrameGraphics.Repaint(); 240 233 } … … 419 412 420 413 /** 414 * Runs two methods alternatively a specified number of times and reports on 415 * the time spent running each method. 416 * 417 * @param fullMethodNameA 418 * @param fullMethodNameB 419 * @param repsPerTest 420 * the number of time each method is run per test 421 * @param tests 422 * the number of tests to conduct 423 * 424 */ 425 public static void CompareMethods(String fullMethodNameA, 426 String fullMethodNameB, int repsPerTest, int tests) { 427 try { 428 String classNameA = getClassName(fullMethodNameA); 429 String classNameB = getClassName(fullMethodNameB); 430 String methodNameA = getMethodName(fullMethodNameA); 431 String methodNameB = getMethodName(fullMethodNameB); 432 433 Class classA = Class.forName(classNameA); 434 Class classB = Class.forName(classNameB); 435 Method methodA = classA.getDeclaredMethod(methodNameA, 436 new Class[] {}); 437 Method methodB = classB.getDeclaredMethod(methodNameB, 438 new Class[] {}); 439 TimeKeeper timeKeeper = new TimeKeeper(); 440 long timeA = 0; 441 long timeB = 0; 442 // Run the tests 443 for (int i = 0; i < tests; i++) { 444 // Test methodA 445 timeKeeper.restart(); 446 for (int j = 0; j < repsPerTest; j++) { 447 methodA.invoke((Object) null, new Object[]{}); 448 } 449 timeA += timeKeeper.getElapsedMillis(); 450 timeKeeper.restart(); 451 // Test methodB 452 for (int j = 0; j < repsPerTest; j++) { 453 methodB.invoke((Object) null, new Object[]{}); 454 } 455 timeB += timeKeeper.getElapsedMillis(); 456 } 457 458 float aveTimeA = timeA * 1000F / repsPerTest / tests; 459 float aveTimeB = timeB * 1000F / repsPerTest / tests; 460 // Display Results 461 FrameGraphics.DisplayMessage("Average Execution Time"); 462 FrameGraphics.DisplayMessage(methodNameA + ": " 463 + TimeKeeper.Formatter.format(aveTimeA) + "us"); 464 FrameGraphics.DisplayMessage(methodNameB + ": " 465 + TimeKeeper.Formatter.format(aveTimeB) + "us"); 466 } catch (Exception e) { 467 FrameGraphics.ErrorMessage(e.getClass().getSimpleName() + ": " 468 + e.getMessage()); 469 } 470 } 471 472 public static String getClassName(String fullMethodName) { 473 assert (fullMethodName != null); 474 assert (fullMethodName.length() > 0); 475 int lastPeriod = fullMethodName.lastIndexOf('.'); 476 if (lastPeriod > 0 && lastPeriod < fullMethodName.length() - 1) 477 return fullMethodName.substring(0, lastPeriod); 478 throw new RuntimeException("Invalid method name: " + fullMethodName); 479 } 480 481 public static String getMethodName(String methodName) { 482 assert (methodName != null); 483 assert (methodName.length() > 0); 484 int lastPeriod = methodName.lastIndexOf('.'); 485 if (lastPeriod > 0 && lastPeriod < methodName.length() - 1) 486 return methodName.substring(1 + lastPeriod); 487 throw new RuntimeException("Invalid method name: " + methodName); 488 } 489 490 /** 421 491 * Loads the Frame linked to by the given Item. The first Item on the Frame 422 492 * that is not the title or name is then placed on the current frame. The … … 458 528 } 459 529 460 private static Item getFirstBodyItemOnChildFrame(Item current, boolean textOnly) { 530 private static Item getFirstBodyItemOnChildFrame(Item current, 531 boolean textOnly) { 461 532 // the item must link to a frame 462 533 if (current.getLink() == null) { … … 476 547 // find the first non-title and non-name item 477 548 List<Item> body = new ArrayList<Item>(); 478 if (textOnly)549 if (textOnly) 479 550 body.addAll(child.getBodyTextItems(false)); 480 551 else -
trunk/src/org/expeditee/actions/Simple.java
r70 r72 1402 1402 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1403 1403 assertVariableType(tokens[2], 2, SPointer.itemPrefix); 1404 Dotdot1 = null;1405 Dotdot2 = null;1404 Item dot1 = null; 1405 Item dot2 = null; 1406 1406 try { 1407 dot1 = ( Dot) context.getPointers().getVariable(tokens[1])1407 dot1 = (Item) context.getPointers().getVariable(tokens[1]) 1408 1408 .getValue(); 1409 1409 } catch (Exception e) { … … 1411 1411 } 1412 1412 try { 1413 dot2 = ( Dot) context.getPointers().getVariable(tokens[2])1413 dot2 = (Item) context.getPointers().getVariable(tokens[2]) 1414 1414 .getValue(); 1415 1415 } catch (Exception e) { -
trunk/src/org/expeditee/agents/DefaultAgent.java
r70 r72 42 42 super(); 43 43 try { 44 _delay = (int) (Double.parseDouble(delay) * 1000);44 _delay = (int) (Double.parseDouble(delay) * 1000); 45 45 } catch (Exception e) { 46 46 } … … 65 65 / (_timer.getElapsedMillis() / 1000.0)); 66 66 String stats = (_itemCount > 0 ? ("Items: " + _itemCount + ", ") : "") 67 + "Frames: " + _frameCount + ", Time: "68 + _timer.getElapsedStringSeconds()67 + (_frameCount > 1 ? ("Frames: " + _frameCount + ", ") : "") 68 + "Time: " + _timer.getElapsedStringSeconds() 69 69 + (framesPerSecond > 1 ? (", FPS: " + framesPerSecond) : ""); 70 70 String msg = this.getClass().getSimpleName() + " stats- "; -
trunk/src/org/expeditee/gui/AttributeUtils.java
r71 r72 75 75 _AllowNull = new LinkedList<Method>(); 76 76 _AllowNull.add(Item.class.getMethod("getColor", param)); 77 _AllowNull.add(Item.class.getMethod("getBackgroundColor", param));78 79 _AllowNull.add(Frame.class.getMethod("getBackgroundColor", param));77 //_AllowNull.add(Item.class.getMethod("getBackgroundColor", param)); 78 79 //_AllowNull.add(Frame.class.getMethod("getBackgroundColor", param)); 80 80 _AllowNull.add(Frame.class.getMethod("getForegroundColor", param)); 81 81 … … 175 175 _SetMethods.put("linkmark", Item.class.getMethod("setLinkMark", 176 176 pBool)); 177 _SetMethods.put("lm", Item.class.getMethod("setLinkMark", 178 pBool)); 177 179 _SetMethods.put("actionmark", Item.class.getMethod("setActionMark", 180 pBool)); 181 _SetMethods.put("am", Item.class.getMethod("setActionMark", 178 182 pBool)); 179 183 … … 197 201 _SetMethods.put("lp", Item.class.getMethod("setLinePattern", 198 202 pIntArray)); 203 199 204 _SetMethods.put("linkframeset", Item.class.getMethod( 200 205 "setLinkFrameset", pString)); 206 _SetMethods.put("lf", Item.class.getMethod( 207 "setLinkFrameset", pString)); 201 208 _SetMethods.put("linktemplate", Item.class.getMethod( 209 "setLinkTemplate", pString)); 210 _SetMethods.put("lt", Item.class.getMethod( 202 211 "setLinkTemplate", pString)); 203 212 … … 222 231 _SetMethods.put("bgc0", Frame.class.getMethod("setBackgroundColor", 223 232 pColor)); 224 225 /* 226 * _Abbreviations = new HashMap<String, String>(); 227 * _Abbreviations.put("a", "Action"); _Abbreviations.put("l", 228 * "Link"); _Abbreviations.put("c", "Color"); 229 * _Abbreviations.put("bgc", "BackgroundColor"); 230 * _Abbreviations.put("fgc", "ForegroundColor"); 231 * _Abbreviations.put("fc", "FillColor"); _Abbreviations.put("s", 232 * "Size"); 233 */ 233 _SetMethods.put("protection", Frame.class.getMethod("setProtection", 234 pString)); 234 235 235 236 } catch (SecurityException e) { … … 413 414 414 415 // create the text Item 415 Text attribs = DisplayIO.getCurrentFrame().createNewText(); 416 attribs.setText(attributes.toString()); 417 attribs.setColor(null); 416 Frame current = DisplayIO.getCurrentFrame(); 417 Text attribs = current.getStatsTextItem(attributes.toString()); 418 418 return attribs; 419 419 } -
trunk/src/org/expeditee/gui/Browser.java
r71 r72 47 47 */ 48 48 public static void main(String[] args) { 49 FrameGraphics.SupressMessages(true); 49 50 _theBrowser = new Browser(); 51 FrameGraphics.SupressMessages(false); 50 52 // Why do we want to ignore repaint? 51 53 //_theBrowser.setIgnoreRepaint(true); -
trunk/src/org/expeditee/gui/DisplayIO.java
r70 r72 15 15 import javax.swing.JOptionPane; 16 16 17 import org.expeditee.actions.NavigationActions;18 17 import org.expeditee.items.Item; 19 18 import org.expeditee.items.ItemParentStateChangedEvent; … … 60 59 * The title to display in the Title bar. 61 60 */ 62 public static final String TITLE = "Exp2 1May2008A";61 public static final String TITLE = "Exp22May2008A"; 63 62 64 63 private DisplayIO() { … … 170 169 setCursorPosition(x, y, true); 171 170 } 172 171 173 172 public static void setCursorPosition(int x, int y, boolean forceArrow) { 174 173 int deltax = x - FrameMouseActions.MouseX; … … 180 179 } 181 180 182 // ensures the cursor doesn't fall behind while waiting for robot183 FrameMouseActions.MouseX = x;184 FrameMouseActions. MouseY = y;185 181 //When the Robot moves the cursor... a short time later a mouseMoved event is generated... 182 //We want to ignore this event by remembering the location the robot was shifted to. 183 FrameMouseActions.setLastRobotMove(x, y); 184 186 185 if (Frame.itemAttachedToCursor()) { 187 186 List<Item> toMove = Frame.FreeItems; … … 193 192 // cheat 194 193 FrameMouseActions.setForceArrow(forceArrow); 195 _Robot.mouseMove((int) _Browser.getContentPane().getLocationOnScreen()194 int mouseX = (int) _Browser.getContentPane().getLocationOnScreen() 196 195 .getX() 197 + x, (int) _Browser.getContentPane().getLocationOnScreen() 196 + x; 197 int mouseY = (int) _Browser.getContentPane().getLocationOnScreen() 198 198 .getY() 199 + y); 199 + y; 200 _Robot.mouseMove(mouseX, mouseY); 201 //System.out.println("MouseMoved: " + x + "," + y); 200 202 } 201 203 … … 327 329 for (Item i : _CurrentFrames[getCurrentSide()].getItems()) { 328 330 i.onParentStateChanged(new ItemParentStateChangedEvent( 329 _CurrentFrames[getCurrentSide()], 331 _CurrentFrames[getCurrentSide()], 330 332 ItemParentStateChangedEvent.EVENT_TYPE_HIDDEN)); 331 333 } … … 336 338 for (Item i : _CurrentFrames[getCurrentSide()].getItems()) { 337 339 i.onParentStateChanged(new ItemParentStateChangedEvent( 338 _CurrentFrames[getCurrentSide()], 340 _CurrentFrames[getCurrentSide()], 339 341 ItemParentStateChangedEvent.EVENT_TYPE_SHOWN)); 340 342 } … … 378 380 List<Frame> seen = new LinkedList<Frame>(); 379 381 seen.addAll(sharedOverlays); // Signify that seen all shared 380 382 // overlays 381 383 seen.remove(_CurrentFrames[getCurrentSide()]); // must ensure 382 384 // excluded 383 385 384 386 // Get all items seen from the current frame - including all … … 390 392 for (Item i : items) { 391 393 i.onParentStateChanged(new ItemParentStateChangedEvent( 392 _CurrentFrames[getCurrentSide()], 394 _CurrentFrames[getCurrentSide()], 393 395 ItemParentStateChangedEvent.EVENT_TYPE_HIDDEN)); 394 396 } … … 420 422 // else ... 421 423 assert (owner != null); 422 i.onParentStateChanged(new ItemParentStateChangedEvent( 423 _CurrentFrames[getCurrentSide()], 424 ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY, 425 owner.Level)); 424 i 425 .onParentStateChanged(new ItemParentStateChangedEvent( 426 _CurrentFrames[getCurrentSide()], 427 ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY, 428 owner.Level)); 426 429 } 427 430 … … 429 432 for (Item i : nonOverlayItems) { 430 433 i.onParentStateChanged(new ItemParentStateChangedEvent( 431 _CurrentFrames[getCurrentSide()], 434 _CurrentFrames[getCurrentSide()], 432 435 ItemParentStateChangedEvent.EVENT_TYPE_SHOWN)); 433 436 } … … 438 441 439 442 public static void UpdateTitle() { 440 StringBuffer title = new StringBuffer(TITLE + " [");443 StringBuffer title = new StringBuffer(TITLE); 441 444 442 445 if (FrameGraphics.isAudienceMode()) 443 446 title.append(" - Audience Mode"); 444 447 else 445 title.append( SessionStats.getShortStats()).append(']');448 title.append(" [").append(SessionStats.getShortStats()).append(']'); 446 449 447 450 _Browser.setTitle(title.toString()); … … 537 540 } 538 541 539 public static void Back() { 542 public static void Back() { 540 543 int side = getCurrentSide(); 541 544 … … 557 560 FrameIO.SuspendCache(); 558 561 Frame frame = null; 559 do {562 do { 560 563 frame = FrameIO.LoadFrame(_VisitedFrames[side].pop()); 561 }while(frame == getCurrentFrame()); 564 } while (frame == getCurrentFrame()); 565 562 566 if (isTwinFramesOn()) 563 567 FrameIO.ResumeCache(); -
trunk/src/org/expeditee/gui/Frame.java
r71 r72 24 24 import org.expeditee.items.Text; 25 25 import org.expeditee.items.WidgetCorner; 26 import org.expeditee.stats.SessionStats; 26 27 27 28 /** … … 49 50 private int _version = 0; 50 51 51 private String _protection = null;52 private String _protection = "" + Item.PERMISSION_FULL; 52 53 53 54 private String _owner = null; … … 70 71 71 72 // The items contained in this Frame 72 73 73 // records whether a change has been made to this Frame (for saving 74 74 // purposes). … … 354 354 } 355 355 356 public Text getStatTemplate() { 357 SessionStats.CreatedText(); 358 Text t = getTemplate(UserSettings.StatTemplate, 359 ItemUtils.TAG_STAT_TEMPLATE); 360 361 if (t == null) { 362 t = getItemTemplate(); 363 } 364 365 return t; 366 } 367 368 public Text getStatsTextItem(String itemText) { 369 Text t = getStatTemplate(); 370 // We dont want the stats to wrap at all 371 t.setMaxSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); 372 t.setText(itemText); 373 t.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY()); 374 addItem(t); 375 return t; 376 } 377 356 378 public Text getCodeCommentTemplate() { 357 379 Text t = getTemplate(UserSettings.CodeCommentTemplate, … … 378 400 379 401 for (Item i : _body) 380 if (i.isVisible() /* && i != _frameName */&& i.intersects(poly)) {402 if (i.isVisible() && i.intersects(poly)) { 381 403 if (!results.contains(i)) 382 404 results.add(i); … … 404 426 String frameset = Conversion.getFrameset(framename, false); 405 427 406 setFrameset(frameset); 407 setFrameNumber(num); 428 setFrameName(frameset, num); 408 429 } 409 430 … … 464 485 public void setProtection(String protection) { 465 486 _protection = protection; 487 488 if (_body.size() > 0) 489 refreshItemPermissions(); 466 490 } 467 491 … … 1125 1149 */ 1126 1150 public Text createBlankText(String templateType) { 1151 SessionStats.CreatedText(); 1127 1152 Text t; 1128 1153 if (templateType.length() == 0) … … 1140 1165 } 1141 1166 1142 public DotcreateDot() {1143 Dotdot = new Dot(DisplayIO.getRealMouseX(), DisplayIO.getMouseY(),1167 public Item createDot() { 1168 Item dot = new Dot(DisplayIO.getRealMouseX(), DisplayIO.getMouseY(), 1144 1169 getNextItemID()); 1145 1170 … … 1167 1192 } 1168 1193 } 1194 1195 if (t == null) 1196 return null; 1169 1197 1170 1198 // If the item is linked apply any attribute pairs on the child frame … … 1216 1244 } 1217 1245 1218 public DotaddDot(int x, int y) {1219 Dotd = new Dot(x, y, getNextItemID());1246 public Item addDot(int x, int y) { 1247 Item d = new Dot(x, y, getNextItemID()); 1220 1248 addItem(d); 1221 1249 return d; … … 1357 1385 Frame.COLOR_WHEEL)); 1358 1386 } 1387 1388 public void setFrameName(String frameset, int i) { 1389 setFrameset(frameset); 1390 setFrameNumber(i); 1391 } 1392 1393 /** 1394 * Sets the item permissions to match the protection for the frame. 1395 * 1396 */ 1397 public void refreshItemPermissions() { 1398 int permission = Item.PERMISSION_FULL; 1399 try{ 1400 permission = Integer.parseInt(_protection); 1401 }catch(Exception e){ 1402 } 1403 1404 _frameName.Permission = permission; 1405 if(permission < Item.PERMISSION_COPY){ 1406 _frameName.setBackgroundColor(new Color(255, 220, 220)); 1407 }else if (permission == Item.PERMISSION_COPY){ 1408 _frameName.setBackgroundColor(new Color(255, 230, 135)); 1409 }else if (permission == Item.PERMISSION_TDFC){ 1410 _frameName.setBackgroundColor(new Color(220, 255, 220)); 1411 }else { 1412 _frameName.setBackgroundColor(null); 1413 } 1414 1415 1416 for(Item i: _body) { 1417 i.Permission = permission; 1418 } 1419 } 1359 1420 } -
trunk/src/org/expeditee/gui/FrameGraphics.java
r70 r72 12 12 import java.awt.RenderingHints; 13 13 import java.awt.image.VolatileImage; 14 import java.util.Collection; 14 15 import java.util.LinkedList; 15 16 import java.util.List; … … 19 20 20 21 import org.expeditee.actions.Misc; 21 import org.expeditee.items.Dot;22 22 import org.expeditee.items.InteractiveWidget; 23 23 import org.expeditee.items.Item; 24 import org.expeditee.items.ItemUtils; 24 25 import org.expeditee.items.Line; 25 26 import org.expeditee.items.Picture; … … 64 65 65 66 // if true, error messages are not shown to the user 66 private static boolean _Supress Errors = false;67 private static boolean _SupressMessages = false; 67 68 68 69 public static String MESSAGES_FRAMESET_NAME = "Messages"; … … 79 80 */ 80 81 public static void ToggleAudienceMode() { 82 Frame current = DisplayIO.getCurrentFrame(); 81 83 if (_Mode == MODE_AUDIENCE) 82 84 _Mode = MODE_NORMAL; 83 else 85 else { 84 86 _Mode = MODE_AUDIENCE; 85 86 FrameUtils.Parse(DisplayIO.getCurrentFrame()); 87 ItemUtils.UpdateConnectedToAnnotations(current.getItems()); 88 } 89 FrameUtils.Parse(current); 87 90 DisplayIO.UpdateTitle(); 88 91 Repaint(); … … 178 181 if (g != null 179 182 && (!isAudienceMode() 180 || (isAudienceMode() && !i.isAnnotation()) || i == FrameUtils.LastEdited)) { 183 || (isAudienceMode() && !i.isConnectedToAnnotation() && !i 184 .isAnnotation()) || i == FrameUtils.LastEdited)) { 181 185 182 186 Graphics2D tg = (Graphics2D) g.create(); … … 503 507 if (i instanceof Picture) 504 508 PaintItem(g, i); 505 else if (i instanceof Dot) 506 ((Dot) i).paintFill(g); 509 else if (i.isLineEnd() && (!isAudienceMode() || 510 !i.isConnectedToAnnotation())) 511 i.paintFill(g); 507 512 } 508 513 } … … 538 543 toDisconnect.setSelectedMode(newMode); 539 544 } else { 540 List<Item> connected = i.getAllConnected();545 Collection<Item> connected = i.getAllConnected(); 541 546 for (Item conn : connected) { 542 547 conn.setSelectedMode(Item.SelectedMode.Connected); … … 585 590 public static void DisplayMessage(String message, Color textColor) { 586 591 displayMessage(message, null, null, textColor); 587 // Misc.Beep();592 // Misc.Beep(); 588 593 } 589 594 590 595 public static void DisplayMessage(Text message) { 591 displayMessage(message.getFirstLine(), message.getLink(), message.getAction(), message.getColor()); 596 displayMessage(message.getFirstLine(), message.getLink(), message 597 .getAction(), message.getColor()); 592 598 // Misc.Beep(); 593 599 } … … 596 602 // _lastMessage = null; 597 603 displayMessage(message, null, null, Color.BLACK); 598 // Misc.Beep();604 // Misc.Beep(); 599 605 } 600 606 601 607 public static void WarningMessage(String message) { 602 608 displayMessage(message, null, null, Color.MAGENTA); 603 // Misc.Beep();609 // Misc.Beep(); 604 610 } 605 611 … … 608 614 private static void displayMessage(String message, String link, 609 615 List<String> actions, Color color) { 610 // add timestamp to message 611 // if (message.equals(_lastMessage)) 612 // return; 613 // _lastMessage = message; 614 615 // message += _formatter.format(Calendar.getInstance().getTime()); 616 617 // if the creator needs to be initialised (happens on first message) 616 if (_SupressMessages) 617 return; 618 618 619 if (_creator == null) { 619 620 _creator = new FrameCreator(MESSAGES_FRAMESET_NAME, true); … … 682 683 */ 683 684 public static void LinkedErrorMessage(String message) { 684 if (_Supress Errors)685 if (_SupressMessages) 685 686 return; 686 687 Misc.Beep(); … … 693 694 694 695 public static void ErrorMessage(String message) { 695 if (_Supress Errors)696 if (_SupressMessages) 696 697 return; 697 698 Misc.Beep(); … … 745 746 } 746 747 747 public static void Supress Errors(boolean val) {748 _Supress Errors = val;748 public static void SupressMessages(boolean val) { 749 _SupressMessages = val; 749 750 } 750 751 -
trunk/src/org/expeditee/gui/FrameIO.java
r70 r72 113 113 // do not display errors encountered to the user 114 114 // (they will be shown at load time) 115 FrameGraphics.Supress Errors(true);115 FrameGraphics.SupressMessages(true); 116 116 // loading automatically caches the frame is caching is turned on 117 117 LoadUnknownPath(framename); 118 FrameGraphics.Supress Errors(false);118 FrameGraphics.SupressMessages(false); 119 119 } 120 120 … … 422 422 if (toDelete == null) 423 423 return false; 424 425 // Dont delete the zero frame 426 if (toDelete.getFrameNumber() == 0) { 427 FrameGraphics.ErrorMessage("Zero frame's can not be deleted"); 428 return false; 429 } 424 430 425 431 SaveFrame(toDelete); … … 474 480 */ 475 481 public static Frame CreateFrame(String frameset, String frameTitle, 476 String templateFrame) { 477 482 String templateFrame) throws RuntimeException { 483 484 if (!FrameIO.isValidFramesetName(frameset)) { 485 throw new RuntimeException(frameset + " is not a valid frameset name"); 486 } 487 478 488 int next = -1; 479 489 480 490 // disable caching of 0 frames 481 491 SuspendCache(); 492 String zeroFrameName = frameset + "0"; 493 Frame destFramesetZero = LoadFrame(zeroFrameName); 494 if (destFramesetZero == null) { 495 throw new RuntimeException(zeroFrameName + " could not be found"); 496 } 482 497 483 498 Frame template = null; 484 if (templateFrame == null) 499 if (templateFrame == null) { 485 500 // load in frame.0 486 template = LoadFrame(frameset + "0");487 else501 template = destFramesetZero; 502 } else { 488 503 template = LoadFrame(templateFrame); 504 if (template == null) { 505 throw new RuntimeException("LinkTemplate " + templateFrame 506 + " could not be found"); 507 } 508 } 489 509 490 510 ResumeCache(); … … 492 512 // read the next number from the INF file 493 513 try { 494 next = ReadINF( template.path, frameset);514 next = ReadINF(destFramesetZero.path, frameset); 495 515 } catch (IOException ioe) { 496 516 ioe.printStackTrace(); 497 Logger.Log(ioe); 498 return null; 517 throw new RuntimeException("INF file could not be read"); 499 518 } 500 519 501 520 // set the number and title of the new frame 502 template.setFrameN umber(++next);521 template.setFrameName(frameset, ++ next); 503 522 template.setTitle(frameTitle); 504 523 … … 634 653 635 654 if (!toSave.hasChanged() || toSave.isSaved()) 655 return ""; 656 657 //Dont save if the frame is protected 658 if (toSave.getFrameNameItem().Permission < Item.PERMISSION_TDFC) 636 659 return ""; 637 660 … … 702 725 // backup tag will be ignored 703 726 original.setFrameNumber(nextnum); 727 original.setProtection("" + Item.PERMISSION_COPY); 704 728 original.change(); 705 729 SaveFrame(original, false, false); … … 845 869 } 846 870 847 assert ( IsValidFramesetName(result.toString()));871 assert (isValidFramesetName(result.toString())); 848 872 return result.toString(); 849 873 } 850 874 851 public static Frame CreateNewFrame(Item linker) {875 public static Frame CreateNewFrame(Item linker) throws RuntimeException { 852 876 String title = null; 853 877 if (linker instanceof Text) 854 878 title = ((Text) linker).getFirstLine(); 855 879 856 String frameset = DisplayIO.getCurrentFrame().getFramesetName();857 858 880 String templateLink = linker.getLinkTemplate(); 881 String framesetLink = linker.getLinkFrameset(); 882 String frameset = (framesetLink != null ? framesetLink : DisplayIO 883 .getCurrentFrame().getFramesetName()); 859 884 860 885 Frame newFrame = FrameIO.CreateFrame(frameset, title, templateLink); … … 942 967 String conversion = frameset + " --> "; 943 968 944 if (! IsValidFramesetName(frameset)) {969 if (!isValidFramesetName(frameset)) { 945 970 throw new Exception("Invalid frameset name"); 946 971 } … … 1016 1041 * @return true if the frameset name is valid 1017 1042 */ 1018 public static boolean IsValidFramesetName(String frameset) {1043 public static boolean isValidFramesetName(String frameset) { 1019 1044 if (frameset == null) { 1020 1045 return false; … … 1123 1148 } 1124 1149 1150 public static boolean isValidLink(String frameName) { 1151 return frameName == null || isPositiveInteger(frameName) || isValidFrameName(frameName); 1152 } 1153 1125 1154 } -
trunk/src/org/expeditee/gui/FrameKeyboardActions.java
r70 r72 9 9 import java.awt.event.KeyListener; 10 10 import java.util.ArrayList; 11 import java.util.Collection; 11 12 import java.util.LinkedList; 12 13 import java.util.List; … … 55 56 public static final int FORCE_REPAINT = 12; 56 57 57 public static final int MINIMUM_SIZE = 10;58 59 58 public synchronized void keyTyped(KeyEvent e) { 60 59 if (Simple.isProgramRunning()) { … … 71 70 return; 72 71 72 if (FrameMouseActions.isWaitingForRobot()) { 73 // try{ 74 // Thread.sleep(10000); 75 // }catch(Exception ex){ 76 // 77 // } 78 // keyTyped(e); 79 // System.out.println("Waiting: " + e.getKeyChar()); 80 return; 81 } 73 82 e.consume(); 74 83 char ch = e.getKeyChar(); 75 84 //System.out.println(ch); 85 76 86 if (e.isAltDown()) { 77 87 if (FrameUtils.getCurrentItem() == null … … 125 135 return; 126 136 } 127 replaceDot((Dot) on, ch); 128 ItemUtils.EnclosedCheck(DisplayIO.getCurrentFrame().getItems()); 137 replaceDot((Item) on, ch); 129 138 return; 130 139 } … … 151 160 // if the user is in free space, create a new text item 152 161 if (on == null || !on.isHighlighted()) { 153 SessionStats.CreatedText();154 162 // DisplayIO.UpdateTitle(); 155 163 text = createText(ch); … … 188 196 } 189 197 190 public static Text replaceDot(Dot dot, char ch) { 191 SessionStats.CreatedText(); 198 public static Text replaceDot(Item dot, char ch) { 192 199 Text text = createText(ch); 193 text.setPosition(dot.getPosition()); 194 text.setThickness(dot.getThickness()); 200 Item.DuplicateItem(dot, text); 195 201 FrameUtils.LastEdited = text; 196 202 197 // Copy the lines list so it can be modified203 // Copy the lines list so it can be modified 198 204 List<Line> lines = new LinkedList<Line>(dot.getLines()); 199 205 for (Line line : lines) 200 206 line.replaceEnd(dot, text); 201 202 DisplayIO.getCurrentFrame().removeItem(dot); 203 DisplayIO.getCurrentFrame().addItem(text); 207 Frame current = DisplayIO.getCurrentFrame(); 208 current.removeItem(dot); 209 current.addItem(text); 210 ItemUtils.EnclosedCheck(current.getItems()); 204 211 return text; 205 212 } 206 213 207 // replaces the given text item with a dot 208 private static void replaceText(Text text) { 209 Dot dot = new Dot(text.getX(), text.getY(), text.getID()); 214 /** 215 * Replaces the given text item with a dot 216 */ 217 public static Item replaceText(Text text) { 218 Item dot = new Dot(text.getX(), text.getY(), text.getID()); 210 219 Item.DuplicateItem(text, dot); 211 220 … … 214 223 if (lines.size() > 0) 215 224 dot.setColor(lines.get(0).getColor()); 216 for (Line line : lines) {225 for (Line line : lines) { 217 226 line.replaceEnd(text, dot); 218 227 } 219 228 text.delete(); 220 DisplayIO.getCurrentFrame().addItem(dot); 229 Frame current = DisplayIO.getCurrentFrame(); 230 current.addItem(dot); 221 231 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 232 ItemUtils.EnclosedCheck(current.getItems()); 233 return dot; 222 234 } 223 235 … … 345 357 case KeyEvent.VK_UP: 346 358 if (e.isControlDown() || e.isShiftDown()) { 347 DisplayIO.getCurrentFrame();359 NextTextItem(FrameUtils.getCurrentItem(), false); 348 360 } else { 349 361 move(Text.UP); … … 351 363 break; 352 364 case KeyEvent.VK_DOWN: 353 move(Text.DOWN); 365 if (e.isControlDown() || e.isShiftDown()) { 366 NextTextItem(FrameUtils.getCurrentItem(), true); 367 } else { 368 move(Text.DOWN); 369 } 354 370 break; 355 371 case KeyEvent.VK_END: … … 365 381 break; 366 382 } 383 } 384 385 /** 386 * Moves the cursor to the next text item on the frame 387 * 388 * @param currentItem 389 * @param direction 390 * move up if direction is negative, down if direction is 391 * positive 392 */ 393 public static void NextTextItem(Item currentItem, boolean down) { 394 // Move the cursor to the next text item 395 Frame current = DisplayIO.getCurrentFrame(); 396 Text title = current.getTitle(); 397 List<Text> textItems = current.getBodyTextItems(false); 398 if (textItems.size() == 0) { 399 DisplayIO.setCursorPosition(title.getPosition()); 400 FrameGraphics.Repaint(); 401 return; 402 } 403 404 if (currentItem == null) { 405 // find the nearest item in the correct direction 406 int currY = DisplayIO.getMouseY(); 407 for (int i = 0; i < textItems.size(); i++) { 408 Text t = textItems.get(i); 409 if (currY < t.getY()) { 410 if (down) { 411 DisplayIO.setCursorPosition(t.getPosition()); 412 } else { 413 if (i == 0) 414 break; 415 DisplayIO.setCursorPosition(textItems.get(i - 1) 416 .getPosition()); 417 } 418 FrameGraphics.Repaint(); 419 return; 420 } 421 } 422 DisplayIO.setCursorPosition(title.getPosition()); 423 return; 424 } 425 426 if (current.getTitle().equals(currentItem)) { 427 if (down) { 428 // Show the first item 429 DisplayIO.setCursorPosition(textItems.get(0).getPosition()); 430 } else { 431 // Show the last item 432 DisplayIO.setCursorPosition(textItems.get(textItems.size() - 1) 433 .getPosition()); 434 } 435 FrameGraphics.Repaint(); 436 return; 437 } 438 // Find the current item... then move to the next item 439 for (int i = 0; i < textItems.size(); i++) { 440 if (textItems.get(i).equals(currentItem)) { 441 int nextIndex = i + (down ? 1 : -1); 442 if (nextIndex >= 0 && nextIndex < textItems.size()) { 443 DisplayIO.setCursorPosition(textItems.get(nextIndex) 444 .getPosition()); 445 } else { 446 DisplayIO.setCursorPosition(title.getPosition()); 447 } 448 FrameGraphics.Repaint(); 449 return; 450 } 451 } 452 367 453 } 368 454 … … 399 485 */ 400 486 private static void controlChar(KeyEvent e, String ch) { 487 if (ch.length() > 1) 488 return; 489 401 490 // if this is a paste command 402 491 if (ch.charAt(0) == KeyEvent.VK_V) { … … 422 511 List<Item> clipboard = new ArrayList<Item>(); 423 512 clipboard.add(text); 424 List<Item> left = FrameMouseActions.merge(clipboard,513 Collection<Item> left = FrameMouseActions.merge(clipboard, 425 514 clicked); 426 515 FrameMouseActions.anchor(left); … … 577 666 578 667 // check for enclosed mode 579 if (on == null || on == null) {580 List<Item> enclosed = FrameUtils.getCurrentItems();668 if (on == null) { 669 Collection<Item> enclosed = FrameUtils.getCurrentItems(); 581 670 582 671 if (enclosed != null && enclosed.size() > 0) { 583 672 // ensure only one dot\line is present in the list 584 List<Item> dots = FrameUtils.getEnclosingDots(); 585 List<Item> connected = dots.get(0).getAllConnected(); 673 Collection<Item> dots = FrameUtils.getEnclosingDots(); 674 Item firstConnected = dots.iterator().next(); 675 Collection<Item> connected = firstConnected.getAllConnected(); 586 676 587 677 // only resize lines if they are not surrounding some non line … … 590 680 for (Item ip : enclosed) { 591 681 if (ip != null) { 592 if (!(ip instanceof Line) && !(ip instanceof Dot)) {682 if (!(ip instanceof Line) && !(ip.isLineEnd())) { 593 683 resizeLines = false; 594 684 break; … … 597 687 } 598 688 599 for (Item ip : enclosed) { 600 if (ip != null && !(connected.indexOf(ip) > 0)) 601 switch (key) { 602 case SIZE_UP: 603 if (resizeLines 604 || (!(ip instanceof Line) && !(ip instanceof Dot))) 605 SetSize(ip, repeat, false); 606 break; 607 case SIZE_DOWN: 608 if (resizeLines 609 || (!(ip instanceof Line) && !(ip instanceof Dot))) 610 SetSize(ip, -repeat, false); 611 break; 612 // case COLOR_CHANGE: SetFillColor(ip); break; 613 case ANNOTATION_CHANGE: 614 ToggleAnnotation(ip); 615 break; 616 case FONT_STYLE_CHANGE: 617 ToggleFontStyle(ip); 618 break; 619 case FONT_FAMILY_CHANGE: 620 ToggleFontFamily(ip); 621 break; 622 case DATE_ITEM: 623 AddDate(ip); 624 break; 625 } 689 switch (key) { 690 case SIZE_UP: 691 if (resizeLines 692 || (!(firstConnected instanceof Line) && !(firstConnected instanceof Dot))) 693 SetSize(firstConnected, repeat, false); 694 break; 695 case SIZE_DOWN: 696 if (resizeLines 697 || (!(firstConnected instanceof Line) && !(firstConnected instanceof Dot))) 698 SetSize(firstConnected, -repeat, false); 699 break; 700 // case COLOR_CHANGE: SetFillColor(firstConnected); break; 701 case ANNOTATION_CHANGE: 702 ToggleAnnotation(firstConnected); 703 break; 704 case FONT_STYLE_CHANGE: 705 ToggleFontStyle(firstConnected); 706 break; 707 case FONT_FAMILY_CHANGE: 708 ToggleFontFamily(firstConnected); 709 break; 710 case DATE_ITEM: 711 AddDate(firstConnected); 712 break; 626 713 } 627 714 … … 693 780 */ 694 781 private static void Drop(Item ip) { 695 String newItemText = DEFAULT_NEW_ITEM_TEXT; 696 697 // if a line is being rubber-banded, this is a no-op 698 if (Frame.rubberbandingLine()) 699 return; // No-op 700 701 // drop requires no permissions 702 Item toDropFrom = null; 703 if (ip != null) 704 toDropFrom = ip; 705 706 // if the cursor is in free space then the drop will happen from the 707 // last non annotation text item on the frame 708 if (toDropFrom == null) { 709 toDropFrom = DisplayIO.getCurrentFrame() 710 .getLastNonAnnotationTextItem(); 711 } 712 713 // if no item was found, return 714 if (toDropFrom == null) { 715 FrameGraphics.ErrorMessage("No item could be found to drop from"); 716 return; 717 } 718 719 if (!(toDropFrom instanceof Text)) { 720 FrameGraphics.DisplayMessage("Only text items can be dropped from"); 721 return; 722 } 723 724 // Get the list of items that must be dropped 725 List<Item> column = DisplayIO.getCurrentFrame().getColumn(toDropFrom); 726 727 if (column == null) { 728 FrameGraphics.ErrorMessage("No column found to align items to"); 729 return; 730 } 731 732 Text title = DisplayIO.getCurrentFrame().getTitle(); 733 734 // We wont do auto bulleting when dropping from titles 735 if (toDropFrom != title) { 736 newItemText = getAutoBullet(((Text) toDropFrom).getFirstLine()); 737 } 738 739 Text dummyItem = null; 740 741 if (Frame.textItemAttachedToCursor()) { 742 dummyItem = (Text) Frame.getItemAttachedToCursor(); 743 String autoBullet = getAutoBullet(dummyItem.getTextNoList()); 744 745 if (autoBullet.length() > 0) 746 newItemText = ""; 747 dummyItem.setText(newItemText + dummyItem.getTextNoList()); 748 } 749 dummyItem = createText(); 750 if (Frame.textItemAttachedToCursor()) { 751 Text t = (Text) Frame.getItemAttachedToCursor(); 752 dummyItem.setSize(t.getSize()); 753 for (int i = 0; i < t.getText().size(); i++) { 754 newItemText += '\n'; 755 } 756 } 757 758 dummyItem.setText(newItemText); 759 760 // If the only item on the frame is the title and the frame name just 761 // drop a specified distance below the title 762 if (column.size() == 0) { 763 Text itemTemplate = DisplayIO.getCurrentFrame().getItemTemplate(); 764 int xPos = title.getX(); 765 int yPos = title.getY() + title.getBoundsHeight() 766 + itemTemplate.getBoundsHeight(); 767 dummyItem.setPosition(xPos, yPos); 768 DisplayIO.setCursorPosition(xPos, yPos); 769 } else { 770 int yPos = column.get(0).getY() + 1; 771 // Either position the new item below the title or just above 772 // the first item below the title 773 if (toDropFrom == title) 774 yPos = Math 775 .min(column.get(0).getY() - 1, title.getY() 776 + title.getBoundsHeight() 777 + dummyItem.getBoundsHeight()); 778 dummyItem.setPosition(column.get(0).getX(), yPos); 779 column.add(dummyItem); 780 FrameUtils.Align(column, false, 0); 781 // Check if it will be outside the frame area 782 if (dummyItem.getY() < 0 783 || dummyItem.getY() > FrameGraphics.getMaxFrameSize() 784 .getHeight()) { 785 // Check for the @more tag! 786 Item i = ItemUtils.FindTag(DisplayIO.getCurrentFrame() 787 .getItems(), "@More"); 788 if (i != null) { 789 Frame firstFrame = DisplayIO.getCurrentFrame(); 790 boolean mouseMoved = FrameMouseActions.tdfc(i); 791 Frame moreFrame = DisplayIO.getCurrentFrame(); 792 moreFrame.setTitle(firstFrame.getTitle().getTextNoList()); 793 // need to move the mouse to the top of the frame if there 794 // wasnt an @start on it 795 if (!mouseMoved) { 796 Item moreTitle = moreFrame.getTitle(); 797 moreTitle.Permission = Item.PERMISSION_FULL; 798 Drop(moreTitle); 782 try { 783 String newItemText = DEFAULT_NEW_ITEM_TEXT; 784 785 // if a line is being rubber-banded, this is a no-op 786 if (Frame.rubberbandingLine()) 787 return; // No-op 788 789 // drop requires no permissions 790 Item toDropFrom = null; 791 if (ip != null) 792 toDropFrom = ip; 793 794 // if the cursor is in free space then the drop will happen from the 795 // last non annotation text item on the frame 796 if (toDropFrom == null) { 797 toDropFrom = DisplayIO.getCurrentFrame() 798 .getLastNonAnnotationTextItem(); 799 } 800 801 // if no item was found, return 802 if (toDropFrom == null) { 803 FrameGraphics 804 .ErrorMessage("No item could be found to drop from"); 805 return; 806 } 807 808 if (!(toDropFrom instanceof Text)) { 809 FrameGraphics 810 .DisplayMessage("Only text items can be dropped from"); 811 return; 812 } 813 814 // Get the list of items that must be dropped 815 List<Item> column = DisplayIO.getCurrentFrame().getColumn( 816 toDropFrom); 817 818 if (column == null) { 819 FrameGraphics.ErrorMessage("No column found to align items to"); 820 return; 821 } 822 823 Text title = DisplayIO.getCurrentFrame().getTitle(); 824 825 // We wont do auto bulleting when dropping from titles 826 if (toDropFrom != title) { 827 newItemText = getAutoBullet(((Text) toDropFrom).getFirstLine()); 828 } 829 830 Text dummyItem = null; 831 832 if (Frame.textItemAttachedToCursor()) { 833 dummyItem = (Text) Frame.getItemAttachedToCursor(); 834 String autoBullet = getAutoBullet(dummyItem.getTextNoList()); 835 836 if (autoBullet.length() > 0) 837 newItemText = ""; 838 dummyItem.setText(newItemText + dummyItem.getTextNoList()); 839 } 840 dummyItem = createText(); 841 if (Frame.textItemAttachedToCursor()) { 842 Text t = (Text) Frame.getItemAttachedToCursor(); 843 dummyItem.setSize(t.getSize()); 844 for (int i = 0; i < t.getText().size(); i++) { 845 newItemText += '\n'; 846 } 847 } 848 849 dummyItem.setText(newItemText); 850 851 // If the only item on the frame is the title and the frame name 852 // just 853 // drop a specified distance below the title 854 if (column.size() == 0) { 855 Text itemTemplate = DisplayIO.getCurrentFrame() 856 .getItemTemplate(); 857 int xPos = title.getX(); 858 int yPos = title.getY() + title.getBoundsHeight() 859 + itemTemplate.getBoundsHeight(); 860 dummyItem.setPosition(xPos, yPos); 861 DisplayIO.setCursorPosition(xPos, yPos); 862 } else { 863 int yPos = column.get(0).getY() + 1; 864 // Either position the new item below the title or just above 865 // the first item below the title 866 if (toDropFrom == title) 867 yPos = Math.min(column.get(0).getY() - 1, title.getY() 868 + title.getBoundsHeight() 869 + dummyItem.getBoundsHeight()); 870 dummyItem.setPosition(column.get(0).getX(), yPos); 871 column.add(dummyItem); 872 FrameUtils.Align(column, false, 0); 873 // Check if it will be outside the frame area 874 if (dummyItem.getY() < 0 875 || dummyItem.getY() > FrameGraphics.getMaxFrameSize() 876 .getHeight()) { 877 // Check for the @more tag! 878 Item i = ItemUtils.FindTag(DisplayIO.getCurrentFrame() 879 .getItems(), "@More"); 880 if (i != null) { 881 Frame firstFrame = DisplayIO.getCurrentFrame(); 882 boolean mouseMoved = FrameMouseActions.tdfc(i); 883 Frame moreFrame = DisplayIO.getCurrentFrame(); 884 moreFrame.setTitle(firstFrame.getTitle() 885 .getTextNoList()); 886 // need to move the mouse to the top of the frame if 887 // there 888 // wasnt an @start on it 889 if (!mouseMoved) { 890 Item moreTitle = moreFrame.getTitle(); 891 moreTitle.Permission = Item.PERMISSION_FULL; 892 Drop(moreTitle); 893 } 894 // Add the bullet text to the item 895 dummyItem.setPosition(DisplayIO.getMouseX(), DisplayIO 896 .getMouseY()); 897 } else { 898 FrameGraphics 899 .WarningMessage("Can not create items outside the frame area"); 900 // ensures correct repainting when items don't move 901 DisplayIO.setCursorPosition(DisplayIO.getMouseX(), 902 DisplayIO.getMouseY()); 903 return; 799 904 } 800 // Add the bullet text to the item 801 dummyItem.setPosition(DisplayIO.getMouseX(), DisplayIO 802 .getMouseY()); 905 } 906 if (!Frame.textItemAttachedToCursor() && !dummyItem.isEmpty()) { 907 DisplayIO.getCurrentFrame().addItem(dummyItem); 908 } 909 910 // Move the item to the cursor position 911 if (Frame.itemAttachedToCursor()) { 912 DisplayIO.setCursorPosition(dummyItem.getX(), dummyItem 913 .getY()); 914 Item firstItem = Frame.getItemAttachedToCursor(); 915 int deltaX = firstItem.getX() - dummyItem.getX(); 916 int deltaY = firstItem.getY() - dummyItem.getY(); 917 918 for (Item i : Frame.FreeItems) { 919 i.setPosition(i.getX() - deltaX, i.getY() - deltaY); 920 } 803 921 } else { 804 FrameGraphics 805 .WarningMessage("Can not create items outside the frame area"); 806 // ensures correct repainting when items don't move 807 DisplayIO.setCursorPosition(DisplayIO.getMouseX(), 808 DisplayIO.getMouseY()); 809 return; 922 DisplayIO.setCursorPosition(dummyItem 923 .getEndParagraphPosition().x, dummyItem.getY()); 810 924 } 811 925 } 812 if (!Frame.textItemAttachedToCursor() && !dummyItem.isEmpty()) { 813 DisplayIO.getCurrentFrame().addItem(dummyItem); 814 } 815 816 // Move the item to the cursor position 817 if (Frame.itemAttachedToCursor()) { 818 DisplayIO.setCursorPosition(dummyItem.getX(), dummyItem.getY()); 819 Item firstItem = Frame.getItemAttachedToCursor(); 820 int deltaX = firstItem.getX() - dummyItem.getX(); 821 int deltaY = firstItem.getY() - dummyItem.getY(); 822 823 for (Item i : Frame.FreeItems) { 824 i.setPosition(i.getX() - deltaX, i.getY() - deltaY); 825 } 826 } else { 827 DisplayIO 828 .setCursorPosition( 829 dummyItem.getEndParagraphPosition().x, 830 dummyItem.getY()); 831 } 832 } 833 834 DisplayIO.resetCursorOffset(); 835 FrameGraphics.Repaint(); 926 927 DisplayIO.resetCursorOffset(); 928 FrameGraphics.Repaint(); 929 } catch (RuntimeException e) { 930 FrameGraphics.ErrorMessage(e.getMessage()); 931 } 836 932 } 837 933 … … 992 1088 * with resizing 993 1089 */ 994 private static void SetSize(Item i p, int diff, boolean moveCursor) {1090 private static void SetSize(Item item, int diff, boolean moveCursor) { 995 1091 List<Item> toSize = new ArrayList<Item>(); 996 1092 // the mouse is only moved when the Item is on the frame, not free … … 999 1095 1000 1096 // if the user is not pointing to any item 1001 if (i p== null) {1097 if (item == null) { 1002 1098 if (Frame.itemAttachedToCursor()) 1003 1099 toSize.addAll(Frame.FreeItems); … … 1009 1105 } else { 1010 1106 // check permissions 1011 if (i p.Permission < Item.PERMISSION_FULL) {1107 if (item.Permission < Item.PERMISSION_FULL) { 1012 1108 FrameGraphics 1013 1109 .DisplayMessage("Insufficient permission to change the size of that item"); 1014 1110 return; 1015 1111 } 1016 toSet = ip; 1017 Item currentItem = FrameUtils.getCurrentItem(); 1018 1019 if (currentItem != null && (currentItem instanceof Text) 1020 && FrameUtils.getCurrentItems() == null) { 1021 toSize.add(currentItem); 1112 toSet = item; 1113 1114 if (!(toSet instanceof Text) && toSet.isLineEnd()) { 1115 toSize.addAll(toSet.getLines()); 1116 } else if (toSet instanceof Line) { 1117 Line line = (Line) toSet; 1118 float current = Math.abs(line.getThickness()); 1119 current = Math.max(current + diff, 1); 1120 line.setThickness(current); 1121 FrameGraphics.Repaint(); 1122 return; 1022 1123 } else { 1023 toSize.addAll(toSet.getLines()); 1024 } 1025 } 1026 1027 if (toSet instanceof Line) { 1028 Line line = (Line) toSet; 1029 float current = Math.abs(line.getThickness()); 1030 current = Math.max(current + diff, 1); 1031 line.setThickness(current); 1032 FrameGraphics.Repaint(); 1033 return; 1034 } 1035 1036 /* 1037 * for(Item i : toSize){ if(i instanceof Dot || i instanceof Line){ 1038 * toSize.removeAll(i.getConnected()); toSize.add(i); } } 1039 */ 1124 toSize.add(toSet); 1125 } 1126 } 1040 1127 1041 1128 int old_width = 0; … … 1056 1143 line.setThickness(current); 1057 1144 } else if (i instanceof Dot) { 1058 Dot dot = (Dot) i;1145 Item dot = (Item) i; 1059 1146 float current = Math.abs(dot.getThickness()); 1060 1147 current = Math.max(current + diff, 1); … … 1063 1150 int current = Math.abs(i.getSize()); 1064 1151 current = Math.max(current + diff, 1); 1065 if (current > MINIMUM_SIZE) 1066 i.setSize(current); 1152 i.setSize(current); 1067 1153 } 1068 1154 } … … 1353 1439 return; 1354 1440 } 1355 1441 1356 1442 if (!(item instanceof Text)) { 1357 1443 FrameGraphics … … 1359 1445 return; 1360 1446 } 1361 1362 // dont create frameset if the item is linked1447 1448 // dont create frameset if the item is linked 1363 1449 if (item.getLink() != null) { 1364 1450 FrameGraphics … … 1366 1452 return; 1367 1453 } 1368 1454 1369 1455 // check permissions 1370 1456 if (item.Permission < Item.PERMISSION_FULL) { -
trunk/src/org/expeditee/gui/FrameMouseActions.java
r70 r72 13 13 import java.util.Date; 14 14 import java.util.HashSet; 15 import java.util.Iterator; 15 16 import java.util.LinkedList; 16 17 import java.util.List; … … 88 89 public static int MouseY; 89 90 90 // Offset coordinates from the mouse position when grabbing items 91 // Distance of mouse cursor from the origin of the item that was picked up 92 // The are used in the move method to calculate the distance moved by the 93 // cursor 91 94 private static int _offX; 92 95 93 // MIKE: Thinks the offsets are used in getting items to draw in the message94 // window?95 96 private static int _offY; 96 97 … … 567 568 if (clicked.Permission < Item.PERMISSION_FOLLOW_LINKS) { 568 569 FrameGraphics 569 .DisplayMessage("Insufficient Permissions foraction on item");570 .DisplayMessage("Insufficient permissions to perform action on item"); 570 571 return; 571 572 } … … 608 609 return; 609 610 } 610 611 tdfc(clickedOn); 611 try { 612 tdfc(clickedOn); 613 } catch (RuntimeException e) { 614 FrameGraphics.ErrorMessage(e.getMessage()); 615 } 612 616 return; 613 617 } … … 667 671 && clicked.getParent() != null 668 672 && clicked.getParent().getFrameNameItem() != clicked) { 669 FrameGraphics.DisplayMessage("Insufficient Permission");673 FrameGraphics.DisplayMessage("Insufficient permission"); 670 674 return; 671 675 } 672 676 673 Item merger 674 assert (merger != null);677 Item merger = Frame.FreeItems.get(0); 678 assert (merger != null); 675 679 // Move the cursor if it is not Text-Text merging 676 680 // Or Item to Line merging … … 679 683 DisplayIO.setCursorPosition(clicked.getPosition()); 680 684 } 681 List<Item> left = merge(Frame.FreeItems, clicked);685 Collection<Item> left = merge(Frame.FreeItems, clicked); 682 686 anchor(left); 683 687 Frame.FreeItems.clear(); … … 700 704 if (clicked.Permission < Item.PERMISSION_FULL) { 701 705 FrameGraphics 702 .DisplayMessage("Insufficient Permission to pick up item");706 .DisplayMessage("Insufficient permission to pick up item"); 703 707 return; 704 708 } … … 781 785 Line newLine = createLine(); 782 786 SessionStats.CreatedItems(newLine.getAllConnected()); 783 787 784 788 // if the user can spot-weld, show the virtual spot 785 789 if (on instanceof Line) { … … 855 859 && clicked.getParent().getFrameNameItem() != clicked) { 856 860 FrameGraphics 857 .DisplayMessage("Insufficient Permission to merge items");861 .DisplayMessage("Insufficient permission to merge items"); 858 862 return; 859 863 } … … 866 870 // get a copy of all enclosed items before merging 867 871 // lineEnds 868 List<Item> items = FrameUtils.getItemsEnclosedBy(872 Collection<Item> items = FrameUtils.getItemsEnclosedBy( 869 873 DisplayIO.getCurrentFrame(), d 870 874 .getEnclosedShape()); … … 892 896 copies = copy(toCopy); 893 897 // Now do the merging 894 List<Item> remain = merge(Frame.FreeItems, clicked); 898 Collection<Item> remain = merge(Frame.FreeItems, 899 clicked); 895 900 // anchor the points 896 901 anchor(remain); … … 900 905 } else if (Frame.FreeItems.size() == 2) { 901 906 copies = ItemUtils.UnreelLine(Frame.FreeItems); 902 List<Item> leftOver = merge(Frame.FreeItems, clicked); 907 Collection<Item> leftOver = merge(Frame.FreeItems, 908 clicked); 903 909 anchor(leftOver); 904 910 if (copies == null) … … 913 919 } else if (Frame.FreeItems.size() == 1) { 914 920 copies = copy(Frame.FreeItems); 915 List<Item> remain = merge(copies, clicked);921 Collection<Item> remain = merge(copies, clicked); 916 922 917 923 // ignore items that could not be merged. … … 982 988 if (Frame.FreeItems.size() == 2) { 983 989 if (clicked != null) { 984 List<Item> leftOver = merge(Frame.FreeItems,990 Collection<Item> leftOver = merge(Frame.FreeItems, 985 991 clicked); 986 992 anchor(leftOver); … … 1033 1039 // Copies will NOT be null if the user right clicked on a point 1034 1040 if (copies == null) { 1035 List<Item> originals = clicked.getConnected();1041 Collection<Item> originals = clicked.getConnected(); 1036 1042 copies = ItemUtils.CopyItems(originals, _extrude); 1037 1043 if (!_extrude) … … 1044 1050 // Set the selection mode for the items that were clicked in 1045 1051 List<Item> enclosed = getFullyEnclosedItems(clickedIn); 1046 copies = copy(enclosed); 1047 // TODO figure out how to get copies to be SELECTED when 1048 // they are anchored 1049 // for (Item i : copies) { 1050 // if (i.isEnclosed()) { 1051 // i.setSelectedMode(Item.SelectedMode.Enclosed); 1052 // i.setSelectedMode(Item.SelectedMode.None); 1053 // } 1054 // } 1055 clearParent(copies); 1056 pickup(copies); 1052 if (enclosed.size() == 0) { 1053 FrameGraphics 1054 .DisplayMessage("Insufficient permission to copy items"); 1055 } else { 1056 copies = copy(enclosed); 1057 // TODO figure out how to get copies to be SELECTED when 1058 // they are anchored 1059 // for (Item i : copies) { 1060 // if (i.isEnclosed()) { 1061 // i.setSelectedMode(Item.SelectedMode.Enclosed); 1062 // i.setSelectedMode(Item.SelectedMode.None); 1063 // } 1064 // } 1065 clearParent(copies); 1066 pickup(copies); 1067 } 1057 1068 // otherwise, create a rectangle 1058 1069 } else { 1059 1070 copies = new ArrayList<Item>(); 1060 Dot[] d = new Dot[RECTANGLE_CORNERS];1071 Item[] d = new Item[RECTANGLE_CORNERS]; 1061 1072 // create dots 1062 1073 for (int i = 0; i < d.length; i++) { … … 1121 1132 Item i = enclosedItems.get(0); 1122 1133 if (i.Permission >= Item.PERMISSION_COPY) { 1123 List<Item> items = i.getAllConnected();1134 Collection<Item> items = i.getAllConnected(); 1124 1135 // Only copy if the entire shape is enclosed 1125 1136 if (enclosedItems.containsAll(items)) { … … 1127 1138 } 1128 1139 enclosedItems.removeAll(items); 1140 } else { 1141 enclosedItems.remove(0); 1129 1142 } 1130 1143 } … … 1226 1239 1227 1240 MouseEvent _lastMouseEvent = null; 1228 1241 private static Integer LastRobotX = null; 1242 private static Integer LastRobotY = null; 1243 1244 public static void setLastRobotMove(int x, int y) { 1245 //Make sure the system is in the right state while waiting for the Robots event to arrive. 1246 MouseX = x; 1247 MouseY = y; 1248 1249 LastRobotX = x; 1250 LastRobotY = y; 1251 } 1252 1253 public static boolean isWaitingForRobot() { 1254 return LastRobotX != null; 1255 } 1256 1257 1229 1258 /** 1230 1259 * Updates the stored mouse position and highlights any items as necessary. 1231 1260 */ 1232 1261 public void mouseMoved(MouseEvent e) { 1262 if(LastRobotX != null){ 1263 //Wait until the last Robot mouse move event arrives before processing other events 1264 if(LastRobotX == e.getX() && LastRobotY == e.getY()){ 1265 LastRobotX = null; 1266 LastRobotY = null; 1267 }else 1268 return; 1269 } 1270 1233 1271 MouseX = e.getX(); 1234 1272 MouseY = e.getY(); … … 1334 1372 // highlighting 1335 1373 } else if (on == null) { 1336 List<Item> enclosure = FrameUtils.getEnclosingDots();1374 Collection<Item> enclosure = FrameUtils.getEnclosingDots(); 1337 1375 if (enclosure != null && enclosure.size() > 1) { 1338 if (enclosure.get(0).getLines().size() > 1 && 1376 Item firstLineEnd = enclosure.iterator().next(); 1377 if (firstLineEnd.getLines().size() > 1 && 1339 1378 // check that the enclosure is not part of a point being 1340 1379 // dragged in space 1341 1380 !ContainsOneOf(enclosure, Frame.FreeItems)) { 1342 on = enclosure.get(0).getLines().get(0);1381 on = firstLineEnd.getLines().get(0); 1343 1382 FrameGraphics.ChangeSelectionMode(on, 1344 1383 Item.SelectedMode.Enclosed); … … 1379 1418 } 1380 1419 1381 private boolean ContainsOneOf(List<Item> enclosure, List<Item> freeItems) { 1420 private boolean ContainsOneOf(Collection<Item> enclosure, 1421 Collection<Item> freeItems) { 1382 1422 if (freeItems == null) 1383 1423 return false; … … 1440 1480 1441 1481 private static void move(List<Item> toMove) { 1482 //System.out.println(_offX + "," + _offY); 1483 1484 // Gets the origin of the first item to move 1442 1485 int xPos = (DisplayIO.getMouseX() - _offX); 1443 1486 1444 1487 Item firstDot = toMove.get(0); 1445 1446 /*1447 * for (Item i: toMove) { if (i instanceof Dot){ firstDot = i; break; } }1448 */1449 1488 1450 1489 int deltax = firstDot.getX() - xPos; … … 1484 1523 * @return 1485 1524 */ 1486 public static boolean tdfc(Item linker) {1525 public static boolean tdfc(Item linker) throws RuntimeException { 1487 1526 if (linker instanceof Line) 1488 1527 return false; … … 1491 1530 if (linker.getID() < 0) 1492 1531 return false; 1532 1533 boolean mouseMoved; 1493 1534 1494 1535 linker.getParent().setChanged(true); … … 1512 1553 FrameUtils.setTdfcItem(linker); 1513 1554 1514 booleanmouseMoved = next.moveMouseToDefaultLocation();1555 mouseMoved = next.moveMouseToDefaultLocation(); 1515 1556 // this needs to be done if the user doesnt move the mouse before doing 1516 1557 // tdfc while the cursor is set to the text cursor … … 1519 1560 // triggers changed to be set to true when it should stay as false 1520 1561 next.setChanged(false); 1521 1522 1562 return mouseMoved; 1523 1563 } … … 1552 1592 // Give the attribute text item the color of the item for which 1553 1593 // attributes are being extracted. 1554 attribs.setColor(item.getColor());1594 // attribs.setColor(item.getColor()); 1555 1595 pickup(attribs); 1556 1596 } … … 1582 1622 return; 1583 1623 } 1584 1585 1624 Text anchored = (Text) toDelete; 1586 1625 Text free = (Text) Frame.FreeItems.get(0); 1587 1626 SessionStats.DeletedItem(free); 1588 1627 // List<String> temp = anchored.getText(); 1589 1628 anchored.setTextList(free.getText()); … … 1613 1652 1614 1653 if (items != null) { 1615 ArrayList<Item> toRemove = new ArrayList<Item>(items.size());1616 for (Item ip : items) 1654 List<Item> toRemove = new ArrayList<Item>(items.size()); 1655 for (Item ip : items) { 1617 1656 if (ip.Permission >= Item.PERMISSION_FULL) { 1657 // Only include lines if one of their enpoints are also 1658 // being removed 1659 if (ip instanceof Line) { 1660 Line l = (Line) ip; 1661 if (!items.contains(l.getEndItem()) 1662 && !items.contains(l.getStartItem())) 1663 continue; 1664 } 1618 1665 toRemove.add(ip); 1619 1666 } 1667 } 1620 1668 1621 1669 deleteItems(toRemove); … … 1643 1691 current.setChanged(true); 1644 1692 1645 List<Item> toUndo = new LinkedList<Item>(); 1646 1693 List<Item> toUndo = null; 1647 1694 if (toDelete.isLineEnd()) { 1648 toUndo.addAll(deleteDot(toDelete)); 1649 } else 1650 toUndo.addAll(copy(toDelete.getConnected())); 1651 1695 toUndo = deleteLineEnd(toDelete); 1696 } else { 1697 toUndo = copy(toDelete.getConnected()); 1698 } 1699 SessionStats.DeletedItems(toUndo); 1652 1700 current.addAllToUndo(toUndo); 1653 1701 current.removeAllItems(toDelete.getConnected()); … … 1677 1725 for (Item i : itemList) { 1678 1726 if (i.getLines().size() > 0) { 1679 List<Item> copy = delete Dot(i);1727 List<Item> copy = deleteLineEnd(i); 1680 1728 // add the copied items to the undo stack 1681 1729 for (Item cop : copy) … … 1698 1746 } 1699 1747 1700 private static List<Item> delete Dot(Item dot) {1701 1702 if ( dotinstanceof WidgetCorner) { // Brook1703 1704 WidgetCorner wc = (WidgetCorner) dot;1748 private static List<Item> deleteLineEnd(Item lineEnd) { 1749 1750 if (lineEnd instanceof WidgetCorner) { // Brook 1751 1752 WidgetCorner wc = (WidgetCorner) lineEnd; 1705 1753 List<Item> wccopy; 1706 1754 … … 1712 1760 } 1713 1761 1714 if (dot.getParent() != null) { 1715 dot.getParent().removeAllItems(wc.getWidgetSource().getItems()); 1762 if (lineEnd.getParent() != null) { 1763 lineEnd.getParent().removeAllItems( 1764 wc.getWidgetSource().getItems()); 1716 1765 } 1717 1766 return wccopy; … … 1719 1768 1720 1769 // create a backup copy of the dot 1721 List<Item> copy = copy( dot.getConnected());1770 List<Item> copy = copy(lineEnd.getConnected()); 1722 1771 // remove lines that are connected to anchored dots 1723 1772 // note: the line is kept so that it can be properly restored … … 1733 1782 1734 1783 // remove all lines being deleted 1735 for (Item ic : dot.getConnected()) {1784 for (Item ic : lineEnd.getConnected()) { 1736 1785 if (ic instanceof Line 1737 && ((Line) ic).getOppositeEnd( dot) != null) {1786 && ((Line) ic).getOppositeEnd(lineEnd) != null) { 1738 1787 Line line = (Line) ic; 1739 1788 1740 Item d = line.getOppositeEnd( dot);1789 Item d = line.getOppositeEnd(lineEnd); 1741 1790 d.removeLine(line); 1742 1791 … … 1750 1799 } 1751 1800 1752 if ( dot.getParent() != null)1753 dot.getParent().removeItem(ic);1801 if (lineEnd.getParent() != null) 1802 lineEnd.getParent().removeItem(ic); 1754 1803 } 1755 1804 } … … 1772 1821 } 1773 1822 1774 public static List<Item> merge(List<Item> merger, Item mergee) {1823 public static Collection<Item> merge(List<Item> merger, Item mergee) { 1775 1824 if (mergee.getParent().getFrameNameItem() == mergee) { 1776 1825 return mergee.getParent().merge(merger); … … 1782 1831 // if this is a corner of a shape 1783 1832 if (corner != null) { 1784 List<Item> allConnected = corner.getAllConnected();1833 Collection<Item> allConnected = corner.getAllConnected(); 1785 1834 // Check if we are collapsing a rectangle 1786 1835 if (allConnected.size() == 8 && allConnected.contains(mergee)) { … … 1898 1947 */ 1899 1948 public static void pickup(Item toGrab) { 1949 if (toGrab.Permission < Item.PERMISSION_FULL) { 1950 FrameGraphics 1951 .DisplayMessage("Insufficient permission pickup the item"); 1952 return; 1953 } 1900 1954 // Brook: If the widget corner is being picked up. Instead refer to 1901 // picking 1902 // up the edge for fixed-sized widgets so it is not so confusing 1955 // picking up the edge for fixed-sized widgets so it is not so confusing 1903 1956 if (toGrab instanceof WidgetCorner) { 1904 1957 WidgetCorner wc = (WidgetCorner) toGrab; 1905 1958 if (wc.getWidgetSource().isFixedSize()) { 1906 toGrab = toGrab.getConnected().get(1); 1907 } 1908 } 1909 1959 for (Item i : toGrab.getConnected()) { 1960 if (i instanceof WidgetEdge) { 1961 toGrab = i; 1962 break; 1963 } 1964 } 1965 } 1966 } 1910 1967 pickup(toGrab.getConnected()); 1911 1968 } 1912 1969 1913 public static void pickup( List<Item> toGrab) {1970 public static void pickup(Collection<Item> toGrab) { 1914 1971 1915 1972 String currentFrame = DisplayIO.getCurrentFrame().getFrameName(); 1916 for (Item i : toGrab) { 1973 Iterator<Item> iter = toGrab.iterator(); 1974 while (iter.hasNext()) { 1975 Item i = iter.next(); 1976 if (i.Permission < Item.PERMISSION_FULL) { 1977 iter.remove(); 1978 continue; 1979 } 1980 1917 1981 // Check if it has a relative link if so make it absolute 1918 1982 i.setAbsoluteLink(); 1919 1920 1983 // parent may be null 1921 1984 if (i.getParent() != null) { … … 1925 1988 } 1926 1989 Frame.FreeItems.add(i); 1927 1928 1990 i.setFloating(true); 1929 1991 } … … 1935 1997 if (toGrab.size() > 1) { 1936 1998 for (Item i : toGrab) { 1999 // MIKE: Why cant we use a line for the offset calculations?!? 1937 2000 if (!(i instanceof Line)) { 1938 2001 _offX = DisplayIO.getMouseX() - i.getX() + i.getOffset().x; … … 1940 2003 1941 2004 // make the offset item the first item in the list (so 1942 // mov ing codeknows which item to use)2005 // move method knows which item to use) 1943 2006 Frame.FreeItems.set(Frame.FreeItems.indexOf(i), 1944 2007 Frame.FreeItems.get(0)); … … 1949 2012 1950 2013 move(Frame.FreeItems); 2014 ItemUtils.EnclosedCheck(toGrab); 1951 2015 // otherwise, just use the first item 1952 2016 } else if (toGrab.size() == 1) { 1953 _offX = DisplayIO.getMouseX() - toGrab.get(0).getX() 1954 + toGrab.get(0).getOffset().x; 1955 _offY = MouseY - toGrab.get(0).getY() + toGrab.get(0).getOffset().y; 1956 } 1957 1958 ItemUtils.EnclosedCheck(toGrab); 2017 Item soleItem = toGrab.iterator().next(); 2018 _offX = DisplayIO.getMouseX() - soleItem.getX() 2019 + soleItem.getOffset().x; 2020 _offY = MouseY - soleItem.getY() + soleItem.getOffset().y; 2021 } else { 2022 FrameGraphics 2023 .DisplayMessage("Insufficient permission pickup the items"); 2024 } 1959 2025 } 1960 2026 1961 2027 private static Line createLine() { 1962 2028 // create the two endpoints 1963 Dotend = DisplayIO.getCurrentFrame().createDot();1964 Dotstart = DisplayIO.getCurrentFrame().createDot();2029 Item end = DisplayIO.getCurrentFrame().createDot(); 2030 Item start = DisplayIO.getCurrentFrame().createDot(); 1965 2031 // create the Line 1966 2032 Line line = new Line(start, end, DisplayIO.getCurrentFrame() … … 2006 2072 } 2007 2073 2008 public static void anchor( List<Item> toAnchor) {2074 public static void anchor(Collection<Item> toAnchor) { 2009 2075 // Need to make sure we check enclosure for overlays etc 2010 2076 List<Frame> checkEnclosure = new ArrayList<Frame>(); … … 2070 2136 clicks = (int) Math.ceil(size / 20.0 * clicks); 2071 2137 } 2072 2073 2138 FrameKeyboardActions.functionKey(rotationType, clicks); 2139 2074 2140 } else if (clicks == MOUSE_WHEEL_THRESHOLD) { 2075 Item i p= FrameUtils.getCurrentItem();2141 Item item = FrameUtils.getCurrentItem(); 2076 2142 2077 2143 // if the user is not pointing to any item 2078 if (i p== null) {2079 Frame Graphics2080 .DisplayMessage("There are no Items selected on the Frame");2144 if (item == null) { 2145 FrameKeyboardActions.NextTextItem(null, 2146 arg0.getWheelRotation() > 0); 2081 2147 return; 2082 } else { 2148 } 2149 2150 if (item instanceof Line) { 2083 2151 // check permissions 2084 if (i p.Permission < Item.PERMISSION_FULL) {2152 if (item.Permission < Item.PERMISSION_FULL) { 2085 2153 FrameGraphics 2086 .DisplayMessage("Insufficient permission to change the size of that item");2154 .DisplayMessage("Insufficient permission to edit the Line"); 2087 2155 return; 2088 2156 } 2089 } 2090 2091 if (ip instanceof Line) { 2092 Line line = (Line) ip; 2157 Line line = (Line) item; 2093 2158 line.toggleDashed(arg0.getWheelRotation()); 2094 2159 line.getParent().change(); 2095 2160 FrameGraphics.Repaint(); 2096 2161 return; 2162 } else if (item instanceof Text) { 2163 FrameKeyboardActions.NextTextItem(item, 2164 arg0.getWheelRotation() > 0); 2097 2165 } 2098 2166 } -
trunk/src/org/expeditee/gui/FrameUtils.java
r70 r72 5 5 import java.io.File; 6 6 import java.util.ArrayList; 7 import java.util.Collection; 7 8 import java.util.Collections; 8 9 import java.util.Comparator; … … 330 331 while (toCheck.size() > 0) { 331 332 Item i = toCheck.get(0); 332 List<Item> connected = i.getAllConnected();333 Collection<Item> connected = i.getAllConnected(); 333 334 334 335 // // Only move completely enclosed items … … 587 588 UserSettings.AnnotationTemplate = ((Text) item) 588 589 .getTemplateForm(); 590 } else if (ItemUtils.isTag(item, ItemUtils.TAG_STAT_TEMPLATE)) { 591 UserSettings.StatTemplate = ((Text) item).getTemplateForm(); 589 592 } else if (ItemUtils.isTag(item, 590 593 ItemUtils.TAG_CODE_COMMENT_TEMPLATE)) { 591 594 UserSettings.CodeCommentTemplate = ((Text) item) 592 595 .getTemplateForm(); 593 } else if (ItemUtils.isTag(item, 594 ItemUtils.TAG_LINE_TEMPLATE)) { 595 UserSettings.LineTemplate = ((Text) item) 596 .getTemplateForm(); 596 } else if (ItemUtils.isTag(item, ItemUtils.TAG_LINE_TEMPLATE)) { 597 UserSettings.LineTemplate = ((Text) item).getTemplateForm(); 597 598 } else if (ItemUtils.isTag(item, "@FramesetDir:")) { 598 599 String dir = getDir(item, null); … … 713 714 ArrayList<String> dirsToAdd = new ArrayList<String>(); 714 715 String dirListFrameName = item.getAbsoluteLink(); 715 716 716 if (dirListFrameName != null) { 717 717 Frame dirListFrame = FrameIO.LoadFrame(dirListFrameName); 718 for (Text t : dirListFrame.getBodyTextItems(false)) { 719 String dirName = t.getTextNoList().trim(); 720 File tester = new File(dirName); 721 if (tester.exists() && tester.isDirectory()) { 722 if (dirName.endsWith(File.separator)) 723 dirsToAdd.add(dirName); 724 else 725 dirsToAdd.add(dirName + File.separator); 718 if (dirListFrame != null) { 719 for (Text t : dirListFrame.getBodyTextItems(false)) { 720 String dirName = t.getTextNoList().trim(); 721 File tester = new File(dirName); 722 if (tester.exists() && tester.isDirectory()) { 723 if (dirName.endsWith(File.separator)) 724 dirsToAdd.add(dirName); 725 else 726 dirsToAdd.add(dirName + File.separator); 727 } 726 728 } 727 729 } … … 916 918 // remove dots of size 1 917 919 if (i instanceof Dot) { 918 Dot dot = (Dot) i;920 Item dot = (Item) i; 919 921 if (dot.getSize() <= 1 920 922 && (dot.getLines() == null || dot.getLines() … … 1029 1031 // names have copy permissions only 1030 1032 if (i == toCheck.getFrameNameItem()) { 1031 i.Permission = Item.PERMISSION_TDFC;1033 //i.Permission = Item.PERMISSION_TDFC; 1032 1034 possibles.add(i); 1033 1035 } else { 1034 i.Permission = Item.PERMISSION_FULL;1036 //i.Permission = Item.PERMISSION_FULL; 1035 1037 possibles.add(i); 1036 1038 } … … 1056 1058 } 1057 1059 1060 // if there are no possible items, return null 1061 if (possibles.size() == 0) 1062 return null; 1063 1058 1064 // if there is only one possibility, return it 1059 1065 if (possibles.size() == 1) 1060 1066 return possibles.get(0); 1061 1062 // if there are no possible items, return null1063 if (possibles.size() == 0)1064 return null;1065 1067 1066 1068 // return closest x,y pair to mouse … … 1076 1078 + Math.pow(Math.abs(i.getY() - y), 2)); 1077 1079 1078 if (d < distance) {1080 if (d <= distance) { 1079 1081 distance = d; 1080 1082 1081 1083 // dots take precedence over lines 1082 /**1083 * TODO: Remove line\dot specification1084 */1085 1084 if ((!(closest instanceof Dot && i instanceof Line)) 1086 1085 && (!(closest instanceof Text && i instanceof Line))) … … 1101 1100 public static List<Item> getCurrentItems() { 1102 1101 1103 List<Item> enclosure = getEnclosingDots();1102 Collection<Item> enclosure = getEnclosingDots(); 1104 1103 if (enclosure == null || enclosure.size() == 0) 1105 1104 return null; 1106 1105 1106 Item firstItem = enclosure.iterator().next(); 1107 1107 1108 List<Item> enclosed = getItemsEnclosedBy(DisplayIO.getCurrentFrame(), 1108 enclosure.get(0).getEnclosedShape());1109 firstItem.getEnclosedShape()); 1109 1110 for (Item i : enclosed) { 1110 1111 if (!enclosure.contains(i)) … … 1115 1116 } 1116 1117 1117 public static List<Item> getEnclosingDots() {1118 public static Collection<Item> getEnclosingDots() { 1118 1119 // update enclosed shapes 1119 1120 Frame current = DisplayIO.getCurrentFrame(); 1120 1121 List<Item> items = current.getItems(); 1121 1122 // Remove all items that are connected to freeItems1122 1123 // Remove all items that are connected to freeItems 1123 1124 List<Item> freeItems = new ArrayList<Item>(Frame.FreeItems); 1124 while (freeItems.size() > 0) {1125 while (freeItems.size() > 0) { 1125 1126 Item item = freeItems.get(0); 1126 List<Item> connected = item.getAllConnected();1127 Collection<Item> connected = item.getAllConnected(); 1127 1128 items.removeAll(connected); 1128 1129 freeItems.removeAll(connected); 1129 1130 } 1130 1131 1131 ArrayList<Item> used = new ArrayList<Item>(0); 1132 ArrayList<Item> seen = new ArrayList<Item>(0); 1133 1134 for (Item i : items) 1135 if (i.isLineEnd()) { 1136 if (i.isEnclosed() && !seen.contains(i)) { 1137 Polygon p = i.getEnclosedShape(); 1138 if (p 1139 .contains(DisplayIO.getMouseX(), DisplayIO 1140 .getMouseY())) { 1141 1142 used.add(i); 1143 seen.addAll(i.getEnclosingDots()); 1144 } 1145 } 1146 } 1132 List<Item> used = new ArrayList<Item>(0); 1133 1134 while (items.size() > 0) { 1135 Item i = items.get(0); 1136 items.remove(i); 1137 if (i.isLineEnd() && i.isEnclosed()) { 1138 Polygon p = i.getEnclosedShape(); 1139 if (p.contains(DisplayIO.getMouseX(), DisplayIO.getMouseY())) { 1140 used.add(i); 1141 items.removeAll(i.getEnclosingDots()); 1142 } 1143 } 1144 } 1147 1145 1148 1146 if (used.size() == 0) … … 1214 1212 // if the item is on the frame 1215 1213 if (item.getParent() == frame || item.getParent() == null) { 1216 item.Permission = Item.PERMISSION_FULL;1214 //item.Permission = Item.PERMISSION_FULL; 1217 1215 results.add(item); 1218 1216 // otherwise, it must be on an overlay frame … … 1275 1273 t = profile.addText(xPos, yPos, "@CommentTemplate", null); 1276 1274 t.setColor(Item.COLOR_WHEEL[3]); 1275 1276 yPos += spacing; 1277 t = profile.addText(xPos, yPos, "@StatTemplate", null); 1278 t.setColor(Color.BLACK); 1279 t.setBackgroundColor(new Color(0.9F, 0.9F, 0.9F)); 1280 t.setFamily(Text.MONOSPACED_FONT); 1281 t.setSize(14); 1277 1282 1278 1283 xPos = 600; … … 1329 1334 SessionStats.CreatedFrame(); 1330 1335 } 1331 1336 1332 1337 setTdfcItem(null); 1333 1338 } -
trunk/src/org/expeditee/gui/UserSettings.java
r70 r72 57 57 public static Text TitleTemplate = null; 58 58 59 public static Text StatTemplate = null; 60 59 61 // add default values 60 62 public static void Init() { -
trunk/src/org/expeditee/io/Conversion.java
r71 r72 22 22 public class Conversion { 23 23 24 private static final double FONT_SCALE = 0.85; 25 26 // used for rounding when converting between Sandbox and KMS font sizes. 27 private static final double FONT_ROUNDING = 0.07; 24 private static final int PERCENT_MAX = 100; 25 private static final int RGB_MAX = 255; 26 private static final double RGB_CONVERSION_FACTOR = 2.55; 28 27 29 28 /** … … 61 60 } 62 61 63 float amount = 10f; 62 final float MAX_AMOUNT = 10F; 63 float amount = MAX_AMOUNT; 64 64 if (num.length() > 0) 65 65 amount = Float.parseFloat(num); 66 66 67 if (amount > 10)68 amount = 10;67 if (amount > MAX_AMOUNT) 68 amount = MAX_AMOUNT; 69 69 70 70 float color[] = { 0, 0, 0 }; 71 71 72 72 if (colorCode.toLowerCase().startsWith("red")) 73 color[0] = amount / 10;73 color[0] = amount / MAX_AMOUNT; 74 74 else if (colorCode.toLowerCase().startsWith("green")) 75 color[1] = amount / 10;75 color[1] = amount / MAX_AMOUNT; 76 76 else if (colorCode.toLowerCase().startsWith("blue")) 77 color[2] = amount / 10;77 color[2] = amount / MAX_AMOUNT; 78 78 else 79 //TODO: Should we not throw an error here! 79 80 return current; 80 81 … … 93 94 94 95 int red = (current == null ? 0 : toColorPercent(current.getRed())); 95 int green = (current == null ? 0 : toColorPercent(current.getGreen())); 96 int green = (current == null ? 0 : toColorPercent(current 97 .getGreen())); 96 98 int blue = (current == null ? 0 : toColorPercent(current.getBlue())); 97 99 color[0] = (Integer) Convert(int.class, r, red); … … 109 111 110 112 private static Integer toColorPercent(int rgb) { 111 int percent = (int) Math.round(rgb / 2.55);112 if (percent > 100)113 percent = 100;113 int percent = (int) Math.round(rgb / RGB_CONVERSION_FACTOR); 114 if (percent > PERCENT_MAX) 115 percent = PERCENT_MAX; 114 116 else if (percent < 0) 115 117 percent = 0; 116 118 117 119 return percent; 118 120 } 119 121 120 122 private static Integer toRGB(int percent) { 121 int rgb = (int) Math.round(percent * 2.55);122 if (rgb > 255)123 rgb = 255;123 int rgb = (int) Math.round(percent * RGB_CONVERSION_FACTOR); 124 if (rgb > RGB_MAX) 125 rgb = RGB_MAX; 124 126 else if (rgb < 0) 125 127 rgb = 0; 126 128 127 129 return rgb; 128 130 } 129 131 132 133 130 134 /** 131 135 * Converts the given Color object to the corresponding KMS color code … … 140 144 return null; 141 145 142 int r = (int) ((color.getRed() / 255.0) * 100 + 0.5);143 int g = (int) ((color.getGreen() / 255.0) * 100 + 0.5);144 int b = (int) ((color.getBlue() / 255.0) * 100 + 0.5);146 int r = (int) Math.round((color.getRed() / RGB_CONVERSION_FACTOR)); 147 int g = (int) Math.round((color.getGreen() / RGB_CONVERSION_FACTOR)); 148 int b = (int) Math.round((color.getBlue() / RGB_CONVERSION_FACTOR)); 145 149 146 150 return r + " " + g + " " + b; … … 179 183 break; 180 184 } 181 182 double dsize = font.getSize() / FONT_SCALE; 183 if ((Math.ceil(dsize)) - dsize < FONT_ROUNDING) 184 dsize = Math.ceil(dsize); 185 else 186 dsize = Math.floor(dsize); 187 188 code += (int) dsize; 189 185 186 code += font.getSize(); 190 187 return code; 191 188 } … … 232 229 try { 233 230 int size = Integer.parseInt(fontCode.substring(2)); 234 double dsize = size * FONT_SCALE; 235 if (dsize - ((int) dsize) > FONT_ROUNDING) 236 dsize = Math.ceil(dsize); 237 238 code += (int) dsize; 239 231 //double dsize = size * FONT_SCALE; 232 //if (dsize - ((int) dsize) > FONT_ROUNDING) 233 // dsize = Math.ceil(dsize); 234 235 //code += (int) dsize; 236 code += size; 237 240 238 font = Font.decode(code); 241 239 } catch (NumberFormatException nfe) { … … 368 366 public static Object Convert(Class type, String value, Object orig) { 369 367 // System.out.println("Orig: " + orig); 370 assert (value != null); 368 if (value == null) 369 return null; 371 370 value = value.trim(); 372 371 … … 387 386 try { 388 387 // Find the field and value of colorName 389 Field field = Class.forName("java.awt.Color").getField( 390 value.toLowerCase()); 388 Field[] fields = Class.forName("java.awt.Color").getFields(); 389 Field field = null; 390 for (int i = 0; i < fields.length; i++) { 391 if (fields[i].getName().equalsIgnoreCase(value)) { 392 field = fields[i]; 393 break; 394 } 395 } 391 396 return (Color) field.get(null); 392 397 } catch (Exception e) { … … 482 487 Class[] types = method.getParameterTypes(); 483 488 if (name.equals("setPosition")) { 484 485 489 Point[] p = new Point[1]; 486 490 p[0] = new Point(); … … 493 497 } else { 494 498 assert (current instanceof Point); 499 assert (p.length == 1); 495 500 Point originalPoint = (Point) current; 496 501 p[0].x = (Integer) Convert(int.class, xPos, originalPoint.x); … … 547 552 return null; 548 553 549 if (method == null) { 550 System.out.println("Output: " + output); 551 } 554 assert(method != null); 552 555 553 556 String name = method.getName(); … … 581 584 // covert points 582 585 if (output instanceof Point) 583 return ((Point) output).x + " " 584 + ((Point) output).y; 586 return ((Point) output).x + " " + ((Point) output).y; 585 587 586 588 if (output instanceof Boolean) -
trunk/src/org/expeditee/io/ExpReader.java
r67 r72 145 145 } 146 146 147 newFrame.refreshItemPermissions(); 147 148 _reader.close(); 148 149 newFrame.setChanged(false); -
trunk/src/org/expeditee/io/ItemWriter.java
r4 r72 37 37 38 38 if (toWrite instanceof Dot) 39 writeDot(( Dot) toWrite);39 writeDot((Item) toWrite); 40 40 } 41 41 … … 51 51 52 52 if (toWrite instanceof Dot) 53 writeAnnotationDot(( Dot) toWrite);53 writeAnnotationDot((Item) toWrite); 54 54 } 55 55 … … 63 63 } 64 64 65 protected void writeAnnotationDot( DottoWrite) throws IOException {65 protected void writeAnnotationDot(Item toWrite) throws IOException { 66 66 } 67 67 … … 75 75 } 76 76 77 protected void writeDot( DottoWrite) throws IOException {77 protected void writeDot(Item toWrite) throws IOException { 78 78 } 79 79 -
trunk/src/org/expeditee/io/KMSReader.java
r67 r72 106 106 _ItemTags.put("k", Text.class.getMethod("setJustification", pInt)); 107 107 108 _ItemTags.put("h", Dot.class.getMethod("setThickness", pFloat));108 _ItemTags.put("h", Item.class.getMethod("setThickness", pFloat)); 109 109 _ItemTags.put("l", Item.class.getMethod("setLineIDs", pString)); 110 110 _ItemTags 111 .put("c", Dot.class.getMethod("setConstraintIDs", pString));111 .put("c", Item.class.getMethod("setConstraintIDs", pString)); 112 112 113 113 // Lines and constraints are created differently … … 178 178 System.out.println("Error reading bodyLine: " + next + " " 179 179 + e.getMessage()); 180 e.printStackTrace(); 180 181 } 181 182 … … 188 189 189 190 _reader.close(); 190 191 if (newFrame != null)191 if (newFrame != null){ 192 newFrame.refreshItemPermissions(); 192 193 newFrame.setChanged(false); 193 194 } 194 195 return newFrame; 195 196 } … … 261 262 java.awt.Point startend = separateValues(_data.get("s")); 262 263 263 Dot a = (Dot)_linePoints.get(startend.x);264 Dot b = (Dot)_linePoints.get(startend.y);264 Item a = _linePoints.get(startend.x); 265 Item b = _linePoints.get(startend.y); 265 266 266 267 new Constraint(a, b, idtype.x, idtype.y); … … 488 489 489 490 try { 490 if (vals != null) 491 if (vals != null){ 491 492 toRun.invoke(toMake, vals); 493 } 492 494 } catch (IllegalArgumentException e) { 493 495 // TODO Auto-generated catch block … … 498 500 } catch (InvocationTargetException e) { 499 501 // TODO Auto-generated catch block 502 e.printStackTrace(); 503 } catch (ClassCastException e) { 504 System.out.println(toRun.getName()); 500 505 e.printStackTrace(); 501 506 } -
trunk/src/org/expeditee/io/KMSWriter.java
r67 r72 203 203 204 204 if (i instanceof Dot) { 205 Dot p = (Dot) i;205 Item p = (Item) i; 206 206 207 207 // if there are any constraints to write -
trunk/src/org/expeditee/items/Dot.java
r70 r72 9 9 import java.util.List; 10 10 11 import org.expeditee.gui.DisplayIO; 11 12 import org.expeditee.gui.Frame; 13 import org.expeditee.gui.FrameKeyboardActions; 12 14 13 15 /** … … 90 92 for (Line line : getLines()) 91 93 line.setColor(c); 92 }93 94 public void paintFill(Graphics2D g) {95 if (getFillColor() != null && getEnclosingDots() != null) {96 g.setColor(getFillColor());97 g.fillPolygon(getEnclosedShape());98 }99 94 } 100 95 … … 186 181 187 182 @Override 188 public Dotcopy() {183 public Item copy() { 189 184 Dot copy = new Dot(getX(), getY(), getID()); 190 185 … … 207 202 @Override 208 203 public void setAnnotation(boolean val) { 209 } 210 211 @Override 212 public boolean isAnnotation() { 213 return false; 204 DisplayIO.setCursorPosition(this.getPosition()); 205 //Make all the dots this dot is connected to be annotations 206 for(Item i: getAllConnected()) 207 if (i.isLineEnd()) 208 i._connectedToAnnotation = val; 209 210 FrameKeyboardActions.replaceDot(this, '@'); 214 211 } 215 212 … … 218 215 // if the item being merged with is another Dot 219 216 if (merger instanceof Dot) { 220 Dot dot = (Dot) merger;217 Item dot = (Item) merger; 221 218 merger.setPosition(this.getPosition()); 222 219 // prevent concurrency issues if removing lines … … 231 228 } else { 232 229 // check for duplicated lines as a result of merging 233 Dot check = (Dot) line.getOppositeEnd(dot);230 Item check = (Item) line.getOppositeEnd(dot); 234 231 boolean dup = false; 235 232 -
trunk/src/org/expeditee/items/Item.java
r71 r72 10 10 import java.awt.geom.Area; 11 11 import java.util.ArrayList; 12 import java.util.Collection; 12 13 import java.util.ConcurrentModificationException; 14 import java.util.LinkedHashSet; 13 15 import java.util.LinkedList; 14 16 import java.util.List; … … 37 39 // contains all dots (including this one) that form an enclosure 38 40 // if this dot is part of an enclosing shape 39 private List<Item> _enclosure = null; 41 private Collection<Item> _enclosure = null; 42 43 protected boolean _connectedToAnnotation = false; 40 44 41 45 public static int PERMISSION_NONE = 0; … … 77 81 public static final int XGRAVITY = 3; 78 82 79 public static final int MARGIN_RIGHT = 5;80 81 public static final int MARGIN_LEFT = 20;83 public static final int MARGIN_RIGHT = 2; 84 85 public static final int MARGIN_LEFT = 15; 82 86 83 87 protected static final double DEFAULT_ARROWHEAD_RATIO = 0.5; … … 109 113 110 114 public static final int JUSTIFICATION_NONE = -1; 111 112 // private boolean _isValidLink = true;113 115 114 116 public static final int JUSTIFICATION_FULL = 0; … … 134 136 dest.setActionLeaveFrame(source.getActionLeaveFrame()); 135 137 dest.setActionMark(source.getActionMark()); 136 dest.setAnnotation(source.isAnnotation());137 138 138 139 dest.setBackgroundColor(source.getBackgroundColor()); … … 162 163 163 164 dest.setParent(source.getParent()); 164 dest.setID(source.getParentOrCurrentFrame().getNextItemID()); 165 Frame parent = source.getParentOrCurrentFrame(); 166 // TODO MIKE says maybe we could tighten up and only give items ID's if 167 // their 168 // current ID is negative? 169 if (parent != null) { 170 dest.setID(source.getParentOrCurrentFrame().getNextItemID()); 171 } 165 172 } 166 173 … … 290 297 } 291 298 292 public void addAllConnected( List<Item> connected) {299 public void addAllConnected(Collection<Item> connected) { 293 300 if (!connected.contains(this)) 294 301 connected.add(this); … … 430 437 } 431 438 432 public List<Item> getAllConnected() { 433 List<Item> list = new LinkedList<Item>(); 439 /** 440 * Gets all the items connected to this item. Uses a recursive approach to 441 * search connected points. 442 * 443 * @return 444 */ 445 public Collection<Item> getAllConnected() { 446 Collection<Item> list = new LinkedHashSet<Item>(); 434 447 addAllConnected(list); 435 448 return list; … … 548 561 } 549 562 550 public List<Item> getConnected() {563 public Collection<Item> getConnected() { 551 564 List<Item> conn = new LinkedList<Item>(); 552 565 conn.add(this); … … 820 833 * @return True if this Item is an annotation, False otherwise. 821 834 */ 822 public abstract boolean isAnnotation(); 835 public boolean isAnnotation() { 836 return false; 837 } 823 838 824 839 public boolean isFloating() { … … 913 928 */ 914 929 public abstract void paint(Graphics2D g); 930 931 public void paintFill(Graphics2D g) { 932 if (getFillColor() != null && getEnclosingDots() != null) { 933 g.setColor(getFillColor()); 934 g.fillPolygon(getEnclosedShape()); 935 } 936 } 915 937 916 938 /** … … 1208 1230 */ 1209 1231 public void setLink(String frameName) { 1210 _link = frameName; 1232 if (FrameIO.isValidLink(frameName)) 1233 _link = frameName; 1234 else 1235 FrameGraphics.ErrorMessage("[" + frameName 1236 + "] is not a valid frame name"); 1237 // TODO make this throw exceptions etc... 1211 1238 } 1212 1239 1213 1240 public void setLinkFrameset(String frameset) { 1214 _link_frameset = frameset; 1241 if (frameset == null || FrameIO.isValidFramesetName(frameset)) 1242 _link_frameset = frameset; 1243 else 1244 FrameGraphics.ErrorMessage("[" + frameset 1245 + "] is not a valid frameset name"); 1246 // TODO make this throw exceptions etc... 1215 1247 } 1216 1248 … … 1220 1252 1221 1253 public void setLinkTemplate(String template) { 1222 _link_template = template; 1254 if (FrameIO.isValidLink(template)) 1255 _link_template = template; 1256 else 1257 FrameGraphics.ErrorMessage("[" + template 1258 + "] is not a valid frame name"); 1259 // TODO make this throw exceptions etc... 1223 1260 } 1224 1261 … … 1484 1521 * or null. 1485 1522 */ 1486 public void setEnclosedList( List<Item> enclosed) {1523 public void setEnclosedList(Collection<Item> enclosed) { 1487 1524 _enclosure = enclosed; 1488 1525 } … … 1514 1551 * null if this Dot is not part of an enclosure. 1515 1552 */ 1516 public List<Item> getEnclosingDots() {1553 public Collection<Item> getEnclosingDots() { 1517 1554 return _enclosure; 1518 1555 } … … 1568 1605 return true; 1569 1606 } 1607 1608 public void setConnectedToAnnotation(boolean val) { 1609 _connectedToAnnotation = val; 1610 } 1611 1612 public boolean isConnectedToAnnotation() { 1613 return _connectedToAnnotation; 1614 } 1570 1615 } -
trunk/src/org/expeditee/items/ItemUtils.java
r70 r72 13 13 import java.util.HashMap; 14 14 import java.util.HashSet; 15 import java.util.LinkedHashSet; 15 16 import java.util.LinkedList; 16 17 import java.util.List; … … 21 22 import org.expeditee.gui.DisplayIO; 22 23 import org.expeditee.gui.Frame; 23 import org.expeditee.stats.SessionStats;24 24 25 25 //Static methods that provide functions for the objects\ … … 70 70 public static final int TAG_LINE_TEMPLATE = 17; 71 71 72 public static final int TAG_STAT_TEMPLATE = 18; 73 72 74 public static final int TAG_MIN = 0; 73 75 74 public static final int TAG_MAX = 1 7;76 public static final int TAG_MAX = 18; 75 77 76 78 /** … … 164 166 return isTag(toCheck, GetTag(tag)); 165 167 } 166 168 167 169 public static boolean isTag(Item toCheck, int tag, boolean hasValue) { 168 170 return isTag(toCheck, GetTag(tag), hasValue); … … 187 189 // tags are ase-insensitive 188 190 return String.CASE_INSENSITIVE_ORDER.compare(txt.getFirstLine().trim(), 189 tag) == 0 || (hasValue && txt.startsWith(tag + " ", true)); 191 tag) == 0 192 || (hasValue && txt.startsWith(tag + " ", true)); 190 193 } 191 194 … … 272 275 */ 273 276 public static String GetTag(int tag) { 277 // TODO refactor so that this uses a map for INT to tags 274 278 switch (tag) { 275 279 case TAG_SORT: … … 289 293 case TAG_ANNOTATION_TEMPLATE: 290 294 return "@annotationtemplate"; 295 case TAG_STAT_TEMPLATE: 296 return "@stattemplate"; 291 297 case TAG_CODE_COMMENT_TEMPLATE: 292 298 return "@commenttemplate"; … … 618 624 copy.removeAllConstraints(); 619 625 620 int num = 0;621 622 // Mike: WHAT IS THIS CODE DOING?!!?623 for (Line line : origEnd.getLines())624 num = Math.min(num, line.getID());625 626 num--;627 628 626 // create a new line 629 Line line = new Line(origEnd, copy, num); 627 Line line = new Line(origEnd, copy, DisplayIO.getCurrentFrame() 628 .getNextItemID()); 630 629 // copy.setFloating(true); 631 630 origEnd.setArrowheadLength(0); … … 636 635 toReturn.add(line); 637 636 return toReturn; 637 } 638 639 public static void New() { 640 EnclosedCheck(DisplayIO.getCurrentFrame().getItems()); 641 } 642 643 public static void Old() { 644 OldEnclosedCheck(DisplayIO.getCurrentFrame().getItems()); 645 } 646 647 /** 648 * Updates the connectedToAnnotation flags for all items 649 */ 650 public static void UpdateConnectedToAnnotations(Collection<Item> items) { 651 // get all lineEnds on the Frame 652 Collection<Item> lineEnds = new LinkedHashSet<Item>(); 653 for (Item i : items) { 654 i.setConnectedToAnnotation(false); 655 if (i.isLineEnd()) { 656 lineEnds.add(i); 657 } 658 } 659 660 // if there are no line endpoints on the Frame, then there can't be an 661 // enclosure 662 if (lineEnds.size() == 0) 663 return; 664 665 // Now find go through line ends and see if any are annotation items 666 while (lineEnds.size() > 0) { 667 Item item = lineEnds.iterator().next(); 668 // If its an annotation item then set the flag for all its connected 669 // items 670 if (item.isAnnotation()) { 671 Collection<Item> connected = item.getAllConnected(); 672 for (Item i : connected) 673 i.setConnectedToAnnotation(true); 674 lineEnds.removeAll(connected); 675 } 676 lineEnds.remove(item); 677 } 638 678 } 639 679 … … 646 686 * is done dynamically (to account for Dots being moved). 647 687 */ 648 public static void EnclosedCheck(List<Item> items) { 688 public static void EnclosedCheck(Collection<Item> items) { 689 // get all lineEnds on the Frame 690 List<Item> lineEnds = new LinkedList<Item>(); 691 for (Item i : items) { 692 if (i.isLineEnd()) { 693 i.setEnclosedList(null); 694 // Add line ends joined to 2 other lines 695 if (i.getLines().size() == 2) 696 lineEnds.add(i); 697 } 698 } 699 700 // if there are no line endpoints on the Frame, then there can't be an 701 // enclosure 702 if (lineEnds.size() == 0) 703 return; 704 705 // New approach 706 while (lineEnds.size() > 0) { 707 Item item = lineEnds.get(0); 708 // Get the lineEnds connected to this item 709 Collection<Item> connected = item.getAllConnected(); 710 Collection<Item> connectedLineEnds = new LinkedHashSet<Item>(); 711 for (Item itemToCheck : connected) { 712 if (itemToCheck.isLineEnd()) 713 connectedLineEnds.add(itemToCheck); 714 } 715 // Check that all the line ends are in our lineEnds list 716 int oldSize = lineEnds.size(); 717 // Remove all the items from our line ends list 718 lineEnds.removeAll(connectedLineEnds); 719 int newSize = lineEnds.size(); 720 int connectedSize = connectedLineEnds.size(); 721 // Check if all the connectedItems were in the lineEnds collection 722 if (oldSize == newSize + connectedSize) { 723 // Set them to be the enclosed list for each of the items 724 for (Item enclosedLineEnd : connectedLineEnds) { 725 enclosedLineEnd.setEnclosedList(connectedLineEnds); 726 } 727 } 728 729 } 730 } 731 732 /** 733 * Checks through all Lines and Dots on the current Frame to detect if any 734 * form an enclosure, which can then be used to manipulate items within the 735 * polygon. If an enclosure is found, then the dots will have their 736 * enclosure value set to true, and a List is created that contains all the 737 * Dots in the order they were processed. Actual calculation of the Polygon 738 * is done dynamically (to account for Dots being moved). 739 */ 740 public static void OldEnclosedCheck(Collection<Item> items) { 649 741 _seen.clear(); 650 742 -
trunk/src/org/expeditee/items/Line.java
r50 r72 12 12 import java.awt.geom.AffineTransform; 13 13 import java.util.ArrayList; 14 import java.util.Collection; 14 15 import java.util.List; 15 16 … … 586 587 @Override 587 588 public void setAnnotation(boolean val) { 589 if (_end.isAnnotation() != val) 590 _end.setAnnotation(val); 591 else if (_start instanceof Text && _start.isAnnotation() != val) 592 _start.setAnnotation(val); 588 593 } 589 594 590 595 @Override 591 596 public boolean isAnnotation() { 592 return false; 597 return _start.isAnnotation() || _end.isAnnotation(); 598 } 599 600 @Override 601 public boolean isConnectedToAnnotation() { 602 return _start.isConnectedToAnnotation() 603 || _end.isConnectedToAnnotation(); 593 604 } 594 605 … … 740 751 } 741 752 742 private Dot_virtualSpot = null;753 private Item _virtualSpot = null; 743 754 744 755 public void showVirtualSpot(Item orig, int mouseX, int mouseY) { … … 750 761 return; 751 762 752 Dotspot = new Dot(-1, orig.getX(), orig.getY());763 Item spot = new Dot(-1, orig.getX(), orig.getY()); 753 764 Item.DuplicateItem(orig, spot); 754 765 spot.setThickness(Math.max(this.getThickness(), 5)); … … 789 800 790 801 public void showVirtualSpot(int mouseX, int mouseY) { 791 Dotspot = new Dot(mouseX, mouseY, -1);802 Item spot = new Dot(mouseX, mouseY, -1); 792 803 spot.setThickness(Math.max(this.getThickness(), 5)); 793 804 if (this.getColor() != Color.RED) … … 898 909 899 910 @Override 900 public List<Item> getConnected() {911 public Collection<Item> getConnected() { 901 912 return getAllConnected(); 902 913 } 903 914 904 public List<Item> getAllConnected() { 905 ArrayList<Item> list = new ArrayList<Item>(); 906 addAllConnected(list); 907 return list; 908 } 909 910 public void addAllConnected(List<Item> connected) { 915 @Override 916 public void addAllConnected(Collection<Item> connected) { 911 917 if (!connected.contains(this)) 912 918 connected.add(this); … … 971 977 */ 972 978 973 Dots = new Dot(_start.getX(), _start.getY(), -1);974 Dote = new Dot(_end.getX(), _end.getY(), -1);979 Item s = new Dot(_start.getX(), _start.getY(), -1); 980 Item e = new Dot(_end.getX(), _end.getY(), -1); 975 981 976 982 one = s.getPolygon().getBounds(); 977 983 two = e.getPolygon().getBounds(); 978 984 } else { 979 Dots = new Dot(_start.getX(), _start.getY(), -1);980 Dote = new Dot(_end.getX(), _end.getY(), -1);985 Item s = new Dot(_start.getX(), _start.getY(), -1); 986 Item e = new Dot(_end.getX(), _end.getY(), -1); 981 987 982 988 one = e.getPolygon().getBounds(); -
trunk/src/org/expeditee/items/Picture.java
r24 r72 530 530 @Override 531 531 public void setAnnotation(boolean val) { 532 // TODO Auto-generated method stub533 534 }535 536 @Override537 public boolean isAnnotation() {538 // TODO Auto-generated method stub539 return false;540 532 } 541 533 -
trunk/src/org/expeditee/items/Text.java
r71 r72 22 22 import java.util.List; 23 23 24 import org.expeditee.gui.DisplayIO; 24 25 import org.expeditee.gui.FrameGraphics; 26 import org.expeditee.gui.FrameKeyboardActions; 25 27 import org.expeditee.gui.FrameMouseActions; 26 28 … … 745 747 } 746 748 749 public static final String MONOSPACED_FONT = "monospaced"; 750 747 751 public static final String[] FONT_WHEEL = { "sansserif", "monospaced", 748 752 "serif", "dialog", "dialoginput" }; … … 751 755 752 756 private static final int NEARBY_GRAVITY = 2; 757 758 private static final int MINIMUM_FONT_SIZE = 8; 753 759 754 760 public void toggleFontFamily() { … … 939 945 } 940 946 941 // check if the cursor is on the left border of the bounding box942 if (Math.abs(mouseX - LEFT_MARGIN - outline.x) <= gravity) {943 return true;944 }945 946 947 for (TextLayout text : _textLayouts) { 947 948 // check left and right of each box … … 953 954 if (mouseY - textY > textOutline.y 954 955 && mouseY - textY < textOutline.y + textOutline.height 955 && mouseX - textX < textOutline.width + gravity) 956 && mouseX - textX < textOutline.width + gravity 957 + Item.MARGIN_RIGHT) 956 958 return true; 957 959 textY += getLineDrop(text); … … 999 1001 } 1000 1002 1001 minX -= Item.MARGIN_RIGHT; 1002 1003 if (getWidth() > 0) 1004 maxX = getWidth(); 1003 minX -= getLeftMargin(); 1004 maxX += Item.MARGIN_RIGHT; 1005 1005 1006 1006 _poly.addPoint(minX - getGravity(), minY - getGravity()); … … 1008 1008 _poly.addPoint(maxX + getGravity(), maxY + getGravity()); 1009 1009 _poly.addPoint(minX - getGravity(), maxY + getGravity()); 1010 1011 // _poly.addPoint(minX, minY); 1012 // _poly.addPoint(maxX, minY); 1013 // _poly.addPoint(maxX, maxY); 1014 // _poly.addPoint(minX, maxY); 1010 } 1011 1012 /** 1013 * Gets the distance between the start of the text and the left border of 1014 * the item. This distance changes depending on whether or not the item is 1015 * linked or has an associated action. 1016 * 1017 * @return the gap size in pixels 1018 */ 1019 private int getLeftMargin() { 1020 return ((getLinkMark() && getLink() != null) 1021 || (getActionMark() && getAction() != null) ? Item.MARGIN_LEFT 1022 - Item.MARGIN_RIGHT : Item.MARGIN_RIGHT); 1015 1023 } 1016 1024 … … 1389 1397 @Override 1390 1398 public void setSize(int size) { 1391 setFont(getPaintFont().deriveFont((float) size)); 1399 if (size >= MINIMUM_FONT_SIZE) 1400 setFont(getPaintFont().deriveFont((float) size)); 1392 1401 } 1393 1402 … … 1399 1408 return; 1400 1409 1401 /*1402 * // Remove 'a: ' from the begining if it is there if1403 * (_text.length() > 3 && _text.charAt(0) == 'a' && _text.charAt(1) ==1404 * ':') { _text.delete(0, 2); while (_text.charAt(0) == ' ')1405 * _text.delete(0, 1); }1406 */1407 1410 _text.insert(0, "@"); 1408 1411 … … 1418 1421 return; 1419 1422 1423 if (_text.length() == 1) { 1424 // Remove and replace with a dot 1425 FrameKeyboardActions.replaceText(this); 1426 1427 DisplayIO.setCursorPosition(this.getPosition()); 1428 return; 1429 } 1430 1420 1431 _text.deleteCharAt(0); 1421 1432 … … 1432 1443 @Override 1433 1444 public boolean isAnnotation() { 1434 if (_text != null && _text.length() > 0 && _text. indexOf("@") == 0)1445 if (_text != null && _text.length() > 0 && _text.charAt(0) == '@') 1435 1446 return true; 1436 1447 -
trunk/src/org/expeditee/stats/SessionStats.java
r70 r72 6 6 import java.text.SimpleDateFormat; 7 7 import java.util.ArrayList; 8 import java.util.Collection; 8 9 import java.util.Date; 9 10 import java.util.List; … … 21 22 public class SessionStats { 22 23 24 private static final int DEFAULT_RATE_WIDTH = 4; 25 26 private static final int DEFAULT_VALUE_WIDTH = 3; 27 23 28 public enum ItemType { 24 29 Text, Dot, Picture, Line; … … 71 76 72 77 private static final int[] EVENT_INTERVALS = new int[] { 1, 2, 3, 4, 5, 10, 73 20, 30, 40, 50, 60, 120, 180, 240, 300, 600, Integer.MAX_VALUE };78 20, 60, 300, 600, Integer.MAX_VALUE }; 74 79 75 80 private static int[] _EventTimes = new int[EVENT_INTERVALS.length]; … … 85 90 "-->" + _DarkTime.getTime() * 100 / elapsedTime + "%\n"); 86 91 92 stats.append(getResponseStats()).append("\n"); 87 93 stats.append(getFrameStats()); 88 stats.append(getResponseStats()).append("\n");89 94 90 95 stats.append(getCharacterStats()); … … 129 134 private static String getFrameStats(boolean newline) { 130 135 StringBuffer stats = new StringBuffer(); 131 appendStat(stats, "FramesAccessed", _AccessedFrames, newline); 132 appendStat(stats, "FramesEdited", _SavedFrames, newline); 136 appendStat(stats, "FramesAccessed", _AccessedFrames, newline, false, DEFAULT_VALUE_WIDTH, 137 DEFAULT_RATE_WIDTH); 138 appendStat(stats, "FramesEdited", _SavedFrames, newline, false, DEFAULT_VALUE_WIDTH, DEFAULT_RATE_WIDTH); 133 139 return stats.toString(); 134 140 } … … 168 174 appendStat(stats, "Words", punct + EOS); 169 175 appendStat(stats, "Sentences", EOS); 170 appendStat(stats, "Text ",176 appendStat(stats, "TextItems", 171 177 _ItemStats[ItemType.Text.ordinal()][StatType.Created.ordinal()]); 172 178 appendStat(stats, "Frames", _CreatedFrames); … … 192 198 */ 193 199 private static void appendStat(StringBuffer stats, String name, int value, 194 boolean newline) { 200 boolean newline, boolean ignoreZero, int minValueWidth, 201 int minRateWidth) { 195 202 // prevent divide by zero errors 196 if ( value <= 0)203 if (ignoreZero && value <= 0) 197 204 return; 198 205 199 int perHour = (int) (value * 60 / getMinutesUsed()); 200 201 stats.append(value).append(" ").append(name).append(" @ ").append( 202 perHour).append("/hour"); 206 String perHour = getRate(value); 207 while (perHour.length() < minRateWidth) 208 perHour = " " + perHour; 209 String valueString = "" + value; 210 while (valueString.length() < minValueWidth) 211 valueString = " " + valueString; 212 stats.append(valueString).append(" @ ").append(perHour.toString()) 213 .append("/hour ").append(name); 203 214 if (newline) 204 215 stats.append("\n"); … … 207 218 208 219 } 220 221 private static String getRate(int value){ 222 return "" + Math.round(value * 60 / getMinutesUsed()); 223 } 209 224 210 225 private static void appendStat(StringBuffer stats, String name, int value) { 211 appendStat(stats, name, value, true );226 appendStat(stats, name, value, true, false, DEFAULT_VALUE_WIDTH, DEFAULT_RATE_WIDTH); 212 227 } 213 228 … … 321 336 } 322 337 323 private static void ItemStats( List<Item> items, StatType stat) {338 private static void ItemStats(Collection<Item> items, StatType stat) { 324 339 if (items == null) 325 340 return; … … 336 351 } 337 352 338 public static void CreatedItems( List<Item> items) {353 public static void CreatedItems(Collection<Item> items) { 339 354 ItemStats(items, StatType.Created); 340 355 } 341 356 342 public static void MovedItems( List<Item> items) {357 public static void MovedItems(Collection<Item> items) { 343 358 ItemStats(items, StatType.Moved); 344 359 } 345 360 346 public static void CopiedItems( List<Item> items) {361 public static void CopiedItems(Collection<Item> items) { 347 362 ItemStats(items, StatType.Copied); 348 363 } 349 364 350 public static void DeletedItems( List<Item> items) {365 public static void DeletedItems(Collection<Item> items) { 351 366 ItemStats(items, StatType.Deleted); 352 367 } … … 358 373 public static String getItemStats() { 359 374 StringBuffer stats = getSessionDateTime(); 360 375 int max = 0; 376 for (int i = 0; i < STAT_TYPES; i++) { 377 for (int j = 0; j < ITEM_TYPES; j++) { 378 if (_ItemStats[j][i] > max) 379 max = _ItemStats[j][i]; 380 } 381 } 382 int maxWidthValue = ("" + max).length(); 383 int maxWidthRate = (getRate(max)).length(); 384 361 385 for (int i = 0; i < STAT_TYPES; i++) { 362 386 int total = 0; … … 374 398 // statType > 1 375 399 if (nonZeroItems > 1) 376 appendStat(stats, "Total" + statName, total );377 } 378 400 appendStat(stats, "Total" + statName, total, true, false, maxWidthValue , maxWidthRate); 401 } 402 stats.deleteCharAt(stats.length() - 1); 379 403 return stats.toString(); 380 404 } … … 382 406 public static String getEventStats() { 383 407 StringBuffer stats = getSessionDateTime(); 408 int max = getMax(_EventTimes); 409 int maxWidthEvents = ("" + max).length(); 410 int maxWidthRate = (getRate(max)).length(); 384 411 for (int i = 0; i < _EventTimes.length - 1; i++) { 385 412 String upperBound = getFormattedTime(EVENT_INTERVALS[i]); 386 appendStat(stats, "<" + upperBound, _EventTimes[i]); 413 appendStat(stats, "<" + upperBound, _EventTimes[i], true, false, 414 maxWidthEvents,maxWidthRate); 387 415 } 388 416 int lastIndex = EVENT_INTERVALS.length - 1; 389 appendStat(stats, getFormattedTime(EVENT_INTERVALS[lastIndex - 1]) 390 + "+", _EventTimes[lastIndex]); 417 appendStat(stats, "+" 418 + getFormattedTime(EVENT_INTERVALS[lastIndex - 1]), 419 _EventTimes[lastIndex], false, false, maxWidthEvents,maxWidthRate); 391 420 return stats.toString(); 421 } 422 423 /** 424 * Gets the highest number in the list of numbers. 425 * 426 * @param nums list of numbers 427 * @return highest number in the list 428 */ 429 private static int getMax(int[] nums) { 430 int max = 0; 431 for (int i = 0; i < nums.length; i++) 432 if (nums[i] > max) 433 max = nums[i]; 434 return max; 392 435 } 393 436 … … 401 444 time = (secs / 60 / 60) + "h"; 402 445 } 446 if (time.length() == 2) 447 time = " " + time; 403 448 return time; 404 449 } … … 424 469 _EventTimes[_EventTimes.length - 1]++; 425 470 } 471 472 public static void DeletedItem(Item toDelete) { 473 List<Item> items = new ArrayList<Item>(); 474 items.add(toDelete); 475 DeletedItems(items); 476 } 426 477 } -
trunk/tests/org/expeditee/gui/FrameIOTest.java
r67 r72 19 19 20 20 public void testIsValidFramesetName() { 21 assertTrue(FrameIO. IsValidFramesetName("a"));22 assertTrue(FrameIO. IsValidFramesetName("a1c"));23 assertFalse(FrameIO. IsValidFramesetName("1a"));24 assertFalse(FrameIO. IsValidFramesetName("$a"));25 assertFalse(FrameIO. IsValidFramesetName("a$"));26 assertFalse(FrameIO. IsValidFramesetName("a.a"));27 assertFalse(FrameIO. IsValidFramesetName(null));28 assertFalse(FrameIO. IsValidFramesetName("1"));21 assertTrue(FrameIO.isValidFramesetName("a")); 22 assertTrue(FrameIO.isValidFramesetName("a1c")); 23 assertFalse(FrameIO.isValidFramesetName("1a")); 24 assertFalse(FrameIO.isValidFramesetName("$a")); 25 assertFalse(FrameIO.isValidFramesetName("a$")); 26 assertFalse(FrameIO.isValidFramesetName("a.a")); 27 assertFalse(FrameIO.isValidFramesetName(null)); 28 assertFalse(FrameIO.isValidFramesetName("1")); 29 29 assertFalse(FrameIO.isValidFrameName("")); 30 30 assertFalse(FrameIO 31 . IsValidFramesetName("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz012345678901A"));31 .isValidFramesetName("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz012345678901A")); 32 32 33 33 } -
trunk/tests/org/expeditee/io/ConversionTest.java
r67 r72 3 3 import java.awt.Color; 4 4 import java.awt.Font; 5 import java.awt.Point; 6 import java.util.ArrayList; 7 import java.util.List; 5 8 6 9 import junit.framework.TestCase; 7 10 8 11 import org.expeditee.items.Item; 12 import org.expeditee.items.Text; 9 13 10 14 public class ConversionTest extends TestCase { 11 15 12 16 public final void testGetColor() { 13 assertTrue(Conversion.getColor("100 0 0", Color.white).equals(Color.red)); 14 assertTrue(Conversion.getColor("0 100 0", Color.white).equals(Color.green)); 15 assertTrue(Conversion.getColor("0 0 100", Color.white).equals(Color.blue)); 16 assertTrue(Conversion.getColor("100 100 100", Color.white).equals(Color.white)); 17 assertEquals(Color.green,Conversion.getColor("-100 0 100", Color.white)); 18 assertEquals(Conversion.getColor("+0 100 0", Color.black),Color.green); 17 assertTrue(Conversion.getColor("100 0 0", Color.white) 18 .equals(Color.red)); 19 assertTrue(Conversion.getColor("0 100 0", Color.white).equals( 20 Color.green)); 21 assertTrue(Conversion.getColor("0 0 100", Color.white).equals( 22 Color.blue)); 23 assertTrue(Conversion.getColor("100 100 100", Color.white).equals( 24 Color.white)); 25 assertEquals(Color.green, Conversion.getColor("-100 +0 -100", 26 Color.white)); 27 assertEquals(Conversion.getColor("+0 +100 +0", Color.black), 28 Color.green); 19 29 assertEquals(Color.white, Conversion.getColor("a0a0a0", Color.white)); 20 assertEquals(Conversion.getColor("red9", Color.white),new Color(0.9F, 0.0F, 0.0F)); 21 assertEquals(Conversion.getColor("BlUe15", Color.white),new Color(0.0F, 0.0F, 1.0F)); 22 assertEquals(Conversion.getColor("GREEN0", Color.white),new Color(0.0F, 0.0F, 0.0F)); 30 assertEquals(Conversion.getColor("red9", Color.white), new Color(0.9F, 31 0.0F, 0.0F)); 32 assertEquals(Conversion.getColor("BlUe15", Color.white), new Color( 33 0.0F, 0.0F, 1.0F)); 34 assertEquals(Conversion.getColor("GREEN0", Color.white), new Color( 35 0.0F, 0.0F, 0.0F)); 36 assertEquals(Color.red, Conversion.getColor("adf", Color.red)); 37 assertEquals(Color.red, Conversion.getColor("none", Color.red)); 38 assertEquals(Color.red, Conversion.getColor("null", Color.red)); 39 assertEquals(Color.red, Conversion.getColor(null, Color.red)); 23 40 } 24 41 … … 29 46 } 30 47 31 /*public final void testAdjustIntInt() {32 fail("Not yet implemented");33 }34 35 public final void testAdjustPoint() {36 fail("Not yet implemented");37 }38 39 public final void testDeAdjust() {40 fail("Not yet implemented");41 }42 43 48 public final void testGetKMSFontCode() { 44 fail("Not yet implemented"); 49 Font testFont = new Font(Text.FONT_WHEEL[1], Font.BOLD, 18); 50 Font testFont2 = new Font(Text.FONT_WHEEL[4], Font.ITALIC, 20); 51 Font testFont3 = new Font("xxx123", Font.ITALIC | Font.BOLD, 52 10); 53 Font testFont4 = new Font(Text.FONT_WHEEL[0], Font.PLAIN, 2); 54 55 String result = Text.FONT_CHARS[1] + "b18"; 56 assertEquals(result, Conversion.getKMSFontCode(testFont)); 57 58 result = Text.FONT_CHARS[4] + "i20"; 59 assertEquals(result, Conversion.getKMSFontCode(testFont2)); 60 61 result = "dp10"; 62 assertEquals(result, Conversion.getKMSFontCode(testFont3)); 63 64 result = Text.FONT_CHARS[0] + "r2"; 65 assertEquals(result, Conversion.getKMSFontCode(testFont4)); 45 66 } 46 67 47 68 public final void testGetFont() { 48 fail("Not yet implemented"); 49 }*/ 69 Font testFont = new Font(Text.FONT_WHEEL[1], Font.BOLD, 18); 70 Font testFont2 = new Font(Text.FONT_WHEEL[4], Font.ITALIC, 20); 71 Font testFont3 = new Font(Text.FONT_WHEEL[3], Font.ITALIC | Font.BOLD, 72 10); 73 Font testFont4 = new Font(Text.FONT_WHEEL[0], Font.PLAIN, 2); 74 75 String code = Text.FONT_CHARS[1] + "b18"; 76 assertEquals(testFont, Conversion.getFont(code)); 77 78 code = Text.FONT_CHARS[4] + "i20"; 79 assertEquals(testFont2, Conversion.getFont(code)); 80 81 code = Text.FONT_CHARS[3] + "p10"; 82 assertEquals(testFont3, Conversion.getFont(code)); 83 84 code = Text.FONT_CHARS[0] + "r2"; 85 assertEquals(testFont4, Conversion.getFont(code)); 86 } 50 87 51 88 public final void testGetFrameNumber() { … … 65 102 66 103 public final void testGetJustification() { 67 assertEquals(Item.JUSTIFICATION_CENTER, Conversion.getJustification("center")); 68 assertEquals(Item.JUSTIFICATION_CENTER, Conversion.getJustification("c")); 104 assertEquals(Item.JUSTIFICATION_CENTER, Conversion 105 .getJustification("center")); 106 assertEquals(Item.JUSTIFICATION_CENTER, Conversion 107 .getJustification("c")); 69 108 assertEquals(Item.JUSTIFICATION_RIGHT, Conversion.getJustification("R")); 70 assertEquals(Item.JUSTIFICATION_RIGHT, Conversion.getJustification("RIGHT")); 109 assertEquals(Item.JUSTIFICATION_RIGHT, Conversion 110 .getJustification("RIGHT")); 71 111 assertEquals(Item.JUSTIFICATION_LEFT, Conversion.getJustification("L")); 72 assertEquals(Item.JUSTIFICATION_LEFT, Conversion.getJustification("lEfT")); 112 assertEquals(Item.JUSTIFICATION_LEFT, Conversion 113 .getJustification("lEfT")); 73 114 assertEquals(Item.JUSTIFICATION_FULL, Conversion.getJustification("f")); 74 assertEquals(Item.JUSTIFICATION_FULL, Conversion.getJustification("FuLl")); 75 assertEquals(Item.JUSTIFICATION_NONE, Conversion.getJustification("NONE")); 115 assertEquals(Item.JUSTIFICATION_FULL, Conversion 116 .getJustification("FuLl")); 117 assertEquals(Item.JUSTIFICATION_NONE, Conversion 118 .getJustification("NONE")); 76 119 } 77 120 78 121 public final void testGetKMSJustificationCode() { 79 assertEquals("C", Conversion.getKMSJustificationCode(Item.JUSTIFICATION_CENTER)); 80 assertEquals("L", Conversion.getKMSJustificationCode(Item.JUSTIFICATION_LEFT)); 81 assertEquals("R", Conversion.getKMSJustificationCode(Item.JUSTIFICATION_RIGHT)); 82 assertEquals("F", Conversion.getKMSJustificationCode(Item.JUSTIFICATION_FULL)); 83 assertEquals(null, Conversion.getKMSJustificationCode(Item.JUSTIFICATION_NONE)); 84 assertEquals(null, Conversion.getKMSJustificationCode(Integer.MAX_VALUE)); 85 assertEquals(null, Conversion.getKMSJustificationCode(Integer.MIN_VALUE)); 122 assertEquals("C", Conversion 123 .getKMSJustificationCode(Item.JUSTIFICATION_CENTER)); 124 assertEquals("L", Conversion 125 .getKMSJustificationCode(Item.JUSTIFICATION_LEFT)); 126 assertEquals("R", Conversion 127 .getKMSJustificationCode(Item.JUSTIFICATION_RIGHT)); 128 assertEquals("F", Conversion 129 .getKMSJustificationCode(Item.JUSTIFICATION_FULL)); 130 assertEquals(null, Conversion 131 .getKMSJustificationCode(Item.JUSTIFICATION_NONE)); 132 assertEquals(null, Conversion 133 .getKMSJustificationCode(Integer.MAX_VALUE)); 134 assertEquals(null, Conversion 135 .getKMSJustificationCode(Integer.MIN_VALUE)); 86 136 } 87 137 … … 89 139 assertEquals("Test", Conversion.Convert(String.class, "Test")); 90 140 assertEquals(null, Conversion.Convert(String.class, "")); 91 assertEquals(Conversion.getFont("tr16"), Conversion.Convert(Font.class, "tr16")); 141 assertEquals(Conversion.getFont("tr16"), Conversion.Convert(Font.class, 142 "tr16")); 143 // Test Color Conversion 144 assertEquals(Color.darkGray, Conversion.Convert(Color.class, 145 "dark_gray")); 146 assertEquals(Color.darkGray, Conversion 147 .Convert(Color.class, "DARKGRAY")); 92 148 assertEquals(Color.red, Conversion.Convert(Color.class, "red")); 93 149 assertEquals(Color.red, Conversion.Convert(Color.class, "Red")); … … 96 152 assertEquals(Color.green, Conversion.Convert(Color.class, "0 100")); 97 153 assertEquals(Color.blue, Conversion.Convert(Color.class, "0 0 100")); 154 // Test Boolean Conversion 155 assertEquals(true, Conversion.Convert(boolean.class, "tRuE")); 156 assertEquals(true, Conversion.Convert(boolean.class, "T")); 157 assertEquals(true, Conversion.Convert(boolean.class, "yes")); 158 assertEquals(true, Conversion.Convert(boolean.class, "Y")); 159 assertEquals(true, Conversion.Convert(boolean.class, "")); 160 assertEquals(false, Conversion.Convert(boolean.class, "FALSE")); 161 assertEquals(false, Conversion.Convert(boolean.class, "no")); 162 assertEquals(false, Conversion.Convert(boolean.class, "n")); 163 assertEquals(false, Conversion.Convert(boolean.class, "f")); 98 164 } 99 165 100 166 public final void testConvertClassStringObject() { 101 assertEquals(Color.red, Conversion.Convert(Color.class, "+100 0 -100", Color.blue)); 102 assertEquals(Color.black, Conversion.Convert(Color.class, "-0 0 100", Color.blue)); 103 //TODO add more stuff to here 167 assertEquals(Color.red, Conversion.Convert(Color.class, "+100 +0 -100", 168 Color.blue)); 169 assertEquals(Color.black, Conversion.Convert(Color.class, "-0 +0 -100", 170 Color.blue)); 171 // Float test 172 assertEquals(2.0F, Conversion.Convert(float.class, "2.0", null)); 173 assertEquals(-8.0F, Conversion.Convert(float.class, "+2.0", -10.0F)); 174 assertEquals(8.0F, Conversion.Convert(float.class, "-2.0", 10.0F)); 175 // Double test 176 assertEquals(2.0, Conversion.Convert(double.class, "2.0", null)); 177 assertEquals(-8.0, Conversion.Convert(double.class, "+2.0", -10.0)); 178 assertEquals(8.0, Conversion.Convert(double.class, "-2.0", 10.0)); 179 // Integer test 180 assertEquals(2, Conversion.Convert(int.class, "2", null)); 181 assertEquals(-8, Conversion.Convert(int.class, "+2", -10)); 182 assertEquals(8, Conversion.Convert(int.class, "-2", 10)); 104 183 } 105 184 … … 111 190 112 191 public final void testConvertToKMS() { 192 try { 193 java.lang.reflect.Method getPosition = Item.class.getMethod( 194 "getPosition", new Class[] {}); 195 java.lang.reflect.Method getJustification = Text.class.getMethod( 196 "getJustification", new Class[] {}); 197 198 assertEquals("C", Conversion.ConvertToKMS(getJustification, 199 Item.JUSTIFICATION_CENTER)); 200 201 assertEquals("Test", Conversion.ConvertToKMS(getPosition, 202 (Object) "Test")); 203 assertEquals("0", Conversion.ConvertToKMS(getPosition, (Object) 0)); 204 assertEquals("0.0", Conversion.ConvertToKMS(getPosition, 205 (Object) 0.0F)); 206 assertEquals(null, Conversion.ConvertToKMS(getPosition, 207 (new Integer(-1)))); 208 assertEquals(null, Conversion.ConvertToKMS(getPosition, (new Float( 209 -0.1F)))); 210 assertEquals(null, Conversion.ConvertToKMS(getPosition, 211 (new Boolean(true)))); 212 assertEquals("F", Conversion.ConvertToKMS(getPosition, 213 (new Boolean(false)))); 214 assertEquals(null, Conversion.ConvertToKMS(getPosition, 215 (new int[] {}))); 216 assertEquals("1 22 333", Conversion.ConvertToKMS(getPosition, 217 (new int[] { 1, 22, 333 }))); 218 219 assertEquals("22 44", Conversion.ConvertToKMS(getPosition, 220 (new Point(22, 44)))); 221 222 assertEquals("100 0 0", Conversion.ConvertToKMS(getPosition, 223 Color.red)); 224 225 assertEquals(null, Conversion.ConvertToKMS(getPosition, null)); 226 List<String> testList = new ArrayList<String>(); 227 testList.add("test"); 228 229 assertEquals(testList, Conversion.ConvertToKMS(getPosition, 230 testList)); 231 232 Font testFont = new Font(Text.FONT_WHEEL[1], Font.BOLD, 18); 233 String result = Text.FONT_CHARS[1] + "b18"; 234 assertEquals(result, Conversion.ConvertToKMS(getPosition, testFont)); 235 } catch (Exception e) { 236 e.printStackTrace(); 237 fail(); 238 } 113 239 } 114 240
Note:
See TracChangeset
for help on using the changeset viewer.