source: trunk/src/org/expeditee/items/Item.java@ 1412

Last change on this file since 1412 was 1412, checked in by bln4, 5 years ago
File size: 100.2 KB
Line 
1/**
2 * Item.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items;
20
21import java.util.ArrayList;
22import java.util.Collection;
23import java.util.ConcurrentModificationException;
24import java.util.HashMap;
25import java.util.HashSet;
26import java.util.LinkedHashSet;
27import java.util.LinkedList;
28import java.util.List;
29import java.util.Map;
30import java.util.Set;
31
32import org.expeditee.actions.Actions;
33import org.expeditee.actions.IncorrectUseOfStatementException;
34import org.expeditee.actions.Javascript;
35import org.expeditee.actions.Misc;
36import org.expeditee.actions.Simple;
37import org.expeditee.core.Anchoring;
38import org.expeditee.core.Colour;
39import org.expeditee.core.Cursor;
40import org.expeditee.core.Dimension;
41import org.expeditee.core.Fill;
42import org.expeditee.core.GradientFill;
43import org.expeditee.core.Point;
44import org.expeditee.core.Stroke;
45import org.expeditee.core.bounds.AxisAlignedBoxBounds;
46import org.expeditee.core.bounds.Bounds;
47import org.expeditee.core.bounds.EllipticalBounds;
48import org.expeditee.core.bounds.PolygonBounds;
49import org.expeditee.encryption.items.surrogates.EncryptionDetail;
50import org.expeditee.encryption.items.surrogates.Surrogate;
51import org.expeditee.gio.EcosystemManager;
52import org.expeditee.gio.GraphicsManager;
53import org.expeditee.gio.gesture.StandardGestureActions;
54import org.expeditee.gui.AttributeValuePair;
55import org.expeditee.gui.DisplayController;
56import org.expeditee.gui.Frame;
57import org.expeditee.gui.FrameIO;
58import org.expeditee.gui.FrameUtils;
59import org.expeditee.gui.FreeItems;
60import org.expeditee.gui.MessageBay;
61import org.expeditee.gui.Overlay;
62import org.expeditee.gui.Vector;
63import org.expeditee.io.Conversion;
64import org.expeditee.io.DefaultFrameWriter;
65import org.expeditee.settings.UserSettings;
66import org.expeditee.settings.legacy.LegacyFeatures;
67import org.expeditee.simple.Context;
68import org.expeditee.stats.AgentStats;
69import org.expeditee.stats.Formatter;
70import org.mozilla.javascript.Scriptable;
71import org.mozilla.javascript.ScriptableObject;
72
73/**
74 * Represents everything that can be drawn on the screen (text, lines, dots,
75 * images). Each specific type is a subclass of Item.
76 *
77 * @author jdm18
78 *
79 */
80public abstract class Item implements Comparable<Item>, Runnable {
81
82 public enum HighlightMode {
83 None, // The item has no highlighting
84 Enclosed, // The item is part of the current enclosure
85 Connected, // The item is connected to the current item
86 Disconnect, // The item is a free item
87 Normal // The item is the current item
88 }
89
90 /** Which edge of the window things are anchored to. */
91 public enum AnchorEdgeType {
92 None, Left, Right, Top, Bottom
93 }
94
95 public static final float SIZE_NOT_APPLICABLE = Float.NaN;
96
97 public static final Float DEFAULT_THICKNESS = 2f;
98
99 public static final Float MINIMUM_THICKNESS = 0f;
100
101 public static final Float MINIMUM_PAINT_THICKNESS = 1f;
102
103 protected static final Stroke.JOIN DEFAULT_JOIN = Stroke.JOIN.ROUND;
104
105 protected static final Stroke.CAP DEFAULT_CAP = Stroke.CAP.BUTT;
106
107 protected static final Stroke DOT_STROKE = new Stroke(DEFAULT_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN);
108
109 protected static final Stroke HIGHLIGHT_STROKE = new Stroke(MINIMUM_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN);
110
111 public static final int LEFT_MARGIN = 13;
112
113 public static final int NEAR_DISTANCE = 15;
114
115 public static final int DEFAULT_HIGHLIGHT_THICKNESS = 2;
116
117 /** The default colour to draw highlighting in */
118 public static final Colour DEFAULT_HIGHLIGHT = Colour.RED;
119
120 public static final Colour DEPRESSED_HIGHLIGHT = Colour.GREEN;
121
122 public static final Colour ALTERNATE_HIGHLIGHT = Colour.BLUE;
123
124 public static final Colour LINK_COLOR = Colour.BLACK;
125
126 public static final Colour ACTION_COLOR = Colour.BLACK;
127
128 public static final Colour LINK_ACTION_COLOR = Colour.RED;
129
130 public static final Colour DEFAULT_FOREGROUND = Colour.BLACK;
131
132 public static final Colour DEFAULT_BACKGROUND = Colour.WHITE;
133
134 public static final Colour TRANSPARENT = new Colour(0, 0, 0, 0);
135
136 /** The number of pixels highlighting should extend around Items. */
137 public static final int XGRAVITY = 3;
138
139 public static final int MARGIN_RIGHT = 2;
140
141 public static final int MARGIN_LEFT = 15;
142
143 protected static final double DEFAULT_ARROWHEAD_RATIO = 0.3; // used to be 0.5
144
145 public static final double DEFAULT_ARROWHEAD_NIB_PERC = 0.75;
146
147 public static final Colour GREEN = Colour.GREEN.darker();
148
149 //public static final int UNCHANGED_CURSOR = -100;
150
151 public static final Cursor.CursorType DEFAULT_CURSOR = Cursor.CursorType.DEFAULT;
152
153 public static final Cursor.CursorType HIDDEN_CURSOR = Cursor.CursorType.CUSTOM;
154
155 public static final Cursor.CursorType TEXT_CURSOR = Cursor.CursorType.TEXT;
156
157 public static final Cursor.CursorType CROP_CURSOR = Cursor.CursorType.CROSSHAIR;
158
159 /** The default value for integer attributes */
160 public static final int DEFAULT_INTEGER = -1;
161
162 private static final int BRIGHTNESS = 185;
163
164 /** Contains all dots (including this one) that form an enclosure if this dot is part of an enclosing shape. */
165 private Collection<Item> _enclosure = null;
166
167 /** The area which this item covers (including its gravity). */
168 private Bounds _bounds = null;
169
170 /** The area this item covered before it was invalidated. */
171 private Bounds _oldBounds = null;
172
173 protected boolean _connectedToAnnotation = false;
174
175 protected boolean _save = true;
176
177 /** The angle of change for gradient colour fills (in radians). */
178 private double _gradientAngle = 0.0;
179
180 private Tooltip _tooltip = new Tooltip();
181
182 protected Anchoring _anchoring = new Anchoring();
183
184 /** The highlight mode for this item. */
185 protected HighlightMode _highlightMode = HighlightMode.None;
186
187 private Point _offset = new Point(0, 0);
188
189 protected float _x;
190 protected float _y;
191
192 private int _id;
193
194 private Item _editTarget = this;
195
196 private String _creationDate = null;
197
198 /** Whether or not this item should display a mark indicating it has a link. */
199 private boolean _linkMark = true;
200
201 /** Whether or not this item should display a mark indicating it has an action. */
202 private boolean _actionMark = true;
203
204 /** TODO: Appears unused? cts16 */
205 private boolean _highlight = true;
206
207 // private int _maxWidth = -1;
208
209 private String _owner = null;
210
211 private String _link = null;
212
213 private boolean _linkHistory = true;
214
215 private StringBuffer _tag = new StringBuffer();
216
217 private List<String> _actionCursorEnter = null;
218
219 private List<String> _actionCursorLeave = null;
220
221 private List<String> _actionEnterFrame = null;
222
223 private List<String> _actionLeaveFrame = null;
224
225 private PermissionTriple _permissionTriple = null;
226
227 private UserAppliedPermission _overlayPermission = null;
228
229 /** The primary fill colour of this item. A fill colour of null represents transparent. */
230 private Colour _fillColour = null;
231
232 /** The secondary fill colour if this item has a gradient fill. Null represents no gradient. */
233 private Colour _gradientColour = null;
234
235 /** The primary draw colour of this item. Null represents the default colour. */
236 private Colour _foregroundColour = null;
237
238 /** The colour to draw highlights on this item. */
239 protected Colour _highlightColour = DEFAULT_HIGHLIGHT;
240
241 /** The background colour for this item. */
242 private Colour _backgroundColour = null;
243
244 private Colour _colorBorder = null;
245
246 private Colour _colorTopShadow = null;
247
248 private Colour _colorBottomShadow = null;
249
250 /** The shape representing the circle drawn next to link/action items. */
251 private static EllipticalBounds _linkCircle = null;
252
253 /** The shape representing the cross drawn next to invalid links. */
254 private static PolygonBounds _linkCircleCross = null;
255
256 private Frame _parent = null;
257 private Frame _oldParent = null;
258
259 protected int _highlightThickness = 2;
260
261 protected int _vectorHighlightThickness = 1;
262
263 // arrowhead parameters
264 private float _arrowheadLength = 0;
265 private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO;
266 private double _arrowheadNibPerc = DEFAULT_ARROWHEAD_NIB_PERC;
267
268 private PolygonBounds _arrowhead = null;
269
270 // the list of lines that this point is part of.
271 private List<Line> _lines = new ArrayList<Line>();
272
273 private int[] _linePattern = null;
274
275 private boolean _floating = false;
276
277 // list of points constrained with this point
278 private List<Constraint> _constraints = new ArrayList<Constraint>();
279
280 private List<String> _actions = null;
281
282 private String _formula = null;
283
284 private String _link_frameset = null;
285
286 private String _link_template = null;
287
288 private String _fillPattern = null;
289
290 private boolean _visible = true;
291
292 private float _thickness = -1.0F;
293
294 protected Collection<XRayable> _enclosures = new HashSet<XRayable>();
295
296 private boolean _deleted = false;
297
298 private Overlay _overlay = null;
299
300 protected AttributeValuePair _attributeValuePair = null;
301
302 private Float _autoStamp = null;
303
304 private Item _magnetizedItemLeft = null;
305
306 private Item _magnetizedItemRight = null;
307
308 private Item _magnetizedItemTop = null;
309
310 private Item _magnetizedItemBottom = null;
311
312 private String _encryptionLabel = null;
313
314 protected DotType _type = DotType.square;
315
316 protected boolean _filled = true;
317
318 private Data _data = new Data();
319
320 private Item surrogateFor = null;
321 private Set<Surrogate> surrogateItems = new HashSet<Surrogate>();
322 private Map<String, EncryptionDetail> propertyEncryption = new HashMap<String, EncryptionDetail>();
323
324 /** Just calls source.duplicateOnto(dest). */
325 public static void DuplicateItem(Item source, Item dest)
326 {
327 if (source == null) return;
328
329 source.duplicateOnto(dest);
330 }
331
332 /** Sets the properties of dest so that they match this item's properties. */
333 public void duplicateOnto(Item dest)
334 {
335 if (dest == null) return;
336
337 dest.setX(this.getX());
338 dest.setY(this.getY());
339
340 dest.setActions(this.getAction());
341 dest.setActionCursorEnter(this.getActionCursorEnter());
342 dest.setActionCursorLeave(this.getActionCursorLeave());
343 dest.setActionEnterFrame(this.getActionEnterFrame());
344 dest.setActionLeaveFrame(this.getActionLeaveFrame());
345 dest.setActionMark(this.getActionMark());
346
347 dest.setBackgroundColor(this.getBackgroundColor());
348 dest.setBottomShadowColor(this.getBottomShadowColor());
349 dest.setColor(this.getColor());
350 dest.setBorderColor(this.getBorderColor());
351
352 dest.setTooltips(this.getTooltip());
353 dest.setData(this.getData());
354 dest.setTag(this.getTag());
355 dest.setFillColor(this.getFillColor());
356 dest.setGradientColor(this.getGradientColor());
357 dest.setGradientAngle(this.getGradientAngle());
358 dest.setFillPattern(this.getFillPattern());
359
360 dest.setHighlight(this.getHighlight());
361 dest.setLink(this.getLink());
362 dest.setLinkFrameset(this.getLinkFrameset());
363 dest.setLinkMark(this.getLinkMark());
364 dest.setLinkTemplate(this.getLinkTemplate());
365
366 // dest.setMaxWidth(this.getMaxWidth());
367
368 dest.setOffset(this.getOffset());
369 // dest.setOwner(this.getOwner());
370 dest.setThickness(this.getThickness());
371 dest.setSize(this.getSize());
372 dest.setTopShadowColor(this.getTopShadowColor());
373 dest.setLinePattern(this.getLinePattern());
374
375 dest.setFloating(this.isFloating());
376 dest.setArrow(this.getArrowheadLength(), this.getArrowheadRatio(), this.getArrowheadNibPerc());
377 dest.setDotType(this.getDotType());
378 dest.setFilled(this.getFilled());
379 /*
380 * Calling the methods will move the item... This messes things up when
381 * the user uses backspace to delete a text line end
382 */
383 // dest._anchorLeft = this._anchorLeft;
384 // dest._anchorRight = this._anchorRight;
385 // dest._anchorTop = this._anchorTop;
386 // dest._anchorBottom = this._anchorBottom;
387 dest.setFormula(this.getFormula());
388 dest._overlay = this._overlay;
389 dest._highlightMode = this._highlightMode;// SelectedMode.None;
390 // dest._highlightColor = this._highlightColor;
391 // dest.setHighlight(this.getHighlight());
392
393 dest._visible = this._visible;
394
395 Frame parent = DisplayController.getCurrentFrame();
396 if (parent == null) parent = this.getParentOrCurrentFrame();
397 dest.setParent(parent);
398
399 /*
400 * TODO MIKE says maybe we could tighten up and only give items ID's if
401 * their current ID is negative?
402 */
403 if (parent != null) {
404 dest.setID(parent.getNextItemID());
405 }
406
407 final String currentUser = UserSettings.UserName.get();
408 if (parent != null && (parent.getOwner() == null || currentUser.compareTo(parent.getOwner()) != 0)) {
409 dest.setOwner(currentUser);
410 }
411 }
412
413 public void setDotType(DotType type) {
414 invalidateAll();
415 _type = type;
416 invalidateAll();
417 }
418
419 public DotType getDotType() {
420 Surrogate surrogate = Surrogate.of(this);
421 if (surrogate != null &&
422 surrogate.isPropertyIsInherited(DefaultFrameWriter.DOT_TYPE + "")) {
423 return this.getClassic().getDotType();
424 } else {
425 return _type;
426 }
427 }
428
429
430 public void setFilled(boolean filled)
431 {
432 invalidateAll();
433 _filled = filled;
434 invalidateAll();
435 }
436
437 public boolean getFilled() {
438 Surrogate surrogate = Surrogate.of(this);
439 if (surrogate != null &&
440 surrogate.isPropertyIsInherited(DefaultFrameWriter.FILLED + "")) {
441 return this.getClassic().getFilled();
442 } else {
443 return _filled;
444 }
445 }
446
447 /**
448 * Sets the angle of colour change for gradient colour fills.
449 *
450 * @param gradientAngle The new angle of colour change.
451 */
452 public void setGradientAngle(double gradientAngle)
453 {
454 _gradientAngle = gradientAngle;
455
456 for (Line line : _lines) {
457 Item other = line.getOppositeEnd(this);
458 if (other.getGradientAngle() != gradientAngle) other.setGradientAngle(gradientAngle);
459 }
460
461 invalidateCommonTrait(ItemAppearence.GradientColor);
462 invalidateFill();
463 }
464
465 /**
466 * Gets the angle of colour change for gradient fills.
467 *
468 * @return The angle of colour change.
469 */
470 public double getGradientAngle() {
471 Surrogate surrogate = Surrogate.of(this);
472 if (surrogate != null &&
473 surrogate.isPropertyIsInherited(DefaultFrameWriter.GRADIENT_ANGLE + "")) {
474 return this.getClassic().getGradientAngle();
475 } else {
476 return _gradientAngle;
477 }
478 }
479
480 /**
481 * Gets the gravity for this item. Gravity is the distance from the item at which mouse interaction
482 * applies to the item (like a small buffer zone so you don't need to click exactly on the item).
483 *
484 * @return The gravity distance for this item.
485 */
486 public int getGravity()
487 {
488 if (isVectorItem()) return 2;
489
490 return UserSettings.Gravity.get();
491 }
492
493 /**
494 * Whether or not line highlights should be shown.
495 * TODO: Not really an item method is it? Goes straight to user settings. Refactor. cts16
496 *
497 * @return <code>true</code> if line highlighting should be shown, <code>false</code> otherwise.
498 */
499 public static boolean shouldShowLineHighlight()
500 {
501 return UserSettings.LineHighlight.get();
502 }
503
504 /**
505 * Sets the highlight mode for this item.
506 *
507 * @param mode The new highlight mode.
508 */
509 public void setHighlightMode(HighlightMode mode)
510 {
511 if (hasPermission(UserAppliedPermission.followLinks) || getEditTarget().hasPermission(UserAppliedPermission.followLinks)) {
512 if (_highlightMode != mode) {
513 _highlightMode = mode;
514 this.invalidateCommonTrait(ItemAppearence.HighlightModeChanged);
515 }
516 }
517 }
518
519 public void setOverlayPermission(UserAppliedPermission overlayPermission)
520 {
521 _overlayPermission = overlayPermission;
522 }
523
524 public void setPermission(PermissionTriple permissionPair) {
525 List<String> groupMembers = getParent() != null ? getParent().getGroupMembers() : new ArrayList<String>();
526 _permissionTriple = permissionPair;
527 if (_permissionTriple.getPermission(_owner, groupMembers) == UserAppliedPermission.denied) {
528 this.getParent().moveItemToBodyHiddenDueToPermission(this);
529 }
530 }
531
532 public PermissionTriple getPermission() {
533 Surrogate surrogate = Surrogate.of(this);
534 if (surrogate != null &&
535 surrogate.isPropertyIsInherited(DefaultFrameWriter.PERMISSION + "")) {
536 return this.getClassic().getPermission();
537 } else {
538 return _permissionTriple;
539 }
540 }
541
542 public UserAppliedPermission getUserAppliedPermission() {
543 List<String> groupMembers = getParent() != null ? getParent().getGroupMembers() : new ArrayList<String>();
544 String owner = _owner != null ? _owner : _parent != null ? _parent.getOwner() : null;
545 if(_permissionTriple != null) return _permissionTriple.getPermission(owner, groupMembers);
546 if(_overlayPermission != null) return _overlayPermission;
547 if(_parent != null) return _parent.getUserAppliedPermission();
548 return UserAppliedPermission.full;
549 }
550
551 public boolean hasPermission(UserAppliedPermission permission) {
552 return getUserAppliedPermission().ordinal() >= permission.ordinal();
553 }
554
555 protected Item() {
556 _creationDate = Formatter.getLongDateTime();
557 }
558
559 /**
560 * Adds an action to this Item.
561 *
562 * @param action
563 * The name of the action to add to this Item.
564 */
565 public void addAction(String action)
566 {
567 if (action == null || action.equals("")) return;
568
569 if (_actions == null) {
570 _actions = new LinkedList<String>();
571 }
572
573 _actions.add(action);
574
575 if (_actions.size() == 1) {
576 invalidateBounds();
577 invalidateCommonTrait(ItemAppearence.LinkChanged);
578 }
579 }
580
581 public void addAllConnected(Collection<Item> connected)
582 {
583 if (!connected.contains(this)) connected.add(this);
584
585 for (Item item : getConnected()) {
586 if (!connected.contains(item)) {
587 item.addAllConnected(connected);
588 }
589 }
590 }
591
592 /**
593 * Adds the given Constraint to this Dot
594 *
595 * @param c
596 * The Constraint to set this Dot as a member of.
597 */
598 public void addConstraint(Constraint c)
599 {
600 // do not add duplicate constraint
601 if (_constraints.contains(c))
602 return;
603
604 _constraints.add(c);
605 }
606
607 /**
608 * Adds a given line to the list of lines that this Point is an end for.
609 *
610 * @param line
611 * The Line that this Point is an end of.
612 */
613 public void addLine(Line line)
614 {
615 if (_lines.contains(line)) {
616 return;
617 }
618
619 _lines.add(line);
620 }
621
622 /**
623 * Items are sorted by their Y coordinate on the screen.
624 *
625 * @param i
626 * The Item to compare this Item to
627 * @return a negative integer, zero, or a positive integer as this object is
628 * less than, equal to, or greater than the specified object.
629 */
630 public int compareTo(Item i)
631 {
632 return getY() - i.getY();
633 }
634
635 /**
636 * Every Item has an area around it defined by a Shape (typically a
637 * rectangle), this method returns true if the given x,y pair lies within
638 * the area and false otherwise.
639 *
640 * @param p
641 * The coordinate to check
642 * @return True if the Shape around this Item contains the given x,y pair,
643 * false otherwise.
644 */
645 public boolean contains(Point p)
646 {
647 return getBounds().contains(p);
648 }
649
650 /**
651 * Returns a deep copy of this Item, note: it is up to the receiver to
652 * change the Item ID etc as necessary.
653 *
654 * @return A deep copy of this Item.
655 */
656 public abstract Item copy();
657
658 public void delete()
659 {
660 _deleted = true;
661 }
662
663 @Override
664 public boolean equals(Object o)
665 {
666 if (o == null)
667 return false;
668 if (getClass().equals(o.getClass())) {
669 Item i = (Item) o;
670 return i.getID() == getID()
671 && ((i.getParent() == _parent) || (i.getParent() != null && i
672 .getParent().equals(_parent)));
673 } else
674 return false;
675 }
676
677 /**
678 * Returns a list of any action code that is currently associated with this
679 * Item
680 *
681 * @return A List of action code associated with this Item, or null if none
682 * has been assigned.
683 */
684 public List<String> getAction() {
685 Surrogate surrogate = Surrogate.of(this);
686 if (surrogate != null &&
687 surrogate.isPropertyIsInherited(DefaultFrameWriter.ACTION + "")) {
688 return this.getClassic().getAction();
689 } else {
690 return _actions;
691 }
692 }
693
694 public List<String> getData() {
695 Surrogate surrogate = Surrogate.of(this);
696 if (surrogate != null &&
697 surrogate.isPropertyIsInherited(DefaultFrameWriter.DATA + "")) {
698 return this.getClassic().getData();
699 } else {
700 return _data.getData();
701 }
702 }
703
704 public List<String> getActionCursorEnter() {
705 Surrogate surrogate = Surrogate.of(this);
706 if (surrogate != null &&
707 surrogate.isPropertyIsInherited(DefaultFrameWriter.ACTION_CURSOR_ENTER + "")) {
708 return this.getClassic().getActionCursorEnter();
709 } else {
710 return _actionCursorEnter;
711 }
712 }
713
714 public List<String> getActionCursorLeave() {
715 Surrogate surrogate = Surrogate.of(this);
716 if (surrogate != null &&
717 surrogate.isPropertyIsInherited(DefaultFrameWriter.ACTION_CURSOR_LEAVE + "")) {
718 return this.getClassic().getActionCursorLeave();
719 } else {
720 return _actionCursorLeave;
721 }
722 }
723
724 public List<String> getActionEnterFrame() {
725 Surrogate surrogate = Surrogate.of(this);
726 if (surrogate != null &&
727 surrogate.isPropertyIsInherited(DefaultFrameWriter.ACTION_ENTER_FRAME + "")) {
728 return this.getClassic().getActionEnterFrame();
729 } else {
730 return _actionEnterFrame;
731 }
732 }
733
734 public List<String> getActionLeaveFrame() {
735 Surrogate surrogate = Surrogate.of(this);
736 if (surrogate != null &&
737 surrogate.isPropertyIsInherited(DefaultFrameWriter.ACTION_LEAVE_FRAME + "")) {
738 return this.getClassic().getActionLeaveFrame();
739 } else {
740 return _actionLeaveFrame;
741 }
742 }
743
744 public boolean getActionMark() {
745 Surrogate surrogate = Surrogate.of(this);
746 if (surrogate != null &&
747 surrogate.isPropertyIsInherited(DefaultFrameWriter.ACTION_MARK + "")) {
748 return this.getClassic().getActionMark();
749 } else {
750 return _actionMark;
751 }
752 }
753
754 /**
755 * Gets all the items connected to this item. Uses a recursive approach to
756 * search connected points.
757 *
758 * @return
759 */
760 public Collection<Item> getAllConnected()
761 {
762 Collection<Item> list = new LinkedHashSet<Item>();
763 addAllConnected(list);
764 return list;
765 }
766
767/* public Area getArea() {
768 return new Area(getPolygon());
769 }*/
770
771 public String getArrow() {
772 Surrogate surrogate = Surrogate.of(this);
773 if (surrogate != null &&
774 surrogate.isPropertyIsInherited(DefaultFrameWriter.ARROW + "")) {
775 return this.getClassic().getArrow();
776 } else {
777 if (!hasVisibleArrow())
778 return null;
779
780 String ratio = "" + getArrowheadRatio();
781 if (ratio.length() - ratio.indexOf(".") > 2)
782 ratio = ratio.substring(0, ratio.indexOf(".") + 3);
783
784 return getArrowheadLength() + " " + ratio + " " + getArrowheadNibPerc();
785 }
786 }
787
788 public PolygonBounds getArrowhead()
789 {
790 return _arrowhead;
791 }
792
793 public float getArrowheadLength()
794 {
795 return _arrowheadLength;
796 }
797
798 public double getArrowheadRatio()
799 {
800 return _arrowheadRatio;
801 }
802
803 public double getArrowheadNibPerc()
804 {
805 return _arrowheadNibPerc;
806 }
807
808 public Colour getBackgroundColor() {
809 Surrogate surrogate = Surrogate.of(this);
810 if (surrogate != null &&
811 surrogate.isPropertyIsInherited(DefaultFrameWriter.BACKGROUND_COLOR + "")) {
812 return this.getClassic().getBackgroundColor();
813 } else {
814 return _backgroundColour;
815 }
816 }
817
818 public Colour getBorderColor() {
819 Surrogate surrogate = Surrogate.of(this);
820 if (surrogate != null &&
821 surrogate.isPropertyIsInherited(DefaultFrameWriter.TYPE_AND_ID + "")) {
822 return this.getClassic().getBorderColor();
823 } else {
824 return _colorBorder;
825 }
826 }
827
828 /**
829 * Returns the Color being used to shade the bottom half of this Item's
830 * border. This can be NULL if no Color is being used
831 *
832 * @return The Color displayed on the bottom\right half of this Item's
833 * border.
834 */
835 public Colour getBottomShadowColor()
836 {
837 return _colorBottomShadow;
838 }
839
840 /**
841 * Returns the height (in pixels) of this Item's surrounding area.
842 *
843 * @return The height (in pixels) of this Item's surrounding area as
844 * returned by getArea().
845 */
846 public int getBoundsHeight()
847 {
848 return AxisAlignedBoxBounds.getEnclosing(getBounds()).getHeight();
849 }
850
851 /**
852 * Returns the width (in pixels) of this Item's surrounding area.
853 *
854 * @return The width (in pixels) of this Item's surrounding area as returned
855 * by getArea().
856 */
857 public int getBoundsWidth()
858 {
859 return AxisAlignedBoxBounds.getEnclosing(getBounds()).getWidth();
860 }
861
862 // TODO: Remove magic constants. cts16
863 public EllipticalBounds getLinkBounds()
864 {
865 if (_linkCircle == null) {
866 _linkCircle = new EllipticalBounds(new Point(6, 3), 7);
867 }
868
869 return _linkCircle;
870 }
871
872 protected PolygonBounds getCircleCross()
873 {
874
875 if (_linkCircleCross == null) {
876 _linkCircleCross = new PolygonBounds();
877
878 EllipticalBounds poly = getLinkBounds();
879 int x1 = poly.getMinX();
880 int x2 = poly.getMaxX();
881 int y1 = poly.getMinY();
882 int y2 = poly.getMaxY();
883 int midX = (x2 + x1) / 2;
884 int midY = (y2 + y1) / 2;
885
886 _linkCircleCross.addPoint(new Point(x1, y1));
887 _linkCircleCross.addPoint(new Point(x2, y2));
888 _linkCircleCross.addPoint(new Point(midX, midY));
889 _linkCircleCross.addPoint(new Point(x1, y2));
890 _linkCircleCross.addPoint(new Point(x2, y1));
891 _linkCircleCross.addPoint(new Point(midX, midY));
892 }
893
894 return _linkCircleCross;
895 }
896
897 public Colour getColor() {
898 Surrogate surrogate = Surrogate.of(this);
899 if (surrogate != null &&
900 surrogate.isPropertyIsInherited(DefaultFrameWriter.COLOR + "")) {
901 return this.getClassic().getColor();
902 } else {
903 return _foregroundColour;
904 }
905 }
906
907 public Collection<Item> getConnected()
908 {
909 List<Item> conn = new LinkedList<Item>();
910 conn.add(this);
911 conn.addAll(getEnclosures());
912 conn.addAll(getLines());
913 return conn;
914 }
915
916 public String getConstraintIDs() {
917 Surrogate surrogate = Surrogate.of(this);
918 if (surrogate != null &&
919 surrogate.isPropertyIsInherited(DefaultFrameWriter.CONSTRAINT_IDS + "")) {
920 return this.getClassic().getConstraintIDs();
921 } else {
922 if (_constraints == null || _constraints.size() == 0)
923 return null;
924
925 String cons = "";
926
927 for (Constraint c : _constraints)
928 cons += c.getID() + " ";
929
930 return cons.trim();
931 }
932 }
933
934 /*
935 * public void setLinkValid(boolean val) { _isValidLink = val; }
936 */
937
938 /**
939 * Returns a List of any Constraints that this Dot is a memeber of.
940 *
941 * @return a List of Constraints that this Dot is a member of.
942 */
943 public List<Constraint> getConstraints()
944 {
945 return _constraints;
946 }
947
948 public String getTag()
949 {
950 if (_tag != null && _tag.length() > 0)
951 return _tag.toString();
952 return null;
953 }
954
955 public String getDateCreated() {
956 Surrogate surrogate = Surrogate.of(this);
957 if (surrogate != null &&
958 surrogate.isPropertyIsInherited(DefaultFrameWriter.DATE_CREATED + "")) {
959 return this.getClassic().getDateCreated();
960 } else {
961 return _creationDate;
962 }
963 }
964
965 public Colour getFillColor() {
966 Surrogate surrogate = Surrogate.of(this);
967 if (surrogate != null &&
968 surrogate.isPropertyIsInherited(DefaultFrameWriter.FILL_COLOR + "")) {
969 return this.getClassic().getFillColor();
970 } else {
971 return _fillColour;
972 }
973 }
974
975 public String getFillPattern() {
976 Surrogate surrogate = Surrogate.of(this);
977 if (surrogate != null &&
978 surrogate.isPropertyIsInherited(DefaultFrameWriter.FILL_PATTERN + "")) {
979 return this.getClassic().getFillPattern();
980 } else {
981 return _fillPattern;
982 }
983 }
984
985 public String getFirstAction()
986 {
987 if (_actions == null || _actions.size() == 0)
988 return null;
989 return _actions.get(0);
990 }
991
992 /**
993 * Gets the value of <code>_highlight</code> for this item.
994 * TODO: Appears unused? cts16.
995 *
996 * @return The value of <code>_highlight</code>.
997 */
998 public boolean getHighlight() {
999 Surrogate surrogate = Surrogate.of(this);
1000 if (surrogate != null &&
1001 surrogate.isPropertyIsInherited(DefaultFrameWriter.HIGHLIGHT + "")) {
1002 return this.getClassic().getHighlight();
1003 } else {
1004 return _highlight;
1005 }
1006 }
1007
1008 public Colour getHighlightColor()
1009 {
1010 if (_highlightColour.equals(getPaintColor())) return getAlternateHighlightColor();
1011
1012 return getDefaultHighlightColor();
1013 }
1014
1015 /**
1016 * Returns the ID of this Item, which must be unique for the Frame.
1017 *
1018 * @return The ID of this Item.
1019 *
1020 * TODO: What does it mean to have a negative ID# (as used in TDFC)? cts16
1021 */
1022 public int getID()
1023 {
1024 return _id;
1025 }
1026
1027 /**
1028 * Returns the list of IDs of the Lines that this Dot is an end of.
1029 *
1030 * @return The list of Line IDs that this point is part of.
1031 */
1032 public String getLineIDs() {
1033 Surrogate surrogate = Surrogate.of(this);
1034 if (surrogate != null &&
1035 surrogate.isPropertyIsInherited(DefaultFrameWriter.LINE_IDS + "")) {
1036 return this.getClassic().getLineIDs();
1037 } else {
1038 String lineID = null;
1039
1040 if (_lines.size() > 0) {
1041 lineID = "" + _lines.get(0).getID();
1042
1043 for (int i = 1; i < _lines.size(); i++)
1044 lineID += " " + _lines.get(i).getID();
1045 }
1046
1047 return lineID;
1048 }
1049 }
1050
1051 public int[] getLinePattern() {
1052 Surrogate surrogate = Surrogate.of(this);
1053 if (surrogate != null &&
1054 surrogate.isPropertyIsInherited(DefaultFrameWriter.LINE_PATTERN + "")) {
1055 return this.getClassic().getLinePattern();
1056 } else {
1057 return _linePattern;
1058 }
1059 }
1060
1061 /**
1062 * Returns a list of Lines where this Dot is an end.
1063 *
1064 * @return A list of the Lines that this Dot is an end for or null if no
1065 * Lines have been added.
1066 */
1067 public List<Line> getLines()
1068 {
1069 return _lines;
1070 }
1071
1072 /**
1073 * Returns the name of a Frame that this Item links to, or null if this Item
1074 * has no link.
1075 *
1076 * @return The name of a Frame that this Item links to (if any) or null if
1077 * this Item does not link to anything.
1078 */
1079 public String getLink() {
1080 Surrogate surrogate = Surrogate.of(this);
1081 if (surrogate != null &&
1082 surrogate.isPropertyIsInherited(DefaultFrameWriter.LINK + "")) {
1083 return this.getClassic().getLink();
1084 } else {
1085 return _link;
1086 }
1087 }
1088
1089 public String getFormula() {
1090 Surrogate surrogate = Surrogate.of(this);
1091 if (surrogate != null &&
1092 surrogate.isPropertyIsInherited(DefaultFrameWriter.FORMULA + "")) {
1093 return this.getClassic().getFormula();
1094 } else {
1095 return _formula;
1096 }
1097 }
1098
1099 public boolean hasFormula()
1100 {
1101 return _formula != null;
1102 }
1103
1104 public boolean hasAttributeValuePair()
1105 {
1106 return _attributeValuePair != null && _attributeValuePair.hasPair();
1107 }
1108
1109 public void setFormula(String formula)
1110 {
1111 _formula = formula;
1112 }
1113
1114 public boolean calculate(String formula)
1115 {
1116 setFormula(formula);
1117 return true;
1118 }
1119
1120 public String getLinkFrameset() {
1121 Surrogate surrogate = Surrogate.of(this);
1122 if (surrogate != null &&
1123 surrogate.isPropertyIsInherited(DefaultFrameWriter.LINK_FRAMESET + "")) {
1124 return this.getClassic().getLinkFrameset();
1125 } else {
1126 return _link_frameset;
1127 }
1128 }
1129
1130 public boolean getLinkMark() {
1131 Surrogate surrogate = Surrogate.of(this);
1132 if (surrogate != null &&
1133 surrogate.isPropertyIsInherited(DefaultFrameWriter.LINK_MARK + "")) {
1134 return this.getClassic().getLinkMark();
1135 } else {
1136 return _linkMark;
1137 }
1138 }
1139
1140 public String getLinkTemplate() {
1141 Surrogate surrogate = Surrogate.of(this);
1142 if (surrogate != null &&
1143 surrogate.isPropertyIsInherited(DefaultFrameWriter.LINK_TEMPLATE + "")) {
1144 return this.getClassic().getLinkTemplate();
1145 } else {
1146 return _link_template;
1147 }
1148 }
1149
1150 // public int getMaxWidth()
1151 // {
1152 // return _maxWidth;
1153 // }
1154
1155 public Point getOffset()
1156 {
1157 return _offset;
1158 }
1159
1160 public String getOwner() {
1161 Surrogate surrogate = Surrogate.of(this);
1162 if (surrogate != null &&
1163 surrogate.isPropertyIsInherited(DefaultFrameWriter.OWNER + "")) {
1164 return this.getClassic().getOwner();
1165 } else {
1166 return _owner;
1167 }
1168 }
1169
1170 public Colour getPaintBackgroundColor()
1171 {
1172 Colour colorBackground = getBackgroundColor();
1173 if (colorBackground == null) {
1174 if (getParent() != null && getParent().getBackgroundColor() != null)
1175 return getParent().getBackgroundColor();
1176
1177 return DEFAULT_BACKGROUND;
1178 }
1179
1180 return colorBackground;
1181 }
1182
1183 /**
1184 * Returns the foreground Color of this Item.
1185 *
1186 * @return The Color of this item (foreground)
1187 */
1188 public final Colour getPaintColor()
1189 {
1190 // If color is null then get the paint foregroundColor for the frame the
1191 // item is on which is a color adjusted to suit the background
1192 Colour color = getColor();
1193
1194 if (color == null) {
1195 if (getParent() != null)
1196 return getParent().getPaintForegroundColor();
1197
1198 Frame current = DisplayController.getCurrentFrame();
1199 if (current == null) {
1200 return DEFAULT_FOREGROUND;
1201 }
1202 return current.getPaintForegroundColor();
1203 }
1204
1205 return color;
1206 }
1207
1208 public final Colour getPaintBorderColor()
1209 {
1210 // If color is null then get the paint foregroundColor for the frame the
1211 // item is on which is a color adjusted to suit the background
1212 Colour color = getBorderColor();
1213
1214 if (color == null) {
1215 if (getParent() != null)
1216 return getParent().getPaintForegroundColor();
1217
1218 Frame current = DisplayController.getCurrentFrame();
1219 if (current == null) {
1220 return DEFAULT_FOREGROUND;
1221 }
1222 return current.getPaintForegroundColor();
1223 }
1224
1225 return color;
1226 }
1227
1228 protected Colour getPaintHighlightColor()
1229 {
1230 Colour highlightColor = getDefaultHighlightColor();
1231 if (hasVisibleBorder()) {
1232 if (getPaintBorderColor().equals(highlightColor)) {
1233 highlightColor = getDefaultHighlightColor();
1234 }
1235 } else if (getPaintBackgroundColor().equals(highlightColor)) {
1236 highlightColor = getDefaultHighlightColor();
1237 }
1238
1239 if (getParent() != null && getParent().getPaintBackgroundColor().equals(highlightColor)) {
1240 highlightColor = getParent().getPaintForegroundColor();
1241 }
1242
1243 if (hasVisibleBorder()) {
1244 if (highlightColor.equals(getBorderColor()) && getThickness() == getHighlightThickness()) {
1245 highlightColor = highlightColor.clone();
1246 highlightColor.setAlpha(Colour.FromComponent255(150));
1247 }
1248 }
1249
1250 return highlightColor;
1251 }
1252
1253 protected Colour getDefaultHighlightColor()
1254 {
1255 if (isVectorItem() && !this.contains(EcosystemManager.getInputManager().getCursorPosition())) {
1256 return Colour.FromRGB255(255, BRIGHTNESS, BRIGHTNESS);
1257 }
1258 return _highlightColour;
1259 }
1260
1261 protected Colour getAlternateHighlightColor()
1262 {
1263 if (isVectorItem() && !this.contains(EcosystemManager.getInputManager().getCursorPosition())) {
1264 return Colour.FromRGB255(BRIGHTNESS, BRIGHTNESS, 255);
1265 }
1266 return ALTERNATE_HIGHLIGHT;
1267 }
1268
1269 protected int getHighlightThickness()
1270 {
1271 if (isVectorItem()) return _vectorHighlightThickness;
1272
1273 return _highlightThickness;
1274 }
1275
1276 public final Frame getParent()
1277 {
1278 return _parent;
1279 }
1280
1281 /** Gets the position of this item. */
1282 public final Point getPosition() {
1283 Surrogate surrogate = Surrogate.of(this);
1284 if (surrogate != null &&
1285 surrogate.isPropertyIsInherited(DefaultFrameWriter.POSITION + "")) {
1286 return this.getClassic().getPosition();
1287 } else {
1288 return new Point(getX(), getY());
1289 }
1290 }
1291
1292 /**
1293 * Returns the size of this Item. For Text this is the Font size, for Lines
1294 * and Dots this is the thickness.
1295 *
1296 * @return The size of this Item.
1297 */
1298 public float getSize()
1299 {
1300 return SIZE_NOT_APPLICABLE;
1301 }
1302
1303 /**
1304 * Returns the Color being used to shade the top half of this Item's border.
1305 * This can be NULL if no Color is being used
1306 *
1307 * @return The Color displayed on the top\left half of this Item's border.
1308 */
1309 public Colour getTopShadowColor()
1310 {
1311 return _colorTopShadow;
1312 }
1313
1314 public String getTypeAndID() {
1315 Surrogate surrogate = Surrogate.of(this);
1316 if (surrogate != null &&
1317 surrogate.isPropertyIsInherited(DefaultFrameWriter.TYPE_AND_ID + "")) {
1318 return this.getClassic().getTypeAndID();
1319 } else {
1320 return "T " + getID();
1321 }
1322 }
1323
1324 public Integer getWidthToSave() {
1325 Surrogate surrogate = Surrogate.of(this);
1326 if (surrogate != null &&
1327 surrogate.isPropertyIsInherited(DefaultFrameWriter.WIDTH_TO_SAVE + "")) {
1328 return this.getClassic().getWidthToSave();
1329 } else {
1330 return getWidth();
1331 }
1332 }
1333
1334 public Integer getMinWidthToSave() {
1335 Surrogate surrogate = Surrogate.of(this);
1336 if (surrogate != null &&
1337 surrogate.isPropertyIsInherited(DefaultFrameWriter.MIN_WIDTH_TO_SAVE + "")) {
1338 return this.getClassic().getMinWidthToSave();
1339 } else {
1340 return getMinWidth();
1341 }
1342 }
1343
1344 public Integer getWidth()
1345 {
1346 return null;
1347 }
1348
1349 public Integer getMinWidth() {
1350 return null;
1351 }
1352
1353 public int getHeight()
1354 {
1355 return 0;
1356 }
1357
1358 /**
1359 * Returns the X coordinate of this Item on the screen
1360 *
1361 * @return The X coordinate of this Item on the screen
1362 */
1363 public int getX() {
1364 Surrogate surrogate = Surrogate.of(this);
1365 if (surrogate != null &&
1366 surrogate.isPropertyIsInherited(DefaultFrameWriter.POSITION + "")) {
1367 return this.getClassic().getX();
1368 } else {
1369 return Math.round(_x);
1370 }
1371 }
1372
1373 /**
1374 * Returns the Y coordinate of this Item on the screen
1375 *
1376 * @return The Y coordinate of this Item on the screen
1377 */
1378 public int getY() {
1379 Surrogate surrogate = Surrogate.of(this);
1380 if (surrogate != null &&
1381 surrogate.isPropertyIsInherited(DefaultFrameWriter.POSITION + "")) {
1382 return this.getClassic().getY();
1383 } else {
1384 return Math.round(_y);
1385 }
1386 }
1387
1388 public boolean hasVisibleArrow()
1389 {
1390 return isLineEnd() && getArrowheadRatio() != 0 && getArrowheadLength() != 0;
1391 }
1392
1393 /**
1394 * Checks if the given Shape intersects with the Shape around this Item.
1395 *
1396 * @param s
1397 * The Shape to check.
1398 * @return True if the two Shapes overlap, False otherwise.
1399 */
1400 public boolean intersects(PolygonBounds otherBounds)
1401 {
1402 if (otherBounds == null) return false;
1403
1404 Bounds thisBounds = getBounds();
1405
1406 // Need to do this check for circles
1407 if (otherBounds.equals(thisBounds)) return true;
1408
1409 return otherBounds.intersects(thisBounds);
1410
1411 // Need to check the second equality so that we dont pick up circles
1412 // inside other circles
1413 //return !a.isEmpty() && !a.equals(new Area(p));
1414 }
1415
1416 /**
1417 * Note: Pictures always return False, as they should be drawn even when no
1418 * other annotation Items are.
1419 *
1420 * @return True if this Item is an annotation, False otherwise.
1421 */
1422 public boolean isAnnotation()
1423 {
1424 return false;
1425 }
1426
1427 public boolean isFloating()
1428 {
1429 return _floating;
1430 }
1431
1432 public boolean isFrameName()
1433 {
1434 if (this.getParent() == null || this.getParent().getNameItem() != this)
1435 return false;
1436 return true;
1437 }
1438
1439 public boolean isFrameTitle()
1440 {
1441 if (this.getParent() == null || this.getParent().getTitleItem() != this)
1442 return false;
1443 return true;
1444 }
1445
1446 /**
1447 * Returns True if this Item is currently highlighted.
1448 *
1449 * @return True if this Item is currently highlighted on the screen, False
1450 * otherwise.
1451 */
1452 public boolean isHighlighted()
1453 {
1454 if (isFloating())
1455 return false;
1456 return _highlightMode != HighlightMode.None;
1457 }
1458
1459 /**
1460 * Tests if the item link is a valid framename, that is, the String must
1461 * begin with a character, end with a number with 0 or more letters and
1462 * numbers in between. If there is a dot in the framename all the chars
1463 * after it must be digits.
1464 *
1465 * @return True if the given framename is proper, false otherwise.
1466 */
1467 public boolean isLinkValid()
1468 {
1469 if (FrameIO.isPositiveInteger(getLink()))
1470 return true;
1471
1472 if (FrameIO.isValidFrameName(getLink()))
1473 return true;
1474 return false;
1475 }
1476
1477 /**
1478 * Checks if the given point is 'near' to the item. Here 'near' means within a certain distance
1479 * of the axis-aligned box bounding the item's polygon.
1480 *
1481 * @param x
1482 * The x-coordinate of the point to check.
1483 *
1484 * @param y
1485 * The y-coordinate of the point to check.
1486 *
1487 * @return
1488 * True if the given point is 'near' to the item, false otherwise.
1489 */
1490 public boolean isNear(int x, int y)
1491 {
1492 AxisAlignedBoxBounds box = ItemUtils.expandRectangle(getBoundingBox(), NEAR_DISTANCE * 2);
1493
1494 return box.contains(x, y);
1495 }
1496
1497 public boolean isOldTag()
1498 {
1499 if (this instanceof Text)
1500 if (((Text) this).getTextList().get(0).toLowerCase().equals("@old"))
1501 return true;
1502 return false;
1503 }
1504
1505 /**
1506 * Merges this Item with the given Item. The merger Item should be left
1507 * unchanged after this method. The merger may or may not be the same class
1508 * as this Item, exact behaviour depends on the subclass, No-op is allowed.
1509 *
1510 * @param merger
1511 * The Item to merge with
1512 * @return any Item that should remain on the cursor
1513 */
1514 public abstract Item merge(Item merger, int mouseX, int mouseY);
1515
1516 /**
1517 * Displays this item directly on the screen. Note: All Items are
1518 * responsible for their own drawing, buffering, etc.
1519 *
1520 * @param g
1521 * The Graphics to draw this Item on.
1522 */
1523 public abstract void paint();
1524
1525 public void setTooltips(final List<String> tooltips)
1526 {
1527 if (tooltips == null || tooltips.size() == 0) {
1528 _tooltip = new Tooltip();
1529 } else {
1530 for (final String content: tooltips) _tooltip.addTooltip(content, this);
1531 }
1532 }
1533
1534 public void setTooltip(final String tooltip)
1535 {
1536 if(tooltip != null && tooltip.trim().length() > 0) {
1537 _tooltip.addTooltip(tooltip, this);
1538 }
1539 }
1540
1541 public List<String> getTooltip() {
1542 Surrogate surrogate = Surrogate.of(this);
1543 if (surrogate != null &&
1544 surrogate.isPropertyIsInherited(DefaultFrameWriter.TOOLTIP + "")) {
1545 return this.getClassic().getTooltip();
1546 } else {
1547 return _tooltip.asStringList();
1548 }
1549 }
1550
1551 public Collection<Text> getTooltipItems()
1552 {
1553 return _tooltip.getTooltips();
1554 }
1555
1556 public void clearTooltips()
1557 {
1558 final Frame frame = this.getParent();
1559 if(_tooltip != null) {
1560 for(final Text tooltip: _tooltip.getTooltips()) frame.removeItem(tooltip);
1561 }
1562 }
1563
1564 public void paintTooltip()
1565 {
1566 final Bounds bounds = AxisAlignedBoxBounds.getEnclosing(this.getBoundingBox());
1567 Dimension frameSize = DisplayController.getFramePaintAreaSize();
1568
1569 int x = bounds.getMaxX();
1570
1571 // If the tooltip goes off the right side of the window, move it left so it's completely on
1572 if(x + _tooltip.getWidth() > frameSize.getWidth()) {
1573 x = frameSize.getWidth() - _tooltip.getWidth();
1574 }
1575
1576 int y = bounds.getMaxY();
1577
1578 if(y + _tooltip.getCollectiveHeight() > frameSize.getHeight()) {
1579 y = (bounds.getMinY() + bounds.getMaxY()) / 2 - _tooltip.getCollectiveHeight();
1580 }
1581
1582 for(final Text tooltip : _tooltip.getTooltips()) {
1583 this.getParent().addItem(tooltip);
1584 tooltip.setPosition(x, y);
1585 tooltip.paint();
1586 y += tooltip.getHeight();
1587 }
1588 }
1589
1590 public void paintFill() {
1591 Colour fillColor = getFillColor();
1592 if (fillColor != null && getEnclosingDots() != null) {
1593 Fill fill = getFill();
1594 EcosystemManager.getGraphicsManager().drawPolygon(getEnclosedShape(), null, null, 0.0f, fill, null, null);
1595 }
1596 }
1597
1598 protected Fill getFill() {
1599 Fill fill;
1600 Colour fillColour = getFillColor();
1601 if (isFloating()) {
1602 // TODO experiment with adding alpha when picking up filled
1603 // items... Slows things down quite alot!!
1604 // TODO: Does nothing as it stands... cts16
1605 fillColour = new Colour(fillColour.getRed(), fillColour.getGreen(),
1606 fillColour.getBlue(), fillColour.getAlpha());
1607 }
1608 Colour gradientColor = getGradientColor();
1609 PolygonBounds poly = getEnclosedShape();
1610 if (gradientColor != null && poly != null) {
1611 /*
1612 * It is slow when painting gradients... modify so this is only done
1613 * once unless it is resized...
1614 */
1615 AxisAlignedBoxBounds b = AxisAlignedBoxBounds.getEnclosing(poly);
1616 double rads = getGradientAngle();
1617 double cos = Math.cos(rads);
1618 double sin = Math.sin(rads);
1619
1620 Point fromPoint = new Point((int) (b.getMinX() + b.getWidth() * (0.2 * cos + 0.5)), (int) (b.getMinY() + b.getHeight() * (0.2 * sin + 0.5)));
1621 Point toPoint = new Point((int) (b.getMinX() + b.getWidth() * (-0.8 * cos + 0.5)), (int) (b.getMinY() + b.getHeight() * (-0.8 * sin + 0.5)));
1622
1623 fill = new GradientFill(fillColour, fromPoint, gradientColor, toPoint);
1624 } else {
1625 fill = new Fill(fillColour);
1626 }
1627
1628 return fill;
1629 }
1630
1631 /**
1632 * This method performs all the actions in an items list. If it contains a
1633 * link as well the link is used as the source frame for all actions.
1634 */
1635 public void performActions() {
1636 Frame sourceFrame = null;
1637 Item sourceItem = FreeItems.getItemAttachedToCursor();
1638
1639 if (sourceItem == null) {
1640 sourceItem = this;
1641 } else {
1642 for (Item i : sourceItem.getAllConnected()) {
1643 if (i instanceof Text) {
1644 sourceItem = i;
1645 break;
1646 }
1647 }
1648 }
1649
1650 // TODO decide whether to have items or
1651 // if a link exists make it the source frame for this action
1652 if (getLink() != null) {
1653 sourceFrame = FrameUtils.getFrame(getAbsoluteLink());
1654 }
1655 // if no link exists or the link is bad then use the
1656 // currently displayed frame as the source frame for the
1657 // action
1658 if (sourceFrame == null) {
1659 // For actions like format they rely on this being set to the
1660 // current frame incase the item being activated is on an overlay
1661 sourceFrame = DisplayController.getCurrentFrame();
1662 }
1663
1664 for (String s : getAction()) {
1665 Object returnValue;
1666 if (LegacyFeatures.UseLegacyActionArgumentMapping.get()) {
1667 returnValue = Actions.LegacyPerformActionCatchErrors(sourceFrame, sourceItem, s);
1668 } else {
1669 returnValue = Actions.PerformActionCatchErrors(sourceFrame, sourceItem, s, this);
1670 }
1671
1672 if (returnValue != null) {
1673 FreeItems.getInstance().clear();
1674 if (returnValue instanceof Item) {
1675 Misc.attachToCursor(((Item) returnValue).getAllConnected());
1676 } else if (returnValue instanceof Collection) {
1677 try {
1678 Misc.attachToCursor((Collection) returnValue);
1679 } catch (Exception e) {
1680 e.printStackTrace();
1681 }
1682 } else {
1683 Misc.attachStatsToCursor(returnValue.toString());
1684 }
1685 }
1686 }
1687 }
1688
1689 /**
1690 * Removes all constraints that this item has.
1691 *
1692 */
1693 public void removeAllConstraints() {
1694 while (_constraints.size() > 0) {
1695 Constraint c = _constraints.get(0);
1696 c.getEnd().removeConstraint(c);
1697 c.getStart().removeConstraint(c);
1698 }
1699 }
1700
1701 /**
1702 * Clears the list of Lines that this Dot is an end of. Note: This only
1703 * clears this Dot's list and does not have any affect on the Lines or other
1704 * Dots.
1705 */
1706 public void removeAllLines() {
1707 for (Line l : _lines) {
1708 l.invalidateAll();
1709 }
1710 _lines.clear();
1711 }
1712
1713 /**
1714 * Removes the given Constraint from the list of constraints that this Dot
1715 * is a part of.
1716 *
1717 * @param c
1718 * The Constraint that this Dot is no longer a part of.
1719 */
1720 public void removeConstraint(Constraint c) {
1721 _constraints.remove(c);
1722 }
1723
1724 /**
1725 * Removes the given Line from the list of lines that this Dot is an end
1726 * for.
1727 *
1728 * @param line
1729 * The Line that this Dot is no longer an end of.
1730 */
1731 public void removeLine(Line line) {
1732 if (_lines.remove(line))
1733 line.invalidateAll();
1734 }
1735
1736 public void run() {
1737 try {
1738
1739 List<String> action = this.getAction();
1740 if (action != null) {
1741 String action_name = action.get(0);
1742 if (action_name.equalsIgnoreCase("RunJavascriptFrame")){
1743 // Associate a new Context with this thread
1744 org.mozilla.javascript.Context javascript_context = org.mozilla.javascript.Context.enter();
1745 try {
1746 Scriptable javascript_scope = javascript_context.initStandardObjects();
1747 Context simple_context = new Context();
1748
1749
1750 //Object jsDisplayIO = org.mozilla.javascript.Context.javaToJS(org.expeditee.gui.DisplayIO, javascript_scope);
1751 //ScriptableObject.putProperty(javascript_scope, "displayIO", jsDisplayIO);
1752
1753
1754 Object jsSimpleContext = org.mozilla.javascript.Context.javaToJS(simple_context, javascript_scope);
1755 ScriptableObject.putProperty(javascript_scope, "simpleContext", jsSimpleContext);
1756
1757 Object jsErr = org.mozilla.javascript.Context.javaToJS(System.err, javascript_scope);
1758 ScriptableObject.putProperty(javascript_scope, "err", jsErr);
1759
1760 Object jsOut = org.mozilla.javascript.Context.javaToJS(System.out, javascript_scope);
1761 ScriptableObject.putProperty(javascript_scope, "out", jsOut);
1762
1763 Javascript.ProgramStarted();
1764 Javascript.RunFrameAndReportError(this, javascript_context,javascript_scope);
1765 MessageBay.displayMessage(AgentStats.getStats(), GREEN);
1766 }
1767 finally {
1768 org.mozilla.javascript.Context.exit();
1769 }
1770 }
1771 }
1772 else {
1773
1774 // assume it is a simple program that is to be run
1775 Simple.ProgramStarted();
1776 Context simple_context = new Context();
1777 Simple.RunFrameAndReportError(this, simple_context);
1778 MessageBay.displayMessage(AgentStats.getStats(), GREEN);
1779 }
1780 } catch (ConcurrentModificationException ce) {
1781 ce.printStackTrace();
1782 } catch (IncorrectUseOfStatementException ise) {
1783 MessageBay.linkedErrorMessage(ise.getMessage());
1784 MessageBay.displayMessage("See SIMPLE doc for ["
1785 + ise.getStatement() + "] statement", ise.getStatement()
1786 + "1", Colour.CYAN.darker(), true, null);
1787 } catch (Exception e) {
1788 MessageBay.linkedErrorMessage(e.getMessage());
1789 }
1790 Simple.ProgramFinished();
1791 // Need to repaint any highlights etc
1792 DisplayController.requestRefresh(true);
1793 }
1794
1795 /**
1796 * Check if it has a relative link if so make it absolute.
1797 *
1798 */
1799 public void setAbsoluteLink() {
1800 String link = getLink();
1801 if (link == null)
1802 return;
1803 // Check if all the characters are digits and hence it is a relative
1804 // link
1805 if (!FrameIO.isPositiveInteger(link))
1806 return;
1807
1808 // Make it an absolute link
1809 String framesetName;
1810
1811 if (_parent == null)
1812 framesetName = DisplayController.getCurrentFrame().getFramesetName();
1813 else
1814 framesetName = _parent.getFramesetName();
1815
1816 setLink(framesetName + link);
1817 }
1818
1819 /**
1820 * Sets any action code that should be associated with this Item Each entry
1821 * in the list is one line of code
1822 *
1823 * @param actions
1824 * The lines of code to associate with this Item
1825 */
1826 public void setActions(List<String> actions)
1827 {
1828 if (actions == null || actions.size() == 0) {
1829 invalidateCommonTrait(ItemAppearence.LinkChanged);
1830 _actions = null;
1831 } else {
1832 _actions = new LinkedList<String>(actions);
1833 }
1834
1835 // Want to resize the highlight box for text items if actions have been added
1836 invalidateBounds();
1837 invalidateCommonTrait(ItemAppearence.LinkChanged);
1838 }
1839
1840 public void setData(List<String> data) {
1841 _data.setData(data);
1842 }
1843
1844 public void setData(String data) {
1845 _data.setData(data);
1846 }
1847
1848 public void addToData(String dataItem) {
1849 _data.addToData(dataItem);
1850 }
1851
1852 public boolean hasData(String dataItem) {
1853 return _data.hasData(dataItem);
1854 }
1855
1856 public void setActionCursorEnter(List<String> enter) {
1857 _actionCursorEnter = enter;
1858 }
1859
1860 public void setActionCursorLeave(List<String> leave) {
1861 _actionCursorLeave = leave;
1862 }
1863
1864 public void setActionEnterFrame(List<String> enter) {
1865 _actionEnterFrame = enter;
1866 }
1867
1868 public void setActionLeaveFrame(List<String> leave) {
1869 _actionLeaveFrame = leave;
1870 }
1871
1872 public void setActionMark(boolean val)
1873 {
1874 if (!val) invalidateCommonTrait(ItemAppearence.LinkChanged);
1875 invalidateBounds();
1876 _actionMark = val;
1877 if (val) invalidateCommonTrait(ItemAppearence.LinkChanged);
1878 }
1879
1880 /**
1881 * Sets whether this Item is an Annotation.
1882 *
1883 * @param val
1884 * True if this Item is an Annotation, False otherwise.
1885 */
1886 public abstract void setAnnotation(boolean val);
1887
1888 /**
1889 * Used to set this Line as an Arrow. If length and ratio are 0, no arrow is
1890 * shown.
1891 *
1892 * @param length
1893 * The how far down the shaft of the line the arrowhead should
1894 * come.
1895 * @param ratio
1896 * The ratio of the arrow's length to its width.
1897 */
1898 public void setArrow(float length, double ratio, double nib_perc) {
1899 _arrowheadLength = length;
1900 _arrowheadRatio = ratio;
1901 _arrowheadNibPerc = nib_perc;
1902 updateArrowPolygon();
1903 }
1904
1905 public void setArrow(float length, double ratio) {
1906 setArrow(length,ratio,DEFAULT_ARROWHEAD_NIB_PERC);
1907 }
1908
1909 public void setArrowhead(PolygonBounds arrow) {
1910 _arrowhead = arrow;
1911 }
1912
1913 public void setArrowheadLength(float length) {
1914 _arrowheadLength = length;
1915 updateArrowPolygon();
1916 }
1917
1918 public void setArrowheadRatio(double ratio) {
1919 _arrowheadRatio = ratio;
1920 updateArrowPolygon();
1921 }
1922
1923 public void setArrowheadNibPerc(double perc) {
1924 _arrowheadNibPerc = perc;
1925 updateArrowPolygon();
1926 }
1927
1928 public void setBackgroundColor(Colour c) {
1929 if (c != _backgroundColour) {
1930 _backgroundColour = c;
1931 invalidateCommonTrait(ItemAppearence.BackgroundColorChanged);
1932 }
1933 }
1934
1935 public void setBorderColor(Colour c) {
1936 if (c != _colorBorder) {
1937 _colorBorder = c;
1938 invalidateCommonTrait(ItemAppearence.BorderColorChanged);
1939 }
1940 }
1941
1942 /**
1943 * Sets the Color to use on the bottom and right sections of this Item's
1944 * border. If top is NULL, then the Item's background Color will be used.
1945 *
1946 * @param top
1947 * The Color to display in the bottom and right sections of this
1948 * Item's border.
1949 */
1950 public void setBottomShadowColor(Colour bottom) {
1951 _colorBottomShadow = bottom;
1952 }
1953
1954 /**
1955 * Sets the foreground Color of this Item to the given Color.
1956 *
1957 * @param c
1958 */
1959 public void setColor(Colour c) {
1960 if (c != _foregroundColour) {
1961 _foregroundColour = c;
1962 invalidateCommonTrait(ItemAppearence.ForegroundColorChanged);
1963 if (hasVector()) {
1964 // TODO make this more efficient so it only repaints the items
1965 // for this vector
1966 StandardGestureActions.Refresh();
1967 }
1968 }
1969 }
1970
1971 public void setConstraintIDs(String IDs) {
1972 }
1973
1974 public void setConstraints(List<Constraint> constraints) {
1975 _constraints = constraints;
1976 }
1977
1978 public void setTag(String newData) {
1979 if (newData != null)
1980 _tag = new StringBuffer(newData);
1981 else
1982 _tag = null;
1983 }
1984
1985 /**
1986 * Sets the created date of this Frame to the given String.
1987 *
1988 * @param date
1989 * The date to use for this Frame.
1990 */
1991 public void setDateCreated(String date) {
1992 _creationDate = date;
1993 }
1994
1995 public void setFillColor(Colour c) {
1996
1997 _fillColour = c;
1998
1999 for (Line line : _lines) {
2000 Item other = line.getOppositeEnd(this);
2001 if (other.getFillColor() != c) {
2002 other.setFillColor(c);
2003 }
2004 }
2005
2006 invalidateCommonTrait(ItemAppearence.FillColor);
2007 invalidateFill();
2008 }
2009
2010 public void setGradientColor(Colour c)
2011 {
2012 _gradientColour = c;
2013
2014 for (Line line : _lines) {
2015 Item other = line.getOppositeEnd(this);
2016 if (other.getGradientColor() != c)
2017 other.setGradientColor(c);
2018 }
2019
2020 invalidateCommonTrait(ItemAppearence.GradientColor);
2021 invalidateFill();
2022 }
2023
2024 public Colour getGradientColor() {
2025 Surrogate surrogate = Surrogate.of(this);
2026 if (surrogate != null &&
2027 surrogate.isPropertyIsInherited(DefaultFrameWriter.GRADIENT_COLOR + "")) {
2028 return this.getClassic().getGradientColor();
2029 } else {
2030 return _gradientColour;
2031 }
2032 }
2033
2034 public void setFillPattern(String patternLink) {
2035 _fillPattern = patternLink;
2036 invalidateCommonTrait(ItemAppearence.FillPattern);
2037 invalidateFill();
2038 }
2039
2040 public void setFloating(boolean val) {
2041 _floating = val;
2042 }
2043
2044 /**
2045 * Sets the value <code>_highlight</code> for this item.
2046 * TODO: Appears unused? cts16
2047 *
2048 * @param val The new value for <code>_highlight</code>.
2049 */
2050 public void setHighlight(boolean val) {
2051 _highlight = val;
2052 }
2053
2054 /**
2055 * Sets the ID of this Item to the given Integer. Note: Items with ID's < 0
2056 * are not saved
2057 *
2058 * @param newID
2059 * The new ID to assign this Item.
2060 */
2061 public void setID(int newID) {
2062 _id = newID;
2063 }
2064
2065 /**
2066 * Sets the list of lines that this point is part of (may be set to null).
2067 *
2068 * @param lineID
2069 * A String of line ID numbers separated by spaces.
2070 */
2071 public void setLineIDs(String lineID) {
2072 }
2073
2074 public void setLinePattern(int[] pattern) {
2075 _linePattern = pattern;
2076
2077 for (Line line : getLines())
2078 line.setLinePattern(pattern);
2079 }
2080
2081 public void setLines(List<Line> lines) {
2082 _lines = lines;
2083
2084 for (Line line : lines)
2085 line.setLinePattern(getLinePattern());
2086
2087 }
2088
2089 /**
2090 * Links this item to the given Frame, this may be set to null to remove a
2091 * link.
2092 *
2093 * @param frameName
2094 * The name of the Frame to link this item to.
2095 */
2096 public void setLink(String frameName)
2097 {
2098 if (frameName == null) invalidateCommonTrait(ItemAppearence.LinkChanged);
2099
2100 // If a link is being removed or set then need to reset _bounds so the
2101 // highlighting is drawn with the correct width
2102 if (frameName == null || getLink() == null) invalidateBounds();
2103
2104 if (FrameIO.isValidLink(frameName)) {
2105 _link = frameName;
2106 } else {
2107 MessageBay.errorMessage("[" + frameName + "] is not a valid frame name");
2108 }
2109 // TODO make this throw exceptions etc...
2110
2111 invalidateCommonTrait(ItemAppearence.LinkChanged);
2112 }
2113
2114 public void setLinkHistory(boolean value) {
2115 _linkHistory = value;
2116 }
2117
2118 public boolean getLinkHistory() {
2119 Surrogate surrogate = Surrogate.of(this);
2120 if (surrogate != null &&
2121 surrogate.isPropertyIsInherited(DefaultFrameWriter.LINK_HISTORY + "")) {
2122 return this.getClassic().getLinkHistory();
2123 } else {
2124 return _linkHistory;
2125 }
2126 }
2127
2128 public void setLinkFrameset(String frameset)
2129 {
2130 if (frameset == null || FrameIO.isValidFramesetName(frameset)) {
2131 _link_frameset = frameset;
2132 } else {
2133 MessageBay.errorMessage("[" + frameset + "] is not a valid frameset name");
2134 }
2135 // TODO make this throw exceptions etc...
2136 }
2137
2138 public void setLinkMark(boolean val)
2139 {
2140 if (!val) invalidateCommonTrait(ItemAppearence.LinkChanged);
2141 invalidateBounds();
2142 _linkMark = val;
2143 if (val) invalidateCommonTrait(ItemAppearence.LinkChanged);
2144 }
2145
2146 public void setLinkTemplate(String template)
2147 {
2148 if (FrameIO.isValidLink(template)) {
2149 _link_template = template;
2150 } else {
2151 MessageBay.errorMessage("[" + template + "] is not a valid frame name");
2152 }
2153 // TODO make this throw exceptions etc...
2154 }
2155
2156 // /**
2157 // * Sets the maximum coordinates on the screen that this item may occupy.
2158 // * This is used by Text items to compute word-wrapping lengths.
2159 // *
2160 // * @param d
2161 // * The Maximum size of the Frame containing this Item.
2162 // */
2163 // public void setMaxWidth(int width) {
2164 // if (width > 0) {
2165 // _maxWidth = width;
2166 // updatePolygon();
2167 // }
2168 // }
2169
2170 public void setOffset(int x, int y) {
2171 _offset.set(x, y);
2172 }
2173
2174 public void setOffset(Point p) {
2175 _offset.set(p);
2176 }
2177
2178 public void setOwner(String own) {
2179 _owner = own;
2180 }
2181
2182 public void setParent(Frame frame) {
2183 _oldParent = _parent;
2184 _parent = frame;
2185
2186 if (_parent == null) { return; }
2187
2188 final String currentUser = UserSettings.UserName.get();
2189 final String existingOwner = _parent.getOwner();
2190 if (currentUser != null && (existingOwner == null || currentUser.compareTo(existingOwner) != 0)) {
2191 setOwner(currentUser);
2192 }
2193 }
2194
2195 /**
2196 * Invalidates this, connected lines and fill
2197 *
2198 * @param trait
2199 */
2200 private void invalidateCommonTraitForAll(ItemAppearence trait) {
2201 invalidateCommonTrait(trait);
2202 if (isLineEnd()) {
2203 boolean hasLinePattern = getLines().get(0).getLinePattern() != null;
2204 if (hasLinePattern) {
2205 for (Item i : getAllConnected()) {
2206 if (i instanceof Line) {
2207 ((Line) i).invalidateCommonTrait(trait);
2208 }
2209 }
2210 } else {
2211 for (Line line : getLines()) {
2212 line.invalidateCommonTrait(trait);
2213 }
2214 }
2215 }
2216 if (_fillColour != null) {
2217 invalidateFill(); // only invalidates if has fill
2218 }
2219 for (XRayable x : getEnclosures()) {
2220 x.invalidateCommonTrait(trait);
2221 }
2222
2223 }
2224
2225 protected void anchorConstraints()
2226 {
2227 // update the position of any dots that are constrained by this one
2228 for (Constraint c : _constraints) {
2229 Item other = c.getOppositeEnd(this);
2230
2231 // only set position if the other dot is still fixed to the
2232 // frame
2233 if (/* this.isFloating() && */!other.isFloating()) {
2234 if (c.getType() == Constraint.HORIZONTAL) {
2235 if (isAnchoredY()) {
2236 // Make the 'other' item have the same anchor top/bottom values as this
2237 other._anchoring.setYAnchor(this._anchoring);
2238 }
2239 } else if (c.getType() == Constraint.VERTICAL) {
2240 if (isAnchoredX()) {
2241 // Make the 'other' item have the same anchor left/right values as this
2242 other._anchoring.setXAnchor(this._anchoring);
2243 }
2244 } else if (c.isDiagonal()) {
2245
2246 System.err.println("Warning: anchorConstraints() not implement for Diagonal setting");
2247 }
2248 }
2249 }
2250 }
2251
2252 /**
2253 * Sets the position of this item on the screen
2254 *
2255 * @param x
2256 * The new X coordinate
2257 * @param y
2258 * The new Y coordinate
2259 */
2260 public void setPosition(float x, float y)
2261 {
2262 float deltaX = x - _x;
2263 float deltaY = y - _y;
2264
2265 if (deltaX == 0 && deltaY == 0) return;
2266
2267 invalidateCommonTraitForAll(ItemAppearence.PreMoved);
2268
2269 _x = x;
2270 _y = y;
2271
2272 for (Item i : getEnclosures()) {
2273 i.invalidateBounds();
2274 }
2275 invalidateBounds();
2276
2277 // update the position of any dots that are constrained by this one
2278 for (Constraint c : _constraints) {
2279 Item other = c.getOppositeEnd(this);
2280
2281 // only set position if the other dot is still fixed to the
2282 // frame
2283 if (/* this.isFloating() && */!other.isFloating()) {
2284 if (c.getType() == Constraint.HORIZONTAL) {
2285 if (other._y != y) {
2286 other.setY(y);
2287 }
2288 } else if (c.getType() == Constraint.VERTICAL) {
2289 if (other._x != x) {
2290 other.setX(x);
2291 }
2292 } else if (c.isDiagonal()) {
2293 if (Math.abs(other._x - x) != Math.abs(other._y - y)) {
2294
2295 float m1 = c.getGradient();
2296 float c1 = y - m1 * x;
2297 // Now work out the equation for the second line
2298 // Get the first line the other end is attached to that
2299 // is not the diagonal line
2300 List<Line> lines = other.getLines();
2301 // If there is only one line...
2302 if (lines.size() == 1) {
2303 if (m1 != 0) {
2304 if (Math.abs(deltaX) > Math.abs(deltaY)) {
2305 other.setX((other._y - c1) / m1);
2306 } else {
2307 other.setY(m1 * other._x + c1);
2308 }
2309 }
2310 } else if (lines.size() > 1) {
2311 Line otherLine = lines.get(0);
2312 Item end = otherLine.getOppositeEnd(other);
2313 if (end.equals(this)) {
2314 otherLine = lines.get(1);
2315 end = otherLine.getOppositeEnd(other);
2316 assert (!end.equals(this));
2317 }
2318
2319 float xDiff = end._x - other._x;
2320 float yDiff = end._y - other._y;
2321 if (xDiff == 0) {
2322 other.setY(m1 * other._x + c1);
2323 } else if (Math.abs(xDiff) == Math.abs(yDiff)
2324 && !this.isFloating() && deltaX == 0
2325 && deltaY == 0) {
2326 if (deltaX == 0) {
2327 _x = (_y - other._y) * m1 + other._x;
2328 } else {
2329 _y = (_x - other._x) * m1 + other._y;
2330 }
2331 } else {
2332 float m2 = yDiff / xDiff;
2333 float c2 = end._y - m2 * end._x;
2334 float mDiff = m1 - m2;
2335 if (Math.abs(mDiff) < 0.000001) {
2336 assert (false);
2337 // TODO how do I handle this case!!
2338 } else {
2339 float newX = (c2 - c1) / mDiff;
2340 float newY = m1 * newX + c1;
2341 if (other._x != newX
2342 /* && other._y != newY */) {
2343 other.setPosition(newX, newY);
2344 }
2345 }
2346 }
2347 }
2348 // Do simultaneous equations to get the new postion for
2349 // the other end of the diagonal line
2350 }
2351 }
2352 }
2353 }
2354
2355 for (Line line : getLines()) {
2356 line.invalidateBounds();
2357 }
2358
2359 // for (Item item : getAllConnected()) {
2360 // item.updatePolygon();
2361 // }
2362
2363 invalidateCommonTraitForAll(ItemAppearence.PostMoved);
2364
2365 }
2366
2367 public void setPosition(Point position) {
2368 setPosition(position.getX(), position.getY());
2369 }
2370
2371 public void setRelativeLink() {
2372 String link = getLink();
2373 if (link == null)
2374 return;
2375 assert (_parent != null);
2376
2377 if (FrameIO.isPositiveInteger(link))
2378 return;
2379
2380 // Check if the link is for the current frameset
2381 if (_parent.getFramesetName().equalsIgnoreCase(
2382 Conversion.getFramesetName(link))) {
2383 setLink("" + Conversion.getFrameNumber(link));
2384 }
2385 }
2386
2387 /**
2388 * Sets the size of this Item. For Text this is the Font size. For Lines and
2389 * Dots this is the thickness.
2390 */
2391 public void setSize(float size) {
2392 }
2393
2394 /**
2395 * Sets the thickness of the item.
2396 *
2397 * @param thick
2398 */
2399 public final void setThickness(float thick) {
2400 setThickness(thick, true);
2401 }
2402
2403 /**
2404 * Sets the thickness of this item.
2405 *
2406 * @param thick
2407 * the new thickness for the item
2408 * @param setConnectedThickness
2409 * true if all items connected to this item should also have
2410 * their thickness set
2411 */
2412 public void setThickness(float thick, boolean setConnectedThickness)
2413 {
2414 if (thick == _thickness) return;
2415
2416 boolean bigger = thick > _thickness;
2417
2418 if (!bigger) {
2419 if (setConnectedThickness) {
2420 // TODO is there a more efficient way of doing this?
2421 for (Item i : getConnected()) i.invalidateCommonTrait(ItemAppearence.Thickness);
2422 } else {
2423 invalidateCommonTrait(ItemAppearence.Thickness);
2424 }
2425 }
2426
2427 _thickness = thick;
2428 // update the size of any lines
2429 /*
2430 * TODO: Revise the way line thickness is set to make it more efficient
2431 * etc...
2432 */
2433 for (Line line : getLines()) line.setThickness(thick, setConnectedThickness);
2434
2435 if (setConnectedThickness) invalidateBounds();
2436
2437 if (bigger) {
2438 if (setConnectedThickness) {
2439 for (Item i : getConnected()) i.invalidateCommonTrait(ItemAppearence.Thickness);
2440 } else {
2441 invalidateCommonTrait(ItemAppearence.Thickness);
2442 }
2443 }
2444 }
2445
2446 /**
2447 * Returns the thickness (in pixels) of this Dot.
2448 *
2449 * @return The 'thickness' of this Dot. (returns -1 if the thickness is not
2450 * set).
2451 */
2452 public float getThickness() {
2453 Surrogate surrogate = Surrogate.of(this);
2454 if (surrogate != null &&
2455 surrogate.isPropertyIsInherited(DefaultFrameWriter.THICKNESS + "")) {
2456 return this.getClassic().getThickness();
2457 } else {
2458 return _thickness;
2459 }
2460 }
2461
2462 /**
2463 * Sets the Color to use on the top and left sections of this Item's border.
2464 * If top is NULL, then the Item's background Color will be used.
2465 *
2466 * @param top
2467 * The Color to display in the top and left sections of this
2468 * Item's border.
2469 */
2470 public void setTopShadowColor(Colour top) {
2471 _colorTopShadow = top;
2472 }
2473
2474 public void setWidth(Integer width) throws UnsupportedOperationException
2475 {
2476 throw new UnsupportedOperationException("Item type does not support width attribute!");
2477 }
2478
2479 public void setMinWidth(final Integer width) throws UnsupportedOperationException {
2480 throw new UnsupportedOperationException("Item type does not support minwidth attribute.");
2481 }
2482
2483 public void setMaxWidth(Integer width) throws UnsupportedOperationException {
2484 throw new UnsupportedOperationException("Item type does not support maxwidth attribute");
2485 }
2486
2487 public void setRightMargin(int i, boolean fixWidth)
2488 {
2489 int newWidth = i - getX() - Item.MARGIN_LEFT;
2490 if (newWidth < 0) newWidth = 0;
2491
2492 if (!fixWidth) {
2493 newWidth *= -1;
2494 }
2495
2496 setWidth(newWidth);
2497 }
2498
2499 /**
2500 * Sets the position of this Item on the X axis
2501 *
2502 * @param newX
2503 * The position on the X axis to assign to this Item
2504 */
2505 public void setX(float newX) {
2506 setPosition(newX, getY());
2507 }
2508
2509 /**
2510 * Sets the position of this Item on the Y axis
2511 *
2512 * @param newY
2513 * The position on the Y axis to assign to this Item
2514 */
2515 public void setY(float newY) {
2516 setPosition(getX(), newY);
2517 }
2518
2519 /**
2520 * Paints any highlighting of this Item. This may include changing the
2521 * thickness (lines) or painting a box around the item (Text, Images). If
2522 * val is True then the Graphics Color is changed to the highlight Color, if
2523 * False then the Graphics Color is left unchanged (for clearing of
2524 * highlighting).
2525 *
2526 * @param val
2527 * True if this Item should be highlighted, false if the
2528 * highlighting is being cleared.
2529 * @return The desired mouse cursor when this Item is highlighted (negative
2530 * means no change)
2531 */
2532
2533 /**
2534 *
2535 *
2536 * @return
2537 */
2538 public void setHighlightColorToDefault() {
2539 setHighlightColor(DEFAULT_HIGHLIGHT);
2540 }
2541
2542 public void setHighlightColor(Colour c) {
2543 if (c == null) return;
2544
2545 if (!this.isVisible() && this.hasVector()) {
2546 for (Item i : this.getParentOrCurrentFrame().getVectorItems()) {
2547 if (i.getEditTarget() == this) {
2548 i.setHighlightColor(c);
2549 }
2550 }
2551 }
2552
2553 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;
2554
2555 Colour selColor = (c != null) ? c : DEFAULT_HIGHLIGHT;
2556 if (_highlightColour != c) {
2557 _highlightColour = selColor;
2558 this.invalidateCommonTrait(ItemAppearence.HighlightColorChanged);
2559 }
2560
2561 }
2562
2563 private void updateArrowPolygon() {
2564 if (getArrowheadLength() < 0 || getArrowheadRatio() < 0 || getArrowheadNibPerc() < 0)
2565 _arrowhead = null;
2566 else {
2567 _arrowhead = Line.createArrowheadPolygon(getX(),getY(),getArrowheadLength(),getArrowheadRatio(),getArrowheadNibPerc());
2568 }
2569 }
2570
2571 /** Returns a Bounds which represents the area covered by the item (including its gravity). */
2572 public abstract Bounds updateBounds();
2573
2574 public void setHidden(boolean state) {
2575 this._visible = !state;
2576 }
2577
2578 public void setVisible(boolean state) {
2579 this._visible = state;
2580 }
2581
2582 public boolean isVisible() {
2583 return _visible && !_deleted;
2584 }
2585
2586 /**
2587 * Raised whenever the item is removed, added, no longer in view (That is,
2588 * when it is not on any of the current frames, of overlays of the current
2589 * frames) or has become visible. That is, when it is either on a current
2590 * frame, or an overlay of a current frame.
2591 *
2592 * @param e
2593 * The event
2594 */
2595 public void onParentStateChanged(ItemParentStateChangedEvent e) {
2596 }
2597
2598 /**
2599 * Sets the highlight mode and colour at the same time.
2600 *
2601 * @param mode The new highlight mode.
2602 * @param colour The new highlight colour.
2603 */
2604 public void setHighlightModeAndColour(HighlightMode mode, Colour colour)
2605 {
2606 setHighlightMode(mode);
2607 setHighlightColor(colour);
2608 }
2609
2610 public HighlightMode getHighlightMode() {
2611 return _highlightMode;
2612 }
2613
2614 public void anchor() {
2615 Frame current = getParentOrCurrentFrame();
2616 // only set the id if we've moved to a different frame, or if the frame already has an item with that id
2617 if(!current.equals(_oldParent) || current.getItemWithID(getID()) != null) {
2618 setID(current.getNextItemID());
2619 } else {
2620 // System.out.println(this + " - Kept old ID of " + _id);
2621 }
2622 setOffset(0, 0);
2623 setParent(current);
2624
2625 current.addItem(this, false);
2626 current.setResort(true);
2627 setRelativeLink();
2628 setFloating(false);
2629
2630 // // If its an unconstrained line end check if we should add a
2631 // constraint
2632 // if (isLineEnd() && getLines().size() <= 2
2633 // && getConstraints().size() <= 1) {
2634 // Constraint existingConstraint = null;
2635 // List<Constraint> constraints = getConstraints();
2636 // // Get the existing constraint
2637 // if (constraints.size() > 0) {
2638 // existingConstraint = constraints.get(0);
2639 // }
2640 // for (Line line : getLines()) {
2641 // Integer constraintType = line.getPossibleConstraint();
2642 // if (constraintType != null) {
2643 // Item oppositeEnd = line.getOppositeEnd(this);
2644 // if (existingConstraint == null
2645 // || !existingConstraint.contains(oppositeEnd)) {
2646 // new Constraint(this, oppositeEnd,
2647 // getParentOrCurrentFrame().getNextItemID(),
2648 // constraintType);
2649 // }
2650 // }
2651 // }
2652 // }
2653 }
2654
2655 /**
2656 * Gets the parent frame if it is set or the current frame if this item does
2657 * not have a parent set.
2658 *
2659 * @return
2660 */
2661 public Frame getParentOrCurrentFrame() {
2662 // if the item is from an overlay the parent will NOT be null
2663 if (getParent() == null) {
2664 return DisplayController.getCurrentFrame();
2665 }
2666 return getParent();
2667 }
2668
2669 /**
2670 * Sets the list of Dots (including this one) that form a closed shape.
2671 * Passing null sets this dot back to its normal (non-enclosed) state.
2672 *
2673 * @param enclosed
2674 * The List of Dots including this one that form a closed shape,
2675 * or null.
2676 */
2677 public void setEnclosedList(Collection<Item> enclosed) {
2678
2679 boolean changed = (_enclosure == null && enclosed != null);
2680
2681 if (_enclosure != null && enclosed == null) {
2682 invalidateFill();
2683 }
2684
2685 _enclosure = enclosed;
2686
2687 if (changed) {
2688 invalidateFill();
2689 ;
2690 }
2691 }
2692
2693 /**
2694 * Returns the polygon that represents the shape created by all the Dots in
2695 * this Dot's enclosed list. If the list is null, then null is returned.
2696 *
2697 * @return A Polygon the same shape and position as created by the Dots in
2698 * the enclosed list.
2699 */
2700 public PolygonBounds getEnclosedShape()
2701 {
2702 if (_enclosure == null) return null;
2703
2704 PolygonBounds poly = new PolygonBounds();
2705 for (Item d : _enclosure) {
2706 poly.addPoint(new Point(d.getX(), d.getY()));
2707 }
2708
2709 return poly;
2710 }
2711
2712 /**
2713 * Returns the list of Dots that, along with this Dot, form an enclosed
2714 * polygon. If this Dot is not part of an enclosure null may be returned.
2715 *
2716 * @return The List of Dots that form an enclosed shape with this Dot, or
2717 * null if this Dot is not part of an enclosure.
2718 */
2719 public Collection<Item> getEnclosingDots() {
2720 return _enclosure;
2721 }
2722
2723 /**
2724 * Returns whether this Dot has an assigned enclosure list of other Dots.
2725 * The result is the same as getEnclosedShape() != null.
2726 *
2727 * @return True if this Dot has an enclosure list of other Dots, false
2728 * otherwise.
2729 */
2730 public boolean isEnclosed() {
2731 return _enclosure != null;
2732 }
2733
2734 /**
2735 * True if this item is the end of a line.
2736 *
2737 * @return
2738 */
2739 public boolean isLineEnd() {
2740 // TODO this will need to be redone when enclosure class is added...
2741 // At the moment enclosures are only circles...we don't want circle
2742 // centres to be lineEnds
2743 return _lines.size() > 0;
2744 }
2745
2746 public boolean hasEnclosures() {
2747 return _enclosures.size() > 0;
2748 }
2749
2750 /**
2751 * Method that is called to notify an item that is on the end of a line that
2752 * its line has changed color.
2753 *
2754 * @param c
2755 * the new color for the line
2756 */
2757 protected void lineColorChanged(Colour c) {
2758 for (Line l : getLines()) {
2759 if (l.getColor() != c)
2760 l.setColor(c);
2761 }
2762 }
2763
2764 /**
2765 * Checks if this item is off the left or top of the screen
2766 *
2767 * @return
2768 */
2769 public boolean offScreenTopOrLeft() {
2770 Bounds bounds = getBoundingBox();
2771
2772 // Check that the bottom right corner of this item is on the screen
2773 if (bounds.getMaxX() >= 0 && bounds.getMaxY() >= 0) {
2774 return false;
2775 }
2776
2777 // Check if all the items it is connected to are offscreen
2778 for (Item i : getAllConnected()) {
2779 bounds = i.getBoundingBox();
2780 // Check that the bottom right corner of this item is on the screen
2781 if (bounds.getMaxX() >= 0 && bounds.getMaxY() >= 0) {
2782 return false;
2783 }
2784 }
2785
2786 return true;
2787 }
2788
2789 public void setConnectedToAnnotation(boolean val) {
2790 _connectedToAnnotation = val;
2791 }
2792
2793 public boolean isConnectedToAnnotation() {
2794 return _connectedToAnnotation;
2795 }
2796
2797 public boolean hasAction() {
2798 List<String> actions = getAction();
2799 return actions != null && actions.size() > 0;
2800 }
2801
2802 public void setAction(String action)
2803 {
2804 // Want to resize the highlight box for text items if actions are been added
2805 if (action == null || action.length() == 0) {
2806 invalidateCommonTrait(ItemAppearence.LinkChanged);
2807 }
2808
2809 if (_actions == null || _actions.size() == 0) {
2810 invalidateBounds();
2811 _actions = new LinkedList<String>();
2812 } else {
2813 _actions.clear();
2814 }
2815
2816 if (action != null && action.length() > 0) _actions.add(action);
2817
2818 invalidateCommonTrait(ItemAppearence.LinkChanged);
2819 }
2820
2821 protected int getLinkYOffset() {
2822 return 0;
2823 }
2824
2825 protected AxisAlignedBoxBounds getLinkDrawArea() {
2826 return getLinkDrawArea(getX() - LEFT_MARGIN, getY() + getLinkYOffset());
2827 }
2828
2829 /**
2830 * TODO: Revise - it would be good to have a member that defines the link
2831 * dimensions.
2832 *
2833 * @param x
2834 * Left of graphic (i.e not centered)
2835 * @param y
2836 * Above graphic (i.e not centered)
2837 *
2838 * @return The drawing area of the link at the given coordinates.
2839 */
2840 public AxisAlignedBoxBounds getLinkDrawArea(int x, int y) {
2841 return new AxisAlignedBoxBounds(x + 2, y - 1, 8, 8);
2842 }
2843
2844 /**
2845 * Paint the link symbol for the item if it is a
2846 *
2847 * @param g
2848 */
2849 protected void paintLink() {
2850 paintLinkGraphic(getX() - LEFT_MARGIN, getY() + getLinkYOffset());
2851 }
2852
2853 /**
2854 * Paint the link symbol for the item at a given position.
2855 *
2856 * @see #paintLink
2857 *
2858 * @param g
2859 * The graphics to paint with
2860 *
2861 * @param x
2862 * The x position of the link. Left of graphic (i.e not centered)
2863 *
2864 * @param y
2865 * The y position of the link. Above of graphic (i.e not
2866 * centered)
2867 */
2868 public void paintLinkGraphic(int x, int y) {
2869
2870 boolean hasLink = hasLink();
2871 boolean hasAction = hasAction();
2872
2873 if (hasLink || hasAction) {
2874 GraphicsManager g = EcosystemManager.getGraphicsManager();
2875 Fill fill = new Fill();
2876 Colour colour = null;
2877 Point offset = new Point(x, y);
2878
2879 if (hasLink && hasAction) {
2880 colour = LINK_ACTION_COLOR;
2881 } else if (hasLink) {
2882 colour = LINK_COLOR;
2883 } else if (hasAction) {
2884 colour = ACTION_COLOR;
2885 }
2886 fill.setColour(colour);
2887
2888 // Small circles look rubbish without AA. cts16
2889 g.setAntialiasing(true);
2890
2891 if (hasLink && getLinkMark()) {
2892 g.drawOval(offset, getLinkBounds().getDiameters(), 0.0f, null, colour, HIGHLIGHT_STROKE);
2893
2894 // if the link is not valid, cross out the circle
2895 if (!isLinkValid()) {
2896 g.drawPolygon(getCircleCross(), offset, null, 0.0f, null, colour, HIGHLIGHT_STROKE);
2897 }
2898 }
2899
2900 if (hasAction && getActionMark()) {
2901 g.drawOval(offset, getLinkBounds().getDiameters(), 0.0f, fill, colour, HIGHLIGHT_STROKE);
2902
2903 // if the link is not valid, cross out the circle
2904 if (!isLinkValid() && getLink() != null) {
2905 g.drawPolygon(getCircleCross(), offset, null, 0.0f, null, getParent().getPaintBackgroundColor(), HIGHLIGHT_STROKE);
2906 }
2907 }
2908
2909 g.setAntialiasing(false);
2910 }
2911 }
2912
2913 /**
2914 * Gets the distance between the start of the text and the left border of
2915 * the item. This distance changes depending on whether or not the item is
2916 * linked or has an associated action.
2917 *
2918 * @return the gap size in pixels
2919 */
2920 protected int getLeftMargin() {
2921 return ((getLinkMark() && getLink() != null)
2922 || (getActionMark() && getAction() != null) ? MARGIN_LEFT
2923 - MARGIN_RIGHT : MARGIN_RIGHT);
2924 }
2925
2926 public String getName() {
2927 return getText();
2928 }
2929
2930 final public String getAbsoluteLinkTemplate() {
2931 return getAbsoluteLink(getLinkTemplate());
2932 }
2933
2934 final public String getAbsoluteLinkFrameset() {
2935 return getAbsoluteLink(getLinkFrameset());
2936 }
2937
2938 final public String getAbsoluteLink() {
2939 return getAbsoluteLink(getLink());
2940 }
2941
2942 /**
2943 * @param link
2944 * @return
2945 */
2946 private String getAbsoluteLink(String link) {
2947 if (link == null)
2948 return null;
2949 // assert (_parent!= null);
2950 Frame parent = getParentOrCurrentFrame();
2951 if (_parent == null) {
2952 // if parent is null it is an item on the message box
2953 // so it must already be absolute
2954 // assert (!FrameIO.isPositiveInteger(link));
2955 // return link;
2956
2957 }
2958
2959 // if its a relative link then return absolute
2960 if (FrameIO.isPositiveInteger(link)) {
2961 return parent.getFramesetName() + link;
2962 }
2963 return link;
2964 }
2965
2966 public static String convertToAbsoluteLink(String link) {
2967 if (link == null)
2968 return null;
2969 // assert (_parent!= null);
2970 Frame parent = DisplayController.getCurrentFrame();
2971 assert (parent != null);
2972
2973 // if its a relative link then return absolute
2974 if (FrameIO.isPositiveInteger(link)) {
2975 return parent.getFramesetName() + link;
2976 }
2977 return link;
2978 }
2979
2980 /**
2981 * Sets the x and y values of this item ignoring constraints.
2982 *
2983 * @param x
2984 * new x position
2985 * @param y
2986 * new y position
2987 */
2988 public void setXY(float x, float y) {
2989 _x = x;
2990 _y = y;
2991 }
2992
2993 /**
2994 * Recursive function for getting the path around a shape. This is used to
2995 * get the path that is painted on the screen.
2996 *
2997 * @param visited
2998 * @param points
2999 * @param addToEnd
3000 * @param toExplore
3001 */
3002 public void appendPath(Collection<Line> visited, LinkedList<Point> points,
3003 boolean addToEnd, Collection<Line> toExplore) {
3004
3005 if (addToEnd) {
3006 // put the start item points into our list
3007 points.addLast(getPosition());
3008 } else {
3009 points.addFirst(getPosition());
3010 }
3011
3012 // Find the line that has not been added yet
3013 LinkedList<Line> lines = new LinkedList<Line>();
3014 lines.addAll(getLines());
3015
3016 while (!lines.isEmpty()) {
3017 Line l = lines.remove();
3018 // if we haven't visited the line yet visit it
3019 if (!visited.contains(l)) {
3020 visited.add(l);
3021 Item otherEnd = l.getOppositeEnd(this);
3022 // Add all the unexplored lines to our list
3023 while (!lines.isEmpty()) {
3024 l = lines.remove();
3025 // Get the paths for the rest of the lines to be explored
3026 // later
3027 if (!toExplore.contains(l) && !visited.contains(l)) {
3028 toExplore.add(l);
3029 }
3030 }
3031 otherEnd.appendPath(visited, points, addToEnd, toExplore);
3032 }
3033 }
3034 }
3035
3036 /**
3037 * Gets the size of the enclosure that this item is part of. Used to
3038 * determine the paint order of items, with smaller items being painted
3039 * first.
3040 *
3041 * @return the area of the box surrounding the enclosed shape that this item
3042 * is part of
3043 */
3044 public double getEnclosedArea()
3045 {
3046 AxisAlignedBoxBounds box = getEnclosedBox();
3047 if (box == null) return 0.0;
3048 return box.getWidth() * box.getHeight();
3049 }
3050
3051 /**
3052 * Gets the box encompassing all points that form an enclosure with this item.
3053 *
3054 * @return An axis-aligned box around all enclosure points.
3055 */
3056 public AxisAlignedBoxBounds getEnclosedBox()
3057 {
3058 if (_enclosure == null) return null;
3059
3060 return AxisAlignedBoxBounds.getEnclosing(getEnclosedShape());
3061 }
3062
3063 public int getEnclosureID()
3064 {
3065 return _enclosure == null ? 0 : _enclosure.hashCode();
3066 }
3067
3068 /**
3069 * Returns the Bounds that surrounds this Item representing this Item's
3070 * 'gravity'.
3071 *
3072 * @return The Bounds surrounding this Item, which represents
3073 * this Items 'gravity'.
3074 */
3075 public final Bounds getBounds()
3076 {
3077 if (_bounds == null) _bounds = updateBounds();
3078
3079 // DEBUG
3080 if (_bounds == null) {
3081 //System.out.println("updateBounds failed!");
3082 }
3083
3084 return _bounds;
3085 }
3086
3087 public final Bounds getOldBounds()
3088 {
3089 return _oldBounds;
3090 }
3091
3092 public final void invalidateBounds()
3093 {
3094 if (_bounds != null) _oldBounds = _bounds;
3095 _bounds = null;
3096 }
3097
3098 public final AxisAlignedBoxBounds getBoundingBox()
3099 {
3100 return AxisAlignedBoxBounds.getEnclosing(getBounds());
3101 }
3102
3103 /**
3104 * Shifts the position of the item along the line between this items
3105 * location and a specified point.
3106 *
3107 * @param origin
3108 * @param ratio
3109 */
3110 public void translate(Point origin, double ratio) {
3111
3112 invalidateCommonTraitForAll(ItemAppearence.PreMoved);
3113
3114 _x = (float) (origin.getX() + ratio * (_x - origin.getX()));
3115 _y = (float) (origin.getY() + ratio * (_y - origin.getY()));
3116 invalidateBounds();
3117 for (Line line : getLines())
3118 line.invalidateBounds();
3119
3120 invalidateCommonTraitForAll(ItemAppearence.PostMoved);
3121
3122 }
3123
3124 private static int[] LinePatterns = new int[] { 0, 10, 20 };
3125
3126 /**
3127 * The rotates through a wheel of dashed lines.
3128 *
3129 * @param amount
3130 * number of rotations around the wheel to toggle by.
3131 */
3132 public void toggleDashed(int amount) {
3133 // find the index of the current line pattern
3134 int[] currentPattern = getLinePattern();
3135
3136 // Find the current pattern and move to the next pattern in the wheel
3137 for (int i = 0; i < LinePatterns.length; i++) {
3138 if (currentPattern == null || currentPattern[0] == LinePatterns[i]) {
3139 i += LinePatterns.length + amount;
3140 i %= LinePatterns.length;
3141
3142 // if we are at the start of the wheel make it 'null' (solid
3143 // line)
3144 if (i == 0) {
3145 setLinePattern(null);
3146 } else {
3147 setLinePattern(new int[] { LinePatterns[i], LinePatterns[i] });
3148 }
3149
3150 invalidateCommonTrait(ItemAppearence.ToggleDashed);
3151 return;
3152 }
3153 }
3154
3155 }
3156
3157 /**
3158 * For now there can only be one enclosure per item
3159 *
3160 * @param enclosure
3161 */
3162 public void addEnclosure(XRayable enclosure) {
3163 _enclosures.clear();
3164 _enclosures.add(enclosure);
3165 }
3166
3167 /**
3168 * Gets any XRayable items that have this item as a source.
3169 *
3170 * @return the collection of items that are linked to this item as source.
3171 * Guaranteed not to be null.
3172 */
3173 public Collection<? extends XRayable> getEnclosures() {
3174 return _enclosures;
3175 }
3176
3177 public void removeEnclosure(Item i) {
3178 _enclosures.remove(i);
3179
3180 }
3181
3182 public boolean isDeleted() {
3183 return _deleted;
3184 }
3185
3186 /**
3187 * @return The full canvas that this item draws to. Must include
3188 * highlighting bounds
3189 */
3190 public AxisAlignedBoxBounds getDrawingArea() {
3191
3192 final AxisAlignedBoxBounds boundingBox = getBoundingBox();
3193 return ItemUtils.expandRectangle(
3194 boundingBox,
3195 (int) Math.ceil(Math.max(_highlightThickness, getThickness())) + 1 // + 1 to make sure
3196 );
3197 }
3198
3199 /**
3200 *
3201 * @param area
3202 * @return True if area intersects with this items drawing area.
3203 */
3204 public final boolean isInDrawingArea(AxisAlignedBoxBounds area)
3205 {
3206 AxisAlignedBoxBounds drawingArea = getDrawingArea();
3207
3208 if (drawingArea == null) return false;
3209
3210 return drawingArea.intersects(area);
3211 }
3212
3213 /**
3214 * Completely invalidates the item - so that it should be redrawn. Note:
3215 * This is handled internally, it should be rare to invoke this externally
3216 */
3217 public final void invalidateAll()
3218 {
3219 invalidate(getDrawingArea());
3220 }
3221
3222 /**
3223 * Invalidates areas on the parent frame. Purpose: to be called on specific
3224 * areas of the item that needs redrawing.
3225 *
3226 * @param damagedAreas
3227 */
3228 protected final void invalidate(Bounds[] damagedAreas)
3229 {
3230 if (damagedAreas != null) for (Bounds b : damagedAreas) invalidate(b);
3231 }
3232
3233 /**
3234 * Invalidates areas on the parent frame. Purpose: to be called on specific
3235 * areas of the item that needs redrawing.
3236 *
3237 * @param damagedAreas
3238 */
3239 protected final void invalidate(Bounds damagedArea)
3240 {
3241 if (damagedArea != null) DisplayController.invalidateItem(this, damagedArea);
3242 }
3243
3244 /**
3245 * Used to invalidate visual traits commonly shared by all items.
3246 *
3247 * @param trait
3248 */
3249 public final void invalidateCommonTrait(ItemAppearence trait)
3250 {
3251 invalidate(getDamagedArea(trait));
3252
3253 if (_fillColour != null && (trait == ItemAppearence.Added || trait == ItemAppearence.Removed)) {
3254 invalidateFill();
3255 }
3256 }
3257
3258 /**
3259 * Invalidates fill if has one, even if no color is set.
3260 */
3261 public void invalidateFill()
3262 {
3263 if (isLineEnd() && _enclosure != null) {
3264 invalidate(getEnclosedBox());
3265 }
3266 }
3267
3268 /**
3269 * Default implementation always uses drawing area except for links, where
3270 * the link drawing area is used. Override to make item drawing more
3271 * efficient - defining only parts of the item that needs redrawing.
3272 *
3273 * @see Item.getDrawingArea
3274 *
3275 * @param trait
3276 * The visual trait that has changed.
3277 *
3278 * @return The damaged area according to the visual trait that has changed.
3279 */
3280 protected AxisAlignedBoxBounds getDamagedArea(ItemAppearence trait)
3281 {
3282 if (trait == ItemAppearence.LinkChanged)
3283 return getLinkDrawArea(); // Invalidate area where link is drawn
3284
3285 return getDrawingArea();
3286 }
3287
3288 public boolean hasVector() {
3289 return _overlay instanceof Vector;
3290 }
3291
3292 public boolean hasOverlay() {
3293 return _overlay != null;
3294 }
3295
3296 public Vector getVector() {
3297 if (_overlay instanceof Vector)
3298 return (Vector) _overlay;
3299 return null;
3300 }
3301
3302 public void setOverlay(Overlay overlay) {
3303 _overlay = overlay;
3304 }
3305
3306 public boolean dontSave() {
3307 /*
3308 * TODO Mike says: checkout if the ID check is still needed- When will
3309 * ID still be -1 when saving a frame? assert (i != null);
3310 */
3311 // make it save stuff that's off the screen so stuff isn't deleted by panning - jts21
3312 return !_save || !isVisible() || getID() < 0; // || offScreenTopOrLeft();
3313 }
3314
3315 public void setAnchorLeft(Integer anchor)
3316 {
3317 this._anchoring.setLeftAnchor(anchor);
3318 if (anchor != null) {
3319 anchorConstraints();
3320 setX(anchor);
3321 }
3322 }
3323
3324 public void setAnchorRight(Integer anchor)
3325 {
3326 this._anchoring.setRightAnchor(anchor);
3327 if (anchor != null) {
3328 anchorConstraints();
3329 setX(DisplayController.getFramePaintArea().getMaxX() - anchor - getBoundsWidth());
3330 }
3331 }
3332
3333 public void setAnchorTop(Integer anchor)
3334 {
3335 this._anchoring.setTopAnchor(anchor);
3336 if (anchor != null) {
3337 anchorConstraints();
3338 setY(anchor);
3339 }
3340 }
3341
3342
3343 public void setAnchorBottom(Integer anchor)
3344 {
3345 this._anchoring.setBottomAnchor(anchor);
3346 if (anchor != null) {
3347 anchorConstraints();
3348 setY(DisplayController.getFramePaintArea().getMaxY() - anchor);
3349 }
3350 }
3351
3352 public boolean isAnchored()
3353 {
3354 return _anchoring.isAnchored();
3355 }
3356
3357 public boolean isAnchoredX() {
3358 return _anchoring.isXAnchored();
3359 }
3360
3361 public boolean isAnchoredY() {
3362 return _anchoring.isYAnchored();
3363 }
3364
3365 public Integer getAnchorLeft() {
3366 Surrogate surrogate = Surrogate.of(this);
3367 if (surrogate != null &&
3368 surrogate.isPropertyIsInherited(DefaultFrameWriter.ANCHOR_LEFT + "")) {
3369 return this.getClassic().getAnchorLeft();
3370 } else {
3371 return _anchoring.getLeftAnchor();
3372 }
3373 }
3374
3375 public Integer getAnchorRight() {
3376 Surrogate surrogate = Surrogate.of(this);
3377 if (surrogate != null &&
3378 surrogate.isPropertyIsInherited(DefaultFrameWriter.ANCHOR_RIGHT + "")) {
3379 return this.getClassic().getAnchorRight();
3380 } else {
3381 return _anchoring.getRightAnchor();
3382 }
3383 }
3384
3385 public Integer getAnchorTop() {
3386 Surrogate surrogate = Surrogate.of(this);
3387 if (surrogate != null &&
3388 surrogate.isPropertyIsInherited(DefaultFrameWriter.ANCHOR_TOP + "")) {
3389 return this.getClassic().getAnchorTop();
3390 } else {
3391 return _anchoring.getTopAnchor();
3392 }
3393 }
3394
3395 public Integer getAnchorBottom() {
3396 Surrogate surrogate = Surrogate.of(this);
3397 if (surrogate != null &&
3398 surrogate.isPropertyIsInherited(DefaultFrameWriter.ANCHOR_BOTTOM + "")) {
3399 return this.getClassic().getAnchorBottom();
3400 } else {
3401 return _anchoring.getBottomAnchor();
3402 }
3403 }
3404
3405 public String getText() {
3406 Surrogate surrogate = Surrogate.of(this);
3407 if (surrogate != null &&
3408 surrogate.isPropertyIsInherited(DefaultFrameWriter.TEXT + "")) {
3409 return this.getClassic().getText();
3410 } else {
3411 return "@" + getClass().getSimpleName() + ":" + getID();
3412 }
3413 }
3414
3415 public void setText(String text) {
3416 }
3417
3418 public boolean recalculateWhenChanged() {
3419 return false;
3420 }
3421
3422 public boolean update() {
3423 return calculate(getText());
3424 }
3425
3426 public Collection<Item> getEnclosedItems() {
3427 return FrameUtils.getItemsEnclosedBy(this.getParentOrCurrentFrame(),
3428 this.getEnclosedShape());
3429 }
3430
3431 public Collection<Text> getEnclosedNonAnnotationText() {
3432 Collection<Text> items = new LinkedHashSet<Text>();
3433 for (Item t : getEnclosedItems()) {
3434 if (t instanceof Text && !t.isAnnotation())
3435 items.add((Text) t);
3436 }
3437
3438 return items;
3439 }
3440
3441 public void dispose() {
3442 setParent(null);
3443 }
3444
3445 /**
3446 * @return
3447 */
3448 protected boolean hasVisibleBorder() {
3449 return getThickness() > 0 && !isLineEnd() && getBorderColor() != null;
3450 }
3451
3452 public Frame getChild() {
3453 String childName = getAbsoluteLink();
3454 if (childName != null) {
3455 return FrameIO.LoadFrame(childName);
3456 }
3457 return null;
3458 }
3459
3460 public boolean hasLink() {
3461 return _link != null;
3462 }
3463
3464 protected void anchorConnectedOLD(AnchorEdgeType anchorEdgeType, Float delta) {
3465 // Check for a more efficient way to do this!!
3466 // Invalidate all the items
3467 for (Item i : this.getAllConnected()) {
3468 i.invalidateAll();
3469 }
3470 // Move the items
3471 for (Item i : this.getAllConnected()) {
3472 if (i.isLineEnd()) {
3473 if (delta != null) {
3474 if ((anchorEdgeType == AnchorEdgeType.Left) || (anchorEdgeType == AnchorEdgeType.Right)) {
3475 // 'delta' encodes a horizontal (x) move
3476 if (anchorEdgeType == AnchorEdgeType.Left) {
3477 i.setAnchorLeft(null);
3478 }
3479 else {
3480 // must be Right
3481 i.setAnchorRight(null);
3482 }
3483
3484 i.setXY(i.getX() + delta, i.getY());
3485 }
3486 if ((anchorEdgeType == AnchorEdgeType.Top) || (anchorEdgeType == AnchorEdgeType.Bottom)) {
3487 // 'delta; encodes a vertical (y) move
3488 if (anchorEdgeType == AnchorEdgeType.Top) {
3489 i.setAnchorTop(null);
3490 }
3491 else {
3492 // must be Bottom
3493 i.setAnchorBottom(null);
3494 }
3495 i.setXY(i.getX(), i.getY() + delta);
3496 }
3497
3498 }
3499 }
3500 }
3501 // Invalidate them again!!
3502 for (Item i : this.getAllConnected()) {
3503 i.invalidateBounds();
3504 i.invalidateAll();
3505 }
3506 }
3507
3508 protected void anchorConnected(AnchorEdgeType anchorEdgeType, Float delta) {
3509
3510 // Check for a more efficient way to do this!!
3511 // Invalidate all the items
3512 for (Item i : this.getAllConnected()) {
3513 i.invalidateAll();
3514 }
3515
3516 // Move the items
3517 for (Item i : this.getAllConnected()) {
3518 if (i.isLineEnd()) {
3519 if (delta != null) {
3520 if ((anchorEdgeType == AnchorEdgeType.Left) || (anchorEdgeType == AnchorEdgeType.Right)) {
3521 // 'delta' encodes a horizontal (x) move
3522 if (anchorEdgeType == AnchorEdgeType.Left) {
3523 // Processing a Left anchor
3524 // => Anything connected that is *not* anchored to the right should be moved by 'delta'
3525 if (i.getAnchorRight()==null) {
3526 i.setXY(i.getX() + delta, i.getY());
3527 }
3528 }
3529 else {
3530 // Processing a Right anchor
3531 // => Anything connected that is *not* anchored to the left should be moved by 'delta'
3532 if (i.getAnchorLeft()==null) {
3533 i.setXY(i.getX() + delta, i.getY());
3534 }
3535 }
3536
3537 }
3538 if ((anchorEdgeType == AnchorEdgeType.Top) || (anchorEdgeType == AnchorEdgeType.Bottom)) {
3539 // 'delta; encodes a vertical (y) move
3540 if (anchorEdgeType == AnchorEdgeType.Top) {
3541 // Processing a Top anchor
3542 // => Anything connected that is *not* anchored to the bottom should be moved by 'delta'
3543 if (i.getAnchorBottom()==null) {
3544 i.setXY(i.getX(), i.getY() + delta);
3545 }
3546 }
3547 else {
3548 // Processing a Bottom anchor
3549 // => Anything connected that is *not* anchored to the top should be moved by 'delta'
3550 if (i.getAnchorTop()==null) {
3551 // must be Bottom
3552 //i.setAnchorBottom(null);
3553 i.setXY(i.getX(), i.getY() + delta);
3554 }
3555 }
3556 }
3557 }
3558 }
3559 }
3560
3561 anchorConstraints();
3562
3563 // Invalidate them again!!
3564 for (Item i : this.getAllConnected()) {
3565 i.invalidateBounds();
3566 i.invalidateAll();
3567 }
3568 }
3569 /**
3570 * Sets the item to pickup when the user attempts to pick this item up.
3571 * EditTarget has a value of 'this' by default but may be set to other
3572 * values if this item is on a vector.
3573 *
3574 * @param target
3575 * the item to be copied or picked up when the user attempts to
3576 * edit this item.
3577 */
3578 public void setEditTarget(Item target) {
3579 _editTarget = target;
3580 }
3581
3582 /**
3583 * Gets the item to pickup when the user attempts to pick this item up.
3584 * EditTarget has a value of 'this' by default but may be set to other
3585 * values if this item is on a vector.
3586 */
3587 public Item getEditTarget() {
3588 return _editTarget;
3589 }
3590
3591 public void scale(Float scale, int originX, int originY) {
3592 setXY((getX() - originX) * scale + originX, (getY() - originY) * scale + originY);
3593 setArrowheadLength(getArrowheadLength() * scale);
3594
3595 float thickness = getThickness();
3596 if (thickness > 0)
3597 setThickness(thickness * scale, false);
3598
3599 // DONT PUT SIZE IN HERE CAUSE IT STUFFS UP CIRCLES
3600
3601 invalidateBounds();
3602 }
3603
3604 protected boolean isVectorItem() {
3605 return _editTarget != this;
3606 }
3607
3608 public AttributeValuePair getAttributeValuePair() {
3609 if (_attributeValuePair == null) {
3610 _attributeValuePair = new AttributeValuePair(getText());
3611 }
3612 return _attributeValuePair;
3613 }
3614
3615 /*
3616 * private static Set<Object> _locks = new HashSet<Object>();
3617 *
3618 * public static void lock(Object itemToLock) { _locks.add(itemToLock); }
3619 *
3620 * public static void unlock(Object itemToUnlock) {
3621 * _locks.remove(itemToUnlock); }
3622 *
3623 * public static boolean isLocked(Object item) { return
3624 * _locks.contains(item); }
3625 */
3626
3627 public void setSave(boolean state) {
3628 _save = state;
3629 }
3630
3631 public boolean getSave() {
3632 return _save;
3633 }
3634
3635 public void setAutoStamp(Float rate) {
3636 _autoStamp = rate;
3637 }
3638
3639 public Float getAutoStamp() {
3640 return _autoStamp;
3641 }
3642
3643 public boolean isAutoStamp() {
3644 return _autoStamp != null && _autoStamp >= 0.0;
3645 }
3646
3647 public int getMagnetizedItemLeft() {
3648 Surrogate surrogate = Surrogate.of(this);
3649 if (surrogate != null &&
3650 surrogate.isPropertyIsInherited(DefaultFrameWriter.MAGNETIZED_ITEM_LEFT + "")) {
3651 return this.getClassic().getMagnetizedItemLeft();
3652 } else {
3653 if(_magnetizedItemLeft != null) return _magnetizedItemLeft.getID();
3654 else return -1;
3655 }
3656 }
3657
3658 public void setMagnetizedItemLeft(final Item item) {
3659 _magnetizedItemLeft = item;
3660 }
3661
3662 public void setMagnetizedItemLeft(final int id) {
3663 setMagnetizedItemLeft(this.getParent().getItemWithID(id));
3664 }
3665
3666 public int getMagnetizedItemRight() {
3667 Surrogate surrogate = Surrogate.of(this);
3668 if (surrogate != null &&
3669 surrogate.isPropertyIsInherited(DefaultFrameWriter.MAGNETIZED_ITEM_RIGHT + "")) {
3670 return this.getClassic().getMagnetizedItemRight();
3671 } else {
3672 if(_magnetizedItemRight != null) return _magnetizedItemRight.getID();
3673 else return -1;
3674 }
3675 }
3676
3677 public void setMagnetizedItemRight(final Item item) {
3678 _magnetizedItemRight = item;
3679 }
3680
3681 public void setMagnetizedItemRight(final int id) {
3682 setMagnetizedItemRight(this.getParent().getItemWithID(id));
3683 }
3684
3685 public int getMagnetizedItemTop() {
3686 Surrogate surrogate = Surrogate.of(this);
3687 if (surrogate != null &&
3688 surrogate.isPropertyIsInherited(DefaultFrameWriter.MAGNETIZED_ITEM_TOP + "")) {
3689 return this.getClassic().getMagnetizedItemTop();
3690 } else {
3691 if(_magnetizedItemTop != null) return _magnetizedItemTop.getID();
3692 else return -1;
3693 }
3694 }
3695
3696 public void setMagnetizedItemTop(final Item item) {
3697 _magnetizedItemTop = item;
3698 }
3699
3700 public void setMagnetizedItemTop(final int id) {
3701 setMagnetizedItemTop(this.getParent().getItemWithID(id));
3702 }
3703
3704 public int getMagnetizedItemBottom() {
3705 Surrogate surrogate = Surrogate.of(this);
3706 if (surrogate != null &&
3707 surrogate.isPropertyIsInherited(DefaultFrameWriter.MAGNETIZED_ITEM_BOTTOM + "")) {
3708 return this.getClassic().getMagnetizedItemBottom();
3709 } else {
3710 if(_magnetizedItemBottom != null) return _magnetizedItemBottom.getID();
3711 else return -1;
3712 }
3713 }
3714
3715 public void setMagnetizedItemBottom(final Item item) {
3716 _magnetizedItemBottom = item;
3717 }
3718
3719 public void setMagnetizedItemBottom(final int id) {
3720 setMagnetizedItemBottom(this.getParent().getItemWithID(id));
3721 }
3722
3723 public String getEncryptionLabel() {
3724 Surrogate surrogate = Surrogate.of(this);
3725 if (surrogate != null &&
3726 surrogate.isPropertyIsInherited(DefaultFrameWriter.ENCRYPTION_LABEL + "")) {
3727 return this.getClassic().getEncryptionLabel();
3728 } else {
3729 return _encryptionLabel;
3730 }
3731 }
3732
3733 public void setEncryptionLabel(String label) {
3734 this._encryptionLabel = label;
3735 if (this.getSurrogates().isEmpty()) {
3736 Surrogate surrogate = Surrogate.forItem(this);
3737 this.addToSurrogates(surrogate);
3738 }
3739
3740 for (Character tag: DefaultFrameWriter.getItemTags().keySet()) {
3741 if (tag == 'S') {
3742 propertyEncryption.put(tag + "", EncryptionDetail.UnencryptedOnSave);
3743 } else {
3744 propertyEncryption.put(tag + "", EncryptionDetail.ReencryptOnSave);
3745 }
3746 }
3747
3748 for (String tag: DefaultFrameWriter.getItemTagsExt().keySet()) {
3749 if (tag == "_el") {
3750 propertyEncryption.put(tag, EncryptionDetail.UnencryptedOnSave);
3751 } else {
3752 propertyEncryption.put(tag, EncryptionDetail.ReencryptOnSave);
3753 }
3754 }
3755 }
3756
3757 public void setEncryptionLabelOnLoad(String label) {
3758 this._encryptionLabel = label;
3759
3760 for (Character tag: DefaultFrameWriter.getItemTags().keySet()) {
3761 if (tag == 'S') {
3762 propertyEncryption.put(tag + "", EncryptionDetail.UnencryptedOnSave);
3763 } else {
3764 propertyEncryption.put(tag + "", EncryptionDetail.ReencryptOnSave);
3765 }
3766 }
3767
3768 for (String tag: DefaultFrameWriter.getItemTagsExt().keySet()) {
3769 if (tag == "_el") {
3770 propertyEncryption.put(tag, EncryptionDetail.UnencryptedOnSave);
3771 } else {
3772 propertyEncryption.put(tag, EncryptionDetail.ReencryptOnSave);
3773 }
3774 }
3775 }
3776
3777 /**
3778 * Replaces the given dot item with a text item displaying the given character.
3779 *
3780 * @param dot
3781 * The Dot item to replace.
3782 *
3783 * @param ch
3784 * The character to display as the text for the created Text item.
3785 *
3786 * @return
3787 * The created Text item.
3788 */
3789 public static Text replaceDot(Item dot, char ch) {
3790 // TODO: Should this make sure 'dot' is actually a Dot and not some other item? cts16
3791 Text text = Text.createText(ch);
3792 Item.DuplicateItem(dot, text);
3793 FrameUtils.setLastEdited(text);
3794
3795 // Copy the lines list so it can be modified
3796 List<Line> lines = new LinkedList<Line>(dot.getLines());
3797 for (Line line : lines)
3798 line.replaceLineEnd(dot, text);
3799 Frame current = dot.getParentOrCurrentFrame();
3800 current.removeItem(dot);
3801 ItemUtils.EnclosedCheck(current.getItems());
3802 return text;
3803 // TODO: Should this add the newly-created Text item to the frame? cts16
3804 }
3805
3806 /**
3807 * Replaces the given text item with a dot
3808 */
3809 public static Item replaceText(Item text) {
3810 Item dot = new Dot(text.getX(), text.getY(), text.getID());
3811 Item.DuplicateItem(text, dot);
3812
3813 List<Line> lines = new LinkedList<Line>();
3814 lines.addAll(text.getLines());
3815 if (lines.size() > 0)
3816 dot.setColor(lines.get(0).getColor());
3817 for (Line line : lines) {
3818 line.replaceLineEnd(text, dot);
3819 }
3820 text.delete();
3821 Frame current = text.getParentOrCurrentFrame();
3822 current.addItem(dot);
3823 DisplayController.setCursor(Item.DEFAULT_CURSOR);
3824 ItemUtils.EnclosedCheck(current.getItems());
3825 return dot;
3826 }
3827
3828 public Set<Surrogate> getSurrogates() {
3829 return surrogateItems;
3830 }
3831
3832 public void setAsSurrogateFor(Item classic) {
3833 this.surrogateFor = classic;
3834 }
3835
3836 public void addToSurrogates(Surrogate surrogate) {
3837 this.surrogateItems.add(surrogate);
3838 }
3839
3840 public boolean isSurrogate() {
3841 return this.surrogateFor != null;
3842 }
3843
3844 public Item getClassic() {
3845 return this.surrogateFor;
3846 }
3847
3848 public EncryptionDetail getEncryptionDetailForTag(String tag) {
3849 EncryptionDetail encryptionDetail = propertyEncryption.get(tag);
3850
3851 if (encryptionDetail == null) {
3852 return EncryptionDetail.UnencryptedOnSave;
3853 } else {
3854 return encryptionDetail;
3855 }
3856 }
3857
3858 public void setEncryptionDetailForTag(String tag, EncryptionDetail encryptionDetail) {
3859 propertyEncryption.put(tag, encryptionDetail);
3860 }
3861}
Note: See TracBrowser for help on using the repository browser.