Changeset 7 for trunk/src/org/expeditee/items/Item.java
- Timestamp:
- 05/01/08 12:26:53 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Item.java
r4 r7 33 33 * 34 34 */ 35 public abstract class Item implements Comparable<Item>, Runnable { 36 35 public abstract class Item implements Comparable<Item>, Runnable { 36 37 public static int PERMISSION_NONE = 0; 38 public static int PERMISSION_FOLLOW_LINKS = 1; 39 public static int PERMISSION_COPY = 2; 40 public static int PERMISSION_TDFC = 3; 41 public static int PERMISSION_FULL = 4; 42 43 public static final int NEAR_DISTANCE = 15; 44 37 45 /** 38 46 * The default Color to draw highlighting in … … 43 51 44 52 public static final Color DEPRESSED_HIGHLIGHT = Color.GREEN; 53 54 public static final Color DISCONNECT_HIGHLIGHT = Color.BLUE; 45 55 46 56 public static final Color LINK_COLOR = Color.BLACK; … … 63 73 public static final int MARGIN_LEFT = 20; 64 74 65 private Point _offset = new Point(0, 0); 66 67 private int _x; 68 69 private int _y; 70 71 private int _id; 72 73 private String _creationDate = null; 74 75 private boolean _linkMark = true; 76 77 private boolean _actionMark = true; 78 79 private boolean _highlight = true; 80 81 private boolean _isHighlighted = false; 82 83 // private boolean _isValidLink = true; 84 85 private Dimension _maxSize = null; 86 87 private String _owner = null; 88 89 private String _link = null; 90 91 private StringBuffer _data = new StringBuffer(); 92 93 private List<String> _actionCursorEnter = null; 94 95 private List<String> _actionCursorLeave = null; 96 97 private List<String> _actionEnterFrame = null; 98 99 private List<String> _actionLeaveFrame = null; 100 101 private Color _colorFill = null; 102 103 private Color _color = null; 104 105 private Color _highlightColor = DEFAULT_HIGHLIGHT; 106 107 private Color _colorBackground = null; 108 109 private Color _colorTopShadow = null; 110 111 private Color _colorBottomShadow = null; 112 113 // the link\action circle 114 private Polygon _circle = null; 115 116 // the invalid link cross 117 private Polygon _circleCross = null; 118 119 private Frame _parent = null; 120 121 protected int _highlightThickness = 2; 122 123 // arrowhead parameters 124 private int _arrowheadLength = 0; 125 126 private double _arrowheadRatio = 0; 127 128 private Polygon _arrowhead = null; 129 130 // the list of lines that this point is part of. 131 private List<Line> _lines = new ArrayList<Line>(); 132 133 private int[] _linePattern = null; 134 135 private boolean _floating = false; 136 137 // list of points constrained with this point 138 private List<Constraint> _constraints = null; 139 75 protected static final double DEFAULT_ARROWHEAD_RATIO = 0.5; 76 140 77 public static final Color GREEN = Color.GREEN.darker(); 141 78 … … 148 85 DisplayIO.DEFAULT_BACKGROUND }; 149 86 87 public static final Color[] FILL_COLOR_WHEEL = { Color.BLACK, new Color(255,150,150), 88 new Color(150,150,255), new Color(150,255,150), new Color(255,150,255), new Color(255,255,100), 89 DisplayIO.DEFAULT_BACKGROUND }; 90 150 91 public static final int UNCHANGED_CURSOR = -100; 151 92 … … 160 101 public static final int JUSTIFICATION_NONE = -1; 161 102 103 // private boolean _isValidLink = true; 104 162 105 public static final int JUSTIFICATION_FULL = 0; 163 106 … … 171 114 172 115 public static final int POINTTYPE_CIRCLE = 0; 173 174 private LinkedList<String> _actions = null;175 176 private String _link_frameset = null;177 178 private String _link_template = null;179 180 private String _fillPattern = null;181 182 protected Item() {183 _creationDate = Logger.EasyDateFormat("ddMMMyyyy:HHmm");184 }185 186 /**187 * Items are sorted by their Y coordinate on the screen.188 *189 * @param i190 * The Item to compare this Item to191 * @return a negative integer, zero, or a positive integer as this object is192 * less than, equal to, or greater than the specified object.193 */194 public int compareTo(Item i) {195 return getY() - i.getY();196 }197 198 public static int getGravity() {199 return org.expeditee.gui.UserSettings.Gravity;200 }201 202 public static boolean showLineHighlight() {203 return org.expeditee.gui.UserSettings.LineHighlight;204 }205 206 public boolean equals(Object o) {207 if (o instanceof Item) {208 Item i = (Item) o;209 return i.getID() == getID()210 && ((i.getParent() == _parent) || (i.getParent() != null && i211 .getParent().equals(_parent)));212 213 } else214 return false;215 }216 217 /**218 * Adds a given line to the list of lines that this Point is an end for.219 *220 * @param line221 * The Line that this Point is an end of.222 */223 public void addLine(Line line) {224 if (_lines.contains(line)) {225 return;226 }227 228 line.setColor(getColor());229 line.setSize(getSize());230 line.setLinePattern(getLinePattern());231 232 _lines.add(line);233 }234 235 /**236 * Removes the given Line from the list of lines that this Dot is an end237 * for.238 *239 * @param line240 * The Line that this Dot is no longer an end of.241 */242 public void removeLine(Line line) {243 _lines.remove(line);244 }245 246 /**247 * Returns a list of Lines where this Dot is an end.248 *249 * @return A list of the Lines that this Dot is an end for or null if no250 * Lines have been added.251 */252 public List<Line> getLines() {253 return _lines;254 }255 256 public void setLines(List<Line> lines) {257 _lines = lines;258 259 for (Line line : lines)260 line.setLinePattern(getLinePattern());261 }262 263 public void setLinePattern(int[] pattern) {264 _linePattern = pattern;265 266 for (Line line : getLines())267 line.setLinePattern(pattern);268 }269 270 public int[] getLinePattern() {271 return _linePattern;272 }273 274 /**275 * Clears the list of Lines that this Dot is an end of. Note: This only276 * clears this Dot's list and does not have any affect on the Lines or other277 * Dots.278 */279 public void removeAllLines() {280 _lines.clear();281 }282 283 /**284 * Returns the list of IDs of the Lines that this Dot is an end of.285 *286 * @return The list of Line IDs that this point is part of.287 */288 public String getLineIDs() {289 String lineID = null;290 291 if (_lines.size() > 0) {292 lineID = "" + _lines.get(0).getID();293 294 for (int i = 1; i < _lines.size(); i++)295 lineID += " " + _lines.get(i).getID();296 }297 298 return lineID;299 }300 301 /**302 * Sets the list of lines that this point is part of (may be set to null).303 *304 * @param lineID305 * A String of line ID numbers separated by spaces.306 */307 public void setLineIDs(String lineID) {308 }309 310 public void setFloating(boolean val) {311 _floating = val;312 }313 314 public boolean isFloating() {315 return _floating;316 }317 318 /**319 * Returns a List of any Constraints that this Dot is a memeber of.320 *321 * @return a List of Constraints that this Dot is a member of.322 */323 public List<Constraint> getConstraints() {324 return _constraints;325 }326 327 public String getConstraintIDs() {328 if (_constraints == null || _constraints.size() == 0)329 return null;330 331 String cons = "";332 333 for (Constraint c : _constraints)334 cons += c.getID() + " ";335 336 return cons.trim();337 }338 339 public void setConstraintIDs(String IDs) {340 };341 342 /**343 * Adds the given Constraint to this Dot344 *345 * @param c346 * The Constraint to set this Dot as a member of.347 */348 public void addConstraint(Constraint c) {349 if (_constraints == null)350 _constraints = new ArrayList<Constraint>();351 352 // do not add duplicate constraint353 if (_constraints.contains(c))354 return;355 356 _constraints.add(c);357 }358 359 public void setConstraints(List<Constraint> constraints) {360 _constraints = constraints;361 }362 363 public void removeAllConstraints() {364 if (_constraints != null)365 _constraints.clear();366 }367 368 /**369 * Removes the given Constraint from the list of constraintss that this Dot370 * is a part of.371 *372 * @param c373 * The Constraint that this Dot is no longer a part of.374 */375 public void removeConstraint(Constraint c) {376 _constraints.remove(c);377 }378 379 /**380 * Returns the ID of this Item, which must be unique for the Frame.381 *382 * @return The ID of this Item.383 */384 public int getID() {385 return _id;386 }387 388 /**389 * Sets the ID of this Item to the given Integer. Note: Items with ID's < 0390 * are not saved391 *392 * @param newID393 * The new ID to assign this Item.394 */395 public void setID(int newID) {396 _id = newID;397 }398 399 /**400 * Returns the Y coordinate of this Item on the screen401 *402 * @return The Y coordinate of this Item on the screen403 */404 public int getY() {405 return _y;406 }407 408 /**409 * Returns the X coordinate of this Item on the screen410 *411 * @return The X coordinate of this Item on the screen412 */413 public int getX() {414 return _x;415 }416 417 /**418 * Sets the position of this item on the screen419 *420 * @param x421 * The new X coordinate422 * @param y423 * The new Y coordinate424 */425 public void setPosition(int x, int y) {426 _x = x;427 _y = y;428 429 updatePolygon();430 431 // update the position of any dots that are constrained by this one432 if (_constraints != null) {433 for (Constraint c : _constraints) {434 Item other = c.getOppositeEnd(this);435 436 // only set the position if the other dot is still fixed to the437 // frame438 if (!other.isFloating()) {439 if (c.getConstraintType() == Constraint.HORIZONTAL440 && other.getY() != getY())441 other.setY(getY());442 443 if (c.getConstraintType() == Constraint.VERTICAL444 && other.getX() != getX())445 other.setX(getX());446 }447 }448 }449 450 for (Line line : getLines())451 line.updatePolygon();452 }453 454 public void setPosition(Point position) {455 setPosition(position.x, position.y);456 }457 458 public Point getPosition() {459 return new Point(getX(), getY());460 }461 462 /**463 * Sets the position of this Item on the X axis464 *465 * @param newX466 * The position on the X axis to assign to this Item467 */468 public void setX(int newX) {469 setPosition(newX, getY());470 }471 472 /**473 * Sets the position of this Item on the Y axis474 *475 * @param newY476 * The position on the Y axis to assign to this Item477 */478 public void setY(int newY) {479 setPosition(getX(), newY);480 }481 482 /**483 * Returns the name of a Frame that this Item links to, or null if this Item484 * has no link.485 *486 * @return The name of a Frame that this Item links to (if any) or null if487 * this Item does not link to anything.488 */489 public String getLink() {490 return _link;491 }492 493 public String getAbsoluteLink() {494 if (_link == null)495 return null;496 assert (_parent!= null);497 if (_parent == null)498 return null;499 500 // if its a relative link then return absolute501 if (FrameIO.isPositiveInteger(_link)) {502 return _parent.getFramesetNameAdjusted()503 + Conversion.getFrameNumber(_link);504 }505 return _link;506 }507 508 /**509 * Links this item to the given Frame, this may be set to null to remove a510 * link.511 *512 * @param frameName513 * The name of the Frame to link this item to.514 */515 public void setLink(String frameName) {516 _link = frameName;517 }518 519 /*520 * public void setLinkValid(boolean val) { _isValidLink = val; }521 */522 523 /**524 * Tests if the item link is a valid framename, that is, the String must525 * begin with a character, end with a number with 0 or more letters and526 * numbers in between. If there is a dot in the framename all the chars527 * after it must be digits.528 *529 * @return True if the given framename is proper, false otherwise.530 */531 public boolean isLinkValid() {532 if (FrameIO.isPositiveInteger(getLink()))533 return true;534 535 if (FrameIO.isValidFrameName(getLink()))536 return true;537 return false;538 }539 540 public void setLinkFrameset(String frameset) {541 _link_frameset = frameset;542 }543 544 public String getLinkFrameset() {545 return _link_frameset;546 }547 548 public void setLinkTemplate(String template) {549 _link_template = template;550 }551 552 public String getLinkTemplate() {553 return _link_template;554 }555 556 /**557 * Adds an action to this Item.558 *559 * @param action560 * The KMS action language to add to this Item561 */562 public void addAction(String action) {563 if (action == null || action.equals("")) {564 return;565 }566 567 if (_actions == null)568 _actions = new LinkedList<String>();569 _actions.add(action);570 }571 572 /**573 * Sets any action code (KMS action language) that should be associated with574 * this Item Each entry in the list is one line of code575 *576 * @param actions577 * The lines of code to associate with this Item578 */579 public void setAction(List<String> actions) {580 if (actions == null || actions.size() == 0)581 _actions = null;582 else583 _actions = new LinkedList<String>(actions);584 }585 586 /**587 * Returns a list of any action code (KMS action language) that is currently588 * associated with this Item589 *590 * @return A List of action code associated with this Item, or null if none591 * has been assigned.592 */593 public List<String> getAction() {594 return _actions;595 }596 597 public String getFirstAction() {598 if (_actions == null)599 return null;600 return _actions.getFirst();601 }602 603 /**604 * Displays this item directly on the screen. Note: All Items are605 * responsible for their own drawing, buffering, etc.606 *607 * @param g608 * The Graphics to draw this Item on.609 */610 public abstract void paint(Graphics2D g);611 612 /**613 * Every Item has an area around it defined by a Shape (typically a614 * rectangle), this method returns true if the given x,y pair lies within615 * the area and false otherwise.616 *617 * @param x618 * The x coordinate to check619 * @param y620 * The y coordinate to check621 * @return True if the Shape around this Item contains the given x,y pair,622 * false otherwise.623 */624 public boolean contains(int x, int y) {625 return getPolygon().contains(x, y);626 }627 628 /**629 * Returns the Shape that surrounds this Item representing this Item's630 * 'gravity'.631 *632 * @return The Shape (rectangle) surrounding this Item, which represents633 * this Items 'gravity'.634 */635 public abstract Polygon getPolygon();636 637 public Area getArea() {638 return new Area(getPolygon());639 }640 641 protected abstract void updatePolygon();642 643 /**644 * Returns the height (in pixels) of this Item's surrounding area.645 *646 * @return The height (in pixels) of this Item's surrounding area as647 * returned by getArea().648 */649 public int getBoundsHeight() {650 return getPolygon().getBounds().height;651 }652 653 /**654 * Returns the width (in pixels) of this Item's surrounding area.655 *656 * @return The width (in pixels) of this Item's surrounding area as returned657 * by getArea().658 */659 public int getBoundsWidth() {660 return getPolygon().getBounds().width;661 }662 663 /**664 * Checks if the given Shape intersects with the Shape around this Item.665 * Note: Both Shape objects should be rectangles for this to work properly.666 *667 * @param s668 * The Shape to check.669 * @return True if the two Shapes overlap, False otherwise.670 */671 public boolean intersects(Polygon p) {672 if (p == null)673 return false;674 675 // return p.getBounds().intersects(getArea().getBounds());676 Area a = new Area(p);677 a.intersect(this.getArea());678 return !a.isEmpty();679 }680 681 /**682 * Paints any highlighting of this Item. This may include changing the683 * thickness (lines) or painting a box around the item (Text, Images). If684 * val is True then the Graphics Color is changed to the highlight Color, if685 * False then the Graphics Color is left unchanged (for clearing of686 * highlighting).687 *688 * @param val689 * True if this Item should be highlighted, false if the690 * highlighting is being cleared.\691 * @return The desired mouse cursor when this Item is highlighted (negative692 * means no change)693 */694 public int showHighlight(boolean val) {695 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;696 return showHighlight(val, DEFAULT_HIGHLIGHT);697 }698 699 public int showDepressedHighlight(boolean val) {700 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;701 return showHighlight(val, DEPRESSED_HIGHLIGHT);702 }703 704 public int showHighlight(boolean val, Color c) {705 _isHighlighted = val;706 if (c != null)707 _highlightColor = c;708 else709 _highlightColor = DEFAULT_HIGHLIGHT;710 711 return Item.UNCHANGED_CURSOR;712 }713 714 /**715 * Returns True if this Item is currently highlighted.716 *717 * @return True if this Item is currently highlighted on the screen, False718 * otherwise.719 */720 public boolean isHighlighted() {721 return _isHighlighted;722 }723 724 public Color getHighlightColor() {725 return _highlightColor;726 }727 728 /**729 * Returns a deep copy of this Item, note: it is up to the receiver to730 * change the Item ID etc as necessary.731 *732 * @return A deep copy of this Item.733 */734 public abstract Item copy();735 116 736 117 public static void DuplicateItem(Item source, Item dest) { … … 777 158 dest.setID(source.getID()); 778 159 } 160 } 161 162 public static int getGravity() { 163 return org.expeditee.gui.UserSettings.Gravity; 164 } 165 166 public static boolean showLineHighlight() { 167 return org.expeditee.gui.UserSettings.LineHighlight; 168 } 169 170 private Point _offset = new Point(0, 0); 171 172 private int _x; 173 174 private int _y; 175 176 private int _id; 177 178 private String _creationDate = null; 179 180 private boolean _linkMark = true; 181 182 private boolean _actionMark = true; 183 184 private boolean _highlight = true; 185 186 private boolean _isHighlighted = false; 187 188 private Dimension _maxSize = null; 189 190 private String _owner = null; 191 192 private String _link = null; 193 194 private StringBuffer _data = new StringBuffer(); 195 196 private List<String> _actionCursorEnter = null; 197 198 private List<String> _actionCursorLeave = null; 199 200 private List<String> _actionEnterFrame = null; 201 202 private List<String> _actionLeaveFrame = null; 203 204 public int Permission = PERMISSION_FULL; 205 206 private Color _colorFill = null; 207 208 private Color _color = null; 209 210 private Color _highlightColor = DEFAULT_HIGHLIGHT; 211 212 private Color _colorBackground = null; 213 214 private Color _colorTopShadow = null; 215 216 private Color _colorBottomShadow = null; 217 218 // the link\action circle 219 private Polygon _circle = null; 220 221 // the invalid link cross 222 private Polygon _circleCross = null; 223 224 private Frame _parent = null; 225 226 protected int _highlightThickness = 2; 227 228 // arrowhead parameters 229 private int _arrowheadLength = 0; 230 231 private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO; 232 233 private Polygon _arrowhead = null; 234 235 // the list of lines that this point is part of. 236 private List<Line> _lines = new ArrayList<Line>(); 237 238 private int[] _linePattern = null; 239 240 private boolean _floating = false; 241 242 // list of points constrained with this point 243 private List<Constraint> _constraints = null; 244 245 private LinkedList<String> _actions = null; 246 247 private String _link_frameset = null; 248 249 private String _link_template = null; 250 251 private String _fillPattern = null; 252 253 private boolean _visible = true; 254 255 protected Item() { 256 _creationDate = Logger.EasyDateFormat("ddMMMyyyy:HHmm"); 257 } 258 259 /** 260 * Adds an action to this Item. 261 * 262 * @param action 263 * The KMS action language to add to this Item 264 */ 265 public void addAction(String action) { 266 if (action == null || action.equals("")) { 267 return; 268 } 269 270 if (_actions == null) 271 _actions = new LinkedList<String>(); 272 _actions.add(action); 273 } 274 275 public void addAllConnected(List<Item> connected) { 276 if (!connected.contains(this)) 277 connected.add(this); 278 279 for (Line line : getLines()) { 280 if (!connected.contains(line)) 281 line.addAllConnected(connected); 282 } 283 } 284 285 /** 286 * Adds the given Constraint to this Dot 287 * 288 * @param c 289 * The Constraint to set this Dot as a member of. 290 */ 291 public void addConstraint(Constraint c) { 292 if (_constraints == null) 293 _constraints = new ArrayList<Constraint>(); 294 295 // do not add duplicate constraint 296 if (_constraints.contains(c)) 297 return; 298 299 _constraints.add(c); 300 } 301 302 /** 303 * Adds a given line to the list of lines that this Point is an end for. 304 * 305 * @param line 306 * The Line that this Point is an end of. 307 */ 308 public void addLine(Line line) { 309 if (_lines.contains(line)) { 310 return; 311 } 312 313 line.setColor(getColor()); 314 line.setSize(getSize()); 315 line.setLinePattern(getLinePattern()); 316 317 _lines.add(line); 318 } 319 320 /** 321 * Items are sorted by their Y coordinate on the screen. 322 * 323 * @param i 324 * The Item to compare this Item to 325 * @return a negative integer, zero, or a positive integer as this object is 326 * less than, equal to, or greater than the specified object. 327 */ 328 public int compareTo(Item i) { 329 return getY() - i.getY(); 330 } 331 332 /** 333 * Every Item has an area around it defined by a Shape (typically a 334 * rectangle), this method returns true if the given x,y pair lies within 335 * the area and false otherwise. 336 * 337 * @param x 338 * The x coordinate to check 339 * @param y 340 * The y coordinate to check 341 * @return True if the Shape around this Item contains the given x,y pair, 342 * false otherwise. 343 */ 344 public boolean contains(int x, int y) { 345 return getPolygon().contains(x, y); 346 } 347 348 /** 349 * Returns a deep copy of this Item, note: it is up to the receiver to 350 * change the Item ID etc as necessary. 351 * 352 * @return A deep copy of this Item. 353 */ 354 public abstract Item copy(); 355 356 public void delete() { 357 setVisible(false); 358 } 359 360 public boolean equals(Object o) { 361 if (o instanceof Item) { 362 Item i = (Item) o; 363 return i.getID() == getID() 364 && ((i.getParent() == _parent) || (i.getParent() != null && i 365 .getParent().equals(_parent))); 366 367 } else 368 return false; 369 } 370 371 final public String getAbsoluteLink() { 372 String link = getLink(); 373 374 if (link == null) 375 return null; 376 //assert (_parent!= null); 377 if (_parent == null){ 378 //if parent is null it is an item on the message box 379 //so it must already be absolute 380 assert(!FrameIO.isPositiveInteger(link)); 381 return link; 382 } 383 384 // if its a relative link then return absolute 385 if (FrameIO.isPositiveInteger(link)) { 386 return _parent.getFramesetNameAdjusted() 387 + Conversion.getFrameNumber(link); 388 } 389 return link; 390 } 391 392 /** 393 * Returns a list of any action code (KMS action language) that is currently 394 * associated with this Item 395 * 396 * @return A List of action code associated with this Item, or null if none 397 * has been assigned. 398 */ 399 public List<String> getAction() { 400 return _actions; 401 } 402 403 public List<String> getActionCursorEnter() { 404 return _actionCursorEnter; 405 } 406 407 public List<String> getActionCursorLeave() { 408 return _actionCursorLeave; 409 } 410 411 public List<String> getActionEnterFrame() { 412 return _actionEnterFrame; 413 } 414 415 public List<String> getActionLeaveFrame() { 416 return _actionLeaveFrame; 417 }; 418 419 public boolean getActionMark() { 420 return _actionMark; 421 } 422 423 public List<Item> getAllConnected() { 424 List<Item> list = new LinkedList<Item>(); 425 addAllConnected(list); 426 return list; 427 } 428 429 public Area getArea() { 430 return new Area(getPolygon()); 431 } 432 433 public String getArrow() { 434 if (!hasVisibleArrow()) 435 return null; 436 437 String ratio = "" + getArrowheadRatio(); 438 if (ratio.length() - ratio.indexOf(".") > 2) 439 ratio = ratio.substring(0, ratio.indexOf(".") + 3); 440 441 return getArrowheadLength() + " " + ratio; 442 } 443 444 public Polygon getArrowhead() { 445 return _arrowhead; 446 } 447 448 public int getArrowheadLength() { 449 return _arrowheadLength; 450 } 451 452 public double getArrowheadRatio() { 453 return _arrowheadRatio; 454 } 455 456 public Color getBackgroundColor() { 457 return _colorBackground; 458 } 459 460 /** 461 * Returns the Color being used to shade the bottom half of this Item's 462 * border. This can be NULL if no Color is being used 463 * 464 * @return The Color displayed on the bottom\right half of this Item's 465 * border. 466 */ 467 public Color getBottomShadowColor() { 468 return _colorBottomShadow; 469 } 470 471 /** 472 * Returns the height (in pixels) of this Item's surrounding area. 473 * 474 * @return The height (in pixels) of this Item's surrounding area as 475 * returned by getArea(). 476 */ 477 public int getBoundsHeight() { 478 return getPolygon().getBounds().height; 479 } 480 481 /** 482 * Returns the width (in pixels) of this Item's surrounding area. 483 * 484 * @return The width (in pixels) of this Item's surrounding area as returned 485 * by getArea(). 486 */ 487 public int getBoundsWidth() { 488 return getPolygon().getBounds().width; 489 } 490 491 protected Polygon getCircle() { 492 if (_circle == null) { 493 int points = 16; 494 495 double radians = 0.0; 496 int xPoints[] = new int[points]; 497 int yPoints[] = new int[xPoints.length]; 498 499 for (int i = 0; i < xPoints.length; i++) { 500 // circle looks best if these values are not related to gravity 501 xPoints[i] = (int) (3.5 * Math.cos(radians)) + 6;// (2 * 502 // GRAVITY); 503 yPoints[i] = (int) (3.5 * Math.sin(radians)) + 3;// GRAVITY; 504 radians += (2.0 * Math.PI) / xPoints.length; 505 } 506 507 _circle = new Polygon(xPoints, yPoints, xPoints.length); 508 } 509 510 return _circle; 511 } 512 513 protected Polygon getCircleCross() { 514 515 if (_circleCross == null) { 516 _circleCross = new Polygon(); 517 518 Rectangle bounds = getCircle().getBounds(); 519 int x1 = (int) bounds.getMinX(); 520 int x2 = (int) bounds.getMaxX(); 521 int y1 = (int) bounds.getMinY(); 522 int y2 = (int) bounds.getMaxY(); 523 int midX = ((x2 - x1) / 2) + x1; 524 int midY = ((y2 - y1) / 2) + y1; 525 526 _circleCross.addPoint(x1, y1); 527 _circleCross.addPoint(x2, y2); 528 _circleCross.addPoint(midX, midY); 529 _circleCross.addPoint(x1, y2); 530 _circleCross.addPoint(x2, y1); 531 _circleCross.addPoint(midX, midY); 532 } 533 534 return _circleCross; 535 } 536 537 public Color getColor() { 538 return _color; 539 } 540 541 public List<Item> getConnected() { 542 List<Item> conn = new LinkedList<Item>(); 543 conn.add(this); 544 545 conn.addAll(getLines()); 546 return conn; 547 } 548 549 public String getConstraintIDs() { 550 if (_constraints == null || _constraints.size() == 0) 551 return null; 552 553 String cons = ""; 554 555 for (Constraint c : _constraints) 556 cons += c.getID() + " "; 557 558 return cons.trim(); 559 } 560 561 /* 562 * public void setLinkValid(boolean val) { _isValidLink = val; } 563 */ 564 565 /** 566 * Returns a List of any Constraints that this Dot is a memeber of. 567 * 568 * @return a List of Constraints that this Dot is a member of. 569 */ 570 public List<Constraint> getConstraints() { 571 return _constraints; 572 } 573 574 public String getData() { 575 if (_data != null && _data.length() > 0) 576 return _data.toString(); 577 return null; 578 } 579 580 public String getDateCreated() { 581 return _creationDate; 582 } 583 584 public Color getFillColor() { 585 return _colorFill; 586 } 587 588 public String getFillPattern() { 589 return _fillPattern; 590 } 591 592 public String getFirstAction() { 593 if (_actions == null) 594 return null; 595 return _actions.getFirst(); 596 } 597 598 public boolean getHighlight() { 599 return _highlight; 600 } 601 602 public Color getHighlightColor() { 603 return _highlightColor; 604 } 605 606 /** 607 * Returns the ID of this Item, which must be unique for the Frame. 608 * 609 * @return The ID of this Item. 610 */ 611 public int getID() { 612 return _id; 613 } 614 615 /** 616 * Returns the list of IDs of the Lines that this Dot is an end of. 617 * 618 * @return The list of Line IDs that this point is part of. 619 */ 620 public String getLineIDs() { 621 String lineID = null; 622 623 if (_lines.size() > 0) { 624 lineID = "" + _lines.get(0).getID(); 625 626 for (int i = 1; i < _lines.size(); i++) 627 lineID += " " + _lines.get(i).getID(); 628 } 629 630 return lineID; 631 } 632 633 public int[] getLinePattern() { 634 return _linePattern; 635 } 636 637 /** 638 * Returns a list of Lines where this Dot is an end. 639 * 640 * @return A list of the Lines that this Dot is an end for or null if no 641 * Lines have been added. 642 */ 643 public List<Line> getLines() { 644 return _lines; 645 } 646 647 /** 648 * Returns the name of a Frame that this Item links to, or null if this Item 649 * has no link. 650 * 651 * @return The name of a Frame that this Item links to (if any) or null if 652 * this Item does not link to anything. 653 */ 654 public String getLink() { 655 return _link; 656 } 657 658 public String getLinkFrameset() { 659 return _link_frameset; 660 } 661 662 public boolean getLinkMark() { 663 return _linkMark; 664 } 665 666 public String getLinkTemplate() { 667 return _link_template; 668 } 669 670 public Dimension getMaxSize() { 671 return _maxSize; 672 } 673 674 public Point getOffset() { 675 return _offset; 676 } 677 678 public String getOwner() { 679 return _owner; 680 } 681 682 public Color getPaintBackgroundColor() { 683 if (_colorBackground == null) { 684 if (getParent() != null && getParent().getBackgroundColor() != null) 685 return getParent().getBackgroundColor(); 686 687 return DEFAULT_BACKGROUND; 688 } 689 690 return _colorBackground; 691 } 692 693 /** 694 * Returns the foreground Color of this Item. 695 * 696 * @return The Color of this item (foreground) 697 */ 698 public Color getPaintColor() { 699 if (_color == null) { 700 if (getParent() != null) 701 return getParent().getPaintForegroundColor(); 702 703 if (DisplayIO.getCurrentFrame() == null) 704 return DEFAULT_FOREGROUND; 705 706 return DisplayIO.getCurrentFrame().getPaintForegroundColor(); 707 } 708 709 return _color; 710 } 711 712 protected Color getPaintHighlightColor() { 713 if (getParent() != null 714 && getParent().getPaintBackgroundColor() 715 .equals(_highlightColor)) 716 return getParent().getPaintForegroundColor(); 717 718 return _highlightColor; 719 } 720 721 public Frame getParent() { 722 return _parent; 723 } 724 725 /** 726 * Returns the Shape that surrounds this Item representing this Item's 727 * 'gravity'. 728 * 729 * @return The Shape (rectangle) surrounding this Item, which represents 730 * this Items 'gravity'. 731 */ 732 public abstract Polygon getPolygon(); 733 734 public Point getPosition() { 735 return new Point(getX(), getY()); 736 } 737 738 /** 739 * Returns the size of this Item. For Text this is the Font size, for Lines 740 * and Dots this is the thickness. 741 * 742 * @return The size of this Item. 743 */ 744 public abstract int getSize(); 745 746 public float getThickness() { 747 return 0; 748 } 749 750 /** 751 * Returns the Color being used to shade the top half of this Item's border. 752 * This can be NULL if no Color is being used 753 * 754 * @return The Color displayed on the top\left half of this Item's border. 755 */ 756 public Color getTopShadowColor() { 757 return _colorTopShadow; 758 } 759 760 public String getTypeAndID() { 761 return "T " + getID(); 762 } 763 764 public int getWidth() { 765 return 0; 766 } 767 768 /** 769 * Returns the X coordinate of this Item on the screen 770 * 771 * @return The X coordinate of this Item on the screen 772 */ 773 public int getX() { 774 return _x; 775 } 776 777 /** 778 * Returns the Y coordinate of this Item on the screen 779 * 780 * @return The Y coordinate of this Item on the screen 781 */ 782 public int getY() { 783 return _y; 784 } 785 786 protected boolean hasVisibleArrow() { 787 return false; 788 } 789 790 /** 791 * Checks if the given Shape intersects with the Shape around this Item. 792 * Note: Both Shape objects should be rectangles for this to work properly. 793 * 794 * @param s 795 * The Shape to check. 796 * @return True if the two Shapes overlap, False otherwise. 797 */ 798 public boolean intersects(Polygon p) { 799 if (p == null) 800 return false; 801 802 // return p.getBounds().intersects(getArea().getBounds()); 803 Area a = new Area(p); 804 805 a.intersect(this.getArea()); 806 return !a.isEmpty(); 807 } 808 809 /** 810 * Note: Pictures always return False, as they should be drawn even when no 811 * other annotation Items are. 812 * 813 * @return True if this Item is an annotation, False otherwise. 814 */ 815 public abstract boolean isAnnotation(); 816 817 public boolean isFloating() { 818 return _floating; 819 } 820 821 public boolean isFrameName() { 822 if (this.getParent() == null || this.getParent().getFrameNameItem() != this) 823 return false; 824 return true; 825 } 826 827 public boolean isFrameTitle() { 828 if (this.getParent() == null || this.getParent().getTitle() != this) 829 return false; 830 return true; 831 } 832 833 /** 834 * Returns True if this Item is currently highlighted. 835 * 836 * @return True if this Item is currently highlighted on the screen, False 837 * otherwise. 838 */ 839 public boolean isHighlighted() { 840 return _isHighlighted; 841 } 842 843 /** 844 * Tests if the item link is a valid framename, that is, the String must 845 * begin with a character, end with a number with 0 or more letters and 846 * numbers in between. If there is a dot in the framename all the chars 847 * after it must be digits. 848 * 849 * @return True if the given framename is proper, false otherwise. 850 */ 851 public boolean isLinkValid() { 852 if (FrameIO.isPositiveInteger(getLink())) 853 return true; 854 855 if (FrameIO.isValidFrameName(getLink())) 856 return true; 857 return false; 858 } 859 860 public boolean isNear(int x, int y) { 861 862 863 int xLeft = getPolygon().getBounds().x; 864 int yTop = getPolygon().getBounds().y; 865 866 return (x > xLeft - NEAR_DISTANCE && y > yTop - NEAR_DISTANCE 867 && x < xLeft + getBoundsWidth() + NEAR_DISTANCE 868 && y < yTop + getBoundsHeight() + NEAR_DISTANCE); 869 } 870 871 /** 872 * Checks if this item is a frame title. 873 * 874 * @return true if the item is a frame title 875 */ 876 /* 877 * public boolean isTitle() { // check if the title has been assigned if 878 * (getID() >= 0 && this instanceof Text) if (getX() < 200 && getY() < 879 * getSize() + system.io.KMSConversion.Y_ADJUST) return true; return false; } 880 */ 881 882 public boolean isOldTag() { 883 if (this instanceof Text) 884 if (((Text) this).getText().get(0).toLowerCase().equals("@old")) 885 return true; 886 return false; 779 887 } 780 888 … … 797 905 798 906 /** 799 * Sets the maximum coordinates on the screen that this item may occupy. 800 * This is used by Text items to compute word-wrapping lengths. 801 * 802 * @param d 803 * The Maximum size of the Frame containing this Item. 804 */ 805 public void setMaxSize(Dimension d) { 806 if (d != null) { 807 _maxSize = d; 808 updatePolygon(); 809 } 810 } 811 812 public Dimension getMaxSize() { 813 return _maxSize; 814 } 815 816 public Color getColor() { 817 return _color; 818 } 819 820 /** 821 * Returns the foreground Color of this Item. 822 * 823 * @return The Color of this item (foreground) 824 */ 825 public Color getPaintColor() { 826 if (_color == null) { 827 if (getParent() != null) 828 return getParent().getPaintForegroundColor(); 829 830 if (DisplayIO.getCurrentFrame() == null) 831 return DEFAULT_FOREGROUND; 832 833 return DisplayIO.getCurrentFrame().getPaintForegroundColor(); 834 } 835 836 return _color; 837 } 838 839 protected Color getPaintHighlightColor() { 840 if (getParent() != null 841 && getParent().getPaintBackgroundColor() 842 .equals(_highlightColor)) 843 return getParent().getPaintForegroundColor(); 844 845 return _highlightColor; 907 * Displays this item directly on the screen. Note: All Items are 908 * responsible for their own drawing, buffering, etc. 909 * 910 * @param g 911 * The Graphics to draw this Item on. 912 */ 913 public abstract void paint(Graphics2D g); 914 915 /** 916 * This method performs all the actions in an items list. If it contains a 917 * link as well the link is used as the source frame for all acitons. 918 */ 919 public void performActions() { 920 Frame sourceFrame = null; 921 // if a link exists make it the source frame for this action 922 if (getLink() != null) { 923 sourceFrame = FrameUtils.getFrame(getLink()); 924 } 925 // if no link exists or the link is bad then use the 926 // currently displayed frame as the source frame for the 927 // action 928 if (sourceFrame == null) { 929 sourceFrame = DisplayIO.getCurrentFrame(); 930 } 931 932 for (String s : getAction()) { 933 Actions.PerformAction(sourceFrame, this, s); 934 } 935 } 936 937 public void removeAllConstraints() { 938 if (_constraints != null) 939 _constraints.clear(); 940 } 941 942 /** 943 * Clears the list of Lines that this Dot is an end of. Note: This only 944 * clears this Dot's list and does not have any affect on the Lines or other 945 * Dots. 946 */ 947 public void removeAllLines() { 948 _lines.clear(); 949 } 950 951 /** 952 * Removes the given Constraint from the list of constraintss that this Dot 953 * is a part of. 954 * 955 * @param c 956 * The Constraint that this Dot is no longer a part of. 957 */ 958 public void removeConstraint(Constraint c) { 959 _constraints.remove(c); 960 } 961 962 /** 963 * Removes the given Line from the list of lines that this Dot is an end 964 * for. 965 * 966 * @param line 967 * The Line that this Dot is no longer an end of. 968 */ 969 public void removeLine(Line line) { 970 _lines.remove(line); 971 } 972 973 public void run() { 974 try { 975 AgentStats.reset(); 976 FrameGraphics 977 .DisplayMessage("Running SimpleProgram...", Color.BLUE); 978 Simple.RunFrameAndReportError(this, new Context()); 979 Simple.ProgramFinished(); 980 FrameGraphics.DisplayMessage(AgentStats.getStats(), GREEN); 981 } catch (ConcurrentModificationException ce) { 982 ce.printStackTrace(); 983 } catch (Exception e) { 984 FrameGraphics.LinkedErrorMessage(e.getMessage()); 985 Simple.ProgramFinished(); 986 } 987 } 988 989 /** 990 * Check if it has a relative link if so make it absolute. 991 * 992 */ 993 public void setAbsoluteLink() { 994 if (_link == null) 995 return; 996 // Check if all the characters are digits and hence it is a relative 997 // link 998 for (int i = 0; i < _link.length(); i++) { 999 if (!Character.isDigit(_link.charAt(i))) 1000 return; 1001 } 1002 1003 // Make it an absolute link 1004 String framesetName; 1005 1006 if (_parent == null) 1007 framesetName = DisplayIO.getCurrentFrame() 1008 .getFramesetNameAdjusted(); 1009 else 1010 framesetName = _parent.getFramesetNameAdjusted(); 1011 1012 _link = framesetName + _link; 1013 } 1014 1015 /** 1016 * Sets any action code (KMS action language) that should be associated with 1017 * this Item Each entry in the list is one line of code 1018 * 1019 * @param actions 1020 * The lines of code to associate with this Item 1021 */ 1022 public void setAction(List<String> actions) { 1023 if (actions == null || actions.size() == 0) 1024 _actions = null; 1025 else 1026 _actions = new LinkedList<String>(actions); 1027 } 1028 1029 public void setActionCursorEnter(List<String> enter) { 1030 _actionCursorEnter = enter; 1031 } 1032 1033 public void setActionCursorLeave(List<String> leave) { 1034 _actionCursorLeave = leave; 1035 } 1036 1037 public void setActionEnterFrame(List<String> enter) { 1038 _actionEnterFrame = enter; 1039 } 1040 1041 public void setActionLeaveFrame(List<String> leave) { 1042 _actionLeaveFrame = leave; 1043 } 1044 1045 public void setActionMark(boolean val) { 1046 _actionMark = val; 1047 } 1048 1049 /** 1050 * Sets whether this Item is an Annotation. 1051 * 1052 * @param val 1053 * True if this Item is an Annotation, False otherwise. 1054 */ 1055 public abstract void setAnnotation(boolean val); 1056 1057 /** 1058 * Used to set this Line as an Arrow. If length and ratio are 0, no arrow is 1059 * shown. 1060 * 1061 * @param length 1062 * The how far down the shaft of the line the arrowhead should 1063 * come. 1064 * @param ratio 1065 * The ratio of the arrow's length to its width. 1066 */ 1067 public void setArrow(int length, double ratio) { 1068 _arrowheadLength = length; 1069 _arrowheadRatio = ratio; 1070 updateArrowPolygon(); 1071 } 1072 1073 public void setArrowhead(Polygon arrow) { 1074 _arrowhead = arrow; 1075 } 1076 1077 public void setArrowheadLength(int length) { 1078 _arrowheadLength = length; 1079 updateArrowPolygon(); 1080 } 1081 1082 public void setArrowheadRatio(double ratio) { 1083 _arrowheadRatio = ratio; 1084 updateArrowPolygon(); 1085 } 1086 1087 public void setBackgroundColor(Color c) { 1088 _colorBackground = c; 1089 } 1090 1091 /** 1092 * Sets the Color to use on the bottom and right sections of this Item's 1093 * border. If top is NULL, then the Item's background Color will be used. 1094 * 1095 * @param top 1096 * The Color to display in the bottom and right sections of this 1097 * Item's border. 1098 */ 1099 public void setBottomShadowColor(Color bottom) { 1100 _colorBottomShadow = bottom; 846 1101 } 847 1102 … … 859 1114 } 860 1115 861 /** 862 * Returns the Color being used to shade the top half of this Item's border. 863 * This can be NULL if no Color is being used 864 * 865 * @return The Color displayed on the top\left half of this Item's border. 866 */ 867 public Color getTopShadowColor() { 868 return _colorTopShadow; 869 } 870 871 /** 872 * Sets the Color to use on the top and left sections of this Item's border. 873 * If top is NULL, then the Item's background Color will be used. 874 * 875 * @param top 876 * The Color to display in the top and left sections of this 877 * Item's border. 878 */ 879 public void setTopShadowColor(Color top) { 880 _colorTopShadow = top; 881 } 882 883 /** 884 * Returns the Color being used to shade the bottom half of this Item's 885 * border. This can be NULL if no Color is being used 886 * 887 * @return The Color displayed on the bottom\right half of this Item's 888 * border. 889 */ 890 public Color getBottomShadowColor() { 891 return _colorBottomShadow; 892 } 893 894 /** 895 * Sets the Color to use on the bottom and right sections of this Item's 896 * border. If top is NULL, then the Item's background Color will be used. 897 * 898 * @param top 899 * The Color to display in the bottom and right sections of this 900 * Item's border. 901 */ 902 public void setBottomShadowColor(Color bottom) { 903 _colorBottomShadow = bottom; 904 } 905 906 protected Polygon getCircle() { 907 if (_circle == null) { 908 int points = 16; 909 910 double radians = 0.0; 911 int xPoints[] = new int[points]; 912 int yPoints[] = new int[xPoints.length]; 913 914 for (int i = 0; i < xPoints.length; i++) { 915 // circle looks best if these values are not related to gravity 916 xPoints[i] = (int) (3.5 * Math.cos(radians)) + 6;// (2 * 917 // GRAVITY); 918 yPoints[i] = (int) (3.5 * Math.sin(radians)) + 3;// GRAVITY; 919 radians += (2.0 * Math.PI) / xPoints.length; 920 } 921 922 _circle = new Polygon(xPoints, yPoints, xPoints.length); 923 } 924 925 return _circle; 926 } 927 928 protected Polygon getCircleCross() { 929 930 if (_circleCross == null) { 931 _circleCross = new Polygon(); 932 933 Rectangle bounds = getCircle().getBounds(); 934 int x1 = (int) bounds.getMinX(); 935 int x2 = (int) bounds.getMaxX(); 936 int y1 = (int) bounds.getMinY(); 937 int y2 = (int) bounds.getMaxY(); 938 int midX = ((x2 - x1) / 2) + x1; 939 int midY = ((y2 - y1) / 2) + y1; 940 941 _circleCross.addPoint(x1, y1); 942 _circleCross.addPoint(x2, y2); 943 _circleCross.addPoint(midX, midY); 944 _circleCross.addPoint(x1, y2); 945 _circleCross.addPoint(x2, y1); 946 _circleCross.addPoint(midX, midY); 947 } 948 949 return _circleCross; 950 } 951 952 public void setFillColor(Color c) { 953 _colorFill = c; 954 955 for (Line line : _lines) { 956 Item other = line.getOppositeEnd(this); 957 if (other.getFillColor() != c) 958 other.setFillColor(c); 959 } 960 } 961 962 public void setBackgroundColor(Color c) { 963 _colorBackground = c; 964 } 965 966 public Color getBackgroundColor() { 967 return _colorBackground; 968 } 969 970 public Color getPaintBackgroundColor() { 971 if (_colorBackground == null) { 972 if (getParent() != null && getParent().getBackgroundColor() != null) 973 return getParent().getBackgroundColor(); 974 975 return DEFAULT_BACKGROUND; 976 } 977 978 return _colorBackground; 979 } 980 981 public Color getFillColor() { 982 return _colorFill; 983 } 984 985 /** 986 * Returns the size of this Item. For Text this is the Font size, for Lines 987 * and Dots this is the thickness. 988 * 989 * @return The size of this Item. 990 */ 991 public abstract int getSize(); 992 993 /** 994 * Sets the size of this Item. For Text this is the Font size. For Lines and 995 * Dots this is the thickness. 996 */ 997 public abstract void setSize(int size); 998 999 /** 1000 * Sets whether this Item is an Annotation. 1001 * 1002 * @param val 1003 * True if this Item is an Annotation, False otherwise. 1004 */ 1005 public abstract void setAnnotation(boolean val); 1006 1007 /** 1008 * Note: Pictures always return False, as they should be drawn even when no 1009 * other annotation Items are. 1010 * 1011 * @return True if this Item is an annotation, False otherwise. 1012 */ 1013 public abstract boolean isAnnotation(); 1014 1015 public List<Item> getConnected() { 1016 List<Item> conn = new LinkedList<Item>(); 1017 conn.add(this); 1018 1019 conn.addAll(getLines()); 1020 return conn; 1021 } 1022 1023 public List<Item> getAllConnected() { 1024 List<Item> list = new LinkedList<Item>(); 1025 addAllConnected(list); 1026 return list; 1027 } 1028 1029 public void addAllConnected(List<Item> connected) { 1030 if (!connected.contains(this)) 1031 connected.add(this); 1032 1033 for (Line line : getLines()) { 1034 if (!connected.contains(line)) 1035 line.addAllConnected(connected); 1036 } 1037 } 1038 1039 public void setOffset(Point p) { 1040 _offset.setLocation(p); 1041 } 1042 1043 public void setOffset(int x, int y) { 1044 _offset.setLocation(x, y); 1045 } 1046 1047 public Point getOffset() { 1048 return _offset; 1049 } 1050 1051 public void setParent(Frame frame) { 1052 _parent = frame; 1053 } 1054 1055 public Frame getParent() { 1056 return _parent; 1057 } 1058 1059 public void setActionMark(boolean val) { 1060 _actionMark = val; 1061 } 1062 1063 public boolean getActionMark() { 1064 return _actionMark; 1065 } 1066 1067 public void setLinkMark(boolean val) { 1068 _linkMark = val; 1069 } 1070 1071 public boolean getLinkMark() { 1072 return _linkMark; 1073 } 1074 1075 public void setOwner(String own) { 1076 _owner = own; 1077 } 1078 1079 public String getOwner() { 1080 return _owner; 1081 } 1082 1083 public void setHighlight(boolean val) { 1084 _highlight = val; 1085 } 1086 1087 public boolean getHighlight() { 1088 return _highlight; 1089 } 1090 1091 public String getData() { 1092 if (_data != null && _data.length() > 0) 1093 return _data.toString(); 1094 return null; 1116 public void setConstraintIDs(String IDs) { 1117 } 1118 1119 public void setConstraints(List<Constraint> constraints) { 1120 _constraints = constraints; 1095 1121 } 1096 1122 … … 1102 1128 } 1103 1129 1104 public List<String> getActionCursorEnter() { 1105 return _actionCursorEnter; 1106 } 1107 1108 public void setActionCursorEnter(List<String> enter) { 1109 _actionCursorEnter = enter; 1110 } 1111 1112 public List<String> getActionCursorLeave() { 1113 return _actionCursorLeave; 1114 } 1115 1116 public void setActionCursorLeave(List<String> leave) { 1117 _actionCursorLeave = leave; 1118 } 1119 1120 public List<String> getActionEnterFrame() { 1121 return _actionEnterFrame; 1122 } 1123 1124 public void setActionEnterFrame(List<String> enter) { 1125 _actionEnterFrame = enter; 1126 } 1127 1128 public List<String> getActionLeaveFrame() { 1129 return _actionLeaveFrame; 1130 } 1131 1132 public void setActionLeaveFrame(List<String> leave) { 1133 _actionLeaveFrame = leave; 1130 /** 1131 * Sets the created date of this Frame to the given String. 1132 * 1133 * @param date 1134 * The date to use for this Frame. 1135 */ 1136 public void setDateCreated(String date) { 1137 _creationDate = date; 1138 } 1139 1140 public void setFillColor(Color c) { 1141 _colorFill = c; 1142 1143 for (Line line : _lines) { 1144 Item other = line.getOppositeEnd(this); 1145 if (other.getFillColor() != c) 1146 other.setFillColor(c); 1147 } 1148 } 1149 1150 public void setFilledHighlight(boolean value) { 1134 1151 } 1135 1152 … … 1138 1155 } 1139 1156 1140 public String getFillPattern() { 1141 return _fillPattern; 1142 } 1143 1144 /** 1145 * Used to set this Line as an Arrow. If length and ratio are 0, no arrow is 1146 * shown. 1147 * 1148 * @param length 1149 * The how far down the shaft of the line the arrowhead should 1150 * come. 1151 * @param ratio 1152 * The ratio of the arrow's length to its width. 1153 */ 1154 public void setArrow(int length, double ratio) { 1155 _arrowheadLength = length; 1156 _arrowheadRatio = ratio; 1157 updateArrowPolygon(); 1158 } 1159 1160 public int getArrowheadLength() { 1161 return _arrowheadLength; 1162 } 1163 1164 public double getArrowheadRatio() { 1165 return _arrowheadRatio; 1166 } 1167 1168 public void setArrowheadLength(int length) { 1169 _arrowheadLength = length; 1170 updateArrowPolygon(); 1171 } 1172 1173 public void setArrowheadRatio(double ratio) { 1174 _arrowheadRatio = ratio; 1175 updateArrowPolygon(); 1176 } 1177 1157 public void setFloating(boolean val) { 1158 _floating = val; 1159 } 1160 1161 public void setHighlight(boolean val) { 1162 _highlight = val; 1163 } 1164 1165 /** 1166 * Sets the ID of this Item to the given Integer. Note: Items with ID's < 0 1167 * are not saved 1168 * 1169 * @param newID 1170 * The new ID to assign this Item. 1171 */ 1172 public void setID(int newID) { 1173 _id = newID; 1174 } 1175 1176 /** 1177 * Sets the list of lines that this point is part of (may be set to null). 1178 * 1179 * @param lineID 1180 * A String of line ID numbers separated by spaces. 1181 */ 1182 public void setLineIDs(String lineID) { 1183 } 1184 1185 public void setLinePattern(int[] pattern) { 1186 _linePattern = pattern; 1187 1188 for (Line line : getLines()) 1189 line.setLinePattern(pattern); 1190 } 1191 1192 public void setLines(List<Line> lines) { 1193 _lines = lines; 1194 1195 for (Line line : lines) 1196 line.setLinePattern(getLinePattern()); 1197 } 1198 1199 /** 1200 * Links this item to the given Frame, this may be set to null to remove a 1201 * link. 1202 * 1203 * @param frameName 1204 * The name of the Frame to link this item to. 1205 */ 1206 public void setLink(String frameName) { 1207 _link = frameName; 1208 } 1209 1210 public void setLinkFrameset(String frameset) { 1211 _link_frameset = frameset; 1212 } 1213 1214 public void setLinkMark(boolean val) { 1215 _linkMark = val; 1216 } 1217 1218 public void setLinkTemplate(String template) { 1219 _link_template = template; 1220 } 1221 1222 /** 1223 * Sets the maximum coordinates on the screen that this item may occupy. 1224 * This is used by Text items to compute word-wrapping lengths. 1225 * 1226 * @param d 1227 * The Maximum size of the Frame containing this Item. 1228 */ 1229 public void setMaxSize(Dimension d) { 1230 if (d != null) { 1231 _maxSize = d; 1232 updatePolygon(); 1233 } 1234 } 1235 1236 public void setOffset(int x, int y) { 1237 _offset.setLocation(x, y); 1238 } 1239 1240 public void setOffset(Point p) { 1241 _offset.setLocation(p); 1242 } 1243 1244 public void setOwner(String own) { 1245 _owner = own; 1246 } 1247 1248 public void setParent(Frame frame) { 1249 _parent = frame; 1250 } 1251 1252 /** 1253 * Sets the position of this item on the screen 1254 * 1255 * @param x 1256 * The new X coordinate 1257 * @param y 1258 * The new Y coordinate 1259 */ 1260 public void setPosition(int x, int y) { 1261 _x = x; 1262 _y = y; 1263 1264 updatePolygon(); 1265 1266 // update the position of any dots that are constrained by this one 1267 if (_constraints != null) { 1268 for (Constraint c : _constraints) { 1269 Item other = c.getOppositeEnd(this); 1270 1271 // only set the position if the other dot is still fixed to the 1272 // frame 1273 if (!other.isFloating()) { 1274 if (c.getConstraintType() == Constraint.HORIZONTAL 1275 && other.getY() != getY()) 1276 other.setY(getY()); 1277 1278 if (c.getConstraintType() == Constraint.VERTICAL 1279 && other.getX() != getX()) 1280 other.setX(getX()); 1281 } 1282 } 1283 } 1284 1285 for (Line line : getLines()) 1286 line.updatePolygon(); 1287 } 1288 1289 public void setPosition(Point position) { 1290 setPosition(position.x, position.y); 1291 } 1292 1293 public void setRelativeLink() { 1294 if (_link == null) 1295 return; 1296 assert (_parent != null); 1297 // Check if the link is for the current frameset 1298 if (_parent.getFramesetName().equalsIgnoreCase( 1299 Conversion.getFrameset(_link))) { 1300 _link = "" + Conversion.getFrameNumber(_link); 1301 } 1302 } 1303 1304 /** 1305 * Sets the size of this Item. For Text this is the Font size. For Lines and 1306 * Dots this is the thickness. 1307 */ 1308 public abstract void setSize(int size); 1309 1310 public void setThickness(float thick) throws UnsupportedOperationException { 1311 throw new UnsupportedOperationException( 1312 "Item type does not support thickness attribute!"); 1313 } 1314 1315 /** 1316 * Sets the Color to use on the top and left sections of this Item's border. 1317 * If top is NULL, then the Item's background Color will be used. 1318 * 1319 * @param top 1320 * The Color to display in the top and left sections of this 1321 * Item's border. 1322 */ 1323 public void setTopShadowColor(Color top) { 1324 _colorTopShadow = top; 1325 } 1326 1327 public void setWidth(int width) throws UnsupportedOperationException { 1328 throw new UnsupportedOperationException( 1329 "Item type does not support width attribute!"); 1330 } 1331 1332 /** 1333 * Sets the position of this Item on the X axis 1334 * 1335 * @param newX 1336 * The position on the X axis to assign to this Item 1337 */ 1338 public void setX(int newX) { 1339 setPosition(newX, getY()); 1340 } 1341 1342 /** 1343 * Sets the position of this Item on the Y axis 1344 * 1345 * @param newY 1346 * The position on the Y axis to assign to this Item 1347 */ 1348 public void setY(int newY) { 1349 setPosition(getX(), newY); 1350 } 1351 1352 public int showDepressedHighlight(boolean val) { 1353 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 1354 return showHighlight(val, DEPRESSED_HIGHLIGHT); 1355 } 1356 1357 public int showDisconnectHighlight(boolean val) { 1358 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 1359 return showHighlight(val, DISCONNECT_HIGHLIGHT); 1360 } 1361 1362 /** 1363 * Paints any highlighting of this Item. This may include changing the 1364 * thickness (lines) or painting a box around the item (Text, Images). If 1365 * val is True then the Graphics Color is changed to the highlight Color, if 1366 * False then the Graphics Color is left unchanged (for clearing of 1367 * highlighting). 1368 * 1369 * @param val 1370 * True if this Item should be highlighted, false if the 1371 * highlighting is being cleared.\ 1372 * @return The desired mouse cursor when this Item is highlighted (negative 1373 * means no change) 1374 */ 1375 public int showHighlight(boolean val) { 1376 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 1377 return showHighlight(val, DEFAULT_HIGHLIGHT); 1378 } 1379 1380 public int showHighlight(boolean val, Color c) { 1381 _isHighlighted = val; 1382 if (c != null) 1383 _highlightColor = c; 1384 else 1385 _highlightColor = DEFAULT_HIGHLIGHT; 1386 1387 return Item.UNCHANGED_CURSOR; 1388 } 1178 1389 private void updateArrowPolygon() { 1179 1390 if (getArrowheadLength() < 0 || getArrowheadRatio() < 0) … … 1193 1404 } 1194 1405 } 1195 1196 protected boolean hasVisibleArrow() { 1197 return false; 1198 } 1199 1200 public String getArrow() { 1201 if (!hasVisibleArrow()) 1202 return null; 1203 1204 String ratio = "" + getArrowheadRatio(); 1205 if (ratio.length() - ratio.indexOf(".") > 2) 1206 ratio = ratio.substring(0, ratio.indexOf(".") + 3); 1207 1208 return getArrowheadLength() + " " + ratio; 1209 } 1210 1211 public Polygon getArrowhead() { 1212 return _arrowhead; 1213 } 1214 1215 public void setArrowhead(Polygon arrow) { 1216 _arrowhead = arrow; 1217 } 1218 1219 /** 1220 * This method performs all the actions in an items list. If it contains a 1221 * link as well the link is used as the source frame for all acitons. 1222 */ 1223 public void performActions() { 1224 Frame sourceFrame = null; 1225 // if a link exists make it the source frame for this action 1226 if (getLink() != null) { 1227 sourceFrame = FrameUtils.getFrame(getLink()); 1228 } 1229 // if no link exists or the link is bad then use the 1230 // currently displayed frame as the source frame for the 1231 // action 1232 if (sourceFrame == null) { 1233 sourceFrame = DisplayIO.getCurrentFrame(); 1234 } 1235 1236 for (String s : getAction()) { 1237 Actions.PerformAction(sourceFrame, this, s); 1238 } 1239 } 1240 1241 /** 1242 * Checks if this item is a frame title. 1243 * 1244 * @return true if the item is a frame title 1245 */ 1246 /* 1247 * public boolean isTitle() { // check if the title has been assigned if 1248 * (getID() >= 0 && this instanceof Text) if (getX() < 200 && getY() < 1249 * getSize() + system.io.KMSConversion.Y_ADJUST) return true; return false; } 1250 */ 1251 1252 public boolean isOldTag() { 1253 if (this instanceof Text) 1254 if (((Text) this).getText().get(0).toLowerCase().equals("@old")) 1255 return true; 1256 return false; 1257 } 1258 1259 public boolean isFrameName() { 1260 if (this.getParent() == null || this.getParent().getName() != this) 1261 return false; 1262 return true; 1263 } 1264 1265 public boolean isFrameTitle() { 1266 if (this.getParent() == null || this.getParent().getTitle() != this) 1267 return false; 1268 return true; 1269 } 1270 1271 /** 1272 * Sets the created date of this Frame to the given String. 1273 * 1274 * @param date 1275 * The date to use for this Frame. 1276 */ 1277 public void setDateCreated(String date) { 1278 _creationDate = date; 1279 } 1280 1281 public String getDateCreated() { 1282 return _creationDate; 1283 } 1284 1285 public float getThickness() { 1286 return 0; 1287 } 1288 1289 public void setThickness(float thick) throws UnsupportedOperationException { 1290 throw new UnsupportedOperationException( 1291 "Item type does not support thickness attribute!"); 1292 } 1293 1294 public void setWidth(int width) throws UnsupportedOperationException { 1295 throw new UnsupportedOperationException( 1296 "Item type does not support width attribute!"); 1297 } 1298 1299 public int getWidth() { 1300 return 0; 1301 } 1302 1303 public void run() { 1304 try { 1305 AgentStats.reset(); 1306 FrameGraphics 1307 .DisplayMessage("Running SimpleProgram...", Color.BLUE); 1308 Simple.RunFrameAndReportError(this, new Context()); 1309 Simple.ProgramFinished(); 1310 FrameGraphics.DisplayMessage(AgentStats.getStats(), GREEN); 1311 } catch (ConcurrentModificationException ce) { 1312 ce.printStackTrace(); 1313 } catch (Exception e) { 1314 FrameGraphics.LinkedErrorMessage(e.getMessage()); 1315 Simple.ProgramFinished(); 1316 } 1317 } 1318 1319 public String getTypeAndID() { 1320 return "T " + getID(); 1321 } 1322 1323 /** 1324 * Check if it has a relative link if so make it absolute. 1325 * 1326 */ 1327 public void setAbsoluteLink() { 1328 if (_link == null) 1329 return; 1330 // Check if all the characters are digits and hence it is a relative 1331 // link 1332 for (int i = 0; i < _link.length(); i++) { 1333 if (!Character.isDigit(_link.charAt(i))) 1334 return; 1335 } 1336 1337 // Make it an absolute link 1338 String framesetName; 1339 1340 if (_parent == null) 1341 framesetName = DisplayIO.getCurrentFrame() 1342 .getFramesetNameAdjusted(); 1343 else 1344 framesetName = _parent.getFramesetNameAdjusted(); 1345 1346 _link = framesetName + _link; 1347 } 1348 1349 public void setRelativeLink() { 1350 if (_link == null) 1351 return; 1352 assert (_parent != null); 1353 // Check if the link is for the current frameset 1354 if (_parent.getFramesetName().equalsIgnoreCase( 1355 Conversion.getFrameset(_link))) { 1356 _link = "" + Conversion.getFrameNumber(_link); 1357 } 1406 1407 protected abstract void updatePolygon(); 1408 1409 public void setVisible(boolean state) { 1410 this._visible = state; 1411 } 1412 1413 public boolean isVisible() { 1414 return _visible; 1358 1415 } 1359 1416 }
Note:
See TracChangeset
for help on using the changeset viewer.