Changeset 1102 for trunk/src/org/expeditee/items/Item.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Item.java
r977 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.BasicStroke;22 import java.awt.Color;23 import java.awt.Cursor;24 import java.awt.GradientPaint;25 import java.awt.Graphics2D;26 import java.awt.Point;27 import java.awt.Polygon;28 import java.awt.Rectangle;29 import java.awt.Shape;30 import java.awt.Stroke;31 import java.awt.geom.AffineTransform;32 import java.awt.geom.Area;33 import java.awt.geom.Point2D;34 import java.awt.geom.Rectangle2D;35 21 import java.util.ArrayList; 36 22 import java.util.Collection; … … 46 32 import org.expeditee.actions.Misc; 47 33 import org.expeditee.actions.Simple; 34 import org.expeditee.core.Anchoring; 35 import org.expeditee.core.Colour; 36 import org.expeditee.core.Cursor; 37 import org.expeditee.core.Dimension; 38 import org.expeditee.core.Fill; 39 import org.expeditee.core.GradientFill; 40 import org.expeditee.core.Point; 41 import org.expeditee.core.Stroke; 42 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 43 import org.expeditee.core.bounds.Bounds; 44 import org.expeditee.core.bounds.EllipticalBounds; 45 import org.expeditee.core.bounds.PolygonBounds; 46 import org.expeditee.gio.EcosystemManager; 47 import org.expeditee.gio.GraphicsManager; 48 import org.expeditee.gio.gesture.StandardGestureActions; 48 49 import org.expeditee.gui.AttributeValuePair; 49 import org.expeditee.gui.Display IO;50 import org.expeditee.gui.DisplayController; 50 51 import org.expeditee.gui.Frame; 51 52 import org.expeditee.gui.FrameGraphics; 52 53 import org.expeditee.gui.FrameIO; 53 import org.expeditee.gui.FrameKeyboardActions;54 import org.expeditee.gui.FrameMouseActions;55 54 import org.expeditee.gui.FrameUtils; 56 55 import org.expeditee.gui.FreeItems; … … 75 74 public abstract class Item implements Comparable<Item>, Runnable { 76 75 77 public static final Float DEFAULT_THICKNESS = 2f; 78 79 public static final Float MINIMUM_THICKNESS = 0f; 80 81 public static final Float MINIMUM_PAINT_THICKNESS = 1f; 82 83 protected final int JOIN = BasicStroke.JOIN_ROUND; 84 85 protected final int CAP = BasicStroke.CAP_BUTT; 86 87 protected final Stroke DOT_STROKE = new BasicStroke(DEFAULT_THICKNESS, 88 CAP, JOIN, 4.0F); 89 90 protected final Stroke HIGHLIGHT_STROKE = new BasicStroke( 91 MINIMUM_THICKNESS, CAP, JOIN, 4.0F); 92 93 // contains all dots (including this one) that form an enclosure 94 // if this dot is part of an enclosing shape 95 private Collection<Item> _enclosure = null; 96 97 public static final int LEFT_MARGIN = 13; 98 99 // indicates which end the arrowhead should be drawn at 100 protected Polygon _poly = null; 101 102 protected boolean _connectedToAnnotation = false; 103 104 protected boolean _save = true; 105 106 private int _gradientAngle = 0; 107 108 public static final int NEAR_DISTANCE = 15; 109 110 /** 111 * The default Color to draw highlighting in 112 */ 113 public static final int DEFAULT_HIGHLIGHT_THICKNESS = 2; 114 115 public static final Color DEFAULT_HIGHLIGHT = Color.RED; 116 117 public static final Color DEPRESSED_HIGHLIGHT = Color.GREEN; 118 119 public static final Color ALTERNATE_HIGHLIGHT = Color.BLUE; 120 121 public static final Color LINK_COLOR = Color.BLACK; 122 123 public static final Color ACTION_COLOR = Color.BLACK; 124 125 public static final Color LINK_ACTION_COLOR = Color.RED; 126 127 public static final Color DEFAULT_FOREGROUND = Color.BLACK; 128 129 public static final Color DEFAULT_BACKGROUND = Color.white; 130 131 public static final Color TRANSPARENT = new Color(0, 0, 0, 0); 132 133 /** 134 * The number of pixels highlighting should extend around Items. 135 */ 136 public static final int XGRAVITY = 3; 137 138 public static final int MARGIN_RIGHT = 2; 139 140 public static final int MARGIN_LEFT = 15; 141 142 protected static final double DEFAULT_ARROWHEAD_RATIO = 0.3; // used to be 0.5 143 144 public static final double DEFAULT_ARROWHEAD_NIB_PERC = 0.75; 145 146 public static final Color GREEN = Color.GREEN.darker(); 147 148 public static final int UNCHANGED_CURSOR = -100; 149 150 public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR; 151 152 public static final int HIDDEN_CURSOR = Cursor.CUSTOM_CURSOR; 153 154 public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR; 155 156 public static final int CROP_CURSOR = Cursor.CROSSHAIR_CURSOR; 157 158 // The default value for integer attributes 159 public static final int DEFAULT_INTEGER = -1; 160 161 protected DotType _type = DotType.square; 162 163 protected boolean _filled = true; 164 165 private Tooltip _tooltip = new Tooltip(); 166 76 public enum HighlightMode { 77 None, // The item has no highlighting 78 Enclosed, // The item is part of the current enclosure 79 Connected, // The item is connected to the current item 80 Disconnect, // The item is a free item 81 Normal // The item is the current item 82 } 83 84 /** Which edge of the window things are anchored to. */ 167 85 public enum AnchorEdgeType { 168 86 None, Left, Right, Top, Bottom 169 87 } 170 171 public static void DuplicateItem(Item source, Item dest) { 172 dest.setX(source.getX()); 173 dest.setY(source.getY()); 174 175 dest.setActions(source.getAction()); 176 dest.setActionCursorEnter(source.getActionCursorEnter()); 177 dest.setActionCursorLeave(source.getActionCursorLeave()); 178 dest.setActionEnterFrame(source.getActionEnterFrame()); 179 dest.setActionLeaveFrame(source.getActionLeaveFrame()); 180 dest.setActionMark(source.getActionMark()); 181 182 dest.setBackgroundColor(source.getBackgroundColor()); 183 dest.setBottomShadowColor(source.getBottomShadowColor()); 184 dest.setColor(source.getColor()); 185 dest.setBorderColor(source.getBorderColor()); 186 187 dest.setTooltips(source.getTooltip()); 188 dest.setData(source.getData()); 189 dest.setTag(source.getTag()); 190 dest.setFillColor(source.getFillColor()); 191 dest.setGradientColor(source.getGradientColor()); 192 dest.setGradientAngle(source.getGradientAngle()); 193 dest.setFillPattern(source.getFillPattern()); 194 195 dest.setHighlight(source.getHighlight()); 196 dest.setLink(source.getLink()); 197 dest.setLinkFrameset(source.getLinkFrameset()); 198 dest.setLinkMark(source.getLinkMark()); 199 dest.setLinkTemplate(source.getLinkTemplate()); 200 201 // dest.setMaxWidth(source.getMaxWidth()); 202 203 dest.setOffset(source.getOffset()); 204 // dest.setOwner(source.getOwner()); 205 dest.setThickness(source.getThickness()); 206 dest.setSize(source.getSize()); 207 dest.setTopShadowColor(source.getTopShadowColor()); 208 dest.setLinePattern(source.getLinePattern()); 209 210 dest.setFloating(source.isFloating()); 211 dest.setArrow(source.getArrowheadLength(), source.getArrowheadRatio(), source.getArrowheadNibPerc()); 212 213 dest.setDotType(source.getDotType()); 214 dest.setFilled(source.getFilled()); 88 89 public static final float SIZE_NOT_APPLICABLE = Float.NaN; 90 91 public static final Float DEFAULT_THICKNESS = 2f; 92 93 public static final Float MINIMUM_THICKNESS = 0f; 94 95 public static final Float MINIMUM_PAINT_THICKNESS = 1f; 96 97 protected static final Stroke.JOIN DEFAULT_JOIN = Stroke.JOIN.ROUND; 98 99 protected static final Stroke.CAP DEFAULT_CAP = Stroke.CAP.BUTT; 100 101 protected static final Stroke DOT_STROKE = new Stroke(DEFAULT_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN); 102 103 protected static final Stroke HIGHLIGHT_STROKE = new Stroke(MINIMUM_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN); 104 105 public static final int LEFT_MARGIN = 13; 106 107 public static final int NEAR_DISTANCE = 15; 108 109 public static final int DEFAULT_HIGHLIGHT_THICKNESS = 2; 110 111 /** The default colour to draw highlighting in */ 112 public static final Colour DEFAULT_HIGHLIGHT = Colour.RED; 113 114 public static final Colour DEPRESSED_HIGHLIGHT = Colour.GREEN; 115 116 public static final Colour ALTERNATE_HIGHLIGHT = Colour.BLUE; 117 118 public static final Colour LINK_COLOR = Colour.BLACK; 119 120 public static final Colour ACTION_COLOR = Colour.BLACK; 121 122 public static final Colour LINK_ACTION_COLOR = Colour.RED; 123 124 public static final Colour DEFAULT_FOREGROUND = Colour.BLACK; 125 126 public static final Colour DEFAULT_BACKGROUND = Colour.WHITE; 127 128 public static final Colour TRANSPARENT = new Colour(0, 0, 0, 0); 129 130 /** The number of pixels highlighting should extend around Items. */ 131 public static final int XGRAVITY = 3; 132 133 public static final int MARGIN_RIGHT = 2; 134 135 public static final int MARGIN_LEFT = 15; 136 137 protected static final double DEFAULT_ARROWHEAD_RATIO = 0.3; // used to be 0.5 138 139 public static final double DEFAULT_ARROWHEAD_NIB_PERC = 0.75; 140 141 public static final Colour GREEN = Colour.GREEN.darker(); 142 143 //public static final int UNCHANGED_CURSOR = -100; 144 145 public static final Cursor.CursorType DEFAULT_CURSOR = Cursor.CursorType.DEFAULT; 146 147 public static final Cursor.CursorType HIDDEN_CURSOR = Cursor.CursorType.CUSTOM; 148 149 public static final Cursor.CursorType TEXT_CURSOR = Cursor.CursorType.TEXT; 150 151 public static final Cursor.CursorType CROP_CURSOR = Cursor.CursorType.CROSSHAIR; 152 153 /** The default value for integer attributes */ 154 public static final int DEFAULT_INTEGER = -1; 155 156 private static final int BRIGHTNESS = 185; 157 158 /** Contains all dots (including this one) that form an enclosure if this dot is part of an enclosing shape. */ 159 private Collection<Item> _enclosure = null; 160 161 /** The area which this item covers (including its gravity). */ 162 private Bounds _bounds = null; 163 164 /** The area this item covered before it was invalidated. */ 165 private Bounds _oldBounds = null; 166 167 protected boolean _connectedToAnnotation = false; 168 169 protected boolean _save = true; 170 171 /** The angle of change for gradient colour fills (in radians). */ 172 private double _gradientAngle = 0.0; 173 174 private Tooltip _tooltip = new Tooltip(); 175 176 protected Anchoring _anchoring = new Anchoring(); 177 178 /** The highlight mode for this item. */ 179 protected HighlightMode _highlightMode = HighlightMode.None; 180 181 private Point _offset = new Point(0, 0); 182 183 protected float _x; 184 protected float _y; 185 186 private int _id; 187 188 private Item _editTarget = this; 189 190 private String _creationDate = null; 191 192 /** Whether or not this item should display a mark indicating it has a link. */ 193 private boolean _linkMark = true; 194 195 /** Whether or not this item should display a mark indicating it has an action. */ 196 private boolean _actionMark = true; 197 198 /** TODO: Appears unused? cts16 */ 199 private boolean _highlight = true; 200 201 // private int _maxWidth = -1; 202 203 private String _owner = null; 204 205 private String _link = null; 206 207 private boolean _linkHistory = true; 208 209 private StringBuffer _tag = new StringBuffer(); 210 211 private List<String> _actionCursorEnter = null; 212 213 private List<String> _actionCursorLeave = null; 214 215 private List<String> _actionEnterFrame = null; 216 217 private List<String> _actionLeaveFrame = null; 218 219 private PermissionPair _permissionPair = null; 220 221 private UserAppliedPermission _overlayPermission = null; 222 223 /** The primary fill colour of this item. A fill colour of null represents transparent. */ 224 private Colour _fillColour = null; 225 226 /** The secondary fill colour if this item has a gradient fill. Null represents no gradient. */ 227 private Colour _gradientColour = null; 228 229 /** The primary draw colour of this item. Null represents the default colour. */ 230 private Colour _foregroundColour = null; 231 232 /** The colour to draw highlights on this item. */ 233 protected Colour _highlightColour = DEFAULT_HIGHLIGHT; 234 235 /** The background colour for this item. */ 236 private Colour _backgroundColour = null; 237 238 private Colour _colorBorder = null; 239 240 private Colour _colorTopShadow = null; 241 242 private Colour _colorBottomShadow = null; 243 244 /** The shape representing the circle drawn next to link/action items. */ 245 private static EllipticalBounds _linkCircle = null; 246 247 /** The shape representing the cross drawn next to invalid links. */ 248 private static PolygonBounds _linkCircleCross = null; 249 250 private Frame _parent = null; 251 private Frame _oldParent = null; 252 253 protected int _highlightThickness = 2; 254 255 protected int _vectorHighlightThickness = 1; 256 257 // arrowhead parameters 258 private float _arrowheadLength = 0; 259 private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO; 260 private double _arrowheadNibPerc = DEFAULT_ARROWHEAD_NIB_PERC; 261 262 private PolygonBounds _arrowhead = null; 263 264 // the list of lines that this point is part of. 265 private List<Line> _lines = new ArrayList<Line>(); 266 267 private int[] _linePattern = null; 268 269 private boolean _floating = false; 270 271 // list of points constrained with this point 272 private List<Constraint> _constraints = new ArrayList<Constraint>(); 273 274 private List<String> _actions = null; 275 276 private List<String> _data = null; 277 278 private String _formula = null; 279 280 private String _link_frameset = null; 281 282 private String _link_template = null; 283 284 private String _fillPattern = null; 285 286 private boolean _visible = true; 287 288 private float _thickness = -1.0F; 289 290 protected Collection<XRayable> _enclosures = new HashSet<XRayable>(); 291 292 private boolean _deleted = false; 293 294 private Overlay _overlay = null; 295 296 protected AttributeValuePair _attributeValuePair = null; 297 298 private Float _autoStamp = null; 299 300 private Item _magnetizedItemLeft = null; 301 302 private Item _magnetizedItemRight = null; 303 304 private Item _magnetizedItemTop = null; 305 306 private Item _magnetizedItemBottom = null; 307 308 protected DotType _type = DotType.square; 309 310 protected boolean _filled = true; 311 312 /** Just calls source.duplicateOnto(dest). */ 313 public static void DuplicateItem(Item source, Item dest) 314 { 315 if (source == null) return; 316 317 source.duplicateOnto(dest); 318 } 319 320 /** Sets the properties of dest so that they match this item's properties. */ 321 public void duplicateOnto(Item dest) 322 { 323 if (dest == null) return; 324 325 dest.setX(this.getX()); 326 dest.setY(this.getY()); 327 328 dest.setActions(this.getAction()); 329 dest.setActionCursorEnter(this.getActionCursorEnter()); 330 dest.setActionCursorLeave(this.getActionCursorLeave()); 331 dest.setActionEnterFrame(this.getActionEnterFrame()); 332 dest.setActionLeaveFrame(this.getActionLeaveFrame()); 333 dest.setActionMark(this.getActionMark()); 334 335 dest.setBackgroundColor(this.getBackgroundColor()); 336 dest.setBottomShadowColor(this.getBottomShadowColor()); 337 dest.setColor(this.getColor()); 338 dest.setBorderColor(this.getBorderColor()); 339 340 dest.setTooltips(this.getTooltip()); 341 dest.setData(this.getData()); 342 dest.setTag(this.getTag()); 343 dest.setFillColor(this.getFillColor()); 344 dest.setGradientColor(this.getGradientColor()); 345 dest.setGradientAngle(this.getGradientAngle()); 346 dest.setFillPattern(this.getFillPattern()); 347 348 dest.setHighlight(this.getHighlight()); 349 dest.setLink(this.getLink()); 350 dest.setLinkFrameset(this.getLinkFrameset()); 351 dest.setLinkMark(this.getLinkMark()); 352 dest.setLinkTemplate(this.getLinkTemplate()); 353 354 // dest.setMaxWidth(this.getMaxWidth()); 355 356 dest.setOffset(this.getOffset()); 357 // dest.setOwner(this.getOwner()); 358 dest.setThickness(this.getThickness()); 359 dest.setSize(this.getSize()); 360 dest.setTopShadowColor(this.getTopShadowColor()); 361 dest.setLinePattern(this.getLinePattern()); 362 363 dest.setFloating(this.isFloating()); 364 dest.setArrow(this.getArrowheadLength(), this.getArrowheadRatio(), this.getArrowheadNibPerc()); 365 dest.setDotType(this.getDotType()); 366 dest.setFilled(this.getFilled()); 215 367 /* 216 368 * Calling the methods will move the item... This messes things up when 217 369 * the user uses backspace to delete a text line end 218 370 */ 219 // dest._anchorLeft = source._anchorLeft; 220 // dest._anchorRight = source._anchorRight; 221 // dest._anchorTop = source._anchorTop; 222 // dest._anchorBottom = source._anchorBottom; 223 dest.setFormula(source.getFormula()); 224 dest._overlay = source._overlay; 225 dest._mode = source._mode;// SelectedMode.None; 226 // dest._highlightColor = source._highlightColor; 227 // dest.setHighlight(source.getHighlight()); 228 229 dest._visible = source._visible; 230 231 Frame parent = DisplayIO.getCurrentFrame(); 232 if (parent == null) 233 parent = source.getParentOrCurrentFrame(); 371 // dest._anchorLeft = this._anchorLeft; 372 // dest._anchorRight = this._anchorRight; 373 // dest._anchorTop = this._anchorTop; 374 // dest._anchorBottom = this._anchorBottom; 375 dest.setFormula(this.getFormula()); 376 dest._overlay = this._overlay; 377 dest._highlightMode = this._highlightMode;// SelectedMode.None; 378 // dest._highlightColor = this._highlightColor; 379 // dest.setHighlight(this.getHighlight()); 380 381 dest._visible = this._visible; 382 383 Frame parent = DisplayController.getCurrentFrame(); 384 if (parent == null) parent = this.getParentOrCurrentFrame(); 234 385 dest.setParent(parent); 235 386 … … 246 397 } 247 398 } 248 249 public void setGradientAngle(int gradientAngle) { 399 400 public void setDotType(DotType type) { 401 invalidateAll(); 402 _type = type; 403 invalidateAll(); 404 } 405 406 public DotType getDotType() { 407 return _type; 408 } 409 410 411 public void setFilled(boolean filled) 412 { 413 invalidateAll(); 414 _filled = filled; 415 invalidateAll(); 416 } 417 418 public boolean getFilled() { 419 return _filled; 420 } 421 422 /** 423 * Sets the angle of colour change for gradient colour fills. 424 * 425 * @param gradientAngle The new angle of colour change. 426 */ 427 public void setGradientAngle(double gradientAngle) 428 { 250 429 _gradientAngle = gradientAngle; 251 430 252 431 for (Line line : _lines) { 253 432 Item other = line.getOppositeEnd(this); 254 if (other.getGradientAngle() != gradientAngle) 255 other.setGradientAngle(gradientAngle); 433 if (other.getGradientAngle() != gradientAngle) other.setGradientAngle(gradientAngle); 256 434 } 257 435 … … 260 438 } 261 439 262 public int getGradientAngle() { 440 /** 441 * Gets the angle of colour change for gradient fills. 442 * 443 * @return The angle of colour change. 444 */ 445 public double getGradientAngle() { 263 446 return _gradientAngle; 264 447 } 265 448 266 public int getGravity() { 267 if (isVectorItem()) { 268 return 2; 269 } 449 /** 450 * Gets the gravity for this item. Gravity is the distance from the item at which mouse interaction 451 * applies to the item (like a small buffer zone so you don't need to click exactly on the item). 452 * 453 * @return The gravity distance for this item. 454 */ 455 public int getGravity() 456 { 457 if (isVectorItem()) return 2; 458 270 459 return UserSettings.Gravity.get(); 271 460 } 272 461 273 public static boolean showLineHighlight() { 462 /** 463 * Whether or not line highlights should be shown. 464 * TODO: Not really an item method is it? Goes straight to user settings. Refactor. cts16 465 * 466 * @return <code>true</code> if line highlighting should be shown, <code>false</code> otherwise. 467 */ 468 public static boolean shouldShowLineHighlight() 469 { 274 470 return UserSettings.LineHighlight.get(); 275 471 } 276 472 277 public enum HighlightMode { 278 None, Enclosed, Connected, Disconnect, Normal 279 } 280 281 public void setHighlightMode(HighlightMode mode) { 282 setHighlightMode(mode, DEFAULT_HIGHLIGHT); 283 } 284 285 protected Float _anchorLeft = null; 286 protected Float _anchorRight = null; 287 288 protected Float _anchorTop = null; 289 protected Float _anchorBottom = null; 290 291 protected HighlightMode _mode = HighlightMode.None; 292 293 private Point _offset = new Point(0, 0); 294 295 protected float _x; 296 protected float _y; 297 298 private int _id; 299 300 private Item _editTarget = this; 301 302 private String _creationDate = null; 303 304 private boolean _linkMark = true; 305 306 private boolean _actionMark = true; 307 308 private boolean _highlight = true; 309 310 // private int _maxWidth = -1; 311 312 private String _owner = null; 313 314 private String _link = null; 315 316 private boolean _linkHistory = true; 317 318 private StringBuffer _tag = new StringBuffer(); 319 320 private List<String> _actionCursorEnter = null; 321 322 private List<String> _actionCursorLeave = null; 323 324 private List<String> _actionEnterFrame = null; 325 326 private List<String> _actionLeaveFrame = null; 327 328 private PermissionPair _permissionPair = null; 329 330 private UserAppliedPermission _overlayPermission = null; 331 332 public void setOverlayPermission(UserAppliedPermission overlayPermission) { 473 /** 474 * Sets the highlight mode for this item. 475 * 476 * @param mode The new highlight mode. 477 */ 478 public void setHighlightMode(HighlightMode mode) 479 { 480 if (hasPermission(UserAppliedPermission.followLinks) || getEditTarget().hasPermission(UserAppliedPermission.followLinks)) { 481 if (_highlightMode != mode) { 482 _highlightMode = mode; 483 this.invalidateCommonTrait(ItemAppearence.HighlightModeChanged); 484 } 485 } 486 } 487 488 public void setOverlayPermission(UserAppliedPermission overlayPermission) 489 { 333 490 _overlayPermission = overlayPermission; 334 491 } 335 492 336 public void setPermission(PermissionPair permissionPair) { 493 public void setPermission(PermissionPair permissionPair) 494 { 337 495 _permissionPair = permissionPair; 338 496 } … … 354 512 } 355 513 356 // A fill color of null represents transparent357 private Color _colorFill = null;358 359 // A gradient color of null represents NO gradient360 private Color _colorGradient = null;361 362 // A fore color of null represents the default color363 private Color _color = null;364 365 protected Color _highlightColor = DEFAULT_HIGHLIGHT;366 367 private Color _colorBackground = null;368 369 private Color _colorBorder = null;370 371 private Color _colorTopShadow = null;372 373 private Color _colorBottomShadow = null;374 375 // the link\action circle376 private Polygon _circle = null;377 378 // the invalid link cross379 private Polygon _circleCross = null;380 381 private Frame _parent = null;382 private Frame _oldParent = null;383 384 protected int _highlightThickness = 2;385 386 protected int _vectorHighlightThickness = 1;387 388 // arrowhead parameters389 private float _arrowheadLength = 0;390 private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO;391 private double _arrowheadNibPerc = DEFAULT_ARROWHEAD_NIB_PERC;392 393 private Polygon _arrowhead = null;394 395 // the list of lines that this point is part of.396 private List<Line> _lines = new ArrayList<Line>();397 398 private int[] _linePattern = null;399 400 private boolean _floating = false;401 402 // list of points constrained with this point403 private List<Constraint> _constraints = new ArrayList<Constraint>();404 405 private List<String> _actions = null;406 407 private List<String> _data = null;408 409 private String _formula = null;410 411 private String _link_frameset = null;412 413 private String _link_template = null;414 415 private String _fillPattern = null;416 417 private boolean _visible = true;418 419 private float _thickness = -1.0F;420 421 514 protected Item() { 422 515 _creationDate = Formatter.getLongDateTime(); … … 427 520 * 428 521 * @param action 429 * The action to add to this Item 430 */ 431 public void addAction(String action) { 432 if (action == null || action.equals("")) { 433 return; 434 } 522 * The name of the action to add to this Item. 523 */ 524 public void addAction(String action) 525 { 526 if (action == null || action.equals("")) return; 435 527 436 528 if (_actions == null) { 437 529 _actions = new LinkedList<String>(); 438 530 } 531 439 532 _actions.add(action); 533 440 534 if (_actions.size() == 1) { 441 _poly = null;535 invalidateBounds(); 442 536 invalidateCommonTrait(ItemAppearence.LinkChanged); 443 537 } 444 538 } 445 539 446 public void addAllConnected(Collection<Item> connected) {447 if (!connected.contains(this))448 540 public void addAllConnected(Collection<Item> connected) 541 { 542 if (!connected.contains(this)) connected.add(this); 449 543 450 544 for (Item item : getConnected()) { 451 if (!connected.contains(item)) 545 if (!connected.contains(item)) { 452 546 item.addAllConnected(connected); 547 } 453 548 } 454 549 } … … 460 555 * The Constraint to set this Dot as a member of. 461 556 */ 462 public void addConstraint(Constraint c) { 557 public void addConstraint(Constraint c) 558 { 463 559 // do not add duplicate constraint 464 560 if (_constraints.contains(c)) … … 474 570 * The Line that this Point is an end of. 475 571 */ 476 public void addLine(Line line) { 572 public void addLine(Line line) 573 { 477 574 if (_lines.contains(line)) { 478 575 return; … … 490 587 * less than, equal to, or greater than the specified object. 491 588 */ 492 public int compareTo(Item i) { 589 public int compareTo(Item i) 590 { 493 591 return getY() - i.getY(); 494 592 } … … 499 597 * the area and false otherwise. 500 598 * 501 * @param x 502 * The x coordinate to check 503 * @param y 504 * The y coordinate to check 599 * @param p 600 * The coordinate to check 505 601 * @return True if the Shape around this Item contains the given x,y pair, 506 602 * false otherwise. 507 603 */ 508 public boolean contains(int x, int y) { 509 return getPolygon().contains(x, y); 604 public boolean contains(Point p) 605 { 606 return getBounds().contains(p); 510 607 } 511 608 … … 518 615 public abstract Item copy(); 519 616 520 public void delete() { 617 public void delete() 618 { 521 619 _deleted = true; 522 620 } 523 621 524 622 @Override 525 public boolean equals(Object o) { 623 public boolean equals(Object o) 624 { 526 625 if (o == null) 527 626 return false; … … 542 641 * has been assigned. 543 642 */ 544 public List<String> getAction() { 643 public List<String> getAction() 644 { 545 645 return _actions; 546 646 } 547 647 548 public List<String> getData() { 648 public List<String> getData() 649 { 549 650 return _data; 550 651 } 551 652 552 public List<String> getActionCursorEnter() { 653 public List<String> getActionCursorEnter() 654 { 553 655 return _actionCursorEnter; 554 656 } 555 657 556 public List<String> getActionCursorLeave() { 658 public List<String> getActionCursorLeave() 659 { 557 660 return _actionCursorLeave; 558 661 } 559 662 560 public List<String> getActionEnterFrame() { 663 public List<String> getActionEnterFrame() 664 { 561 665 return _actionEnterFrame; 562 666 } 563 667 564 public List<String> getActionLeaveFrame() { 668 public List<String> getActionLeaveFrame() 669 { 565 670 return _actionLeaveFrame; 566 671 }; 567 672 568 public boolean getActionMark() { 673 public boolean getActionMark() 674 { 569 675 return _actionMark; 570 676 } … … 576 682 * @return 577 683 */ 578 public Collection<Item> getAllConnected() { 684 public Collection<Item> getAllConnected() 685 { 579 686 Collection<Item> list = new LinkedHashSet<Item>(); 580 687 addAllConnected(list); … … 582 689 } 583 690 584 public Area getArea() {691 /* public Area getArea() { 585 692 return new Area(getPolygon()); 586 } 587 588 public String getArrow() { 693 }*/ 694 695 public String getArrow() 696 { 589 697 if (!hasVisibleArrow()) 590 698 return null; … … 597 705 } 598 706 599 public Polygon getArrowhead() { 707 public PolygonBounds getArrowhead() 708 { 600 709 return _arrowhead; 601 710 } 602 711 603 public float getArrowheadLength() { 712 public float getArrowheadLength() 713 { 604 714 return _arrowheadLength; 605 715 } 606 716 607 public double getArrowheadRatio() { 717 public double getArrowheadRatio() 718 { 608 719 return _arrowheadRatio; 609 720 } 610 721 611 public double getArrowheadNibPerc() { 722 public double getArrowheadNibPerc() 723 { 612 724 return _arrowheadNibPerc; 613 725 } 614 726 615 public Color getBackgroundColor() { 616 return _colorBackground; 617 } 618 619 public Color getBorderColor() { 727 public Colour getBackgroundColor() 728 { 729 return _backgroundColour; 730 } 731 732 public Colour getBorderColor() 733 { 620 734 return _colorBorder; 621 735 } … … 628 742 * border. 629 743 */ 630 public Color getBottomShadowColor() { 744 public Colour getBottomShadowColor() 745 { 631 746 return _colorBottomShadow; 632 747 } … … 638 753 * returned by getArea(). 639 754 */ 640 public int getBoundsHeight() { 641 return getPolygon().getBounds().height; 755 public int getBoundsHeight() 756 { 757 return AxisAlignedBoxBounds.getEnclosing(getBounds()).getHeight(); 642 758 } 643 759 … … 648 764 * by getArea(). 649 765 */ 650 public int getBoundsWidth() { 651 return getPolygon().getBounds().width; 652 } 653 654 // TODO draw the link with a circle rather than a polygon!! 655 public Polygon getLinkPoly() { 656 if (_circle == null) { 657 int points = 16; 658 659 double radians = 0.0; 660 int xPoints[] = new int[points]; 661 int yPoints[] = new int[xPoints.length]; 662 663 for (int i = 0; i < xPoints.length; i++) { 664 // circle looks best if these values are not related to gravity 665 xPoints[i] = (int) (3.5 * Math.cos(radians)) + 6;// (2 * 666 // GRAVITY); 667 yPoints[i] = (int) (3.5 * Math.sin(radians)) + 3;// GRAVITY; 668 radians += (2.0 * Math.PI) / xPoints.length; 669 } 670 671 _circle = new Polygon(xPoints, yPoints, xPoints.length); 672 } 673 674 return _circle; 675 } 676 677 protected Polygon getCircleCross() { 678 679 if (_circleCross == null) { 680 _circleCross = new Polygon(); 681 682 Rectangle bounds = getLinkPoly().getBounds(); 683 int x1 = (int) bounds.getMinX(); 684 int x2 = (int) bounds.getMaxX(); 685 int y1 = (int) bounds.getMinY(); 686 int y2 = (int) bounds.getMaxY(); 687 int midX = ((x2 - x1) / 2) + x1; 688 int midY = ((y2 - y1) / 2) + y1; 689 690 _circleCross.addPoint(x1, y1); 691 _circleCross.addPoint(x2, y2); 692 _circleCross.addPoint(midX, midY); 693 _circleCross.addPoint(x1, y2); 694 _circleCross.addPoint(x2, y1); 695 _circleCross.addPoint(midX, midY); 696 } 697 698 return _circleCross; 699 } 700 701 public Color getColor() { 702 return _color; 703 } 704 705 public Collection<Item> getConnected() { 766 public int getBoundsWidth() 767 { 768 return AxisAlignedBoxBounds.getEnclosing(getBounds()).getWidth(); 769 } 770 771 // TODO: Remove magic constants. cts16 772 public EllipticalBounds getLinkBounds() 773 { 774 if (_linkCircle == null) { 775 _linkCircle = new EllipticalBounds(new Point(6, 3), 7); 776 } 777 778 return _linkCircle; 779 } 780 781 protected PolygonBounds getCircleCross() 782 { 783 784 if (_linkCircleCross == null) { 785 _linkCircleCross = new PolygonBounds(); 786 787 EllipticalBounds poly = getLinkBounds(); 788 int x1 = poly.getMinX(); 789 int x2 = poly.getMaxX(); 790 int y1 = poly.getMinY(); 791 int y2 = poly.getMaxY(); 792 int midX = (x2 + x1) / 2; 793 int midY = (y2 + y1) / 2; 794 795 _linkCircleCross.addPoint(new Point(x1, y1)); 796 _linkCircleCross.addPoint(new Point(x2, y2)); 797 _linkCircleCross.addPoint(new Point(midX, midY)); 798 _linkCircleCross.addPoint(new Point(x1, y2)); 799 _linkCircleCross.addPoint(new Point(x2, y1)); 800 _linkCircleCross.addPoint(new Point(midX, midY)); 801 } 802 803 return _linkCircleCross; 804 } 805 806 public Colour getColor() 807 { 808 return _foregroundColour; 809 } 810 811 public Collection<Item> getConnected() 812 { 706 813 List<Item> conn = new LinkedList<Item>(); 707 814 conn.add(this); … … 711 818 } 712 819 713 public String getConstraintIDs() { 820 public String getConstraintIDs() 821 { 714 822 if (_constraints == null || _constraints.size() == 0) 715 823 return null; … … 732 840 * @return a List of Constraints that this Dot is a member of. 733 841 */ 734 public List<Constraint> getConstraints() { 842 public List<Constraint> getConstraints() 843 { 735 844 return _constraints; 736 845 } 737 846 738 public String getTag() { 847 public String getTag() 848 { 739 849 if (_tag != null && _tag.length() > 0) 740 850 return _tag.toString(); … … 742 852 } 743 853 744 public String getDateCreated() { 854 public String getDateCreated() 855 { 745 856 return _creationDate; 746 857 } 747 858 748 public Color getFillColor() { 749 return _colorFill; 750 } 751 752 public String getFillPattern() { 859 public Colour getFillColor() 860 { 861 return _fillColour; 862 } 863 864 public String getFillPattern() 865 { 753 866 return _fillPattern; 754 867 } 755 868 756 public String getFirstAction() { 869 public String getFirstAction() 870 { 757 871 if (_actions == null || _actions.size() == 0) 758 872 return null; … … 760 874 } 761 875 762 public boolean getHighlight() { 876 /** 877 * Gets the value of <code>_highlight</code> for this item. 878 * TODO: Appears unused? cts16. 879 * 880 * @return The value of <code>_highlight</code>. 881 */ 882 public boolean getHighlight() 883 { 763 884 return _highlight; 764 885 } 765 886 766 public Color getHighlightColor() { 767 if (_highlightColor.equals(getPaintColor())) 768 return getAlternateHighlightColor(); 887 public Colour getHighlightColor() 888 { 889 if (_highlightColour.equals(getPaintColor())) return getAlternateHighlightColor(); 890 769 891 return getDefaultHighlightColor(); 770 892 } … … 774 896 * 775 897 * @return The ID of this Item. 776 */ 777 public int getID() { 898 * 899 * TODO: What does it mean to have a negative ID# (as used in TDFC)? cts16 900 */ 901 public int getID() 902 { 778 903 return _id; 779 904 } … … 784 909 * @return The list of Line IDs that this point is part of. 785 910 */ 786 public String getLineIDs() { 911 public String getLineIDs() 912 { 787 913 String lineID = null; 788 914 … … 797 923 } 798 924 799 public int[] getLinePattern() { 925 public int[] getLinePattern() 926 { 800 927 return _linePattern; 801 928 } … … 807 934 * Lines have been added. 808 935 */ 809 public List<Line> getLines() { 936 public List<Line> getLines() 937 { 810 938 return _lines; 811 939 } … … 818 946 * this Item does not link to anything. 819 947 */ 820 public String getLink() { 948 public String getLink() 949 { 821 950 return _link; 822 951 } 823 952 824 public String getFormula() { 953 public String getFormula() 954 { 825 955 return _formula; 826 956 } 827 957 828 public boolean hasFormula() { 958 public boolean hasFormula() 959 { 829 960 return _formula != null; 830 961 } 831 962 832 public boolean hasAttributeValuePair() { 963 public boolean hasAttributeValuePair() 964 { 833 965 return _attributeValuePair != null && _attributeValuePair.hasPair(); 834 966 } 835 967 836 public void setFormula(String formula) { 968 public void setFormula(String formula) 969 { 837 970 _formula = formula; 838 971 } 839 972 840 public boolean calculate(String formula) { 973 public boolean calculate(String formula) 974 { 841 975 setFormula(formula); 842 976 return true; 843 977 } 844 978 845 public String getLinkFrameset() { 979 public String getLinkFrameset() 980 { 846 981 return _link_frameset; 847 982 } 848 983 849 public boolean getLinkMark() { 984 public boolean getLinkMark() 985 { 850 986 return _linkMark; 851 987 } 852 988 853 public String getLinkTemplate() { 989 public String getLinkTemplate() 990 { 854 991 return _link_template; 855 992 } 856 993 857 // public int getMaxWidth() { 994 // public int getMaxWidth() 995 // { 858 996 // return _maxWidth; 859 997 // } 860 998 861 public Point getOffset() { 999 public Point getOffset() 1000 { 862 1001 return _offset; 863 1002 } 864 1003 865 public String getOwner() { 1004 public String getOwner() 1005 { 866 1006 return _owner; 867 1007 } 868 1008 869 public Color getPaintBackgroundColor() { 870 Color colorBackground = getBackgroundColor(); 1009 public Colour getPaintBackgroundColor() 1010 { 1011 Colour colorBackground = getBackgroundColor(); 871 1012 if (colorBackground == null) { 872 1013 if (getParent() != null && getParent().getBackgroundColor() != null) … … 884 1025 * @return The Color of this item (foreground) 885 1026 */ 886 public final Color getPaintColor() { 1027 public final Colour getPaintColor() 1028 { 887 1029 // If color is null then get the paint foregroundColor for the frame the 888 1030 // item is on which is a color adjusted to suit the background 889 Colo r color = getColor();1031 Colour color = getColor(); 890 1032 891 1033 if (color == null) { … … 893 1035 return getParent().getPaintForegroundColor(); 894 1036 895 Frame current = Display IO.getCurrentFrame();1037 Frame current = DisplayController.getCurrentFrame(); 896 1038 if (current == null) { 897 1039 return DEFAULT_FOREGROUND; … … 903 1045 } 904 1046 905 public final Color getPaintBorderColor() { 1047 public final Colour getPaintBorderColor() 1048 { 906 1049 // If color is null then get the paint foregroundColor for the frame the 907 1050 // item is on which is a color adjusted to suit the background 908 Colo r color = getBorderColor();1051 Colour color = getBorderColor(); 909 1052 910 1053 if (color == null) { … … 912 1055 return getParent().getPaintForegroundColor(); 913 1056 914 Frame current = Display IO.getCurrentFrame();1057 Frame current = DisplayController.getCurrentFrame(); 915 1058 if (current == null) { 916 1059 return DEFAULT_FOREGROUND; … … 922 1065 } 923 1066 924 protected Color getPaintHighlightColor() { 925 Color highlightColor = getDefaultHighlightColor(); 1067 protected Colour getPaintHighlightColor() 1068 { 1069 Colour highlightColor = getDefaultHighlightColor(); 926 1070 if (hasVisibleBorder()) { 927 1071 if (getPaintBorderColor().equals(highlightColor)) { … … 931 1075 highlightColor = getDefaultHighlightColor(); 932 1076 } 933 if (getParent() != null934 && getParent().getPaintBackgroundColor().equals(highlightColor))1077 1078 if (getParent() != null && getParent().getPaintBackgroundColor().equals(highlightColor)) { 935 1079 highlightColor = getParent().getPaintForegroundColor(); 1080 } 936 1081 937 1082 if (hasVisibleBorder()) { 938 if (highlightColor.equals(getBorderColor()) 939 && getThickness() == getHighlightThickness()) { 940 highlightColor = new Color(highlightColor.getRed(), 941 highlightColor.getGreen(), highlightColor.getBlue(), 942 150); 1083 if (highlightColor.equals(getBorderColor()) && getThickness() == getHighlightThickness()) { 1084 highlightColor = highlightColor.clone(); 1085 highlightColor.setAlpha(Colour.FromComponent255(150)); 943 1086 } 944 1087 } … … 947 1090 } 948 1091 949 static final int BRIGHTNESS = 185; 950 951 protected Color getDefaultHighlightColor() { 952 if (isVectorItem() 953 && !this.contains(FrameMouseActions.getX(), FrameMouseActions 954 .getY())) { 955 return new Color(255, BRIGHTNESS, BRIGHTNESS); 956 } 957 return _highlightColor; 958 } 959 960 protected Color getAlternateHighlightColor() { 961 if (isVectorItem() 962 && !this.contains(FrameMouseActions.getX(), FrameMouseActions 963 .getY())) { 964 return new Color(BRIGHTNESS, BRIGHTNESS, 255); 1092 protected Colour getDefaultHighlightColor() 1093 { 1094 if (isVectorItem() && !this.contains(EcosystemManager.getInputManager().getCursorPosition())) { 1095 return Colour.FromRGB255(255, BRIGHTNESS, BRIGHTNESS); 1096 } 1097 return _highlightColour; 1098 } 1099 1100 protected Colour getAlternateHighlightColor() 1101 { 1102 if (isVectorItem() && !this.contains(EcosystemManager.getInputManager().getCursorPosition())) { 1103 return Colour.FromRGB255(BRIGHTNESS, BRIGHTNESS, 255); 965 1104 } 966 1105 return ALTERNATE_HIGHLIGHT; 967 1106 } 968 1107 969 protected int getHighlightThickness() { 970 if (isVectorItem()) 971 return _vectorHighlightThickness; 1108 protected int getHighlightThickness() 1109 { 1110 if (isVectorItem()) return _vectorHighlightThickness; 1111 972 1112 return _highlightThickness; 973 1113 } 974 1114 975 public final Frame getParent() { 1115 public final Frame getParent() 1116 { 976 1117 return _parent; 977 1118 } 978 1119 979 public final Point getPosition() { 1120 /** Gets the position of this item. */ 1121 public final Point getPosition() 1122 { 980 1123 return new Point(getX(), getY()); 981 1124 } … … 987 1130 * @return The size of this Item. 988 1131 */ 989 public float getSize() { 990 return -1.0F; 1132 public float getSize() 1133 { 1134 return SIZE_NOT_APPLICABLE; 991 1135 } 992 1136 … … 997 1141 * @return The Color displayed on the top\left half of this Item's border. 998 1142 */ 999 public Color getTopShadowColor() { 1143 public Colour getTopShadowColor() 1144 { 1000 1145 return _colorTopShadow; 1001 1146 } 1002 1147 1003 public String getTypeAndID() { 1148 public String getTypeAndID() 1149 { 1004 1150 return "T " + getID(); 1005 1151 } 1006 1152 1007 public Integer getWidthToSave() { 1153 public Integer getWidthToSave() 1154 { 1008 1155 return getWidth(); 1009 1156 } 1010 1157 1011 public Integer getWidth() { 1158 public Integer getWidth() 1159 { 1012 1160 return null; 1013 1161 } 1014 1162 1015 public int getHeight() { 1163 public int getHeight() 1164 { 1016 1165 return 0; 1017 1166 } … … 1022 1171 * @return The X coordinate of this Item on the screen 1023 1172 */ 1024 public int getX() { 1173 public int getX() 1174 { 1025 1175 return Math.round(_x); 1026 1176 } … … 1031 1181 * @return The Y coordinate of this Item on the screen 1032 1182 */ 1033 public int getY() { 1183 public int getY() 1184 { 1034 1185 return Math.round(_y); 1035 1186 } 1036 1187 1037 public boolean hasVisibleArrow() { 1188 public boolean hasVisibleArrow() 1189 { 1038 1190 return isLineEnd() && getArrowheadRatio() != 0 && getArrowheadLength() != 0; 1039 1191 } … … 1046 1198 * @return True if the two Shapes overlap, False otherwise. 1047 1199 */ 1048 public boolean intersects(Polygon p) {1049 if (p == null)1050 1051 1052 Area a = new Area(p);1053 Area thisArea = this.getArea();1200 public boolean intersects(PolygonBounds otherBounds) 1201 { 1202 if (otherBounds == null) return false; 1203 1204 Bounds thisBounds = getBounds(); 1205 1054 1206 // Need to do this check for circles 1055 if (a.equals(thisArea)) 1056 return true; 1057 1058 a.intersect(thisArea); 1207 if (otherBounds.equals(thisBounds)) return true; 1208 1209 return otherBounds.intersects(thisBounds); 1059 1210 1060 1211 // Need to check the second equality so that we dont pick up circles 1061 1212 // inside other circles 1062 return !a.isEmpty() && !a.equals(new Area(p));1213 //return !a.isEmpty() && !a.equals(new Area(p)); 1063 1214 } 1064 1215 … … 1069 1220 * @return True if this Item is an annotation, False otherwise. 1070 1221 */ 1071 public boolean isAnnotation() { 1222 public boolean isAnnotation() 1223 { 1072 1224 return false; 1073 1225 } 1074 1226 1075 public boolean isFloating() { 1227 public boolean isFloating() 1228 { 1076 1229 return _floating; 1077 1230 } 1078 1231 1079 public boolean isFrameName() { 1232 public boolean isFrameName() 1233 { 1080 1234 if (this.getParent() == null || this.getParent().getNameItem() != this) 1081 1235 return false; … … 1083 1237 } 1084 1238 1085 public boolean isFrameTitle() { 1239 public boolean isFrameTitle() 1240 { 1086 1241 if (this.getParent() == null || this.getParent().getTitleItem() != this) 1087 1242 return false; … … 1095 1250 * otherwise. 1096 1251 */ 1097 public boolean isHighlighted() { 1252 public boolean isHighlighted() 1253 { 1098 1254 if (isFloating()) 1099 1255 return false; 1100 return _ mode != HighlightMode.None;1256 return _highlightMode != HighlightMode.None; 1101 1257 } 1102 1258 … … 1109 1265 * @return True if the given framename is proper, false otherwise. 1110 1266 */ 1111 public boolean isLinkValid() { 1267 public boolean isLinkValid() 1268 { 1112 1269 if (FrameIO.isPositiveInteger(getLink())) 1113 1270 return true; … … 1118 1275 } 1119 1276 1120 public boolean isNear(int x, int y) { 1121 1122 int xLeft = getPolygon().getBounds().x; 1123 int yTop = getPolygon().getBounds().y; 1124 1125 return (x > xLeft - NEAR_DISTANCE && y > yTop - NEAR_DISTANCE 1126 && x < xLeft + getBoundsWidth() + NEAR_DISTANCE && y < yTop 1127 + getBoundsHeight() + NEAR_DISTANCE); 1128 } 1129 1130 public boolean isOldTag() { 1277 /** 1278 * Checks if the given point is 'near' to the item. Here 'near' means within a certain distance 1279 * of the axis-aligned box bounding the item's polygon. 1280 * 1281 * @param x 1282 * The x-coordinate of the point to check. 1283 * 1284 * @param y 1285 * The y-coordinate of the point to check. 1286 * 1287 * @return 1288 * True if the given point is 'near' to the item, false otherwise. 1289 */ 1290 public boolean isNear(int x, int y) 1291 { 1292 AxisAlignedBoxBounds box = ItemUtils.expandRectangle(getBoundingBox(), NEAR_DISTANCE * 2); 1293 1294 return box.contains(x, y); 1295 } 1296 1297 public boolean isOldTag() 1298 { 1131 1299 if (this instanceof Text) 1132 1300 if (((Text) this).getTextList().get(0).toLowerCase().equals("@old")) … … 1153 1321 * The Graphics to draw this Item on. 1154 1322 */ 1155 public abstract void paint(Graphics2D g); 1156 1157 public void setTooltips(final List<String> tooltips) { 1158 if(tooltips == null || tooltips.size() == 0) _tooltip = new Tooltip(); 1159 else for(final String content: tooltips) _tooltip.addTooltip(content, this); 1160 } 1161 1162 public void setTooltip(final String tooltip) { 1323 public abstract void paint(); 1324 1325 public void setTooltips(final List<String> tooltips) 1326 { 1327 if (tooltips == null || tooltips.size() == 0) { 1328 _tooltip = new Tooltip(); 1329 } else { 1330 for (final String content: tooltips) _tooltip.addTooltip(content, this); 1331 } 1332 } 1333 1334 public void setTooltip(final String tooltip) 1335 { 1163 1336 if(tooltip != null && tooltip.trim().length() > 0) { 1164 1337 _tooltip.addTooltip(tooltip, this); … … 1166 1339 } 1167 1340 1168 public List<String> getTooltip() { 1341 public List<String> getTooltip() 1342 { 1169 1343 return _tooltip.asStringList(); 1170 1344 } 1171 1345 1172 public Collection<Text> getTooltipItems() { 1346 public Collection<Text> getTooltipItems() 1347 { 1173 1348 return _tooltip.getTooltips(); 1174 1349 } 1175 1350 1176 public void clearTooltips() { 1351 public void clearTooltips() 1352 { 1177 1353 final Frame frame = this.getParent(); 1178 if(_tooltip != null) 1354 if(_tooltip != null) { 1179 1355 for(final Text tooltip: _tooltip.getTooltips()) frame.removeItem(tooltip); 1180 } 1181 1182 public void paintTooltip(final Graphics2D g) { 1183 final Rectangle bounds = this.getPolygon().getBounds(); 1184 int x = bounds.x + bounds.width; 1185 if(x + _tooltip.getWidth() > FrameGraphics.getMaxFrameSize().width) { 1186 x -= x + _tooltip.getWidth() - FrameGraphics.getMaxFrameSize().width; 1187 } 1188 int y = bounds.y + bounds.height; 1189 if(y + _tooltip.getCollectiveHeight() > FrameGraphics.getMaxFrameSize().height) { 1190 y = bounds.y + bounds.height / 2 - _tooltip.getCollectiveHeight(); 1191 } 1356 } 1357 } 1358 1359 public void paintTooltip() 1360 { 1361 final Bounds bounds = AxisAlignedBoxBounds.getEnclosing(this.getBoundingBox()); 1362 Dimension frameSize = DisplayController.getFramePaintArea().getSize(); 1363 1364 int x = bounds.getMaxX(); 1365 1366 // If the tooltip goes off the right side of the window, move it left so it's completely on 1367 if(x + _tooltip.getWidth() > frameSize.getWidth()) { 1368 x = frameSize.getWidth() - _tooltip.getWidth(); 1369 } 1370 1371 int y = bounds.getMaxY(); 1372 1373 if(y + _tooltip.getCollectiveHeight() > frameSize.getHeight()) { 1374 y = (bounds.getMinY() + bounds.getMaxY()) / 2 - _tooltip.getCollectiveHeight(); 1375 } 1376 1192 1377 for(final Text tooltip : _tooltip.getTooltips()) { 1193 1378 this.getParent().addItem(tooltip); 1194 1379 tooltip.setPosition(x, y); 1195 tooltip.paint( g);1380 tooltip.paint(); 1196 1381 y += tooltip.getHeight(); 1197 1382 } 1198 1383 } 1199 1384 1200 public void paintFill( Graphics2D g) {1201 Colo r fillColor = getFillColor();1385 public void paintFill() { 1386 Colour fillColor = getFillColor(); 1202 1387 if (fillColor != null && getEnclosingDots() != null) { 1203 setFillPaint(g); 1204 g.fillPolygon(getEnclosedShape()); 1205 } 1206 } 1207 1208 protected void setFillPaint(Graphics2D g) { 1209 Color fillColor = getFillColor(); 1388 Fill fill = getFill(); 1389 EcosystemManager.getGraphicsManager().drawPolygon(getEnclosedShape(), null, null, 0.0f, fill, null, null); 1390 } 1391 } 1392 1393 protected Fill getFill() { 1394 Fill fill; 1395 Colour fillColour = getFillColor(); 1210 1396 if (isFloating()) { 1211 1397 // TODO experiment with adding alpha when picking up filled 1212 1398 // items... Slows things down quite alot!! 1213 fillColor = new Color(fillColor.getRed(), fillColor.getGreen(), 1214 fillColor.getBlue(), fillColor.getAlpha()); 1215 } 1216 g.setColor(fillColor); 1217 Color gradientColor = getGradientColor(); 1218 if (gradientColor != null) { 1399 // TODO: Does nothing as it stands... cts16 1400 fillColour = new Colour(fillColour.getRed(), fillColour.getGreen(), 1401 fillColour.getBlue(), fillColour.getAlpha()); 1402 } 1403 Colour gradientColor = getGradientColor(); 1404 PolygonBounds poly = getEnclosedShape(); 1405 if (gradientColor != null && poly != null) { 1219 1406 /* 1220 1407 * It is slow when painting gradients... modify so this is only done 1221 1408 * once unless it is resized... 1222 1409 */ 1223 Shape s = getEnclosedShape(); 1224 if (s != null) { 1225 Rectangle b = s.getBounds(); 1226 double rads = getGradientAngle() * Math.PI / 180; 1227 double cos = Math.cos(rads); 1228 double sin = Math.sin(rads); 1229 1230 GradientPaint gp = new GradientPaint((int) (b.x + b.width 1231 * (0.2 * cos + 0.5)), (int) (b.y + b.height 1232 * (0.2 * sin + 0.5)), fillColor, (int) (b.x + b.width 1233 * (-0.8 * cos + 0.5)), (int) (b.y + b.height 1234 * (-0.8 * sin + 0.5)), gradientColor); 1235 g.setPaint(gp); 1236 } 1237 } 1410 AxisAlignedBoxBounds b = AxisAlignedBoxBounds.getEnclosing(poly); 1411 double rads = getGradientAngle(); 1412 double cos = Math.cos(rads); 1413 double sin = Math.sin(rads); 1414 1415 Point fromPoint = new Point((int) (b.getMinX() + b.getWidth() * (0.2 * cos + 0.5)), (int) (b.getMinY() + b.getHeight() * (0.2 * sin + 0.5))); 1416 Point toPoint = new Point((int) (b.getMinX() + b.getWidth() * (-0.8 * cos + 0.5)), (int) (b.getMinY() + b.getHeight() * (-0.8 * sin + 0.5))); 1417 1418 fill = new GradientFill(fillColour, fromPoint, gradientColor, toPoint); 1419 } else { 1420 fill = new Fill(fillColour); 1421 } 1422 1423 return fill; 1238 1424 } 1239 1425 1240 1426 /** 1241 1427 * This method performs all the actions in an items list. If it contains a 1242 * link as well the link is used as the source frame for all ac itons.1428 * link as well the link is used as the source frame for all actions. 1243 1429 */ 1244 1430 public void performActions() { … … 1268 1454 // For actions like format they rely on this being set to the 1269 1455 // current frame incase the item being activated is on an overlay 1270 sourceFrame = Display IO.getCurrentFrame();1456 sourceFrame = DisplayController.getCurrentFrame(); 1271 1457 } 1272 1458 … … 1388 1574 MessageBay.displayMessage("See SIMPLE doc for [" 1389 1575 + ise.getStatement() + "] statement", ise.getStatement() 1390 + "1", Colo r.CYAN.darker(), true, null);1576 + "1", Colour.CYAN.darker(), true, null); 1391 1577 } catch (Exception e) { 1392 1578 MessageBay.linkedErrorMessage(e.getMessage()); … … 1394 1580 Simple.ProgramFinished(); 1395 1581 // Need to repaint any highlights etc 1396 FrameGraphics.requestRefresh(true);1582 DisplayController.requestRefresh(true); 1397 1583 } 1398 1584 … … 1414 1600 1415 1601 if (_parent == null) 1416 framesetName = Display IO.getCurrentFrame().getFramesetName();1602 framesetName = DisplayController.getCurrentFrame().getFramesetName(); 1417 1603 else 1418 1604 framesetName = _parent.getFramesetName(); … … 1428 1614 * The lines of code to associate with this Item 1429 1615 */ 1430 public void setActions(List<String> actions) { 1616 public void setActions(List<String> actions) 1617 { 1431 1618 if (actions == null || actions.size() == 0) { 1432 1619 invalidateCommonTrait(ItemAppearence.LinkChanged); 1433 1620 _actions = null; 1434 } else 1621 } else { 1435 1622 _actions = new LinkedList<String>(actions); 1436 1437 // Want to resize the highlight box for text items if actions have been1438 // added1439 _poly = null;1623 } 1624 1625 // Want to resize the highlight box for text items if actions have been added 1626 invalidateBounds(); 1440 1627 invalidateCommonTrait(ItemAppearence.LinkChanged); 1441 1628 } … … 1481 1668 } 1482 1669 1483 public void setActionMark(boolean val) {1484 if (!val)1485 1486 _poly = null;1670 public void setActionMark(boolean val) 1671 { 1672 if (!val) invalidateCommonTrait(ItemAppearence.LinkChanged); 1673 invalidateBounds(); 1487 1674 _actionMark = val; 1488 if (val) 1489 invalidateCommonTrait(ItemAppearence.LinkChanged); 1675 if (val) invalidateCommonTrait(ItemAppearence.LinkChanged); 1490 1676 } 1491 1677 … … 1519 1705 } 1520 1706 1521 public void setArrowhead(Polygon arrow) {1707 public void setArrowhead(PolygonBounds arrow) { 1522 1708 _arrowhead = arrow; 1523 1709 } … … 1538 1724 } 1539 1725 1540 public void setBackgroundColor(Colo r c) {1541 if (c != _ colorBackground) {1542 _ colorBackground= c;1726 public void setBackgroundColor(Colour c) { 1727 if (c != _backgroundColour) { 1728 _backgroundColour = c; 1543 1729 invalidateCommonTrait(ItemAppearence.BackgroundColorChanged); 1544 1730 } 1545 1731 } 1546 1732 1547 public void setBorderColor(Colo r c) {1733 public void setBorderColor(Colour c) { 1548 1734 if (c != _colorBorder) { 1549 1735 _colorBorder = c; … … 1560 1746 * Item's border. 1561 1747 */ 1562 public void setBottomShadowColor(Colo r bottom) {1748 public void setBottomShadowColor(Colour bottom) { 1563 1749 _colorBottomShadow = bottom; 1564 1750 } … … 1569 1755 * @param c 1570 1756 */ 1571 public void setColor(Colo r c) {1572 if (c != _ color) {1573 _ color = c;1757 public void setColor(Colour c) { 1758 if (c != _foregroundColour) { 1759 _foregroundColour = c; 1574 1760 invalidateCommonTrait(ItemAppearence.ForegroundColorChanged); 1575 1761 if (hasVector()) { 1576 1762 // TODO make this more efficient so it only repaints the items 1577 1763 // for this vector 1578 FrameKeyboardActions.Refresh();1764 StandardGestureActions.Refresh(); 1579 1765 } 1580 1766 } … … 1605 1791 } 1606 1792 1607 public void setFillColor(Colo r c) {1608 1609 _ colorFill= c;1793 public void setFillColor(Colour c) { 1794 1795 _fillColour = c; 1610 1796 1611 1797 for (Line line : _lines) { … … 1620 1806 } 1621 1807 1622 public void setGradientColor(Color c) { 1623 _colorGradient = c; 1808 public void setGradientColor(Colour c) 1809 { 1810 _gradientColour = c; 1624 1811 1625 1812 for (Line line : _lines) { … … 1633 1820 } 1634 1821 1635 public Colo r getGradientColor() {1636 return _ colorGradient;1822 public Colour getGradientColor() { 1823 return _gradientColour; 1637 1824 } 1638 1825 … … 1647 1834 } 1648 1835 1836 /** 1837 * Sets the value <code>_highlight</code> for this item. 1838 * TODO: Appears unused? cts16 1839 * 1840 * @param val The new value for <code>_highlight</code>. 1841 */ 1649 1842 public void setHighlight(boolean val) { 1650 1843 _highlight = val; … … 1693 1886 * The name of the Frame to link this item to. 1694 1887 */ 1695 public void setLink(String frameName) { 1696 if (frameName == null) { 1697 invalidateCommonTrait(ItemAppearence.LinkChanged); 1698 } 1699 1700 // If a link is being removed or set then need to reset poly so the 1888 public void setLink(String frameName) 1889 { 1890 if (frameName == null) invalidateCommonTrait(ItemAppearence.LinkChanged); 1891 1892 // If a link is being removed or set then need to reset _bounds so the 1701 1893 // highlighting is drawn with the correct width 1702 if (frameName == null || getLink() == null) 1703 _poly = null; 1704 1705 if (FrameIO.isValidLink(frameName)) 1894 if (frameName == null || getLink() == null) invalidateBounds(); 1895 1896 if (FrameIO.isValidLink(frameName)) { 1706 1897 _link = frameName; 1707 else1708 MessageBay.errorMessage("[" + frameName 1709 + "] is not a valid frame name");1898 } else { 1899 MessageBay.errorMessage("[" + frameName + "] is not a valid frame name"); 1900 } 1710 1901 // TODO make this throw exceptions etc... 1711 1902 … … 1721 1912 } 1722 1913 1723 public void setLinkFrameset(String frameset) { 1724 if (frameset == null || FrameIO.isValidFramesetName(frameset)) 1914 public void setLinkFrameset(String frameset) 1915 { 1916 if (frameset == null || FrameIO.isValidFramesetName(frameset)) { 1725 1917 _link_frameset = frameset; 1726 else1727 MessageBay.errorMessage("[" + frameset 1728 + "] is not a valid frameset name");1918 } else { 1919 MessageBay.errorMessage("[" + frameset + "] is not a valid frameset name"); 1920 } 1729 1921 // TODO make this throw exceptions etc... 1730 1922 } 1731 1923 1732 public void setLinkMark(boolean val) {1733 if (!val)1734 1735 _poly = null;1924 public void setLinkMark(boolean val) 1925 { 1926 if (!val) invalidateCommonTrait(ItemAppearence.LinkChanged); 1927 invalidateBounds(); 1736 1928 _linkMark = val; 1737 if (val) 1738 invalidateCommonTrait(ItemAppearence.LinkChanged);1739 } 1740 1741 public void setLinkTemplate(String template){1742 if (FrameIO.isValidLink(template)) 1929 if (val) invalidateCommonTrait(ItemAppearence.LinkChanged); 1930 } 1931 1932 public void setLinkTemplate(String template) 1933 { 1934 if (FrameIO.isValidLink(template)) { 1743 1935 _link_template = template; 1744 else1745 MessageBay.errorMessage("[" + template 1746 + "] is not a valid frame name");1936 } else { 1937 MessageBay.errorMessage("[" + template + "] is not a valid frame name"); 1938 } 1747 1939 // TODO make this throw exceptions etc... 1748 1940 } … … 1763 1955 1764 1956 public void setOffset(int x, int y) { 1765 _offset.set Location(x, y);1957 _offset.set(x, y); 1766 1958 } 1767 1959 1768 1960 public void setOffset(Point p) { 1769 _offset.set Location(p);1961 _offset.set(p); 1770 1962 } 1771 1963 … … 1805 1997 } 1806 1998 } 1807 if (_ colorFill!= null) {1999 if (_fillColour != null) { 1808 2000 invalidateFill(); // only invalidates if has fill 1809 2001 } … … 1814 2006 } 1815 2007 1816 1817 1818 1819 1820 2008 protected void anchorConstraints() 1821 2009 { … … 1830 2018 if (isAnchoredY()) { 1831 2019 // Make the 'other' item have the same anchor top/bottom values as this 1832 other._anchorTop = _anchorTop; 1833 other._anchorBottom = _anchorBottom; 2020 other._anchoring.setYAnchor(this._anchoring); 1834 2021 } 1835 2022 } else if (c.getType() == Constraint.VERTICAL) { 1836 2023 if (isAnchoredX()) { 1837 2024 // Make the 'other' item have the same anchor left/right values as this 1838 other._anchorLeft = _anchorLeft; 1839 other._anchorRight = _anchorRight; 2025 other._anchoring.setXAnchor(this._anchoring); 1840 2026 } 1841 2027 } else if (c.isDiagonal()) { … … 1855 2041 * The new Y coordinate 1856 2042 */ 1857 public void setPosition(float x, float y) { 2043 public void setPosition(float x, float y) 2044 { 1858 2045 float deltaX = x - _x; 1859 2046 float deltaY = y - _y; 1860 2047 1861 if (deltaX == 0 && deltaY == 0) 1862 return; 2048 if (deltaX == 0 && deltaY == 0) return; 1863 2049 1864 2050 invalidateCommonTraitForAll(ItemAppearence.PreMoved); … … 1868 2054 1869 2055 for (Item i : getEnclosures()) { 1870 i. updatePolygon();1871 } 1872 updatePolygon();2056 i.invalidateBounds(); 2057 } 2058 invalidateBounds(); 1873 2059 1874 2060 // update the position of any dots that are constrained by this one … … 1951 2137 1952 2138 for (Line line : getLines()) { 1953 line. updatePolygon();2139 line.invalidateBounds(); 1954 2140 } 1955 2141 … … 2007 2193 * their thickness set 2008 2194 */ 2009 public void setThickness(float thick, boolean setConnectedThickness) { 2010 if (thick == _thickness) 2011 return; 2195 public void setThickness(float thick, boolean setConnectedThickness) 2196 { 2197 if (thick == _thickness) return; 2198 2012 2199 boolean bigger = thick > _thickness; 2013 2200 … … 2015 2202 if (setConnectedThickness) { 2016 2203 // TODO is there a more efficient way of doing this? 2017 for (Item i : getConnected()) 2018 i.invalidateCommonTrait(ItemAppearence.Thickness); 2204 for (Item i : getConnected()) i.invalidateCommonTrait(ItemAppearence.Thickness); 2019 2205 } else { 2020 2206 invalidateCommonTrait(ItemAppearence.Thickness); … … 2028 2214 * etc... 2029 2215 */ 2030 for (Line line : getLines()) 2031 line.setThickness(thick, setConnectedThickness); 2032 2033 if (setConnectedThickness) 2034 updatePolygon(); 2216 for (Line line : getLines()) line.setThickness(thick, setConnectedThickness); 2217 2218 if (setConnectedThickness) invalidateBounds(); 2035 2219 2036 2220 if (bigger) { 2037 2221 if (setConnectedThickness) { 2038 for (Item i : getConnected()) 2039 i.invalidateCommonTrait(ItemAppearence.Thickness); 2222 for (Item i : getConnected()) i.invalidateCommonTrait(ItemAppearence.Thickness); 2040 2223 } else { 2041 2224 invalidateCommonTrait(ItemAppearence.Thickness); … … 2050 2233 * set). 2051 2234 */ 2052 public float getThickness() { 2235 public float getThickness() 2236 { 2053 2237 return _thickness; 2054 2238 } … … 2062 2246 * Item's border. 2063 2247 */ 2064 public void setTopShadowColor(Colo r top) {2248 public void setTopShadowColor(Colour top) { 2065 2249 _colorTopShadow = top; 2066 2250 } 2067 2251 2068 public void setWidth(Integer width) throws UnsupportedOperationException { 2069 throw new UnsupportedOperationException( 2070 "Item type does not support width attribute!"); 2071 } 2072 2073 public void setRightMargin(int i, boolean fixWidth) { 2252 public void setWidth(Integer width) throws UnsupportedOperationException 2253 { 2254 throw new UnsupportedOperationException("Item type does not support width attribute!"); 2255 } 2256 2257 public void setRightMargin(int i, boolean fixWidth) 2258 { 2074 2259 int newWidth = i - getX() - Item.MARGIN_LEFT; 2260 if (newWidth < 0) newWidth = 0; 2075 2261 if (!fixWidth) { 2076 2262 newWidth *= -1; … … 2113 2299 * means no change) 2114 2300 */ 2115 public int setHighlightColor() { 2116 return setHighlightColor(DEFAULT_HIGHLIGHT); 2117 } 2118 2119 public int setHighlightColor(Color c) { 2301 2302 /** 2303 * 2304 * 2305 * @return 2306 */ 2307 public void setHighlightColorToDefault() { 2308 setHighlightColor(DEFAULT_HIGHLIGHT); 2309 } 2310 2311 public void setHighlightColor(Colour c) { 2312 if (c == null) return; 2313 2120 2314 if (!this.isVisible() && this.hasVector()) { 2121 2315 for (Item i : this.getParentOrCurrentFrame().getVectorItems()) { … … 2128 2322 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 2129 2323 2130 Colo r selColor = (c != null) ? c : DEFAULT_HIGHLIGHT;2131 if (_highlightColo r != c) {2132 _highlightColo r = selColor;2324 Colour selColor = (c != null) ? c : DEFAULT_HIGHLIGHT; 2325 if (_highlightColour != c) { 2326 _highlightColour = selColor; 2133 2327 this.invalidateCommonTrait(ItemAppearence.HighlightColorChanged); 2134 2328 } 2135 2136 return Item.UNCHANGED_CURSOR;2137 2329 2138 2330 } … … 2146 2338 } 2147 2339 2148 public abstract void updatePolygon(); 2340 /** Returns a Bounds which represents the area covered by the item (including its gravity). */ 2341 public abstract Bounds updateBounds(); 2149 2342 2150 2343 public void setHidden(boolean state) { … … 2172 2365 } 2173 2366 2174 public void setHighlightMode(HighlightMode mode, Color color) { 2175 setHighlightColor(color); 2176 if (hasPermission(UserAppliedPermission.followLinks) 2177 || getEditTarget().hasPermission(UserAppliedPermission.followLinks)) { 2178 if (_mode != mode) { 2179 _mode = mode; 2180 this.invalidateCommonTrait(ItemAppearence.HighlightModeChanged); 2181 } 2182 } 2367 /** 2368 * Sets the highlight mode and colour at the same time. 2369 * 2370 * @param mode The new highlight mode. 2371 * @param colour The new highlight colour. 2372 */ 2373 public void setHighlightModeAndColour(HighlightMode mode, Colour colour) 2374 { 2375 setHighlightMode(mode); 2376 setHighlightColor(colour); 2183 2377 } 2184 2378 2185 2379 public HighlightMode getHighlightMode() { 2186 return _ mode;2380 return _highlightMode; 2187 2381 } 2188 2382 … … 2191 2385 // only set the id if we've moved to a different frame, or if the frame already has an item with that id 2192 2386 if(!current.equals(_oldParent) || current.getItemWithID(getID()) != null) { 2193 int id = _id;2194 2387 setID(current.getNextItemID()); 2195 // System.out.println(this + " - Set ID to " + _id + " (was " + id + ")");2196 2388 } else { 2197 2389 // System.out.println(this + " - Kept old ID of " + _id); … … 2239 2431 // if the item is from an overlay the parent will NOT be null 2240 2432 if (getParent() == null) { 2241 return Display IO.getCurrentFrame();2433 return DisplayController.getCurrentFrame(); 2242 2434 } 2243 2435 return getParent(); … … 2275 2467 * the enclosed list. 2276 2468 */ 2277 public Polygon getEnclosedShape() {2278 if (_enclosure == null)2279 2280 2281 Polygon poly = new Polygon();2469 public PolygonBounds getEnclosedShape() 2470 { 2471 if (_enclosure == null) return null; 2472 2473 PolygonBounds poly = new PolygonBounds(); 2282 2474 for (Item d : _enclosure) { 2283 poly.addPoint( d.getX(), d.getY());2475 poly.addPoint(new Point(d.getX(), d.getY())); 2284 2476 } 2285 2477 … … 2332 2524 * the new color for the line 2333 2525 */ 2334 protected void lineColorChanged(Colo r c) {2526 protected void lineColorChanged(Colour c) { 2335 2527 for (Line l : getLines()) { 2336 2528 if (l.getColor() != c) … … 2345 2537 */ 2346 2538 public boolean offScreenTopOrLeft() { 2347 Rectangle itemRect = getArea().getBounds(); 2539 Bounds bounds = getBoundingBox(); 2540 2348 2541 // Check that the bottom right corner of this item is on the screen 2349 if (itemRect.x + itemRect.width >= 0 2350 && itemRect.y + itemRect.height >= 0) 2542 if (bounds.getMaxX() >= 0 && bounds.getMaxY() >= 0) { 2351 2543 return false; 2544 } 2545 2352 2546 // Check if all the items it is connected to are offscreen 2353 2547 for (Item i : getAllConnected()) { 2354 Rectangle iRect = i.getArea().getBounds();2548 bounds = i.getBoundingBox(); 2355 2549 // Check that the bottom right corner of this item is on the screen 2356 if ( iRect.x + iRect.width >= 0 && iRect.y + iRect.height>= 0) {2550 if (bounds.getMaxX() >= 0 && bounds.getMaxY() >= 0) { 2357 2551 return false; 2358 2552 } 2359 2553 } 2554 2360 2555 return true; 2361 2556 } … … 2374 2569 } 2375 2570 2376 public void setAction(String action) {2377 // Want to resize the highlight box for text items if actions are been2378 // added2571 public void setAction(String action) 2572 { 2573 // Want to resize the highlight box for text items if actions are been added 2379 2574 if (action == null || action.length() == 0) { 2380 2575 invalidateCommonTrait(ItemAppearence.LinkChanged); 2381 2576 } 2577 2382 2578 if (_actions == null || _actions.size() == 0) { 2383 _poly = null;2579 invalidateBounds(); 2384 2580 _actions = new LinkedList<String>(); 2385 2581 } else { 2386 2582 _actions.clear(); 2387 2583 } 2388 if (action != null && action.length() > 0) 2389 _actions.add(action); 2584 2585 if (action != null && action.length() > 0) _actions.add(action); 2586 2390 2587 invalidateCommonTrait(ItemAppearence.LinkChanged); 2391 2588 } … … 2395 2592 } 2396 2593 2397 protected RectanglegetLinkDrawArea() {2594 protected AxisAlignedBoxBounds getLinkDrawArea() { 2398 2595 return getLinkDrawArea(getX() - LEFT_MARGIN, getY() + getLinkYOffset()); 2399 2596 } … … 2410 2607 * @return The drawing area of the link at the given coordinates. 2411 2608 */ 2412 public RectanglegetLinkDrawArea(int x, int y) {2413 return new Rectangle(x + 2, y - 1, 8, 8);2609 public AxisAlignedBoxBounds getLinkDrawArea(int x, int y) { 2610 return new AxisAlignedBoxBounds(x + 2, y - 1, 8, 8); 2414 2611 } 2415 2612 … … 2419 2616 * @param g 2420 2617 */ 2421 protected void paintLink( Graphics2D g) {2422 paintLinkGraphic(g , getX() - LEFT_MARGIN, getY() + getLinkYOffset());2618 protected void paintLink() { 2619 paintLinkGraphic(getX() - LEFT_MARGIN, getY() + getLinkYOffset()); 2423 2620 } 2424 2621 … … 2438 2635 * centered) 2439 2636 */ 2440 public void paintLinkGraphic( Graphics2D g,int x, int y) {2441 2442 boolean hasLink = getLink() != null;2637 public void paintLinkGraphic(int x, int y) { 2638 2639 boolean hasLink = hasLink(); 2443 2640 boolean hasAction = hasAction(); 2444 2641 2445 2642 if (hasLink || hasAction) { 2446 g.setStroke(HIGHLIGHT_STROKE); 2643 GraphicsManager g = EcosystemManager.getGraphicsManager(); 2644 Fill fill = new Fill(); 2645 Colour colour = null; 2646 Point offset = new Point(x, y); 2647 2447 2648 if (hasLink && hasAction) { 2448 g.setColor(LINK_ACTION_COLOR);2649 colour = LINK_ACTION_COLOR; 2449 2650 } else if (hasLink) { 2450 g.setColor(LINK_COLOR);2651 colour = LINK_COLOR; 2451 2652 } else if (hasAction) { 2452 g.setColor(ACTION_COLOR);2653 colour = ACTION_COLOR; 2453 2654 } 2454 2455 AffineTransform at = new AffineTransform(); 2456 AffineTransform orig = g.getTransform(); 2457 at.translate(x, y); 2458 g.setTransform(at); 2459 2460 if (getLinkMark() && getLink() != null) { 2461 g.drawPolygon(getLinkPoly()); 2462 2655 fill.setColour(colour); 2656 2657 // Small circles look rubbish without AA. cts16 2658 g.setAntialiasing(true); 2659 2660 if (hasLink && getLinkMark()) { 2661 g.drawOval(offset, getLinkBounds().getDiameters(), 0.0f, null, colour, HIGHLIGHT_STROKE); 2662 2463 2663 // if the link is not valid, cross out the circle 2464 if (!isLinkValid()) 2465 g.drawPolygon(getCircleCross()); 2664 if (!isLinkValid()) { 2665 g.drawPolygon(getCircleCross(), offset, null, 0.0f, null, colour, HIGHLIGHT_STROKE); 2666 } 2466 2667 } 2467 2668 2468 if (getActionMark() && hasAction()) { 2469 g.drawPolygon(getLinkPoly()); 2470 g.fillPolygon(getLinkPoly()); 2669 if (hasAction && getActionMark()) { 2670 g.drawOval(offset, getLinkBounds().getDiameters(), 0.0f, fill, colour, HIGHLIGHT_STROKE); 2471 2671 2472 2672 // if the link is not valid, cross out the circle 2473 2673 if (!isLinkValid() && getLink() != null) { 2474 g.setColor(getParent().getPaintBackgroundColor()); 2475 g.drawPolygon(getCircleCross()); 2674 g.drawPolygon(getCircleCross(), offset, null, 0.0f, null, getParent().getPaintBackgroundColor(), HIGHLIGHT_STROKE); 2476 2675 } 2477 2676 } 2478 2479 // reset the graphics tranformation 2480 g.setTransform(orig); 2677 2678 g.setAntialiasing(false); 2481 2679 } 2482 2680 } … … 2539 2737 return null; 2540 2738 // assert (_parent!= null); 2541 Frame parent = Display IO.getCurrentFrame();2739 Frame parent = DisplayController.getCurrentFrame(); 2542 2740 assert (parent != null); 2543 2741 … … 2587 2785 while (!lines.isEmpty()) { 2588 2786 Line l = lines.remove(); 2589 // if we hav nt visited the line yet visit it2787 // if we haven't visited the line yet visit it 2590 2788 if (!visited.contains(l)) { 2591 2789 visited.add(l); 2592 2790 Item otherEnd = l.getOppositeEnd(this); 2593 // Add all the enexplored lines to our list2791 // Add all the unexplored lines to our list 2594 2792 while (!lines.isEmpty()) { 2595 2793 l = lines.remove(); … … 2613 2811 * is part of 2614 2812 */ 2615 public double getEnclosedArea() {2616 if (_enclosure == null)2617 return 0.0;2618 Rectangle2D box = getEnclosedShape().getBounds2D();2813 public double getEnclosedArea() 2814 { 2815 AxisAlignedBoxBounds box = getEnclosedBox(); 2816 if (box == null) return 0.0; 2619 2817 return box.getWidth() * box.getHeight(); 2620 2818 } 2621 2819 2622 public Rectangle getEnclosedRectangle() { 2623 if (_enclosure == null) 2624 return null; 2625 return getEnclosedShape().getBounds(); 2626 } 2627 2628 public int getEnclosureID() { 2820 /** 2821 * Gets the box encompassing all points that form an enclosure with this item. 2822 * 2823 * @return An axis-aligned box around all enclosure points. 2824 */ 2825 public AxisAlignedBoxBounds getEnclosedBox() 2826 { 2827 if (_enclosure == null) return null; 2828 2829 return AxisAlignedBoxBounds.getEnclosing(getEnclosedShape()); 2830 } 2831 2832 public int getEnclosureID() 2833 { 2629 2834 return _enclosure == null ? 0 : _enclosure.hashCode(); 2630 2835 } 2631 2836 2632 2837 /** 2633 * Returns the Shapethat surrounds this Item representing this Item's2838 * Returns the Bounds that surrounds this Item representing this Item's 2634 2839 * 'gravity'. 2635 2840 * 2636 * @return The Shape (rectangle)surrounding this Item, which represents2841 * @return The Bounds surrounding this Item, which represents 2637 2842 * this Items 'gravity'. 2638 2843 */ 2639 public final Polygon getPolygon() { 2640 if (_poly == null) 2641 updatePolygon(); 2642 2643 return new Polygon(_poly.xpoints, _poly.ypoints, _poly.npoints); 2844 public final Bounds getBounds() 2845 { 2846 if (_bounds == null) _bounds = updateBounds(); 2847 2848 // DEBUG 2849 if (_bounds == null) { 2850 //System.out.println("updateBounds failed!"); 2851 } 2852 2853 return _bounds; 2854 } 2855 2856 public final Bounds getOldBounds() 2857 { 2858 return _oldBounds; 2859 } 2860 2861 public final void invalidateBounds() 2862 { 2863 if (_bounds != null) _oldBounds = _bounds; 2864 _bounds = null; 2865 } 2866 2867 public final AxisAlignedBoxBounds getBoundingBox() 2868 { 2869 return AxisAlignedBoxBounds.getEnclosing(getBounds()); 2644 2870 } 2645 2871 … … 2651 2877 * @param ratio 2652 2878 */ 2653 public void translate(Point 2Dorigin, double ratio) {2879 public void translate(Point origin, double ratio) { 2654 2880 2655 2881 invalidateCommonTraitForAll(ItemAppearence.PreMoved); 2656 2882 2657 _x = (float) (origin. getX() + ratio * (_x - origin.getX()));2658 _y = (float) (origin. getY() + ratio * (_y - origin.getY()));2659 updatePolygon();2883 _x = (float) (origin.x + ratio * (_x - origin.x)); 2884 _y = (float) (origin.y + ratio * (_y - origin.y)); 2885 invalidateBounds(); 2660 2886 for (Line line : getLines()) 2661 line. updatePolygon();2887 line.invalidateBounds(); 2662 2888 2663 2889 invalidateCommonTraitForAll(ItemAppearence.PostMoved); … … 2698 2924 } 2699 2925 2700 Collection<XRayable> _enclosures = new HashSet<XRayable>();2701 2702 private boolean _deleted = false;2703 2704 private Overlay _overlay = null;2705 2706 protected AttributeValuePair _attributeValuePair = null;2707 2708 private Float _autoStamp = null;2709 2710 2926 /** 2711 2927 * For now there can only be one enclosure per item … … 2741 2957 * highlighting bounds 2742 2958 */ 2743 public Rectangle[]getDrawingArea() {2744 2745 return new Rectangle[] { ItemUtils.expandRectangle(getPolygon()2746 .getBounds(), (int) Math.ceil(Math.max(_highlightThickness,2747 getThickness()))) };2748 2959 public AxisAlignedBoxBounds getDrawingArea() { 2960 2961 return ItemUtils.expandRectangle( 2962 getBoundingBox(), 2963 (int) Math.ceil(Math.max(_highlightThickness, getThickness())) + 1 // + 1 to make sure 2964 ); 2749 2965 } 2750 2966 … … 2754 2970 * @return True if area intersects with this items drawing area. 2755 2971 */ 2756 public final boolean isInDrawingArea(Area area) { 2757 for (Rectangle r : getDrawingArea()) { 2758 if (area.intersects(r)) 2759 return true; 2760 } 2761 return false; 2762 } 2763 2764 /** 2765 * Completetly invalidates the item - so that it should be redrawed. Note: 2766 * This is handled internally, it should be reare to invoke this externally 2767 */ 2768 public final void invalidateAll() { 2972 public final boolean isInDrawingArea(AxisAlignedBoxBounds area) 2973 { 2974 AxisAlignedBoxBounds drawingArea = getDrawingArea(); 2975 2976 if (drawingArea == null) return false; 2977 2978 return drawingArea.intersects(area); 2979 } 2980 2981 /** 2982 * Completely invalidates the item - so that it should be redrawn. Note: 2983 * This is handled internally, it should be rare to invoke this externally 2984 */ 2985 public final void invalidateAll() 2986 { 2769 2987 invalidate(getDrawingArea()); 2770 2988 } … … 2776 2994 * @param damagedAreas 2777 2995 */ 2778 protected final void invalidate( Rectangle[] damagedAreas) {2779 for (Rectangle r : damagedAreas)2780 invalidate(r);2996 protected final void invalidate(Bounds[] damagedAreas) 2997 { 2998 if (damagedAreas != null) for (Bounds b : damagedAreas) invalidate(b); 2781 2999 } 2782 3000 … … 2787 3005 * @param damagedAreas 2788 3006 */ 2789 protected final void invalidate(Rectangle damagedArea) { 2790 FrameGraphics.invalidateItem(this, damagedArea); 3007 protected final void invalidate(Bounds damagedArea) 3008 { 3009 if (damagedArea != null) DisplayController.invalidateItem(this, damagedArea); 2791 3010 } 2792 3011 … … 2796 3015 * @param trait 2797 3016 */ 2798 public final void invalidateCommonTrait(ItemAppearence trait) { 3017 public final void invalidateCommonTrait(ItemAppearence trait) 3018 { 2799 3019 invalidate(getDamagedArea(trait)); 2800 3020 2801 if (_colorFill != null 2802 && (trait == ItemAppearence.Added || trait == ItemAppearence.Removed)) { 3021 if (_fillColour != null && (trait == ItemAppearence.Added || trait == ItemAppearence.Removed)) { 2803 3022 invalidateFill(); 2804 3023 } … … 2808 3027 * Invalidates fill if has one, even if no color is set. 2809 3028 */ 2810 public void invalidateFill() { 3029 public void invalidateFill() 3030 { 2811 3031 if (isLineEnd() && _enclosure != null) { 2812 invalidate(getEnclosed Shape().getBounds());3032 invalidate(getEnclosedBox()); 2813 3033 } 2814 3034 } … … 2826 3046 * @return The damaged area according to the visual trait that has changed. 2827 3047 */ 2828 protected Rectangle[] getDamagedArea(ItemAppearence trait) {2829 3048 protected AxisAlignedBoxBounds getDamagedArea(ItemAppearence trait) 3049 { 2830 3050 if (trait == ItemAppearence.LinkChanged) 2831 return new Rectangle[] { getLinkDrawArea() }; // Invalidate area 2832 // where link is 2833 // drawn 3051 return getLinkDrawArea(); // Invalidate area where link is drawn 2834 3052 2835 3053 return getDrawingArea(); 2836 2837 3054 } 2838 3055 … … 2864 3081 } 2865 3082 2866 public void setAnchorLeft( Float anchor) {2867 this._anchorLeft = anchor;2868 this._anchor Right = null;3083 public void setAnchorLeft(Integer anchor) 3084 { 3085 this._anchoring.setLeftAnchor(anchor); 2869 3086 if (anchor != null) { 2870 3087 anchorConstraints(); … … 2873 3090 } 2874 3091 2875 public void setAnchorRight( Float anchor) {2876 this._anchorRight = anchor;2877 this._anchor Left = null;3092 public void setAnchorRight(Integer anchor) 3093 { 3094 this._anchoring.setRightAnchor(anchor); 2878 3095 if (anchor != null) { 2879 3096 anchorConstraints(); 2880 setX(FrameGraphics.getMaxFrameSize().width - anchor 2881 - getBoundsWidth()); 2882 } 2883 } 2884 2885 public void setAnchorTop(Float anchor) { 2886 this._anchorTop = anchor; 2887 this._anchorBottom = null; 3097 setX(DisplayController.getFramePaintArea().getMaxX() - anchor - getBoundsWidth()); 3098 } 3099 } 3100 3101 public void setAnchorTop(Integer anchor) 3102 { 3103 this._anchoring.setTopAnchor(anchor); 2888 3104 if (anchor != null) { 2889 3105 anchorConstraints(); … … 2893 3109 2894 3110 2895 public void setAnchorBottom( Float anchor) {2896 this._anchorBottom = anchor;2897 this._anchor Top = null;3111 public void setAnchorBottom(Integer anchor) 3112 { 3113 this._anchoring.setBottomAnchor(anchor); 2898 3114 if (anchor != null) { 2899 3115 anchorConstraints(); 2900 setY(FrameGraphics.getMaxFrameSize().height - anchor); 2901 } 2902 } 2903 2904 2905 public boolean isAnchored() { 2906 return ((_anchorLeft != null) || (_anchorRight != null) 2907 || (_anchorTop != null) || (_anchorBottom != null)); 3116 setY(DisplayController.getFramePaintArea().getMaxY() - anchor); 3117 } 3118 } 3119 3120 public boolean isAnchored() 3121 { 3122 return _anchoring.isAnchored(); 2908 3123 } 2909 3124 2910 3125 public boolean isAnchoredX() { 2911 return ((_anchorLeft != null) || (_anchorRight != null));3126 return _anchoring.isXAnchored(); 2912 3127 } 2913 3128 2914 3129 public boolean isAnchoredY() { 2915 return ((_anchorTop != null) || (_anchorBottom != null));2916 } 2917 2918 public FloatgetAnchorLeft() {2919 return _anchor Left;2920 } 2921 2922 public FloatgetAnchorRight() {2923 return _anchor Right;2924 } 2925 2926 public FloatgetAnchorTop() {2927 return _anchor Top;2928 } 2929 2930 public FloatgetAnchorBottom() {2931 return _anchor Bottom;3130 return _anchoring.isYAnchored(); 3131 } 3132 3133 public Integer getAnchorLeft() { 3134 return _anchoring.getLeftAnchor(); 3135 } 3136 3137 public Integer getAnchorRight() { 3138 return _anchoring.getRightAnchor(); 3139 } 3140 3141 public Integer getAnchorTop() { 3142 return _anchoring.getTopAnchor(); 3143 } 3144 3145 public Integer getAnchorBottom() { 3146 return _anchoring.getBottomAnchor(); 2932 3147 } 2933 3148 … … 3024 3239 // Invalidate them again!! 3025 3240 for (Item i : this.getAllConnected()) { 3026 i. updatePolygon();3241 i.invalidateBounds(); 3027 3242 i.invalidateAll(); 3028 3243 } 3029 3244 } 3030 3245 3031 3032 3246 protected void anchorConnected(AnchorEdgeType anchorEdgeType, Float delta) { 3033 3247 … … 3087 3301 // Invalidate them again!! 3088 3302 for (Item i : this.getAllConnected()) { 3089 i. updatePolygon();3303 i.invalidateBounds(); 3090 3304 i.invalidateAll(); 3091 3305 } … … 3123 3337 // DONT PUT SIZE IN HERE CAUSE IT STUFFS UP CIRCLES 3124 3338 3125 updatePolygon();3339 invalidateBounds(); 3126 3340 } 3127 3341 … … 3168 3382 return _autoStamp != null && _autoStamp >= 0.0; 3169 3383 } 3170 3171 public void setDotType(DotType type) {3172 invalidateAll();3173 _type = type;3174 invalidateAll();3175 }3176 3177 public DotType getDotType() {3178 return _type;3179 }3180 3181 public void setFilled(boolean filled) {3182 invalidateAll();3183 _filled = filled;3184 invalidateAll();3185 }3186 3187 public boolean getFilled() {3188 return _filled;3189 }3190 3191 private Item _magnetizedItemLeft = null;3192 private Item _magnetizedItemRight = null;3193 private Item _magnetizedItemTop = null;3194 private Item _magnetizedItemBottom = null;3195 3384 3196 3385 public int getMagnetizedItemLeft() { … … 3245 3434 setMagnetizedItemBottom(this.getParent().getItemWithID(id)); 3246 3435 } 3436 3437 /** 3438 * Replaces the given dot item with a text item displaying the given character. 3439 * 3440 * @param dot 3441 * The Dot item to replace. 3442 * 3443 * @param ch 3444 * The character to display as the text for the created Text item. 3445 * 3446 * @return 3447 * The created Text item. 3448 */ 3449 public static Text replaceDot(Item dot, char ch) { 3450 // TODO: Should this make sure 'dot' is actually a Dot and not some other item? cts16 3451 Text text = Text.createText(ch); 3452 Item.DuplicateItem(dot, text); 3453 FrameUtils.setLastEdited(text); 3454 3455 // Copy the lines list so it can be modified 3456 List<Line> lines = new LinkedList<Line>(dot.getLines()); 3457 for (Line line : lines) 3458 line.replaceLineEnd(dot, text); 3459 Frame current = dot.getParentOrCurrentFrame(); 3460 current.removeItem(dot); 3461 ItemUtils.EnclosedCheck(current.getItems()); 3462 return text; 3463 // TODO: Should this add the newly-created Text item to the frame? cts16 3464 } 3465 3466 /** 3467 * Replaces the given text item with a dot 3468 */ 3469 public static Item replaceText(Item text) { 3470 Item dot = new Dot(text.getX(), text.getY(), text.getID()); 3471 Item.DuplicateItem(text, dot); 3472 3473 List<Line> lines = new LinkedList<Line>(); 3474 lines.addAll(text.getLines()); 3475 if (lines.size() > 0) 3476 dot.setColor(lines.get(0).getColor()); 3477 for (Line line : lines) { 3478 line.replaceLineEnd(text, dot); 3479 } 3480 text.delete(); 3481 Frame current = text.getParentOrCurrentFrame(); 3482 current.addItem(dot); 3483 DisplayController.setCursor(Item.DEFAULT_CURSOR); 3484 ItemUtils.EnclosedCheck(current.getItems()); 3485 return dot; 3486 } 3247 3487 }
Note:
See TracChangeset
for help on using the changeset viewer.