Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/Item.java

    r977 r1102  
    1919package org.expeditee.items;
    2020
    21 import java.awt.BasicStroke;
    22 import java.awt.Color;
    23 import java.awt.Cursor;
    24 import java.awt.GradientPaint;
    25 import java.awt.Graphics2D;
    26 import java.awt.Point;
    27 import java.awt.Polygon;
    28 import java.awt.Rectangle;
    29 import java.awt.Shape;
    30 import java.awt.Stroke;
    31 import java.awt.geom.AffineTransform;
    32 import java.awt.geom.Area;
    33 import java.awt.geom.Point2D;
    34 import java.awt.geom.Rectangle2D;
    3521import java.util.ArrayList;
    3622import java.util.Collection;
     
    4632import org.expeditee.actions.Misc;
    4733import org.expeditee.actions.Simple;
     34import org.expeditee.core.Anchoring;
     35import org.expeditee.core.Colour;
     36import org.expeditee.core.Cursor;
     37import org.expeditee.core.Dimension;
     38import org.expeditee.core.Fill;
     39import org.expeditee.core.GradientFill;
     40import org.expeditee.core.Point;
     41import org.expeditee.core.Stroke;
     42import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     43import org.expeditee.core.bounds.Bounds;
     44import org.expeditee.core.bounds.EllipticalBounds;
     45import org.expeditee.core.bounds.PolygonBounds;
     46import org.expeditee.gio.EcosystemManager;
     47import org.expeditee.gio.GraphicsManager;
     48import org.expeditee.gio.gesture.StandardGestureActions;
    4849import org.expeditee.gui.AttributeValuePair;
    49 import org.expeditee.gui.DisplayIO;
     50import org.expeditee.gui.DisplayController;
    5051import org.expeditee.gui.Frame;
    5152import org.expeditee.gui.FrameGraphics;
    5253import org.expeditee.gui.FrameIO;
    53 import org.expeditee.gui.FrameKeyboardActions;
    54 import org.expeditee.gui.FrameMouseActions;
    5554import org.expeditee.gui.FrameUtils;
    5655import org.expeditee.gui.FreeItems;
     
    7574public abstract class Item implements Comparable<Item>, Runnable {
    7675
    77         public static final Float DEFAULT_THICKNESS = 2f;
    78 
    79         public static final Float MINIMUM_THICKNESS = 0f;
    80 
    81         public static final Float MINIMUM_PAINT_THICKNESS = 1f;
    82 
    83         protected final int JOIN = BasicStroke.JOIN_ROUND;
    84 
    85         protected final int CAP = BasicStroke.CAP_BUTT;
    86 
    87         protected final Stroke DOT_STROKE = new BasicStroke(DEFAULT_THICKNESS,
    88                         CAP, JOIN, 4.0F);
    89 
    90         protected final Stroke HIGHLIGHT_STROKE = new BasicStroke(
    91                         MINIMUM_THICKNESS, CAP, JOIN, 4.0F);
    92 
    93         // contains all dots (including this one) that form an enclosure
    94         // if this dot is part of an enclosing shape
    95         private Collection<Item> _enclosure = null;
    96 
    97         public static final int LEFT_MARGIN = 13;
    98 
    99         // indicates which end the arrowhead should be drawn at
    100         protected Polygon _poly = null;
    101 
    102         protected boolean _connectedToAnnotation = false;
    103 
    104         protected boolean _save = true;
    105 
    106         private int _gradientAngle = 0;
    107 
    108         public static final int NEAR_DISTANCE = 15;
    109 
    110         /**
    111          * The default Color to draw highlighting in
    112          */
    113         public static final int DEFAULT_HIGHLIGHT_THICKNESS = 2;
    114 
    115         public static final Color DEFAULT_HIGHLIGHT = Color.RED;
    116 
    117         public static final Color DEPRESSED_HIGHLIGHT = Color.GREEN;
    118 
    119         public static final Color ALTERNATE_HIGHLIGHT = Color.BLUE;
    120 
    121         public static final Color LINK_COLOR = Color.BLACK;
    122 
    123         public static final Color ACTION_COLOR = Color.BLACK;
    124 
    125         public static final Color LINK_ACTION_COLOR = Color.RED;
    126 
    127         public static final Color DEFAULT_FOREGROUND = Color.BLACK;
    128 
    129         public static final Color DEFAULT_BACKGROUND = Color.white;
    130 
    131         public static final Color TRANSPARENT = new Color(0, 0, 0, 0);
    132 
    133         /**
    134          * The number of pixels highlighting should extend around Items.
    135          */
    136         public static final int XGRAVITY = 3;
    137 
    138         public static final int MARGIN_RIGHT = 2;
    139 
    140         public static final int MARGIN_LEFT = 15;
    141 
    142         protected static final double DEFAULT_ARROWHEAD_RATIO     = 0.3; // used to be 0.5
    143 
    144         public static final double DEFAULT_ARROWHEAD_NIB_PERC  = 0.75;
    145        
    146         public static final Color GREEN = Color.GREEN.darker();
    147 
    148         public static final int UNCHANGED_CURSOR = -100;
    149 
    150         public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR;
    151 
    152         public static final int HIDDEN_CURSOR = Cursor.CUSTOM_CURSOR;
    153 
    154         public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR;
    155 
    156         public static final int CROP_CURSOR = Cursor.CROSSHAIR_CURSOR;
    157 
    158         // The default value for integer attributes
    159         public static final int DEFAULT_INTEGER = -1;
    160 
    161         protected DotType _type = DotType.square;
    162 
    163         protected boolean _filled = true;
    164        
    165         private Tooltip _tooltip = new Tooltip();
    166 
     76        public enum HighlightMode {
     77                None, // The item has no highlighting
     78                Enclosed, // The item is part of the current enclosure
     79                Connected, // The item is connected to the current item
     80                Disconnect, // The item is a free item
     81                Normal // The item is the current item
     82        }
     83
     84        /** Which edge of the window things are anchored to. */
    16785        public enum AnchorEdgeType {
    16886                None, Left, Right, Top, Bottom
    16987        }
    170 
    171         public static void DuplicateItem(Item source, Item dest) {
    172                 dest.setX(source.getX());
    173                 dest.setY(source.getY());
    174 
    175                 dest.setActions(source.getAction());
    176                 dest.setActionCursorEnter(source.getActionCursorEnter());
    177                 dest.setActionCursorLeave(source.getActionCursorLeave());
    178                 dest.setActionEnterFrame(source.getActionEnterFrame());
    179                 dest.setActionLeaveFrame(source.getActionLeaveFrame());
    180                 dest.setActionMark(source.getActionMark());
    181 
    182                 dest.setBackgroundColor(source.getBackgroundColor());
    183                 dest.setBottomShadowColor(source.getBottomShadowColor());
    184                 dest.setColor(source.getColor());
    185                 dest.setBorderColor(source.getBorderColor());
    186 
    187                 dest.setTooltips(source.getTooltip());
    188                 dest.setData(source.getData());
    189                 dest.setTag(source.getTag());
    190                 dest.setFillColor(source.getFillColor());
    191                 dest.setGradientColor(source.getGradientColor());
    192                 dest.setGradientAngle(source.getGradientAngle());
    193                 dest.setFillPattern(source.getFillPattern());
    194 
    195                 dest.setHighlight(source.getHighlight());
    196                 dest.setLink(source.getLink());
    197                 dest.setLinkFrameset(source.getLinkFrameset());
    198                 dest.setLinkMark(source.getLinkMark());
    199                 dest.setLinkTemplate(source.getLinkTemplate());
    200 
    201                 // dest.setMaxWidth(source.getMaxWidth());
    202 
    203                 dest.setOffset(source.getOffset());
    204                 // dest.setOwner(source.getOwner());
    205                 dest.setThickness(source.getThickness());
    206                 dest.setSize(source.getSize());
    207                 dest.setTopShadowColor(source.getTopShadowColor());
    208                 dest.setLinePattern(source.getLinePattern());
    209 
    210                 dest.setFloating(source.isFloating());
    211                 dest.setArrow(source.getArrowheadLength(), source.getArrowheadRatio(), source.getArrowheadNibPerc());
    212 
    213                 dest.setDotType(source.getDotType());
    214                 dest.setFilled(source.getFilled());
     88       
     89        public static final float SIZE_NOT_APPLICABLE = Float.NaN;
     90       
     91        public static final Float DEFAULT_THICKNESS = 2f;
     92
     93        public static final Float MINIMUM_THICKNESS = 0f;
     94
     95        public static final Float MINIMUM_PAINT_THICKNESS = 1f;
     96
     97        protected static final Stroke.JOIN DEFAULT_JOIN = Stroke.JOIN.ROUND;
     98
     99        protected static final Stroke.CAP DEFAULT_CAP = Stroke.CAP.BUTT;
     100
     101        protected static final Stroke DOT_STROKE = new Stroke(DEFAULT_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN);
     102
     103        protected static final Stroke HIGHLIGHT_STROKE = new Stroke(MINIMUM_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN);
     104       
     105        public static final int LEFT_MARGIN = 13;
     106
     107        public static final int NEAR_DISTANCE = 15;
     108
     109        public static final int DEFAULT_HIGHLIGHT_THICKNESS = 2;
     110
     111        /** The default colour to draw highlighting in */
     112        public static final Colour DEFAULT_HIGHLIGHT = Colour.RED;
     113
     114        public static final Colour DEPRESSED_HIGHLIGHT = Colour.GREEN;
     115
     116        public static final Colour ALTERNATE_HIGHLIGHT = Colour.BLUE;
     117
     118        public static final Colour LINK_COLOR = Colour.BLACK;
     119
     120        public static final Colour ACTION_COLOR = Colour.BLACK;
     121
     122        public static final Colour LINK_ACTION_COLOR = Colour.RED;
     123
     124        public static final Colour DEFAULT_FOREGROUND = Colour.BLACK;
     125
     126        public static final Colour DEFAULT_BACKGROUND = Colour.WHITE;
     127
     128        public static final Colour TRANSPARENT = new Colour(0, 0, 0, 0);
     129
     130        /** The number of pixels highlighting should extend around Items. */
     131        public static final int XGRAVITY = 3;
     132
     133        public static final int MARGIN_RIGHT = 2;
     134
     135        public static final int MARGIN_LEFT = 15;
     136
     137        protected static final double DEFAULT_ARROWHEAD_RATIO = 0.3; // used to be 0.5
     138
     139        public static final double DEFAULT_ARROWHEAD_NIB_PERC  = 0.75;
     140       
     141        public static final Colour GREEN = Colour.GREEN.darker();
     142
     143        //public static final int UNCHANGED_CURSOR = -100;
     144
     145        public static final Cursor.CursorType DEFAULT_CURSOR = Cursor.CursorType.DEFAULT;
     146
     147        public static final Cursor.CursorType HIDDEN_CURSOR = Cursor.CursorType.CUSTOM;
     148
     149        public static final Cursor.CursorType TEXT_CURSOR = Cursor.CursorType.TEXT;
     150
     151        public static final Cursor.CursorType CROP_CURSOR = Cursor.CursorType.CROSSHAIR;
     152
     153        /** The default value for integer attributes */
     154        public static final int DEFAULT_INTEGER = -1;
     155
     156        private static final int BRIGHTNESS = 185;
     157
     158        /** Contains all dots (including this one) that form an enclosure if this dot is part of an enclosing shape. */
     159        private Collection<Item> _enclosure = null;
     160
     161        /** The area which this item covers (including its gravity). */
     162        private Bounds _bounds = null;
     163       
     164        /** The area this item covered before it was invalidated. */
     165        private Bounds _oldBounds = null;
     166
     167        protected boolean _connectedToAnnotation = false;
     168
     169        protected boolean _save = true;
     170
     171        /** The angle of change for gradient colour fills (in radians). */
     172        private double _gradientAngle = 0.0;
     173       
     174        private Tooltip _tooltip = new Tooltip();
     175
     176        protected Anchoring _anchoring = new Anchoring();
     177
     178        /** The highlight mode for this item. */
     179        protected HighlightMode _highlightMode = HighlightMode.None;
     180
     181        private Point _offset = new Point(0, 0);
     182
     183        protected float _x;
     184        protected float _y;
     185
     186        private int _id;
     187
     188        private Item _editTarget = this;
     189
     190        private String _creationDate = null;
     191
     192        /** Whether or not this item should display a mark indicating it has a link. */
     193        private boolean _linkMark = true;
     194
     195        /** Whether or not this item should display a mark indicating it has an action. */
     196        private boolean _actionMark = true;
     197
     198        /** TODO: Appears unused? cts16 */
     199        private boolean _highlight = true;
     200
     201        // private int _maxWidth = -1;
     202
     203        private String _owner = null;
     204
     205        private String _link = null;
     206       
     207        private boolean _linkHistory = true;
     208
     209        private StringBuffer _tag = new StringBuffer();
     210
     211        private List<String> _actionCursorEnter = null;
     212
     213        private List<String> _actionCursorLeave = null;
     214
     215        private List<String> _actionEnterFrame = null;
     216
     217        private List<String> _actionLeaveFrame = null;
     218
     219        private PermissionPair _permissionPair = null;
     220       
     221        private UserAppliedPermission _overlayPermission = null;
     222
     223        /** The primary fill colour of this item. A fill colour of null represents transparent. */
     224        private Colour _fillColour = null;
     225
     226        /** The secondary fill colour if this item has a gradient fill. Null represents no gradient. */
     227        private Colour _gradientColour = null;
     228
     229        /** The primary draw colour of this item. Null represents the default colour. */
     230        private Colour _foregroundColour = null;
     231
     232        /** The colour to draw highlights on this item. */
     233        protected Colour _highlightColour = DEFAULT_HIGHLIGHT;
     234
     235        /** The background colour for this item. */
     236        private Colour _backgroundColour = null;
     237
     238        private Colour _colorBorder = null;
     239
     240        private Colour _colorTopShadow = null;
     241
     242        private Colour _colorBottomShadow = null;
     243
     244        /** The shape representing the circle drawn next to link/action items. */
     245        private static EllipticalBounds _linkCircle = null;
     246
     247        /** The shape representing the cross drawn next to invalid links. */
     248        private static PolygonBounds _linkCircleCross = null;
     249
     250        private Frame _parent = null;
     251        private Frame _oldParent = null;
     252
     253        protected int _highlightThickness = 2;
     254
     255        protected int _vectorHighlightThickness = 1;
     256
     257        // arrowhead parameters
     258        private float  _arrowheadLength  = 0;
     259        private double _arrowheadRatio   = DEFAULT_ARROWHEAD_RATIO;
     260        private double _arrowheadNibPerc = DEFAULT_ARROWHEAD_NIB_PERC;
     261       
     262        private PolygonBounds _arrowhead = null;
     263
     264        // the list of lines that this point is part of.
     265        private List<Line> _lines = new ArrayList<Line>();
     266
     267        private int[] _linePattern = null;
     268
     269        private boolean _floating = false;
     270
     271        // list of points constrained with this point
     272        private List<Constraint> _constraints = new ArrayList<Constraint>();
     273
     274        private List<String> _actions = null;
     275
     276        private List<String> _data = null;
     277
     278        private String _formula = null;
     279
     280        private String _link_frameset = null;
     281
     282        private String _link_template = null;
     283
     284        private String _fillPattern = null;
     285
     286        private boolean _visible = true;
     287
     288        private float _thickness = -1.0F;
     289
     290        protected Collection<XRayable> _enclosures = new HashSet<XRayable>();
     291
     292        private boolean _deleted = false;
     293
     294        private Overlay _overlay = null;
     295
     296        protected AttributeValuePair _attributeValuePair = null;
     297
     298        private Float _autoStamp = null;
     299       
     300        private Item _magnetizedItemLeft = null;
     301       
     302        private Item _magnetizedItemRight = null;
     303       
     304        private Item _magnetizedItemTop = null;
     305       
     306        private Item _magnetizedItemBottom = null;
     307
     308        protected DotType _type = DotType.square;
     309
     310        protected boolean _filled = true;
     311
     312        /** Just calls source.duplicateOnto(dest). */
     313        public static void DuplicateItem(Item source, Item dest)
     314        {
     315                if (source == null) return;
     316               
     317                source.duplicateOnto(dest);
     318        }
     319       
     320        /** Sets the properties of dest so that they match this item's properties. */
     321        public void duplicateOnto(Item dest)
     322        {
     323                if (dest == null) return;
     324               
     325                dest.setX(this.getX());
     326                dest.setY(this.getY());
     327
     328                dest.setActions(this.getAction());
     329                dest.setActionCursorEnter(this.getActionCursorEnter());
     330                dest.setActionCursorLeave(this.getActionCursorLeave());
     331                dest.setActionEnterFrame(this.getActionEnterFrame());
     332                dest.setActionLeaveFrame(this.getActionLeaveFrame());
     333                dest.setActionMark(this.getActionMark());
     334
     335                dest.setBackgroundColor(this.getBackgroundColor());
     336                dest.setBottomShadowColor(this.getBottomShadowColor());
     337                dest.setColor(this.getColor());
     338                dest.setBorderColor(this.getBorderColor());
     339
     340                dest.setTooltips(this.getTooltip());
     341                dest.setData(this.getData());
     342                dest.setTag(this.getTag());
     343                dest.setFillColor(this.getFillColor());
     344                dest.setGradientColor(this.getGradientColor());
     345                dest.setGradientAngle(this.getGradientAngle());
     346                dest.setFillPattern(this.getFillPattern());
     347
     348                dest.setHighlight(this.getHighlight());
     349                dest.setLink(this.getLink());
     350                dest.setLinkFrameset(this.getLinkFrameset());
     351                dest.setLinkMark(this.getLinkMark());
     352                dest.setLinkTemplate(this.getLinkTemplate());
     353
     354                // dest.setMaxWidth(this.getMaxWidth());
     355
     356                dest.setOffset(this.getOffset());
     357                // dest.setOwner(this.getOwner());
     358                dest.setThickness(this.getThickness());
     359                dest.setSize(this.getSize());
     360                dest.setTopShadowColor(this.getTopShadowColor());
     361                dest.setLinePattern(this.getLinePattern());
     362
     363                dest.setFloating(this.isFloating());
     364                dest.setArrow(this.getArrowheadLength(), this.getArrowheadRatio(), this.getArrowheadNibPerc());
     365                dest.setDotType(this.getDotType());
     366                dest.setFilled(this.getFilled());
    215367                /*
    216368                 * Calling the methods will move the item... This messes things up when
    217369                 * the user uses backspace to delete a text line end
    218370                 */
    219                 // dest._anchorLeft = source._anchorLeft;
    220                 // dest._anchorRight = source._anchorRight;
    221                 // dest._anchorTop = source._anchorTop;
    222                 // dest._anchorBottom = source._anchorBottom;
    223                 dest.setFormula(source.getFormula());
    224                 dest._overlay = source._overlay;
    225                 dest._mode = source._mode;// SelectedMode.None;
    226                 // dest._highlightColor = source._highlightColor;
    227                 // dest.setHighlight(source.getHighlight());
    228 
    229                 dest._visible = source._visible;
    230 
    231                 Frame parent = DisplayIO.getCurrentFrame();
    232                 if (parent == null)
    233                         parent = source.getParentOrCurrentFrame();
     371                // dest._anchorLeft = this._anchorLeft;
     372                // dest._anchorRight = this._anchorRight;
     373                // dest._anchorTop = this._anchorTop;
     374                // dest._anchorBottom = this._anchorBottom;
     375                dest.setFormula(this.getFormula());
     376                dest._overlay = this._overlay;
     377                dest._highlightMode = this._highlightMode;// SelectedMode.None;
     378                // dest._highlightColor = this._highlightColor;
     379                // dest.setHighlight(this.getHighlight());
     380
     381                dest._visible = this._visible;
     382
     383                Frame parent = DisplayController.getCurrentFrame();
     384                if (parent == null) parent = this.getParentOrCurrentFrame();
    234385                dest.setParent(parent);
    235386
     
    246397                }
    247398        }
    248 
    249         public void setGradientAngle(int gradientAngle) {
     399       
     400        public void setDotType(DotType type) {
     401                invalidateAll();
     402                _type = type;
     403                invalidateAll();
     404        }
     405
     406        public DotType getDotType() {
     407                return _type;
     408        }
     409
     410       
     411        public void setFilled(boolean filled)
     412        {
     413                invalidateAll();
     414                _filled = filled;
     415                invalidateAll();
     416        }
     417
     418        public boolean getFilled() {
     419                return _filled;
     420        }
     421
     422        /**
     423         * Sets the angle of colour change for gradient colour fills.
     424         *
     425         * @param gradientAngle The new angle of colour change.
     426         */
     427        public void setGradientAngle(double gradientAngle)
     428        {
    250429                _gradientAngle = gradientAngle;
    251430
    252431                for (Line line : _lines) {
    253432                        Item other = line.getOppositeEnd(this);
    254                         if (other.getGradientAngle() != gradientAngle)
    255                                 other.setGradientAngle(gradientAngle);
     433                        if (other.getGradientAngle() != gradientAngle) other.setGradientAngle(gradientAngle);
    256434                }
    257435
     
    260438        }
    261439
    262         public int getGradientAngle() {
     440        /**
     441         * Gets the angle of colour change for gradient fills.
     442         *
     443         * @return The angle of colour change.
     444         */
     445        public double getGradientAngle() {
    263446                return _gradientAngle;
    264447        }
    265448
    266         public int getGravity() {
    267                 if (isVectorItem()) {
    268                         return 2;
    269                 }
     449        /**
     450         * Gets the gravity for this item. Gravity is the distance from the item at which mouse interaction
     451         * applies to the item (like a small buffer zone so you don't need to click exactly on the item).
     452         *
     453         * @return The gravity distance for this item.
     454         */
     455        public int getGravity()
     456        {
     457                if (isVectorItem()) return 2;
     458               
    270459                return UserSettings.Gravity.get();
    271460        }
    272461
    273         public static boolean showLineHighlight() {
     462        /**
     463         * Whether or not line highlights should be shown.
     464         * TODO: Not really an item method is it? Goes straight to user settings. Refactor. cts16
     465         *
     466         * @return <code>true</code> if line highlighting should be shown, <code>false</code> otherwise.
     467         */
     468        public static boolean shouldShowLineHighlight()
     469        {
    274470                return UserSettings.LineHighlight.get();
    275471        }
    276472
    277         public enum HighlightMode {
    278                 None, Enclosed, Connected, Disconnect, Normal
    279         }
    280 
    281         public void setHighlightMode(HighlightMode mode) {
    282                 setHighlightMode(mode, DEFAULT_HIGHLIGHT);
    283         }
    284 
    285         protected Float _anchorLeft = null;
    286         protected Float _anchorRight = null;
    287 
    288         protected Float _anchorTop = null;
    289         protected Float _anchorBottom = null;
    290 
    291         protected HighlightMode _mode = HighlightMode.None;
    292 
    293         private Point _offset = new Point(0, 0);
    294 
    295         protected float _x;
    296         protected float _y;
    297 
    298         private int _id;
    299 
    300         private Item _editTarget = this;
    301 
    302         private String _creationDate = null;
    303 
    304         private boolean _linkMark = true;
    305 
    306         private boolean _actionMark = true;
    307 
    308         private boolean _highlight = true;
    309 
    310         // private int _maxWidth = -1;
    311 
    312         private String _owner = null;
    313 
    314         private String _link = null;
    315        
    316         private boolean _linkHistory = true;
    317 
    318         private StringBuffer _tag = new StringBuffer();
    319 
    320         private List<String> _actionCursorEnter = null;
    321 
    322         private List<String> _actionCursorLeave = null;
    323 
    324         private List<String> _actionEnterFrame = null;
    325 
    326         private List<String> _actionLeaveFrame = null;
    327 
    328         private PermissionPair _permissionPair = null;
    329        
    330         private UserAppliedPermission _overlayPermission = null;
    331        
    332         public void setOverlayPermission(UserAppliedPermission overlayPermission) {
     473        /**
     474         * Sets the highlight mode for this item.
     475         *
     476         * @param mode The new highlight mode.
     477         */
     478        public void setHighlightMode(HighlightMode mode)
     479        {
     480                if (hasPermission(UserAppliedPermission.followLinks) || getEditTarget().hasPermission(UserAppliedPermission.followLinks)) {
     481                        if (_highlightMode != mode) {
     482                                _highlightMode = mode;
     483                                this.invalidateCommonTrait(ItemAppearence.HighlightModeChanged);
     484                        }
     485                }
     486        }
     487       
     488        public void setOverlayPermission(UserAppliedPermission overlayPermission)
     489        {
    333490                _overlayPermission = overlayPermission;
    334491        }
    335492
    336         public void setPermission(PermissionPair permissionPair) {
     493        public void setPermission(PermissionPair permissionPair)
     494        {
    337495                _permissionPair = permissionPair;
    338496        }
     
    354512        }
    355513
    356         // A fill color of null represents transparent
    357         private Color _colorFill = null;
    358 
    359         // A gradient color of null represents NO gradient
    360         private Color _colorGradient = null;
    361 
    362         // A fore color of null represents the default color
    363         private Color _color = null;
    364 
    365         protected Color _highlightColor = DEFAULT_HIGHLIGHT;
    366 
    367         private Color _colorBackground = null;
    368 
    369         private Color _colorBorder = null;
    370 
    371         private Color _colorTopShadow = null;
    372 
    373         private Color _colorBottomShadow = null;
    374 
    375         // the link\action circle
    376         private Polygon _circle = null;
    377 
    378         // the invalid link cross
    379         private Polygon _circleCross = null;
    380 
    381         private Frame _parent = null;
    382         private Frame _oldParent = null;
    383 
    384         protected int _highlightThickness = 2;
    385 
    386         protected int _vectorHighlightThickness = 1;
    387 
    388         // arrowhead parameters
    389         private float  _arrowheadLength  = 0;
    390         private double _arrowheadRatio   = DEFAULT_ARROWHEAD_RATIO;
    391         private double _arrowheadNibPerc = DEFAULT_ARROWHEAD_NIB_PERC;
    392        
    393         private Polygon _arrowhead = null;
    394 
    395         // the list of lines that this point is part of.
    396         private List<Line> _lines = new ArrayList<Line>();
    397 
    398         private int[] _linePattern = null;
    399 
    400         private boolean _floating = false;
    401 
    402         // list of points constrained with this point
    403         private List<Constraint> _constraints = new ArrayList<Constraint>();
    404 
    405         private List<String> _actions = null;
    406 
    407         private List<String> _data = null;
    408 
    409         private String _formula = null;
    410 
    411         private String _link_frameset = null;
    412 
    413         private String _link_template = null;
    414 
    415         private String _fillPattern = null;
    416 
    417         private boolean _visible = true;
    418 
    419         private float _thickness = -1.0F;
    420 
    421514        protected Item() {
    422515                _creationDate = Formatter.getLongDateTime();
     
    427520         *
    428521         * @param action
    429          *            The action to add to this Item
    430          */
    431         public void addAction(String action) {
    432                 if (action == null || action.equals("")) {
    433                         return;
    434                 }
     522         *            The name of the action to add to this Item.
     523         */
     524        public void addAction(String action)
     525        {
     526                if (action == null || action.equals("")) return;
    435527
    436528                if (_actions == null) {
    437529                        _actions = new LinkedList<String>();
    438530                }
     531               
    439532                _actions.add(action);
     533               
    440534                if (_actions.size() == 1) {
    441                         _poly = null;
     535                        invalidateBounds();
    442536                        invalidateCommonTrait(ItemAppearence.LinkChanged);
    443537                }
    444538        }
    445539
    446         public void addAllConnected(Collection<Item> connected) {
    447                 if (!connected.contains(this))
    448                         connected.add(this);
     540        public void addAllConnected(Collection<Item> connected)
     541        {
     542                if (!connected.contains(this)) connected.add(this);
    449543
    450544                for (Item item : getConnected()) {
    451                         if (!connected.contains(item))
     545                        if (!connected.contains(item)) {
    452546                                item.addAllConnected(connected);
     547                        }
    453548                }
    454549        }
     
    460555         *            The Constraint to set this Dot as a member of.
    461556         */
    462         public void addConstraint(Constraint c) {
     557        public void addConstraint(Constraint c)
     558        {
    463559                // do not add duplicate constraint
    464560                if (_constraints.contains(c))
     
    474570         *            The Line that this Point is an end of.
    475571         */
    476         public void addLine(Line line) {
     572        public void addLine(Line line)
     573        {
    477574                if (_lines.contains(line)) {
    478575                        return;
     
    490587         *         less than, equal to, or greater than the specified object.
    491588         */
    492         public int compareTo(Item i) {
     589        public int compareTo(Item i)
     590        {
    493591                return getY() - i.getY();
    494592        }
     
    499597         * the area and false otherwise.
    500598         *
    501          * @param x
    502          *            The x coordinate to check
    503          * @param y
    504          *            The y coordinate to check
     599         * @param p
     600         *            The coordinate to check
    505601         * @return True if the Shape around this Item contains the given x,y pair,
    506602         *         false otherwise.
    507603         */
    508         public boolean contains(int x, int y) {
    509                 return getPolygon().contains(x, y);
     604        public boolean contains(Point p)
     605        {
     606                return getBounds().contains(p);
    510607        }
    511608
     
    518615        public abstract Item copy();
    519616
    520         public void delete() {
     617        public void delete()
     618        {
    521619                _deleted = true;
    522620        }
    523621
    524622        @Override
    525         public boolean equals(Object o) {
     623        public boolean equals(Object o)
     624        {
    526625                if (o == null)
    527626                        return false;
     
    542641         *         has been assigned.
    543642         */
    544         public List<String> getAction() {
     643        public List<String> getAction()
     644        {
    545645                return _actions;
    546646        }
    547647
    548         public List<String> getData() {
     648        public List<String> getData()
     649        {
    549650                return _data;
    550651        }
    551652
    552         public List<String> getActionCursorEnter() {
     653        public List<String> getActionCursorEnter()
     654        {
    553655                return _actionCursorEnter;
    554656        }
    555657
    556         public List<String> getActionCursorLeave() {
     658        public List<String> getActionCursorLeave()
     659        {
    557660                return _actionCursorLeave;
    558661        }
    559662
    560         public List<String> getActionEnterFrame() {
     663        public List<String> getActionEnterFrame()
     664        {
    561665                return _actionEnterFrame;
    562666        }
    563667
    564         public List<String> getActionLeaveFrame() {
     668        public List<String> getActionLeaveFrame()
     669        {
    565670                return _actionLeaveFrame;
    566671        };
    567672
    568         public boolean getActionMark() {
     673        public boolean getActionMark()
     674        {
    569675                return _actionMark;
    570676        }
     
    576682         * @return
    577683         */
    578         public Collection<Item> getAllConnected() {
     684        public Collection<Item> getAllConnected()
     685        {
    579686                Collection<Item> list = new LinkedHashSet<Item>();
    580687                addAllConnected(list);
     
    582689        }
    583690
    584         public Area getArea() {
     691/*      public Area getArea() {
    585692                return new Area(getPolygon());
    586         }
    587 
    588         public String getArrow() {
     693        }*/
     694
     695        public String getArrow()
     696        {
    589697                if (!hasVisibleArrow())
    590698                        return null;
     
    597705        }
    598706
    599         public Polygon getArrowhead() {
     707        public PolygonBounds getArrowhead()
     708        {
    600709                return _arrowhead;
    601710        }
    602711
    603         public float getArrowheadLength() {
     712        public float getArrowheadLength()
     713        {
    604714                return _arrowheadLength;
    605715        }
    606716
    607         public double getArrowheadRatio() {
     717        public double getArrowheadRatio()
     718        {
    608719                return _arrowheadRatio;
    609720        }
    610721
    611         public double getArrowheadNibPerc() {
     722        public double getArrowheadNibPerc()
     723        {
    612724                return _arrowheadNibPerc;
    613725        }
    614726       
    615         public Color getBackgroundColor() {
    616                 return _colorBackground;
    617         }
    618 
    619         public Color getBorderColor() {
     727        public Colour getBackgroundColor()
     728        {
     729                return _backgroundColour;
     730        }
     731
     732        public Colour getBorderColor()
     733        {
    620734                return _colorBorder;
    621735        }
     
    628742         *         border.
    629743         */
    630         public Color getBottomShadowColor() {
     744        public Colour getBottomShadowColor()
     745        {
    631746                return _colorBottomShadow;
    632747        }
     
    638753         *         returned by getArea().
    639754         */
    640         public int getBoundsHeight() {
    641                 return getPolygon().getBounds().height;
     755        public int getBoundsHeight()
     756        {
     757                return AxisAlignedBoxBounds.getEnclosing(getBounds()).getHeight();
    642758        }
    643759
     
    648764         *         by getArea().
    649765         */
    650         public int getBoundsWidth() {
    651                 return getPolygon().getBounds().width;
    652         }
    653 
    654         // TODO draw the link with a circle rather than a polygon!!
    655         public Polygon getLinkPoly() {
    656                 if (_circle == null) {
    657                         int points = 16;
    658 
    659                         double radians = 0.0;
    660                         int xPoints[] = new int[points];
    661                         int yPoints[] = new int[xPoints.length];
    662 
    663                         for (int i = 0; i < xPoints.length; i++) {
    664                                 // circle looks best if these values are not related to gravity
    665                                 xPoints[i] = (int) (3.5 * Math.cos(radians)) + 6;// (2 *
    666                                 // GRAVITY);
    667                                 yPoints[i] = (int) (3.5 * Math.sin(radians)) + 3;// GRAVITY;
    668                                 radians += (2.0 * Math.PI) / xPoints.length;
    669                         }
    670 
    671                         _circle = new Polygon(xPoints, yPoints, xPoints.length);
    672                 }
    673 
    674                 return _circle;
    675         }
    676 
    677         protected Polygon getCircleCross() {
    678 
    679                 if (_circleCross == null) {
    680                         _circleCross = new Polygon();
    681 
    682                         Rectangle bounds = getLinkPoly().getBounds();
    683                         int x1 = (int) bounds.getMinX();
    684                         int x2 = (int) bounds.getMaxX();
    685                         int y1 = (int) bounds.getMinY();
    686                         int y2 = (int) bounds.getMaxY();
    687                         int midX = ((x2 - x1) / 2) + x1;
    688                         int midY = ((y2 - y1) / 2) + y1;
    689 
    690                         _circleCross.addPoint(x1, y1);
    691                         _circleCross.addPoint(x2, y2);
    692                         _circleCross.addPoint(midX, midY);
    693                         _circleCross.addPoint(x1, y2);
    694                         _circleCross.addPoint(x2, y1);
    695                         _circleCross.addPoint(midX, midY);
    696                 }
    697 
    698                 return _circleCross;
    699         }
    700 
    701         public Color getColor() {
    702                 return _color;
    703         }
    704 
    705         public Collection<Item> getConnected() {
     766        public int getBoundsWidth()
     767        {
     768                return AxisAlignedBoxBounds.getEnclosing(getBounds()).getWidth();
     769        }
     770
     771        // TODO: Remove magic constants. cts16
     772        public EllipticalBounds getLinkBounds()
     773        {
     774                if (_linkCircle == null) {
     775                        _linkCircle = new EllipticalBounds(new Point(6, 3), 7);
     776                }
     777
     778                return _linkCircle;
     779        }
     780
     781        protected PolygonBounds getCircleCross()
     782        {
     783
     784                if (_linkCircleCross == null) {
     785                        _linkCircleCross = new PolygonBounds();
     786
     787                        EllipticalBounds poly = getLinkBounds();
     788                        int x1 = poly.getMinX();
     789                        int x2 = poly.getMaxX();
     790                        int y1 = poly.getMinY();
     791                        int y2 = poly.getMaxY();
     792                        int midX = (x2 + x1) / 2;
     793                        int midY = (y2 + y1) / 2;
     794
     795                        _linkCircleCross.addPoint(new Point(x1, y1));
     796                        _linkCircleCross.addPoint(new Point(x2, y2));
     797                        _linkCircleCross.addPoint(new Point(midX, midY));
     798                        _linkCircleCross.addPoint(new Point(x1, y2));
     799                        _linkCircleCross.addPoint(new Point(x2, y1));
     800                        _linkCircleCross.addPoint(new Point(midX, midY));
     801                }
     802
     803                return _linkCircleCross;
     804        }
     805
     806        public Colour getColor()
     807        {
     808                return _foregroundColour;
     809        }
     810
     811        public Collection<Item> getConnected()
     812        {
    706813                List<Item> conn = new LinkedList<Item>();
    707814                conn.add(this);
     
    711818        }
    712819
    713         public String getConstraintIDs() {
     820        public String getConstraintIDs()
     821        {
    714822                if (_constraints == null || _constraints.size() == 0)
    715823                        return null;
     
    732840         * @return a List of Constraints that this Dot is a member of.
    733841         */
    734         public List<Constraint> getConstraints() {
     842        public List<Constraint> getConstraints()
     843        {
    735844                return _constraints;
    736845        }
    737846
    738         public String getTag() {
     847        public String getTag()
     848        {
    739849                if (_tag != null && _tag.length() > 0)
    740850                        return _tag.toString();
     
    742852        }
    743853
    744         public String getDateCreated() {
     854        public String getDateCreated()
     855        {
    745856                return _creationDate;
    746857        }
    747858
    748         public Color getFillColor() {
    749                 return _colorFill;
    750         }
    751 
    752         public String getFillPattern() {
     859        public Colour getFillColor()
     860        {
     861                return _fillColour;
     862        }
     863
     864        public String getFillPattern()
     865        {
    753866                return _fillPattern;
    754867        }
    755868
    756         public String getFirstAction() {
     869        public String getFirstAction()
     870        {
    757871                if (_actions == null || _actions.size() == 0)
    758872                        return null;
     
    760874        }
    761875
    762         public boolean getHighlight() {
     876        /**
     877         * Gets the value of <code>_highlight</code> for this item.
     878         * TODO: Appears unused? cts16.
     879         *
     880         * @return The value of <code>_highlight</code>.
     881         */
     882        public boolean getHighlight()
     883        {
    763884                return _highlight;
    764885        }
    765886
    766         public Color getHighlightColor() {
    767                 if (_highlightColor.equals(getPaintColor()))
    768                         return getAlternateHighlightColor();
     887        public Colour getHighlightColor()
     888        {
     889                if (_highlightColour.equals(getPaintColor())) return getAlternateHighlightColor();
     890               
    769891                return getDefaultHighlightColor();
    770892        }
     
    774896         *
    775897         * @return The ID of this Item.
    776          */
    777         public int getID() {
     898         *
     899         * TODO: What does it mean to have a negative ID# (as used in TDFC)? cts16
     900         */
     901        public int getID()
     902        {
    778903                return _id;
    779904        }
     
    784909         * @return The list of Line IDs that this point is part of.
    785910         */
    786         public String getLineIDs() {
     911        public String getLineIDs()
     912        {
    787913                String lineID = null;
    788914
     
    797923        }
    798924
    799         public int[] getLinePattern() {
     925        public int[] getLinePattern()
     926        {
    800927                return _linePattern;
    801928        }
     
    807934         *         Lines have been added.
    808935         */
    809         public List<Line> getLines() {
     936        public List<Line> getLines()
     937        {
    810938                return _lines;
    811939        }
     
    818946         *         this Item does not link to anything.
    819947         */
    820         public String getLink() {
     948        public String getLink()
     949        {
    821950                return _link;
    822951        }
    823952
    824         public String getFormula() {
     953        public String getFormula()
     954        {
    825955                return _formula;
    826956        }
    827957
    828         public boolean hasFormula() {
     958        public boolean hasFormula()
     959        {
    829960                return _formula != null;
    830961        }
    831962
    832         public boolean hasAttributeValuePair() {
     963        public boolean hasAttributeValuePair()
     964        {
    833965                return _attributeValuePair != null && _attributeValuePair.hasPair();
    834966        }
    835967
    836         public void setFormula(String formula) {
     968        public void setFormula(String formula)
     969        {
    837970                _formula = formula;
    838971        }
    839972
    840         public boolean calculate(String formula) {
     973        public boolean calculate(String formula)
     974        {
    841975                setFormula(formula);
    842976                return true;
    843977        }
    844978
    845         public String getLinkFrameset() {
     979        public String getLinkFrameset()
     980        {
    846981                return _link_frameset;
    847982        }
    848983
    849         public boolean getLinkMark() {
     984        public boolean getLinkMark()
     985        {
    850986                return _linkMark;
    851987        }
    852988
    853         public String getLinkTemplate() {
     989        public String getLinkTemplate()
     990        {
    854991                return _link_template;
    855992        }
    856993
    857         // public int getMaxWidth() {
     994        // public int getMaxWidth()
     995        // {
    858996        // return _maxWidth;
    859997        // }
    860998
    861         public Point getOffset() {
     999        public Point getOffset()
     1000        {
    8621001                return _offset;
    8631002        }
    8641003
    865         public String getOwner() {
     1004        public String getOwner()
     1005        {
    8661006                return _owner;
    8671007        }
    8681008
    869         public Color getPaintBackgroundColor() {
    870                 Color colorBackground = getBackgroundColor();
     1009        public Colour getPaintBackgroundColor()
     1010        {
     1011                Colour colorBackground = getBackgroundColor();
    8711012                if (colorBackground == null) {
    8721013                        if (getParent() != null && getParent().getBackgroundColor() != null)
     
    8841025         * @return The Color of this item (foreground)
    8851026         */
    886         public final Color getPaintColor() {
     1027        public final Colour getPaintColor()
     1028        {
    8871029                // If color is null then get the paint foregroundColor for the frame the
    8881030                // item is on which is a color adjusted to suit the background
    889                 Color color = getColor();
     1031                Colour color = getColor();
    8901032
    8911033                if (color == null) {
     
    8931035                                return getParent().getPaintForegroundColor();
    8941036
    895                         Frame current = DisplayIO.getCurrentFrame();
     1037                        Frame current = DisplayController.getCurrentFrame();
    8961038                        if (current == null) {
    8971039                                return DEFAULT_FOREGROUND;
     
    9031045        }
    9041046
    905         public final Color getPaintBorderColor() {
     1047        public final Colour getPaintBorderColor()
     1048        {
    9061049                // If color is null then get the paint foregroundColor for the frame the
    9071050                // item is on which is a color adjusted to suit the background
    908                 Color color = getBorderColor();
     1051                Colour color = getBorderColor();
    9091052
    9101053                if (color == null) {
     
    9121055                                return getParent().getPaintForegroundColor();
    9131056
    914                         Frame current = DisplayIO.getCurrentFrame();
     1057                        Frame current = DisplayController.getCurrentFrame();
    9151058                        if (current == null) {
    9161059                                return DEFAULT_FOREGROUND;
     
    9221065        }
    9231066
    924         protected Color getPaintHighlightColor() {
    925                 Color highlightColor = getDefaultHighlightColor();
     1067        protected Colour getPaintHighlightColor()
     1068        {
     1069                Colour highlightColor = getDefaultHighlightColor();
    9261070                if (hasVisibleBorder()) {
    9271071                        if (getPaintBorderColor().equals(highlightColor)) {
     
    9311075                        highlightColor = getDefaultHighlightColor();
    9321076                }
    933                 if (getParent() != null
    934                                 && getParent().getPaintBackgroundColor().equals(highlightColor))
     1077               
     1078                if (getParent() != null && getParent().getPaintBackgroundColor().equals(highlightColor)) {
    9351079                        highlightColor = getParent().getPaintForegroundColor();
     1080                }
    9361081
    9371082                if (hasVisibleBorder()) {
    938                         if (highlightColor.equals(getBorderColor())
    939                                         && getThickness() == getHighlightThickness()) {
    940                                 highlightColor = new Color(highlightColor.getRed(),
    941                                                 highlightColor.getGreen(), highlightColor.getBlue(),
    942                                                 150);
     1083                        if (highlightColor.equals(getBorderColor()) && getThickness() == getHighlightThickness()) {
     1084                                highlightColor = highlightColor.clone();
     1085                                highlightColor.setAlpha(Colour.FromComponent255(150));
    9431086                        }
    9441087                }
     
    9471090        }
    9481091
    949         static final int BRIGHTNESS = 185;
    950 
    951         protected Color getDefaultHighlightColor() {
    952                 if (isVectorItem()
    953                                 && !this.contains(FrameMouseActions.getX(), FrameMouseActions
    954                                                 .getY())) {
    955                         return new Color(255, BRIGHTNESS, BRIGHTNESS);
    956                 }
    957                 return _highlightColor;
    958         }
    959 
    960         protected Color getAlternateHighlightColor() {
    961                 if (isVectorItem()
    962                                 && !this.contains(FrameMouseActions.getX(), FrameMouseActions
    963                                                 .getY())) {
    964                         return new Color(BRIGHTNESS, BRIGHTNESS, 255);
     1092        protected Colour getDefaultHighlightColor()
     1093        {
     1094                if (isVectorItem() && !this.contains(EcosystemManager.getInputManager().getCursorPosition())) {
     1095                        return Colour.FromRGB255(255, BRIGHTNESS, BRIGHTNESS);
     1096                }
     1097                return _highlightColour;
     1098        }
     1099
     1100        protected Colour getAlternateHighlightColor()
     1101        {
     1102                if (isVectorItem() && !this.contains(EcosystemManager.getInputManager().getCursorPosition())) {
     1103                        return Colour.FromRGB255(BRIGHTNESS, BRIGHTNESS, 255);
    9651104                }
    9661105                return ALTERNATE_HIGHLIGHT;
    9671106        }
    9681107
    969         protected int getHighlightThickness() {
    970                 if (isVectorItem())
    971                         return _vectorHighlightThickness;
     1108        protected int getHighlightThickness()
     1109        {
     1110                if (isVectorItem()) return _vectorHighlightThickness;
     1111               
    9721112                return _highlightThickness;
    9731113        }
    9741114
    975         public final Frame getParent() {
     1115        public final Frame getParent()
     1116        {
    9761117                return _parent;
    9771118        }
    9781119
    979         public final Point getPosition() {
     1120        /** Gets the position of this item. */
     1121        public final Point getPosition()
     1122        {
    9801123                return new Point(getX(), getY());
    9811124        }
     
    9871130         * @return The size of this Item.
    9881131         */
    989         public float getSize() {
    990                 return -1.0F;
     1132        public float getSize()
     1133        {
     1134                return SIZE_NOT_APPLICABLE;
    9911135        }
    9921136
     
    9971141         * @return The Color displayed on the top\left half of this Item's border.
    9981142         */
    999         public Color getTopShadowColor() {
     1143        public Colour getTopShadowColor()
     1144        {
    10001145                return _colorTopShadow;
    10011146        }
    10021147
    1003         public String getTypeAndID() {
     1148        public String getTypeAndID()
     1149        {
    10041150                return "T " + getID();
    10051151        }
    10061152
    1007         public Integer getWidthToSave() {
     1153        public Integer getWidthToSave()
     1154        {
    10081155                return getWidth();
    10091156        }
    10101157
    1011         public Integer getWidth() {
     1158        public Integer getWidth()
     1159        {
    10121160                return null;
    10131161        }
    10141162
    1015         public int getHeight() {
     1163        public int getHeight()
     1164        {
    10161165                return 0;
    10171166        }
     
    10221171         * @return The X coordinate of this Item on the screen
    10231172         */
    1024         public int getX() {
     1173        public int getX()
     1174        {
    10251175                return Math.round(_x);
    10261176        }
     
    10311181         * @return The Y coordinate of this Item on the screen
    10321182         */
    1033         public int getY() {
     1183        public int getY()
     1184        {
    10341185                return Math.round(_y);
    10351186        }
    10361187
    1037         public boolean hasVisibleArrow() {
     1188        public boolean hasVisibleArrow()
     1189        {
    10381190                return isLineEnd() && getArrowheadRatio() != 0 && getArrowheadLength() != 0;
    10391191        }
     
    10461198         * @return True if the two Shapes overlap, False otherwise.
    10471199         */
    1048         public boolean intersects(Polygon p) {
    1049                 if (p == null)
    1050                         return false;
    1051 
    1052                 Area a = new Area(p);
    1053                 Area thisArea = this.getArea();
     1200        public boolean intersects(PolygonBounds otherBounds)
     1201        {
     1202                if (otherBounds == null) return false;
     1203               
     1204                Bounds thisBounds = getBounds();
     1205               
    10541206                // Need to do this check for circles
    1055                 if (a.equals(thisArea))
    1056                         return true;
    1057 
    1058                 a.intersect(thisArea);
     1207                if (otherBounds.equals(thisBounds)) return true;
     1208
     1209                return otherBounds.intersects(thisBounds);
    10591210
    10601211                // Need to check the second equality so that we dont pick up circles
    10611212                // inside other circles
    1062                 return !a.isEmpty() && !a.equals(new Area(p));
     1213                //return !a.isEmpty() && !a.equals(new Area(p));
    10631214        }
    10641215
     
    10691220         * @return True if this Item is an annotation, False otherwise.
    10701221         */
    1071         public boolean isAnnotation() {
     1222        public boolean isAnnotation()
     1223        {
    10721224                return false;
    10731225        }
    10741226
    1075         public boolean isFloating() {
     1227        public boolean isFloating()
     1228        {
    10761229                return _floating;
    10771230        }
    10781231
    1079         public boolean isFrameName() {
     1232        public boolean isFrameName()
     1233        {
    10801234                if (this.getParent() == null || this.getParent().getNameItem() != this)
    10811235                        return false;
     
    10831237        }
    10841238
    1085         public boolean isFrameTitle() {
     1239        public boolean isFrameTitle()
     1240        {
    10861241                if (this.getParent() == null || this.getParent().getTitleItem() != this)
    10871242                        return false;
     
    10951250         *         otherwise.
    10961251         */
    1097         public boolean isHighlighted() {
     1252        public boolean isHighlighted()
     1253        {
    10981254                if (isFloating())
    10991255                        return false;
    1100                 return _mode != HighlightMode.None;
     1256                return _highlightMode != HighlightMode.None;
    11011257        }
    11021258
     
    11091265         * @return True if the given framename is proper, false otherwise.
    11101266         */
    1111         public boolean isLinkValid() {
     1267        public boolean isLinkValid()
     1268        {
    11121269                if (FrameIO.isPositiveInteger(getLink()))
    11131270                        return true;
     
    11181275        }
    11191276
    1120         public boolean isNear(int x, int y) {
    1121 
    1122                 int xLeft = getPolygon().getBounds().x;
    1123                 int yTop = getPolygon().getBounds().y;
    1124 
    1125                 return (x > xLeft - NEAR_DISTANCE && y > yTop - NEAR_DISTANCE
    1126                                 && x < xLeft + getBoundsWidth() + NEAR_DISTANCE && y < yTop
    1127                                 + getBoundsHeight() + NEAR_DISTANCE);
    1128         }
    1129 
    1130         public boolean isOldTag() {
     1277        /**
     1278         * Checks if the given point is 'near' to the item. Here 'near' means within a certain distance
     1279         * of the axis-aligned box bounding the item's polygon.
     1280         *
     1281         * @param x
     1282         *              The x-coordinate of the point to check.
     1283         *
     1284         * @param y
     1285         *              The y-coordinate of the point to check.
     1286         *
     1287         * @return
     1288         *              True if the given point is 'near' to the item, false otherwise.
     1289         */
     1290        public boolean isNear(int x, int y)
     1291        {
     1292                AxisAlignedBoxBounds box = ItemUtils.expandRectangle(getBoundingBox(), NEAR_DISTANCE * 2);
     1293               
     1294                return box.contains(x, y);
     1295        }
     1296
     1297        public boolean isOldTag()
     1298        {
    11311299                if (this instanceof Text)
    11321300                        if (((Text) this).getTextList().get(0).toLowerCase().equals("@old"))
     
    11531321         *            The Graphics to draw this Item on.
    11541322         */
    1155         public abstract void paint(Graphics2D g);
    1156        
    1157         public void setTooltips(final List<String> tooltips) {
    1158                 if(tooltips == null || tooltips.size() == 0) _tooltip = new Tooltip();
    1159                 else for(final String content: tooltips) _tooltip.addTooltip(content, this);
    1160         }
    1161        
    1162         public void setTooltip(final String tooltip) {
     1323        public abstract void paint();
     1324       
     1325        public void setTooltips(final List<String> tooltips)
     1326        {
     1327                if (tooltips == null || tooltips.size() == 0) {
     1328                        _tooltip = new Tooltip();
     1329                } else {
     1330                        for (final String content: tooltips) _tooltip.addTooltip(content, this);
     1331                }
     1332        }
     1333       
     1334        public void setTooltip(final String tooltip)
     1335        {
    11631336                if(tooltip != null && tooltip.trim().length() > 0) {
    11641337                        _tooltip.addTooltip(tooltip, this);
     
    11661339        }
    11671340       
    1168         public List<String> getTooltip() {
     1341        public List<String> getTooltip()
     1342        {
    11691343                return _tooltip.asStringList();
    11701344        }
    11711345       
    1172         public Collection<Text> getTooltipItems() {
     1346        public Collection<Text> getTooltipItems()
     1347        {
    11731348                return _tooltip.getTooltips();
    11741349        }
    11751350
    1176         public void clearTooltips() {
     1351        public void clearTooltips()
     1352        {
    11771353                final Frame frame = this.getParent();
    1178                 if(_tooltip != null)
     1354                if(_tooltip != null) {
    11791355                        for(final Text tooltip: _tooltip.getTooltips()) frame.removeItem(tooltip);
    1180         }
    1181        
    1182         public void paintTooltip(final Graphics2D g) {
    1183                 final Rectangle bounds = this.getPolygon().getBounds();
    1184                 int x = bounds.x + bounds.width;
    1185                 if(x + _tooltip.getWidth() > FrameGraphics.getMaxFrameSize().width) {
    1186                         x -= x + _tooltip.getWidth() - FrameGraphics.getMaxFrameSize().width;
    1187                 }
    1188                 int y = bounds.y + bounds.height;
    1189                 if(y + _tooltip.getCollectiveHeight() > FrameGraphics.getMaxFrameSize().height) {
    1190                         y = bounds.y + bounds.height / 2 - _tooltip.getCollectiveHeight();
    1191                 }
     1356                }
     1357        }
     1358       
     1359        public void paintTooltip()
     1360        {
     1361                final Bounds bounds = AxisAlignedBoxBounds.getEnclosing(this.getBoundingBox());
     1362                Dimension frameSize = DisplayController.getFramePaintArea().getSize();
     1363               
     1364                int x = bounds.getMaxX();
     1365               
     1366                // If the tooltip goes off the right side of the window, move it left so it's completely on
     1367                if(x + _tooltip.getWidth() > frameSize.getWidth()) {
     1368                        x = frameSize.getWidth() - _tooltip.getWidth();
     1369                }
     1370               
     1371                int y = bounds.getMaxY();
     1372               
     1373                if(y + _tooltip.getCollectiveHeight() > frameSize.getHeight()) {
     1374                        y = (bounds.getMinY() + bounds.getMaxY()) / 2 - _tooltip.getCollectiveHeight();
     1375                }
     1376               
    11921377                for(final Text tooltip : _tooltip.getTooltips()) {
    11931378                        this.getParent().addItem(tooltip);
    11941379                        tooltip.setPosition(x, y);
    1195                         tooltip.paint(g);
     1380                        tooltip.paint();
    11961381                        y += tooltip.getHeight();
    11971382                }
    11981383        }
    11991384       
    1200         public void paintFill(Graphics2D g) {
    1201                 Color fillColor = getFillColor();
     1385        public void paintFill() {
     1386                Colour fillColor = getFillColor();
    12021387                if (fillColor != null && getEnclosingDots() != null) {
    1203                         setFillPaint(g);
    1204                         g.fillPolygon(getEnclosedShape());
    1205                 }
    1206         }
    1207 
    1208         protected void setFillPaint(Graphics2D g) {
    1209                 Color fillColor = getFillColor();
     1388                        Fill fill = getFill();
     1389                        EcosystemManager.getGraphicsManager().drawPolygon(getEnclosedShape(), null, null, 0.0f, fill, null, null);
     1390                }
     1391        }
     1392
     1393        protected Fill getFill() {
     1394                Fill fill;
     1395                Colour fillColour = getFillColor();
    12101396                if (isFloating()) {
    12111397                        // TODO experiment with adding alpha when picking up filled
    12121398                        // items... Slows things down quite alot!!
    1213                         fillColor = new Color(fillColor.getRed(), fillColor.getGreen(),
    1214                                         fillColor.getBlue(), fillColor.getAlpha());
    1215                 }
    1216                 g.setColor(fillColor);
    1217                 Color gradientColor = getGradientColor();
    1218                 if (gradientColor != null) {
     1399                        // TODO: Does nothing as it stands... cts16
     1400                        fillColour = new Colour(fillColour.getRed(), fillColour.getGreen(),
     1401                                        fillColour.getBlue(), fillColour.getAlpha());
     1402                }
     1403                Colour gradientColor = getGradientColor();
     1404                PolygonBounds poly = getEnclosedShape();
     1405                if (gradientColor != null && poly != null) {
    12191406                        /*
    12201407                         * It is slow when painting gradients... modify so this is only done
    12211408                         * once unless it is resized...
    12221409                         */
    1223                         Shape s = getEnclosedShape();
    1224                         if (s != null) {
    1225                                 Rectangle b = s.getBounds();
    1226                                 double rads = getGradientAngle() * Math.PI / 180;
    1227                                 double cos = Math.cos(rads);
    1228                                 double sin = Math.sin(rads);
    1229 
    1230                                 GradientPaint gp = new GradientPaint((int) (b.x + b.width
    1231                                                 * (0.2 * cos + 0.5)), (int) (b.y + b.height
    1232                                                 * (0.2 * sin + 0.5)), fillColor, (int) (b.x + b.width
    1233                                                 * (-0.8 * cos + 0.5)), (int) (b.y + b.height
    1234                                                 * (-0.8 * sin + 0.5)), gradientColor);
    1235                                 g.setPaint(gp);
    1236                         }
    1237                 }
     1410                        AxisAlignedBoxBounds b = AxisAlignedBoxBounds.getEnclosing(poly);
     1411                        double rads = getGradientAngle();
     1412                        double cos = Math.cos(rads);
     1413                        double sin = Math.sin(rads);
     1414
     1415                        Point fromPoint = new Point((int) (b.getMinX() + b.getWidth() * (0.2 * cos + 0.5)), (int) (b.getMinY() + b.getHeight() * (0.2 * sin + 0.5)));
     1416                        Point toPoint = new Point((int) (b.getMinX() + b.getWidth() * (-0.8 * cos + 0.5)), (int) (b.getMinY() + b.getHeight() * (-0.8 * sin + 0.5)));
     1417                       
     1418                        fill = new GradientFill(fillColour, fromPoint, gradientColor, toPoint);
     1419                } else {
     1420                        fill = new Fill(fillColour);
     1421                }
     1422               
     1423                return fill;
    12381424        }
    12391425
    12401426        /**
    12411427         * This method performs all the actions in an items list. If it contains a
    1242          * link as well the link is used as the source frame for all acitons.
     1428         * link as well the link is used as the source frame for all actions.
    12431429         */
    12441430        public void performActions() {
     
    12681454                        // For actions like format they rely on this being set to the
    12691455                        // current frame incase the item being activated is on an overlay
    1270                         sourceFrame = DisplayIO.getCurrentFrame();
     1456                        sourceFrame = DisplayController.getCurrentFrame();
    12711457                }
    12721458
     
    13881574                        MessageBay.displayMessage("See SIMPLE doc for ["
    13891575                                        + ise.getStatement() + "] statement", ise.getStatement()
    1390                                         + "1", Color.CYAN.darker(), true, null);
     1576                                        + "1", Colour.CYAN.darker(), true, null);
    13911577                } catch (Exception e) {
    13921578                        MessageBay.linkedErrorMessage(e.getMessage());
     
    13941580                Simple.ProgramFinished();
    13951581                // Need to repaint any highlights etc
    1396                 FrameGraphics.requestRefresh(true);
     1582                DisplayController.requestRefresh(true);
    13971583        }
    13981584
     
    14141600
    14151601                if (_parent == null)
    1416                         framesetName = DisplayIO.getCurrentFrame().getFramesetName();
     1602                        framesetName = DisplayController.getCurrentFrame().getFramesetName();
    14171603                else
    14181604                        framesetName = _parent.getFramesetName();
     
    14281614         *            The lines of code to associate with this Item
    14291615         */
    1430         public void setActions(List<String> actions) {
     1616        public void setActions(List<String> actions)
     1617        {
    14311618                if (actions == null || actions.size() == 0) {
    14321619                        invalidateCommonTrait(ItemAppearence.LinkChanged);
    14331620                        _actions = null;
    1434                 } else
     1621                } else {
    14351622                        _actions = new LinkedList<String>(actions);
    1436 
    1437                 // Want to resize the highlight box for text items if actions have been
    1438                 // added
    1439                 _poly = null;
     1623                }
     1624               
     1625                // Want to resize the highlight box for text items if actions have been added
     1626                invalidateBounds();
    14401627                invalidateCommonTrait(ItemAppearence.LinkChanged);
    14411628        }
     
    14811668        }
    14821669
    1483         public void setActionMark(boolean val) {
    1484                 if (!val)
    1485                         invalidateCommonTrait(ItemAppearence.LinkChanged);
    1486                 _poly = null;
     1670        public void setActionMark(boolean val)
     1671        {
     1672                if (!val) invalidateCommonTrait(ItemAppearence.LinkChanged);
     1673                invalidateBounds();
    14871674                _actionMark = val;
    1488                 if (val)
    1489                         invalidateCommonTrait(ItemAppearence.LinkChanged);
     1675                if (val) invalidateCommonTrait(ItemAppearence.LinkChanged);
    14901676        }
    14911677
     
    15191705        }
    15201706       
    1521         public void setArrowhead(Polygon arrow) {
     1707        public void setArrowhead(PolygonBounds arrow) {
    15221708                _arrowhead = arrow;
    15231709        }
     
    15381724        }
    15391725
    1540         public void setBackgroundColor(Color c) {
    1541                 if (c != _colorBackground) {
    1542                         _colorBackground = c;
     1726        public void setBackgroundColor(Colour c) {
     1727                if (c != _backgroundColour) {
     1728                        _backgroundColour = c;
    15431729                        invalidateCommonTrait(ItemAppearence.BackgroundColorChanged);
    15441730                }
    15451731        }
    15461732
    1547         public void setBorderColor(Color c) {
     1733        public void setBorderColor(Colour c) {
    15481734                if (c != _colorBorder) {
    15491735                        _colorBorder = c;
     
    15601746         *            Item's border.
    15611747         */
    1562         public void setBottomShadowColor(Color bottom) {
     1748        public void setBottomShadowColor(Colour bottom) {
    15631749                _colorBottomShadow = bottom;
    15641750        }
     
    15691755         * @param c
    15701756         */
    1571         public void setColor(Color c) {
    1572                 if (c != _color) {
    1573                         _color = c;
     1757        public void setColor(Colour c) {
     1758                if (c != _foregroundColour) {
     1759                        _foregroundColour = c;
    15741760                        invalidateCommonTrait(ItemAppearence.ForegroundColorChanged);
    15751761                        if (hasVector()) {
    15761762                                // TODO make this more efficient so it only repaints the items
    15771763                                // for this vector
    1578                                 FrameKeyboardActions.Refresh();
     1764                                StandardGestureActions.Refresh();
    15791765                        }
    15801766                }
     
    16051791        }
    16061792
    1607         public void setFillColor(Color c) {
    1608 
    1609                 _colorFill = c;
     1793        public void setFillColor(Colour c) {
     1794
     1795                _fillColour = c;
    16101796
    16111797                for (Line line : _lines) {
     
    16201806        }
    16211807
    1622         public void setGradientColor(Color c) {
    1623                 _colorGradient = c;
     1808        public void setGradientColor(Colour c)
     1809        {
     1810                _gradientColour = c;
    16241811
    16251812                for (Line line : _lines) {
     
    16331820        }
    16341821
    1635         public Color getGradientColor() {
    1636                 return _colorGradient;
     1822        public Colour getGradientColor() {
     1823                return _gradientColour;
    16371824        }
    16381825
     
    16471834        }
    16481835
     1836        /**
     1837         * Sets the value <code>_highlight</code> for this item.
     1838         * TODO: Appears unused? cts16
     1839         *
     1840         * @param val The new value for <code>_highlight</code>.
     1841         */
    16491842        public void setHighlight(boolean val) {
    16501843                _highlight = val;
     
    16931886         *            The name of the Frame to link this item to.
    16941887         */
    1695         public void setLink(String frameName) {
    1696                 if (frameName == null) {
    1697                         invalidateCommonTrait(ItemAppearence.LinkChanged);
    1698                 }
    1699 
    1700                 // If a link is being removed or set then need to reset poly so the
     1888        public void setLink(String frameName)
     1889        {
     1890                if (frameName == null) invalidateCommonTrait(ItemAppearence.LinkChanged);
     1891
     1892                // If a link is being removed or set then need to reset _bounds so the
    17011893                // highlighting is drawn with the correct width
    1702                 if (frameName == null || getLink() == null)
    1703                         _poly = null;
    1704 
    1705                 if (FrameIO.isValidLink(frameName))
     1894                if (frameName == null || getLink() == null) invalidateBounds();
     1895
     1896                if (FrameIO.isValidLink(frameName)) {
    17061897                        _link = frameName;
    1707                 else
    1708                         MessageBay.errorMessage("[" + frameName
    1709                                         + "] is not a valid frame name");
     1898                } else {
     1899                        MessageBay.errorMessage("[" + frameName + "] is not a valid frame name");
     1900                }
    17101901                // TODO make this throw exceptions etc...
    17111902
     
    17211912        }
    17221913
    1723         public void setLinkFrameset(String frameset) {
    1724                 if (frameset == null || FrameIO.isValidFramesetName(frameset))
     1914        public void setLinkFrameset(String frameset)
     1915        {
     1916                if (frameset == null || FrameIO.isValidFramesetName(frameset)) {
    17251917                        _link_frameset = frameset;
    1726                 else
    1727                         MessageBay.errorMessage("[" + frameset
    1728                                         + "] is not a valid frameset name");
     1918                } else {
     1919                        MessageBay.errorMessage("[" + frameset + "] is not a valid frameset name");
     1920                }
    17291921                // TODO make this throw exceptions etc...
    17301922        }
    17311923
    1732         public void setLinkMark(boolean val) {
    1733                 if (!val)
    1734                         invalidateCommonTrait(ItemAppearence.LinkChanged);
    1735                 _poly = null;
     1924        public void setLinkMark(boolean val)
     1925        {
     1926                if (!val) invalidateCommonTrait(ItemAppearence.LinkChanged);
     1927                invalidateBounds();
    17361928                _linkMark = val;
    1737                 if (val)
    1738                         invalidateCommonTrait(ItemAppearence.LinkChanged);
    1739         }
    1740 
    1741         public void setLinkTemplate(String template) {
    1742                 if (FrameIO.isValidLink(template))
     1929                if (val) invalidateCommonTrait(ItemAppearence.LinkChanged);
     1930        }
     1931
     1932        public void setLinkTemplate(String template)
     1933        {
     1934                if (FrameIO.isValidLink(template)) {
    17431935                        _link_template = template;
    1744                 else
    1745                         MessageBay.errorMessage("[" + template
    1746                                         + "] is not a valid frame name");
     1936                } else {
     1937                        MessageBay.errorMessage("[" + template + "] is not a valid frame name");
     1938                }
    17471939                // TODO make this throw exceptions etc...
    17481940        }
     
    17631955
    17641956        public void setOffset(int x, int y) {
    1765                 _offset.setLocation(x, y);
     1957                _offset.set(x, y);
    17661958        }
    17671959
    17681960        public void setOffset(Point p) {
    1769                 _offset.setLocation(p);
     1961                _offset.set(p);
    17701962        }
    17711963
     
    18051997                        }
    18061998                }
    1807                 if (_colorFill != null) {
     1999                if (_fillColour != null) {
    18082000                        invalidateFill(); // only invalidates if has fill
    18092001                }
     
    18142006        }
    18152007
    1816        
    1817        
    1818        
    1819        
    18202008        protected void anchorConstraints()
    18212009        {
     
    18302018                                        if (isAnchoredY()) {
    18312019                                                // Make the 'other' item have the same anchor top/bottom values as this
    1832                                                 other._anchorTop    = _anchorTop;
    1833                                                 other._anchorBottom = _anchorBottom;
     2020                                                other._anchoring.setYAnchor(this._anchoring);
    18342021                                        }
    18352022                                } else if (c.getType() == Constraint.VERTICAL) {
    18362023                                        if (isAnchoredX()) {
    18372024                                                // Make the 'other' item have the same anchor left/right values as this
    1838                                                 other._anchorLeft  = _anchorLeft;
    1839                                                 other._anchorRight = _anchorRight;
     2025                                                other._anchoring.setXAnchor(this._anchoring);
    18402026                                        }
    18412027                                } else if (c.isDiagonal()) {
     
    18552041         *            The new Y coordinate
    18562042         */
    1857         public void setPosition(float x, float y) {
     2043        public void setPosition(float x, float y)
     2044        {
    18582045                float deltaX = x - _x;
    18592046                float deltaY = y - _y;
    18602047
    1861                 if (deltaX == 0 && deltaY == 0)
    1862                         return;
     2048                if (deltaX == 0 && deltaY == 0) return;
    18632049
    18642050                invalidateCommonTraitForAll(ItemAppearence.PreMoved);
     
    18682054
    18692055                for (Item i : getEnclosures()) {
    1870                         i.updatePolygon();
    1871                 }
    1872                 updatePolygon();
     2056                        i.invalidateBounds();
     2057                }
     2058                invalidateBounds();
    18732059
    18742060                // update the position of any dots that are constrained by this one
     
    19512137
    19522138                for (Line line : getLines()) {
    1953                         line.updatePolygon();
     2139                        line.invalidateBounds();
    19542140                }
    19552141
     
    20072193         *            their thickness set
    20082194         */
    2009         public void setThickness(float thick, boolean setConnectedThickness) {
    2010                 if (thick == _thickness)
    2011                         return;
     2195        public void setThickness(float thick, boolean setConnectedThickness)
     2196        {
     2197                if (thick == _thickness) return;
     2198               
    20122199                boolean bigger = thick > _thickness;
    20132200
     
    20152202                        if (setConnectedThickness) {
    20162203                                // TODO is there a more efficient way of doing this?
    2017                                 for (Item i : getConnected())
    2018                                         i.invalidateCommonTrait(ItemAppearence.Thickness);
     2204                                for (Item i : getConnected()) i.invalidateCommonTrait(ItemAppearence.Thickness);
    20192205                        } else {
    20202206                                invalidateCommonTrait(ItemAppearence.Thickness);
     
    20282214                 * etc...
    20292215                 */
    2030                 for (Line line : getLines())
    2031                         line.setThickness(thick, setConnectedThickness);
    2032 
    2033                 if (setConnectedThickness)
    2034                         updatePolygon();
     2216                for (Line line : getLines()) line.setThickness(thick, setConnectedThickness);
     2217
     2218                if (setConnectedThickness) invalidateBounds();
    20352219
    20362220                if (bigger) {
    20372221                        if (setConnectedThickness) {
    2038                                 for (Item i : getConnected())
    2039                                         i.invalidateCommonTrait(ItemAppearence.Thickness);
     2222                                for (Item i : getConnected()) i.invalidateCommonTrait(ItemAppearence.Thickness);
    20402223                        } else {
    20412224                                invalidateCommonTrait(ItemAppearence.Thickness);
     
    20502233         *         set).
    20512234         */
    2052         public float getThickness() {
     2235        public float getThickness()
     2236        {
    20532237                return _thickness;
    20542238        }
     
    20622246         *            Item's border.
    20632247         */
    2064         public void setTopShadowColor(Color top) {
     2248        public void setTopShadowColor(Colour top) {
    20652249                _colorTopShadow = top;
    20662250        }
    20672251
    2068         public void setWidth(Integer width) throws UnsupportedOperationException {
    2069                 throw new UnsupportedOperationException(
    2070                                 "Item type does not support width attribute!");
    2071         }
    2072 
    2073         public void setRightMargin(int i, boolean fixWidth) {
     2252        public void setWidth(Integer width) throws UnsupportedOperationException
     2253        {
     2254                throw new UnsupportedOperationException("Item type does not support width attribute!");
     2255        }
     2256
     2257        public void setRightMargin(int i, boolean fixWidth)
     2258        {
    20742259                int newWidth = i - getX() - Item.MARGIN_LEFT;
     2260                if (newWidth < 0) newWidth = 0;
    20752261                if (!fixWidth) {
    20762262                        newWidth *= -1;
     
    21132299         *         means no change)
    21142300         */
    2115         public int setHighlightColor() {
    2116                 return setHighlightColor(DEFAULT_HIGHLIGHT);
    2117         }
    2118 
    2119         public int setHighlightColor(Color c) {
     2301       
     2302        /**
     2303         *
     2304         *
     2305         * @return
     2306         */
     2307        public void setHighlightColorToDefault() {
     2308                setHighlightColor(DEFAULT_HIGHLIGHT);
     2309        }
     2310
     2311        public void setHighlightColor(Colour c) {
     2312                if (c == null) return;
     2313               
    21202314                if (!this.isVisible() && this.hasVector()) {
    21212315                        for (Item i : this.getParentOrCurrentFrame().getVectorItems()) {
     
    21282322                _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;
    21292323
    2130                 Color selColor = (c != null) ? c : DEFAULT_HIGHLIGHT;
    2131                 if (_highlightColor != c) {
    2132                         _highlightColor = selColor;
     2324                Colour selColor = (c != null) ? c : DEFAULT_HIGHLIGHT;
     2325                if (_highlightColour != c) {
     2326                        _highlightColour = selColor;
    21332327                        this.invalidateCommonTrait(ItemAppearence.HighlightColorChanged);
    21342328                }
    2135 
    2136                 return Item.UNCHANGED_CURSOR;
    21372329
    21382330        }
     
    21462338        }
    21472339
    2148         public abstract void updatePolygon();
     2340        /** Returns a Bounds which represents the area covered by the item (including its gravity). */
     2341        public abstract Bounds updateBounds();
    21492342
    21502343        public void setHidden(boolean state) {
     
    21722365        }
    21732366
    2174         public void setHighlightMode(HighlightMode mode, Color color) {
    2175                 setHighlightColor(color);
    2176                 if (hasPermission(UserAppliedPermission.followLinks)
    2177                                 || getEditTarget().hasPermission(UserAppliedPermission.followLinks)) {
    2178                         if (_mode != mode) {
    2179                                 _mode = mode;
    2180                                 this.invalidateCommonTrait(ItemAppearence.HighlightModeChanged);
    2181                         }
    2182                 }
     2367        /**
     2368         * Sets the highlight mode and colour at the same time.
     2369         *
     2370         * @param mode The new highlight mode.
     2371         * @param colour The new highlight colour.
     2372         */
     2373        public void setHighlightModeAndColour(HighlightMode mode, Colour colour)
     2374        {
     2375                setHighlightMode(mode);
     2376                setHighlightColor(colour);
    21832377        }
    21842378
    21852379        public HighlightMode getHighlightMode() {
    2186                 return _mode;
     2380                return _highlightMode;
    21872381        }
    21882382
     
    21912385                // only set the id if we've moved to a different frame, or if the frame already has an item with that id
    21922386                if(!current.equals(_oldParent) || current.getItemWithID(getID()) != null) {
    2193                         int id = _id;
    21942387                        setID(current.getNextItemID());
    2195                         // System.out.println(this + " - Set ID to " + _id + " (was " + id + ")");
    21962388                } else {
    21972389                        // System.out.println(this + " - Kept old ID of " + _id);
     
    22392431                // if the item is from an overlay the parent will NOT be null
    22402432                if (getParent() == null) {
    2241                         return DisplayIO.getCurrentFrame();
     2433                        return DisplayController.getCurrentFrame();
    22422434                }
    22432435                return getParent();
     
    22752467         *         the enclosed list.
    22762468         */
    2277         public Polygon getEnclosedShape() {
    2278                 if (_enclosure == null)
    2279                         return null;
    2280 
    2281                 Polygon poly = new Polygon();
     2469        public PolygonBounds getEnclosedShape()
     2470        {
     2471                if (_enclosure == null) return null;
     2472
     2473                PolygonBounds poly = new PolygonBounds();
    22822474                for (Item d : _enclosure) {
    2283                         poly.addPoint(d.getX(), d.getY());
     2475                        poly.addPoint(new Point(d.getX(), d.getY()));
    22842476                }
    22852477
     
    23322524         *            the new color for the line
    23332525         */
    2334         protected void lineColorChanged(Color c) {
     2526        protected void lineColorChanged(Colour c) {
    23352527                for (Line l : getLines()) {
    23362528                        if (l.getColor() != c)
     
    23452537         */
    23462538        public boolean offScreenTopOrLeft() {
    2347                 Rectangle itemRect = getArea().getBounds();
     2539                Bounds bounds = getBoundingBox();
     2540               
    23482541                // Check that the bottom right corner of this item is on the screen
    2349                 if (itemRect.x + itemRect.width >= 0
    2350                                 && itemRect.y + itemRect.height >= 0)
     2542                if (bounds.getMaxX() >= 0 && bounds.getMaxY() >= 0) {
    23512543                        return false;
     2544                }
     2545               
    23522546                // Check if all the items it is connected to are offscreen
    23532547                for (Item i : getAllConnected()) {
    2354                         Rectangle iRect = i.getArea().getBounds();
     2548                        bounds = i.getBoundingBox();
    23552549                        // Check that the bottom right corner of this item is on the screen
    2356                         if (iRect.x + iRect.width >= 0 && iRect.y + iRect.height >= 0) {
     2550                        if (bounds.getMaxX() >= 0 && bounds.getMaxY() >= 0) {
    23572551                                return false;
    23582552                        }
    23592553                }
     2554               
    23602555                return true;
    23612556        }
     
    23742569        }
    23752570
    2376         public void setAction(String action) {
    2377                 // Want to resize the highlight box for text items if actions are been
    2378                 // added
     2571        public void setAction(String action)
     2572        {
     2573                // Want to resize the highlight box for text items if actions are been added
    23792574                if (action == null || action.length() == 0) {
    23802575                        invalidateCommonTrait(ItemAppearence.LinkChanged);
    23812576                }
     2577               
    23822578                if (_actions == null || _actions.size() == 0) {
    2383                         _poly = null;
     2579                        invalidateBounds();
    23842580                        _actions = new LinkedList<String>();
    23852581                } else {
    23862582                        _actions.clear();
    23872583                }
    2388                 if (action != null && action.length() > 0)
    2389                         _actions.add(action);
     2584               
     2585                if (action != null && action.length() > 0) _actions.add(action);
     2586               
    23902587                invalidateCommonTrait(ItemAppearence.LinkChanged);
    23912588        }
     
    23952592        }
    23962593
    2397         protected Rectangle getLinkDrawArea() {
     2594        protected AxisAlignedBoxBounds getLinkDrawArea() {
    23982595                return getLinkDrawArea(getX() - LEFT_MARGIN, getY() + getLinkYOffset());
    23992596        }
     
    24102607         * @return The drawing area of the link at the given coordinates.
    24112608         */
    2412         public Rectangle getLinkDrawArea(int x, int y) {
    2413                 return new Rectangle(x + 2, y - 1, 8, 8);
     2609        public AxisAlignedBoxBounds getLinkDrawArea(int x, int y) {
     2610                return new AxisAlignedBoxBounds(x + 2, y - 1, 8, 8);
    24142611        }
    24152612
     
    24192616         * @param g
    24202617         */
    2421         protected void paintLink(Graphics2D g) {
    2422                 paintLinkGraphic(g, getX() - LEFT_MARGIN, getY() + getLinkYOffset());
     2618        protected void paintLink() {
     2619                paintLinkGraphic(getX() - LEFT_MARGIN, getY() + getLinkYOffset());
    24232620        }
    24242621
     
    24382635         *            centered)
    24392636         */
    2440         public void paintLinkGraphic(Graphics2D g, int x, int y) {
    2441 
    2442                 boolean hasLink = getLink() != null;
     2637        public void paintLinkGraphic(int x, int y) {
     2638
     2639                boolean hasLink = hasLink();
    24432640                boolean hasAction = hasAction();
    24442641
    24452642                if (hasLink || hasAction) {
    2446                         g.setStroke(HIGHLIGHT_STROKE);
     2643                        GraphicsManager g = EcosystemManager.getGraphicsManager();
     2644                        Fill fill = new Fill();
     2645                        Colour colour = null;
     2646                        Point offset = new Point(x, y);
     2647                       
    24472648                        if (hasLink && hasAction) {
    2448                                 g.setColor(LINK_ACTION_COLOR);
     2649                                colour = LINK_ACTION_COLOR;
    24492650                        } else if (hasLink) {
    2450                                 g.setColor(LINK_COLOR);
     2651                                colour = LINK_COLOR;
    24512652                        } else if (hasAction) {
    2452                                 g.setColor(ACTION_COLOR);
     2653                                colour = ACTION_COLOR;
    24532654                        }
    2454 
    2455                         AffineTransform at = new AffineTransform();
    2456                         AffineTransform orig = g.getTransform();
    2457                         at.translate(x, y);
    2458                         g.setTransform(at);
    2459 
    2460                         if (getLinkMark() && getLink() != null) {
    2461                                 g.drawPolygon(getLinkPoly());
    2462 
     2655                        fill.setColour(colour);
     2656
     2657                        // Small circles look rubbish without AA. cts16
     2658                        g.setAntialiasing(true);
     2659                       
     2660                        if (hasLink && getLinkMark()) {
     2661                                g.drawOval(offset, getLinkBounds().getDiameters(), 0.0f, null, colour, HIGHLIGHT_STROKE);
     2662                               
    24632663                                // if the link is not valid, cross out the circle
    2464                                 if (!isLinkValid())
    2465                                         g.drawPolygon(getCircleCross());
     2664                                if (!isLinkValid()) {
     2665                                        g.drawPolygon(getCircleCross(), offset, null, 0.0f, null, colour, HIGHLIGHT_STROKE);
     2666                                }
    24662667                        }
    24672668
    2468                         if (getActionMark() && hasAction()) {
    2469                                 g.drawPolygon(getLinkPoly());
    2470                                 g.fillPolygon(getLinkPoly());
     2669                        if (hasAction && getActionMark()) {
     2670                                g.drawOval(offset, getLinkBounds().getDiameters(), 0.0f, fill, colour, HIGHLIGHT_STROKE);
    24712671
    24722672                                // if the link is not valid, cross out the circle
    24732673                                if (!isLinkValid() && getLink() != null) {
    2474                                         g.setColor(getParent().getPaintBackgroundColor());
    2475                                         g.drawPolygon(getCircleCross());
     2674                                        g.drawPolygon(getCircleCross(), offset, null, 0.0f, null, getParent().getPaintBackgroundColor(), HIGHLIGHT_STROKE);
    24762675                                }
    24772676                        }
    2478 
    2479                         // reset the graphics tranformation
    2480                         g.setTransform(orig);
     2677                       
     2678                        g.setAntialiasing(false);
    24812679                }
    24822680        }
     
    25392737                        return null;
    25402738                // assert (_parent!= null);
    2541                 Frame parent = DisplayIO.getCurrentFrame();
     2739                Frame parent = DisplayController.getCurrentFrame();
    25422740                assert (parent != null);
    25432741
     
    25872785                while (!lines.isEmpty()) {
    25882786                        Line l = lines.remove();
    2589                         // if we havnt visited the line yet visit it
     2787                        // if we haven't visited the line yet visit it
    25902788                        if (!visited.contains(l)) {
    25912789                                visited.add(l);
    25922790                                Item otherEnd = l.getOppositeEnd(this);
    2593                                 // Add all the enexplored lines to our list
     2791                                // Add all the unexplored lines to our list
    25942792                                while (!lines.isEmpty()) {
    25952793                                        l = lines.remove();
     
    26132811         *         is part of
    26142812         */
    2615         public double getEnclosedArea() {
    2616                 if (_enclosure == null)
    2617                         return 0.0;
    2618                 Rectangle2D box = getEnclosedShape().getBounds2D();
     2813        public double getEnclosedArea()
     2814        {
     2815                AxisAlignedBoxBounds box = getEnclosedBox();
     2816                if (box == null) return 0.0;
    26192817                return box.getWidth() * box.getHeight();
    26202818        }
    26212819
    2622         public Rectangle getEnclosedRectangle() {
    2623                 if (_enclosure == null)
    2624                         return null;
    2625                 return getEnclosedShape().getBounds();
    2626         }
    2627 
    2628         public int getEnclosureID() {
     2820        /**
     2821         * Gets the box encompassing all points that form an enclosure with this item.
     2822         *
     2823         * @return An axis-aligned box around all enclosure points.
     2824         */
     2825        public AxisAlignedBoxBounds getEnclosedBox()
     2826        {
     2827                if (_enclosure == null) return null;
     2828               
     2829                return AxisAlignedBoxBounds.getEnclosing(getEnclosedShape());
     2830        }
     2831
     2832        public int getEnclosureID()
     2833        {
    26292834                return _enclosure == null ? 0 : _enclosure.hashCode();
    26302835        }
    26312836
    26322837        /**
    2633          * Returns the Shape that surrounds this Item representing this Item's
     2838         * Returns the Bounds that surrounds this Item representing this Item's
    26342839         * 'gravity'.
    26352840         *
    2636          * @return The Shape (rectangle) surrounding this Item, which represents
     2841         * @return The Bounds surrounding this Item, which represents
    26372842         *         this Items 'gravity'.
    26382843         */
    2639         public final Polygon getPolygon() {
    2640                 if (_poly == null)
    2641                         updatePolygon();
    2642 
    2643                 return new Polygon(_poly.xpoints, _poly.ypoints, _poly.npoints);
     2844        public final Bounds getBounds()
     2845        {
     2846                if (_bounds == null) _bounds = updateBounds();
     2847               
     2848                // DEBUG
     2849                if (_bounds == null) {
     2850                        //System.out.println("updateBounds failed!");
     2851                }
     2852
     2853                return _bounds;
     2854        }
     2855       
     2856        public final Bounds getOldBounds()
     2857        {
     2858                return _oldBounds;
     2859        }
     2860       
     2861        public final void invalidateBounds()
     2862        {
     2863                if (_bounds != null) _oldBounds = _bounds;
     2864                _bounds = null;
     2865        }
     2866       
     2867        public final AxisAlignedBoxBounds getBoundingBox()
     2868        {
     2869                return AxisAlignedBoxBounds.getEnclosing(getBounds());
    26442870        }
    26452871
     
    26512877         * @param ratio
    26522878         */
    2653         public void translate(Point2D origin, double ratio) {
     2879        public void translate(Point origin, double ratio) {
    26542880
    26552881                invalidateCommonTraitForAll(ItemAppearence.PreMoved);
    26562882
    2657                 _x = (float) (origin.getX() + ratio * (_x - origin.getX()));
    2658                 _y = (float) (origin.getY() + ratio * (_y - origin.getY()));
    2659                 updatePolygon();
     2883                _x = (float) (origin.x + ratio * (_x - origin.x));
     2884                _y = (float) (origin.y + ratio * (_y - origin.y));
     2885                invalidateBounds();
    26602886                for (Line line : getLines())
    2661                         line.updatePolygon();
     2887                        line.invalidateBounds();
    26622888
    26632889                invalidateCommonTraitForAll(ItemAppearence.PostMoved);
     
    26982924        }
    26992925
    2700         Collection<XRayable> _enclosures = new HashSet<XRayable>();
    2701 
    2702         private boolean _deleted = false;
    2703 
    2704         private Overlay _overlay = null;
    2705 
    2706         protected AttributeValuePair _attributeValuePair = null;
    2707 
    2708         private Float _autoStamp = null;
    2709 
    27102926        /**
    27112927         * For now there can only be one enclosure per item
     
    27412957         *         highlighting bounds
    27422958         */
    2743         public Rectangle[] getDrawingArea() {
    2744 
    2745                 return new Rectangle[] { ItemUtils.expandRectangle(getPolygon()
    2746                                 .getBounds(), (int) Math.ceil(Math.max(_highlightThickness,
    2747                                 getThickness()))) };
    2748 
     2959        public AxisAlignedBoxBounds getDrawingArea() {
     2960
     2961                return ItemUtils.expandRectangle(
     2962                                        getBoundingBox(),
     2963                                        (int) Math.ceil(Math.max(_highlightThickness, getThickness())) + 1 // + 1 to make sure
     2964                );
    27492965        }
    27502966
     
    27542970         * @return True if area intersects with this items drawing area.
    27552971         */
    2756         public final boolean isInDrawingArea(Area area) {
    2757                 for (Rectangle r : getDrawingArea()) {
    2758                         if (area.intersects(r))
    2759                                 return true;
    2760                 }
    2761                 return false;
    2762         }
    2763 
    2764         /**
    2765          * Completetly invalidates the item - so that it should be redrawed. Note:
    2766          * This is handled internally, it should be reare to invoke this externally
    2767          */
    2768         public final void invalidateAll() {
     2972        public final boolean isInDrawingArea(AxisAlignedBoxBounds area)
     2973        {
     2974                AxisAlignedBoxBounds drawingArea = getDrawingArea();
     2975               
     2976                if (drawingArea == null) return false;
     2977               
     2978                return drawingArea.intersects(area);
     2979        }
     2980
     2981        /**
     2982         * Completely invalidates the item - so that it should be redrawn. Note:
     2983         * This is handled internally, it should be rare to invoke this externally
     2984         */
     2985        public final void invalidateAll()
     2986        {
    27692987                invalidate(getDrawingArea());
    27702988        }
     
    27762994         * @param damagedAreas
    27772995         */
    2778         protected final void invalidate(Rectangle[] damagedAreas) {
    2779                 for (Rectangle r : damagedAreas)
    2780                         invalidate(r);
     2996        protected final void invalidate(Bounds[] damagedAreas)
     2997        {
     2998                if (damagedAreas != null) for (Bounds b : damagedAreas) invalidate(b);
    27812999        }
    27823000
     
    27873005         * @param damagedAreas
    27883006         */
    2789         protected final void invalidate(Rectangle damagedArea) {
    2790                 FrameGraphics.invalidateItem(this, damagedArea);
     3007        protected final void invalidate(Bounds damagedArea)
     3008        {
     3009                if (damagedArea != null) DisplayController.invalidateItem(this, damagedArea);
    27913010        }
    27923011
     
    27963015         * @param trait
    27973016         */
    2798         public final void invalidateCommonTrait(ItemAppearence trait) {
     3017        public final void invalidateCommonTrait(ItemAppearence trait)
     3018        {
    27993019                invalidate(getDamagedArea(trait));
    28003020
    2801                 if (_colorFill != null
    2802                                 && (trait == ItemAppearence.Added || trait == ItemAppearence.Removed)) {
     3021                if (_fillColour != null && (trait == ItemAppearence.Added || trait == ItemAppearence.Removed)) {
    28033022                        invalidateFill();
    28043023                }
     
    28083027         * Invalidates fill if has one, even if no color is set.
    28093028         */
    2810         public void invalidateFill() {
     3029        public void invalidateFill()
     3030        {
    28113031                if (isLineEnd() && _enclosure != null) {
    2812                         invalidate(getEnclosedShape().getBounds());
     3032                        invalidate(getEnclosedBox());
    28133033                }
    28143034        }
     
    28263046         * @return The damaged area according to the visual trait that has changed.
    28273047         */
    2828         protected Rectangle[] getDamagedArea(ItemAppearence trait) {
    2829 
     3048        protected AxisAlignedBoxBounds getDamagedArea(ItemAppearence trait)
     3049        {
    28303050                if (trait == ItemAppearence.LinkChanged)
    2831                         return new Rectangle[] { getLinkDrawArea() }; // Invalidate area
    2832                 // where link is
    2833                 // drawn
     3051                        return getLinkDrawArea(); // Invalidate area where link is drawn
    28343052
    28353053                return getDrawingArea();
    2836 
    28373054        }
    28383055
     
    28643081        }
    28653082
    2866         public void setAnchorLeft(Float anchor) {
    2867                 this._anchorLeft = anchor;
    2868                 this._anchorRight = null;
     3083        public void setAnchorLeft(Integer anchor)
     3084        {
     3085                this._anchoring.setLeftAnchor(anchor);
    28693086                if (anchor != null) {
    28703087                        anchorConstraints();
     
    28733090        }
    28743091
    2875         public void setAnchorRight(Float anchor) {
    2876                 this._anchorRight = anchor;
    2877                 this._anchorLeft = null;
     3092        public void setAnchorRight(Integer anchor)
     3093        {
     3094                this._anchoring.setRightAnchor(anchor);
    28783095                if (anchor != null) {
    28793096                        anchorConstraints();
    2880                         setX(FrameGraphics.getMaxFrameSize().width - anchor
    2881                                         - getBoundsWidth());
    2882                 }
    2883         }
    2884 
    2885         public void setAnchorTop(Float anchor) {
    2886                 this._anchorTop = anchor;
    2887                 this._anchorBottom = null;
     3097                        setX(DisplayController.getFramePaintArea().getMaxX() - anchor - getBoundsWidth());
     3098                }
     3099        }
     3100
     3101        public void setAnchorTop(Integer anchor)
     3102        {
     3103                this._anchoring.setTopAnchor(anchor);
    28883104                if (anchor != null) {
    28893105                        anchorConstraints();
     
    28933109
    28943110
    2895         public void setAnchorBottom(Float anchor) {
    2896                 this._anchorBottom = anchor;
    2897                 this._anchorTop = null;
     3111        public void setAnchorBottom(Integer anchor)
     3112        {
     3113                this._anchoring.setBottomAnchor(anchor);
    28983114                if (anchor != null) {
    28993115                        anchorConstraints();
    2900                         setY(FrameGraphics.getMaxFrameSize().height - anchor);
    2901                 }
    2902         }
    2903 
    2904 
    2905         public boolean isAnchored() {
    2906             return ((_anchorLeft != null) || (_anchorRight != null)
    2907                     || (_anchorTop != null) || (_anchorBottom != null));
     3116                        setY(DisplayController.getFramePaintArea().getMaxY() - anchor);
     3117                }
     3118        }
     3119
     3120        public boolean isAnchored()
     3121        {
     3122            return _anchoring.isAnchored();
    29083123        }
    29093124
    29103125        public boolean isAnchoredX() {
    2911             return ((_anchorLeft != null) || (_anchorRight != null));
     3126            return _anchoring.isXAnchored();
    29123127        }
    29133128
    29143129        public boolean isAnchoredY() {
    2915             return ((_anchorTop != null) || (_anchorBottom != null));
    2916         }
    2917 
    2918         public Float getAnchorLeft() {
    2919                 return _anchorLeft;
    2920         }
    2921 
    2922         public Float getAnchorRight() {
    2923                 return _anchorRight;
    2924         }
    2925 
    2926         public Float getAnchorTop() {
    2927                 return _anchorTop;
    2928         }
    2929 
    2930         public Float getAnchorBottom() {
    2931                 return _anchorBottom;
     3130            return _anchoring.isYAnchored();
     3131        }
     3132
     3133        public Integer getAnchorLeft() {
     3134                return _anchoring.getLeftAnchor();
     3135        }
     3136
     3137        public Integer getAnchorRight() {
     3138                return _anchoring.getRightAnchor();
     3139        }
     3140
     3141        public Integer getAnchorTop() {
     3142                return _anchoring.getTopAnchor();
     3143        }
     3144
     3145        public Integer getAnchorBottom() {
     3146                return _anchoring.getBottomAnchor();
    29323147        }
    29333148
     
    30243239                // Invalidate them again!!
    30253240                for (Item i : this.getAllConnected()) {
    3026                         i.updatePolygon();
     3241                        i.invalidateBounds();
    30273242                        i.invalidateAll();
    30283243                }
    30293244        }
    30303245
    3031        
    30323246        protected void anchorConnected(AnchorEdgeType anchorEdgeType, Float delta) {
    30333247               
     
    30873301                // Invalidate them again!!
    30883302                for (Item i : this.getAllConnected()) {
    3089                         i.updatePolygon();
     3303                        i.invalidateBounds();
    30903304                        i.invalidateAll();
    30913305                }
     
    31233337                // DONT PUT SIZE IN HERE CAUSE IT STUFFS UP CIRCLES
    31243338
    3125                 updatePolygon();
     3339                invalidateBounds();
    31263340        }
    31273341
     
    31683382                return _autoStamp != null && _autoStamp >= 0.0;
    31693383        }
    3170 
    3171         public void setDotType(DotType type) {
    3172                 invalidateAll();
    3173                 _type = type;
    3174                 invalidateAll();
    3175         }
    3176 
    3177         public DotType getDotType() {
    3178                 return _type;
    3179         }
    3180 
    3181         public void setFilled(boolean filled) {
    3182                 invalidateAll();
    3183                 _filled = filled;
    3184                 invalidateAll();
    3185         }
    3186 
    3187         public boolean getFilled() {
    3188                 return _filled;
    3189         }
    3190                
    3191         private Item _magnetizedItemLeft = null;
    3192         private Item _magnetizedItemRight = null;
    3193         private Item _magnetizedItemTop = null;
    3194         private Item _magnetizedItemBottom = null;
    31953384       
    31963385        public int getMagnetizedItemLeft() {
     
    32453434                setMagnetizedItemBottom(this.getParent().getItemWithID(id));
    32463435        }
     3436
     3437        /**
     3438         * Replaces the given dot item with a text item displaying the given character.
     3439         *
     3440         * @param dot
     3441         *              The Dot item to replace.
     3442         *
     3443         * @param ch
     3444         *              The character to display as the text for the created Text item.
     3445         *
     3446         * @return
     3447         *              The created Text item.
     3448         */
     3449        public static Text replaceDot(Item dot, char ch) {
     3450                // TODO: Should this make sure 'dot' is actually a Dot and not some other item? cts16
     3451                Text text = Text.createText(ch);
     3452                Item.DuplicateItem(dot, text);
     3453                FrameUtils.setLastEdited(text);
     3454
     3455                // Copy the lines list so it can be modified
     3456                List<Line> lines = new LinkedList<Line>(dot.getLines());
     3457                for (Line line : lines)
     3458                        line.replaceLineEnd(dot, text);
     3459                Frame current = dot.getParentOrCurrentFrame();
     3460                current.removeItem(dot);
     3461                ItemUtils.EnclosedCheck(current.getItems());
     3462                return text;
     3463                // TODO: Should this add the newly-created Text item to the frame? cts16
     3464        }
     3465
     3466        /**
     3467         * Replaces the given text item with a dot
     3468         */
     3469        public static Item replaceText(Item text) {
     3470                Item dot = new Dot(text.getX(), text.getY(), text.getID());
     3471                Item.DuplicateItem(text, dot);
     3472
     3473                List<Line> lines = new LinkedList<Line>();
     3474                lines.addAll(text.getLines());
     3475                if (lines.size() > 0)
     3476                        dot.setColor(lines.get(0).getColor());
     3477                for (Line line : lines) {
     3478                        line.replaceLineEnd(text, dot);
     3479                }
     3480                text.delete();
     3481                Frame current = text.getParentOrCurrentFrame();
     3482                current.addItem(dot);
     3483                DisplayController.setCursor(Item.DEFAULT_CURSOR);
     3484                ItemUtils.EnclosedCheck(current.getItems());
     3485                return dot;
     3486        }
    32473487}
Note: See TracChangeset for help on using the changeset viewer.