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/gui/Frame.java

    r998 r1102  
    1919package org.expeditee.gui;
    2020
    21 import java.awt.Color;
    22 import java.awt.Image;
    23 import java.awt.Polygon;
    24 import java.awt.image.ImageObserver;
    25 import java.awt.image.VolatileImage;
    2621import java.sql.Time;
    2722import java.util.ArrayList;
     
    3732
    3833import org.expeditee.actions.Simple;
     34import org.expeditee.core.Colour;
     35import org.expeditee.core.Image;
     36import org.expeditee.core.bounds.PolygonBounds;
     37import org.expeditee.gio.gesture.StandardGestureActions;
     38import org.expeditee.gio.input.StandardInputEventListeners;
     39import org.expeditee.gio.input.KBMInputEvent.Key;
    3940import org.expeditee.io.Conversion;
    4041import org.expeditee.items.Constraint;
     
    5051import org.expeditee.items.UserAppliedPermission;
    5152import org.expeditee.items.XRayable;
    52 import org.expeditee.items.widgets.InteractiveWidget;
     53import org.expeditee.items.widgets.Widget;
    5354import org.expeditee.items.widgets.WidgetCorner;
    5455import org.expeditee.settings.UserSettings;
     
    6667 *
    6768 */
    68 public class Frame implements ImageObserver {
     69public class Frame {
     70       
     71        /** The frame number to indicate this is a virtual frame. */
     72        public static final int VIRTUAL_FRAME_NUMBER = -1;
     73       
     74        /** The background colour the frame name should take if the frame has user permission level 'none'. */
     75        public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_NONE = Colour.FromRGB255(255, 220, 220);
     76        /** The background colour the frame name should take if the frame has user permission level 'followLinks'. */
     77        public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FOLLOW_LINKS = Colour.FromRGB255(255, 230, 135);
     78        /** The background colour the frame name should take if the frame has user permission level 'copy'. */
     79        public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_COPY = Colour.FromRGB255(255, 255, 155);
     80        /** The background colour the frame name should take if the frame has user permission level 'createFrames'. */
     81        public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_CREATE_FRAMES = Colour.FromRGB255(220, 255, 220);
     82        /** The background colour the frame name should take if the frame has user permission level 'full'. */
     83        public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FULL = null;
    6984
    7085        private boolean _protectionChanged = false;
    71 
    72         public boolean isReadOnly() {
    73                 return !_frameName.hasPermission(UserAppliedPermission.full)
    74                                 && !_protectionChanged;
    75         }
    7686
    7787        // The various attributes of this Frame
     
    95105
    96106        // Background color is clear
    97         private Color _background = null;
     107        private Colour _background = null;
    98108
    99109        // Foreground color is automatic by default
    100         private Color _foreground = null;
     110        private Colour _foreground = null;
    101111
    102112        private String path;
     
    105115
    106116        private boolean _sorted = true;
    107 
    108         // The items contained in this Frame
    109         // records whether a change has been made to this Frame (for saving
    110         // purposes).
     117       
     118        /** Whether the frame has changed and therefore needs saving. */
    111119        private boolean _change = false;
    112120
     121        /** Whether the frame has been saved. */
    113122        private boolean _saved = false;
    114 
    115         private static final class History {
    116                 public enum Type {
    117                         deletion,
    118                         movement
    119                 }
    120                 public final List<Item> items;
    121                 public final Type type;
    122                
    123                 public History(Collection<Item> items, Type type) {
    124                         this.items = new LinkedList<Item>(items);
    125                         this.type = type;
    126                 }
    127                
    128                 public String toString() {
    129                         return this.type.toString() + ":\n" + this.items.toString();
    130                 }
    131         }
    132123       
    133124        // list of deleted items that can be restored
     
    141132
    142133        // for drawing purposes
    143         private List<InteractiveWidget> _iWidgets = new ArrayList<InteractiveWidget>();
     134        private List<Widget> _iWidgets = new ArrayList<Widget>();
    144135
    145136        private int _lineCount = 0;
     
    170161        private Text _dotTemplate = TemplateSettings.DotTemplate.get().copy();
    171162
    172         /**
    173          * Default constructor, nothing is set.
    174          */
    175         public Frame() {
    176         }
    177 
    178         public void reset() {
     163        Map<String, Text> _annotations = null;
     164
     165        private Collection<FrameObserver> _observers = new HashSet<FrameObserver>();
     166
     167        /** Default constructor, nothing is set. */
     168        public Frame()
     169        {
     170        }
     171
     172        public boolean isReadOnly()
     173        {
     174                return !_frameName.hasPermission(UserAppliedPermission.full) && !_protectionChanged;
     175        }
     176
     177        public void reset()
     178        {
    179179                refreshItemPermissions(UserAppliedPermission.full);
    180                 //System.out.println("Reset");
    181180                resetDot();
    182181                SessionStats.NewFrameSession();
    183182        }
    184183
    185         private void resetDot() {
     184        private void resetDot()
     185        {
    186186            _dotTemplate.setColor(TemplateSettings.ColorWheel.getSafe(1));
    187187            _dotTemplate.setFillColor(TemplateSettings.FillColorWheel.getSafe(0));
    188188        }
    189189
    190         public void nextDot() {
    191                 _dotTemplate.setFillColor(ColorUtils.getNextColor(_dotTemplate
    192                                 .getFillColor(), TemplateSettings.FillColorWheel.get(), null));
    193                 _dotTemplate.setColor(ColorUtils.getNextColor(_dotTemplate.getColor(),
    194                                 TemplateSettings.ColorWheel.get(), null));
    195 
    196                 if (_dotTemplate.getColor() == null || _dotTemplate.getColor().equals(Color.white)) {
    197                         resetDot();
    198                 }
    199         }
    200 
    201         public Image getBuffer() {
     190        public void nextDot()
     191        {
     192                _dotTemplate.setFillColor(ColorUtils.getNextColor(_dotTemplate.getFillColor(), TemplateSettings.FillColorWheel.get(), null));
     193                _dotTemplate.setColor(ColorUtils.getNextColor(_dotTemplate.getColor(), TemplateSettings.ColorWheel.get(), null));
     194                if (_dotTemplate.getColor() == null || _dotTemplate.getColor().equals(Colour.WHITE)) resetDot();
     195        }
     196
     197        public Image getBuffer()
     198        {
    202199                return _buffer;
    203200        }
    204201
    205         public void setBuffer(Image newBuffer) {
     202        public void setBuffer(Image newBuffer)
     203        {
    206204                _buffer = newBuffer;
    207205        }
    208206
    209         public boolean isBufferValid() {
    210                 if (_buffer == null
    211                                 || (_buffer instanceof VolatileImage && ((VolatileImage) _buffer)
    212                                                 .contentsLost()))
    213                         return false;
     207        public boolean isBufferValid()
     208        {
     209                if (_buffer == null) return false;
    214210
    215211                return _validBuffer;
    216212        }
    217213
    218         private void setBufferValid(boolean newValue) {
     214        private void setBufferValid(boolean newValue)
     215        {
    219216                _validBuffer = newValue;
    220217        }
    221218
    222         public int getNextItemID() {
     219        public int getNextItemID()
     220        {
    223221                return ++_itemCount;
    224222        }
    225223
    226         public void updateIDs(List<Item> items) {
    227                 for (Item i : items)
    228                         if (!(i instanceof Line))
     224        public void updateIDs(List<Item> items)
     225        {
     226                for (Item i : items) {
     227                        if (!(i instanceof Line)) {
    229228                                i.setID(getNextItemID());
    230                         else
     229                        } else {
    231230                                i.setID(++_lineCount);
     231                        }
     232                }
    232233        }
    233234
     
    237238         *         Hence it excludes free-widgets. Returns a copy
    238239         */
    239         public List<InteractiveWidget> getInteractiveWidgets() {
    240                 LinkedList<InteractiveWidget> clone = new LinkedList<InteractiveWidget>();
     240        public List<Widget> getInteractiveWidgets()
     241        {
     242                LinkedList<Widget> clone = new LinkedList<Widget>();
    241243                clone.addAll(this._iWidgets);
    242244                return clone;
     
    248250         * @return True if this Frame has been altered, false otherwise.
    249251         */
    250         public boolean hasChanged() {
     252        public boolean hasChanged()
     253        {
    251254                // virtual frames are never saved
    252                 if (_number == -1)
    253                         return false;
     255                if (_number == VIRTUAL_FRAME_NUMBER) return false;
    254256
    255257                return _change;
     
    260262         *
    261263         * @param value
    262          *            False if this Frame should be saved to disk, False otherwise.
    263          */
    264         public void setChanged(boolean value) {
    265                 // System.out.println(getName() + " " + value);
    266                 boolean oldValue = _change;
    267 
    268                 // if (value) {
    269                 // notifyObservers();
    270                 // }
    271 
    272                 if (oldValue == value)
    273                         return;
     264         *            True if this Frame should be saved to disk, False otherwise.
     265         */
     266        public void setChanged(boolean value)
     267        {
     268                if (_change == value) return;
    274269
    275270                _change = value;
     
    281276        }
    282277
    283         // private static int updateCount = 0;
    284 
    285278        /**
    286279         * Notify items observing the data on this frame that the frame content has
     
    290283         *            true if the frame should be recalculated first.
    291284         */
    292         public void notifyObservers(boolean bRecalculate) {
    293                 if (bRecalculate) {
    294                         recalculate();
    295                 }
     285        public void notifyObservers(boolean bRecalculate)
     286        {
     287                if (bRecalculate) recalculate();
    296288                // Notify the frame listeners that the frame has changed
    297289                /*
     
    301293                 * changing this frames observer list.
    302294                 */
    303                 Collection<FrameObserver> observersCopy = new LinkedList<FrameObserver>(
    304                                 _observers);
     295                Collection<FrameObserver> observersCopy = new LinkedList<FrameObserver>(_observers);
    305296                // System.out.println(++updateCount + " update");
    306297
    307298                for (FrameObserver fl : observersCopy) {
    308                         if (/* !Item.isLocked(fl) && */fl.isVisible())
    309                                 fl.update();
     299                        if (fl.isVisible()) fl.update();
    310300                }
    311301        }
    312302
    313303        // indicates the frame has changed
    314         public void change() {
     304        public void change()
     305        {
    315306                setChanged(true);
    316307                _interactableItems.clear();
     
    323314         * @return The list of Item objects that are on this Frame.
    324315         */
    325         public List<Item> getItems(boolean visible) {
     316        public List<Item> getItems(boolean visible)
     317        {
    326318                if (!_sorted) {
    327                         for(int i = 0; i < _body.size();)
    328                                 if(_body.get(i) == null) _body.remove(i);
    329                                 else i++;
     319                        for(int i = 0; i < _body.size();) {
     320                                if(_body.get(i) == null) {
     321                                        _body.remove(i);
     322                                } else {
     323                                        i++;
     324                                }
     325                        }
    330326                        Collections.sort(_body);
    331327                        _sorted = true;
     
    335331
    336332                for (Item i : _body) {
    337                         if (i == null)
    338                                 continue;
     333                        if (i == null) continue;
     334                       
    339335                        if (i.isVisible() || (!visible && !i.isDeleted())) {
    340336                                items.add(i);
     
    345341        }
    346342
    347         public List<Item> getItems() {
     343        /** TODO: Comment. cts16 */
     344        public List<Item> getItems()
     345        {
    348346                return getItems(false);
    349347        }
     
    354352         * @return True if this frame contains i.
    355353         */
    356         public boolean containsItem(Item i) {
    357                 if (i == null)
    358                         throw new NullPointerException("i");
     354        public boolean containsItem(Item i)
     355        {
     356                if (i == null) throw new NullPointerException("i");
     357               
    359358                return _body.contains(i);
    360359        }
     
    372371         * @return the list of body text items.
    373372         */
    374         public List<Text> getBodyTextItems(boolean includeAnnotations) {
     373        public List<Text> getBodyTextItems(boolean includeAnnotations)
     374        {
    375375                List<Text> bodyTextItems = new ArrayList<Text>();
     376               
    376377                for (Item i : getItems(true)) {
    377378                        // only add up normal body text items
    378                         if ((i instanceof Text)
    379                                         && ((includeAnnotations && !((Text) i)
    380                                                         .isSpecialAnnotation()) || !i.isAnnotation())
    381                                         && !i.isLineEnd()) {
     379                        if ((i instanceof Text) && ((includeAnnotations && !((Text) i).isSpecialAnnotation()) || !i.isAnnotation()) && !i.isLineEnd()) {
    382380                                bodyTextItems.add((Text) i);
    383381                        }
    384382                }
     383               
    385384                bodyTextItems.remove(getTitleItem());
    386385
     
    388387        }
    389388
    390         public Collection<Item> getNonAnnotationItems(boolean removeTitle) {
     389        public Collection<Item> getNonAnnotationItems(boolean removeTitle)
     390        {
    391391                Collection<Item> items = new ArrayList<Item>();
    392392                for (Item i : getItems(true)) {
    393393                        // only add up normal body text items
    394                         if (!i.isAnnotation()) {
    395                                 items.add(i);
    396                         }
    397                 }
     394                        if (!i.isAnnotation()) items.add(i);
     395                }
     396               
    398397                if (removeTitle) {
    399398                        items.remove(getTitleItem());
    400399                }
     400               
    401401                return items;
    402402        }
     
    408408         * @return the last non annotation text item.
    409409         */
    410         public Item getLastNonAnnotationTextItem() {
     410        public Item getLastNonAnnotationTextItem()
     411        {
    411412                List<Item> items = getItems();
    412413
     
    431432         *         found.
    432433         */
    433         public Item getItemWithID(int id) {
    434                 for (Item i : _body)
    435                         if (i.getID() == id)
     434        public Item getItemWithID(int id)
     435        {
     436                for (Item i : _body) {
     437                        if (i.getID() == id) {
    436438                                return i;
    437 
     439                        }
     440                }
    438441                return null;
    439442        }
     
    445448         *            The title to assign to this Frame
    446449         */
    447         public void setTitle(String title) {
    448                 if (title == null || title.equals(""))
    449                         return;
     450        public void setTitle(String title)
     451        {
     452                if (title == null || title.equals("")) return;
    450453
    451454                boolean oldchange = _change;
     
    476479                        // title = ItemUtils.StripTagSymbol(title);
    477480                        frameTitle.setText(title);
    478                         // If the @ symbol is followed by numbering or a bullet remove that
    479                         // too
    480                         String autoBulletText = FrameKeyboardActions.getAutoBullet(title);
     481                        // If the @ symbol is followed by numbering or a bullet remove that too
     482                        String autoBulletText = StandardGestureActions.getAutoBullet(title);
    481483                        if (autoBulletText.length() > 0)
    482484                                frameTitle.stripFirstWord();
     
    485487                // Brook: Cannot figure what is going on above... widget annot titles
    486488                // should be stripped always
    487                 if (ItemUtils.startsWithTag(frameTitle, ItemUtils
    488                                 .GetTag(ItemUtils.TAG_IWIDGET))) {
     489                if (ItemUtils.startsWithTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) {
    489490                        frameTitle.stripFirstWord();
    490491                }
     
    496497        }
    497498
    498         public Text getTitleItem() {
     499        public Text getTitleItem()
     500        {
    499501                List<Item> items = getVisibleItems();
     502               
    500503                for (Item i : items) {
    501                         if (i instanceof Text && i.getX() < UserSettings.TitlePosition.get()
    502                                         && i.getY() < UserSettings.TitlePosition.get())
     504                        if (i instanceof Text && i.getX() < UserSettings.TitlePosition.get() && i.getY() < UserSettings.TitlePosition.get()) {
    503505                                return (Text) i;
     506                        }
    504507                }
    505508
     
    507510        }
    508511
    509         public String getTitle() {
     512        public String getTitle()
     513        {
    510514                Text title = getTitleItem();
    511                 if (title == null)
    512                         return getName();
     515                if (title == null) return getName();
    513516
    514517                return title.getFirstLine();
    515518        }
    516519
    517         public Item getNameItem() {
     520        public Item getNameItem()
     521        {
    518522                return _frameName;
    519523        }
    520524
    521         public Text getItemTemplate() {
    522                 return getTemplate(TemplateSettings.ItemTemplate.get(),
    523                                 ItemUtils.TAG_ITEM_TEMPLATE);
    524         }
    525 
    526         public Text getAnnotationTemplate() {
    527                 Text t = getTemplate(TemplateSettings.AnnotationTemplate.get(),
    528                                 ItemUtils.TAG_ANNOTATION_TEMPLATE);
     525        public Text getItemTemplate()
     526        {
     527                return getTemplate(TemplateSettings.ItemTemplate.get(), ItemUtils.TAG_ITEM_TEMPLATE);
     528        }
     529
     530        public Text getAnnotationTemplate()
     531        {
     532                Text t = getTemplate(TemplateSettings.AnnotationTemplate.get(), ItemUtils.TAG_ANNOTATION_TEMPLATE);
    529533
    530534                if (t == null) {
     
    535539        }
    536540
    537         public Text getStatTemplate() {
     541        public Text getStatTemplate()
     542        {
    538543                SessionStats.CreatedText();
    539                 Text t = getTemplate(TemplateSettings.StatTemplate.get(),
    540                                 ItemUtils.TAG_STAT_TEMPLATE);
     544                Text t = getTemplate(TemplateSettings.StatTemplate.get(), ItemUtils.TAG_STAT_TEMPLATE);
    541545
    542546                if (t == null) {
     
    547551        }
    548552       
    549         public Item getTooltipTextItem(String tooltipText) {
     553        public Item getTooltipTextItem(String tooltipText)
     554        {
    550555                return getTextItem(tooltipText, TemplateSettings.TooltipTemplate.get().copy());
    551556        }
    552557
    553         public Item getStatsTextItem(String itemText) {
     558        public Item getStatsTextItem(String itemText)
     559        {
    554560                return getTextItem(itemText, getStatTemplate());
    555561        }
    556562
    557         public Item getTextItem(String itemText) {
     563        public Item getTextItem(String itemText)
     564        {
    558565                return getTextItem(itemText, getItemTemplate());
    559566        }
    560567
    561         private Item getTextItem(String itemText, Text template) {
     568        private Item getTextItem(String itemText, Text template)
     569        {
    562570                Text t = template;
    563571                // We dont want the stats to wrap at all
    564572                // t.setMaxWidth(Integer.MAX_VALUE);
    565                 t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
     573                t.setPosition(DisplayController.getMousePosition());
    566574                // The next line is needed to make sure the item is removed from the
    567575                // frame when picked up
     
    571579        }
    572580
    573         public Text getCodeCommentTemplate() {
    574                 Text t = getTemplate(TemplateSettings.CommentTemplate.get(),
    575                                 ItemUtils.TAG_CODE_COMMENT_TEMPLATE);
     581        public Text getCodeCommentTemplate()
     582        {
     583                Text t = getTemplate(TemplateSettings.CommentTemplate.get(), ItemUtils.TAG_CODE_COMMENT_TEMPLATE);
    576584
    577585                if (t == null) {
     
    592600         *         Item.intersects(shape) return true.
    593601         */
    594         public Collection<Item> getItemsWithin(Polygon poly) {
     602        public Collection<Item> getItemsWithin(PolygonBounds poly)
     603        {
    595604                Collection<Item> results = new LinkedHashSet<Item>();
    596605                for (Item i : getVisibleItems()) {
     
    606615                }
    607616
    608                 for (Overlay o : _overlays.keySet())
     617                for (Overlay o : _overlays.keySet()) {
    609618                        results.addAll(o.Frame.getItemsWithin(poly));
    610 
     619                }
     620               
    611621                for (Item i : getVectorItems()) {
    612622                        if (i.intersects(poly)) {
     
    626636         *            The name to use for this Frame.
    627637         */
    628         public void setFrameset(String name) {
     638        public void setFrameset(String name)
     639        {
    629640                _frameset = name;
    630641        }
    631642
    632         public void setName(String framename) {
     643        public void setName(String framename)
     644        {
    633645                int num = Conversion.getFrameNumber(framename);
    634646                String frameset = Conversion.getFramesetName(framename, false);
     
    643655         *            The number to set as the frame number
    644656         */
    645         public void setFrameNumber(int number) {
     657        public void setFrameNumber(int number)
     658        {
    646659                assert (number >= 0);
    647660
    648                 if (_number == number)
    649                         return;
     661                if (_number == number) return;
    650662
    651663                _number = number;
     
    659671                        id = -1 * getNextItemID();
    660672                }
     673               
    661674                _frameName = new Text(id);
    662675                _frameName.setParent(this);
     
    671684         * @return The Frame number of this Frame or -1 if it is not set.
    672685         */
    673         public int getNumber() {
     686        public int getNumber()
     687        {
    674688                return _number;
    675689        }
     
    681695         *            The version to use for this Frame.
    682696         */
    683         public void setVersion(int version) {
     697        public void setVersion(int version)
     698        {
    684699                _version = version;
    685700        }
     
    691706         *            The protection to use for this Frame.
    692707         */
    693         public void setPermission(PermissionPair permission) {
    694                 if (_permissionPair != null && _permissionPair.getPermission(this._owner).equals(permission))
     708        public void setPermission(PermissionPair permission)
     709        {
     710                if (_permissionPair != null && _permissionPair.getPermission(this._owner).equals(permission)) {
    695711                        _protectionChanged = true;
     712                }
    696713
    697714                _permissionPair = new PermissionPair(permission);
    698715
    699                 if (_body.size() > 0)
    700                         refreshItemPermissions(permission.getPermission(_owner));
     716                if (_body.size() > 0) refreshItemPermissions(permission.getPermission(_owner));
    701717        }
    702718
     
    707723         *            The owner to use for this Frame.
    708724         */
    709         public void setOwner(String owner) {
     725        public void setOwner(String owner)
     726        {
    710727                _owner = owner;
    711728        }
     
    717734         *            The date to use for this Frame.
    718735         */
    719         public void setDateCreated(String date) {
     736        public void setDateCreated(String date)
     737        {
    720738                _creationDate = date;
    721739                _modifiedDate = date;
     
    729747         *
    730748         */
    731         public void resetDateCreated() {
     749        public void resetDateCreated()
     750        {
    732751                setDateCreated(Formatter.getDateTime());
    733752                resetTimes();
     
    735754        }
    736755
    737         private void resetTimes() {
     756        private void resetTimes()
     757        {
    738758                setActiveTime(new Time(0));
    739759                setDarkTime(new Time(0));
     
    746766         *            The user to set as the last modifying user.
    747767         */
    748         public void setLastModifyUser(String user) {
     768        public void setLastModifyUser(String user)
     769        {
    749770                _modifiedUser = user;
    750771        }
     
    756777         *            The date to set as the last modified date.
    757778         */
    758         public void setLastModifyDate(String date) {
     779        public void setLastModifyDate(String date)
     780        {
    759781                _modifiedDate = date;
    760782        }
     
    766788         *            The date to set as the last frozen date.
    767789         */
    768         public void setFrozenDate(String date) {
     790        public void setFrozenDate(String date)
     791        {
    769792                _frozenDate = date;
    770793        }
    771794
    772         public void setResort(boolean value) {
     795        public void setResort(boolean value)
     796        {
    773797                _sorted = !value;
    774798        }
     
    780804         *            The Item to add to this Frame.
    781805         */
    782         public void addItem(Item item) {
     806        public void addItem(Item item)
     807        {
    783808                addItem(item, true);
    784809        }
    785810
    786         public void addItem(Item item, boolean recalculate) {
    787                 if (item == null || item.equals(_frameName) || _body.contains(item))
    788                         return;
     811        public void addItem(Item item, boolean recalculate)
     812        {
     813                if (item == null || item.equals(_frameName) || _body.contains(item)) return;
    789814
    790815                // When an annotation item is anchored the annotation list must be
     
    794819                }
    795820
    796                 if (item instanceof Line)
    797                         _lineCount++;
     821                if (item instanceof Line) _lineCount++;
    798822
    799823                _itemCount = Math.max(_itemCount, item.getID());
     
    816840                // add widget items to the list of widgets
    817841                if (item instanceof WidgetCorner) {
    818                         InteractiveWidget iw = ((WidgetCorner) item).getWidgetSource();
     842                        Widget iw = ((WidgetCorner) item).getWidgetSource();
    819843                        if (!this._iWidgets.contains(iw)) { // A set would have been
    820                                 if (FrameMouseActions.isControlDown())
     844                                if (StandardInputEventListeners.kbmStateListener.isKeyDown(Key.CTRL)) {
    821845                                        _iWidgets.add(iw);
    822                                 else
     846                                } else {
    823847                                        _iWidgets.add(0, iw);
    824                         }
    825                 }
    826 
    827                 item.onParentStateChanged(new ItemParentStateChangedEvent(this,
    828                                 ItemParentStateChangedEvent.EVENT_TYPE_ADDED));
     848                                }
     849                        }
     850                }
     851
     852                item.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED));
    829853
    830854                // if (recalculate && item.recalculateWhenChanged())
     
    834858        }
    835859
    836         public void refreshSize() {
    837                 // assert (size != null);
     860        public void refreshSize()
     861        {
    838862                boolean bReparse = false;
     863               
    839864                for (Item i : getItems()) {
    840                         Float anchorLeft   = i.getAnchorLeft();
    841                         Float anchorRight  = i.getAnchorRight();
    842                         Float anchorTop    = i.getAnchorTop();
    843                         Float anchorBottom = i.getAnchorBottom();
     865                        Integer anchorLeft   = i.getAnchorLeft();
     866                        Integer anchorRight  = i.getAnchorRight();
     867                        Integer anchorTop    = i.getAnchorTop();
     868                        Integer anchorBottom = i.getAnchorBottom();
    844869       
    845870                       
     
    885910        }
    886911
    887         public void addAllItems(Collection<Item> toAdd) {
     912        public void addAllItems(Collection<Item> toAdd)
     913        {
    888914                for (Item i : toAdd) {
    889915                        // If an annotation is being deleted clear the annotation list
    890                         if (i.isAnnotation())
    891                                 i.getParentOrCurrentFrame().clearAnnotations();
     916                        if (i.isAnnotation()) i.getParentOrCurrentFrame().clearAnnotations();
    892917                        // TODO Improve efficiency when addAll is called
    893918                        addItem(i);
     
    895920        }
    896921
    897         public void removeAllItems(Collection<Item> toRemove) {
     922        public void removeAllItems(Collection<Item> toRemove)
     923        {
    898924                for (Item i : toRemove) {
    899925                        // If an annotation is being deleted clear the annotation list
    900                         if (i.isAnnotation())
    901                                 i.getParentOrCurrentFrame().clearAnnotations();
     926                        if (i.isAnnotation()) i.getParentOrCurrentFrame().clearAnnotations();
    902927                        removeItem(i);
    903928                }
    904929        }
    905930
    906         public void removeItem(Item item) {
     931        public void removeItem(Item item)
     932        {
    907933                removeItem(item, true);
    908934        }
    909935
    910         public void removeItem(Item item, boolean recalculate) {
     936        public void removeItem(Item item, boolean recalculate)
     937        {
    911938                // If an annotation is being deleted clear the annotation list
    912                 if (item.isAnnotation())
    913                         item.getParentOrCurrentFrame().clearAnnotations();
     939                if (item.isAnnotation()) item.getParentOrCurrentFrame().clearAnnotations();
    914940
    915941                if (_body.remove(item)) {
     
    917943                        // Remove widgets from the widget list
    918944                        if (item != null) {
    919                                 item.onParentStateChanged(new ItemParentStateChangedEvent(this,
    920                                                 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED));
     945                                item.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_REMOVED));
     946                               
    921947                                if (item instanceof WidgetCorner) {
    922948                                        _iWidgets.remove(((WidgetCorner) item).getWidgetSource());
    923949                                }
     950                               
    924951                                item.invalidateCommonTrait(ItemAppearence.Removed);
    925952                        }
     
    937964         * @param type  The type of event that occurred
    938965         */
    939         private void addToUndo(Collection<Item> items, History.Type type) {
    940                 if (items.size() < 1)
    941                         return;
    942                
    943                 // System.out.println("Added: " + items);
     966        private void addToUndo(Collection<Item> items, History.Type type)
     967        {
     968                if (items.size() < 1) return;
    944969
    945970                _undo.push(new History(items, type));
    946971        }
    947972       
    948         public void addToUndoDelete(Collection<Item> items) {
     973        public void addToUndoDelete(Collection<Item> items)
     974        {
    949975                addToUndo(items, History.Type.deletion);
    950976        }
    951         public void addToUndoMove(Collection<Item> items) {
     977       
     978        public void addToUndoMove(Collection<Item> items)
     979        {
    952980                addToUndo(items, History.Type.movement);
    953981        }
    954982
    955         public void undo() {
     983        public void undo()
     984        {
    956985                boolean bReparse = false;
    957986                boolean bRecalculate = false;
    958987
    959                 if (_undo.size() <= 0)
    960                         return;
     988                if (_undo.size() <= 0) return;
    961989
    962990                History undo = _undo.pop();
     
    9921020                        break;
    9931021                }
     1022               
    9941023                change();
    995                 FrameMouseActions.getInstance().refreshHighlights();
     1024               
     1025                StandardGestureActions.refreshHighlights();
     1026               
    9961027                if (bReparse) {
    9971028                        FrameUtils.Parse(this, false, false);
     
    9991030                        notifyObservers(bRecalculate);
    10001031                }
     1032               
    10011033                // always request a refresh otherwise filled shapes
    10021034                // that were broken by a deletion and then reconnected by the undo
    10031035                // don't get filled until the user otherwise causes them to redraw
    1004                 FrameGraphics.requestRefresh(false);
    1005                 FrameGraphics.Repaint();
     1036                DisplayController.requestRefresh(false);
    10061037                // ItemUtils.EnclosedCheck(_body);
    10071038                ItemUtils.Justify(this);
    10081039        }
    10091040       
    1010         public void redo() {
     1041        public void redo()
     1042        {
    10111043                boolean bReparse = false;
    10121044                boolean bRecalculate = false;
    10131045
    1014                 if (_redo.size() <= 0)
    1015                         return;
     1046                if (_redo.size() <= 0) return;
    10161047
    10171048                History redo = _redo.pop();
     
    10471078                        break;
    10481079                }
     1080               
    10491081                change();
    1050                 FrameMouseActions.getInstance().refreshHighlights();
     1082               
     1083                StandardGestureActions.refreshHighlights();
     1084               
    10511085                if (bReparse) {
    10521086                        FrameUtils.Parse(this, false, false);
     
    10541088                        notifyObservers(bRecalculate);
    10551089                }
     1090               
    10561091                // always request a refresh otherwise filled shapes
    10571092                // that were broken by a deletion and then reconnected by the undo
    10581093                // don't get filled until the user otherwise causes them to redraw
    1059                 FrameGraphics.requestRefresh(false);
    1060                 FrameGraphics.Repaint();
     1094                DisplayController.requestRefresh(false);
    10611095                // ItemUtils.EnclosedCheck(_body);
    10621096                ItemUtils.Justify(this);
     
    10681102         * @return The name of this Frame's frameset.
    10691103         */
    1070         public String getFramesetName() {
     1104        public String getFramesetName()
     1105        {
    10711106                return _frameset;
    10721107        }
    10731108
    1074         public String getName() {
     1109        public String getName()
     1110        {
    10751111                return getFramesetName() + _number;
    10761112        }
     
    10811117         * @return The version of this Frame.
    10821118         */
    1083         public int getVersion() {
     1119        public int getVersion()
     1120        {
    10841121                return _version;
    10851122        }
    10861123
    1087         public PermissionPair getPermission() {
     1124        public PermissionPair getPermission()
     1125        {
    10881126                return _permissionPair;
    10891127        }
    10901128       
    1091         public UserAppliedPermission getUserAppliedPermission() {
     1129        public UserAppliedPermission getUserAppliedPermission()
     1130        {
    10921131                return getUserAppliedPermission(UserAppliedPermission.full);
    10931132        }
    10941133
    1095         public UserAppliedPermission getUserAppliedPermission(UserAppliedPermission defaultPermission) {
    1096                 if (_permissionPair == null)
    1097                         return defaultPermission;
     1134        public UserAppliedPermission getUserAppliedPermission(UserAppliedPermission defaultPermission)
     1135        {
     1136                if (_permissionPair == null) return defaultPermission;
    10981137
    10991138                return _permissionPair.getPermission(_owner);
    11001139        }
    11011140
    1102        
    1103         public String getOwner() {
     1141        public String getOwner()
     1142        {
    11041143                return _owner;
    11051144        }
    11061145
    1107         public String getDateCreated() {
     1146        public String getDateCreated()
     1147        {
    11081148                return _creationDate;
    11091149        }
    11101150
    1111         public String getLastModifyUser() {
     1151        public String getLastModifyUser()
     1152        {
    11121153                return _modifiedUser;
    11131154        }
    11141155
    1115         public String getLastModifyDate() {
     1156        public String getLastModifyDate()
     1157        {
    11161158                return _modifiedDate;
    11171159        }
    11181160
    1119         public String getFrozenDate() {
     1161        public String getFrozenDate()
     1162        {
    11201163                return _frozenDate;
    11211164        }
    11221165
    1123         public void setBackgroundColor(Color back) {
     1166        public void setBackgroundColor(Colour back)
     1167        {
    11241168                _background = back;
     1169               
    11251170                change();
    11261171
    1127                 if (this == DisplayIO.getCurrentFrame()) {
    1128                         FrameGraphics.refresh(false);
    1129                 }
    1130         }
    1131 
    1132         public Color getBackgroundColor() {
     1172                if (this == DisplayController.getCurrentFrame()) {
     1173                        DisplayController.requestRefresh(false);
     1174                }
     1175        }
     1176
     1177        public Colour getBackgroundColor()
     1178        {
    11331179                return _background;
    11341180        }
    11351181
    1136         public Color getPaintBackgroundColor() {
     1182        public Colour getPaintBackgroundColor()
     1183        {
    11371184                // If null... return white
    11381185                if (_background == null) {
     
    11431190        }
    11441191
    1145         public void setForegroundColor(Color front) {
     1192        public void setForegroundColor(Colour front)
     1193        {
    11461194                _foreground = front;
     1195               
    11471196                change();
    1148                 // FrameGraphics.Repaint();
    1149         }
    1150 
    1151         public Color getForegroundColor() {
     1197        }
     1198
     1199        public Colour getForegroundColor()
     1200        {
    11521201                return _foreground;
    11531202        }
    11541203
    1155         public Color getPaintForegroundColor() {
    1156                 final int GRAY = Color.gray.getBlue();
    1157                 final int THRESHOLD = 10;
     1204        public Colour getPaintForegroundColor()
     1205        {
     1206                final int GRAY = Colour.GREY.getBlue();
     1207                final int THRESHOLD = Colour.FromComponent255(10);
    11581208
    11591209                if (_foreground == null) {
    1160                         Color back = getPaintBackgroundColor();
     1210                        Colour back = getPaintBackgroundColor();
    11611211                        if (Math.abs(back.getRed() - GRAY) < THRESHOLD
    11621212                                        && Math.abs(back.getBlue() - GRAY) < THRESHOLD
    11631213                                        && Math.abs(back.getGreen() - GRAY) < THRESHOLD)
    1164                                 return Color.WHITE;
    1165 
    1166                         Color fore = new Color(
    1167                                         Math.abs(Conversion.RGB_MAX - back.getRed()), Math
    1168                                                         .abs(Conversion.RGB_MAX - back.getGreen()), Math
    1169                                                         .abs(Conversion.RGB_MAX - back.getBlue()));
     1214                        {
     1215                                return Colour.WHITE;
     1216                        }
     1217                       
     1218                        Colour fore = back.inverse();
     1219                       
    11701220                        return fore;
    11711221                }
     
    11741224        }
    11751225
    1176         public String toString() {
     1226        public String toString()
     1227        {
    11771228                StringBuilder s = new StringBuilder();
    11781229                s.append(String.format("Name: %s%d%n", _frameset, _number));
     
    11871238        }
    11881239
    1189         public Text getTextAbove(Text current) {
     1240        public Text getTextAbove(Text current)
     1241        {
    11901242                Collection<Text> currentTextItems = FrameUtils.getCurrentTextItems();
    11911243                List<Text> toCheck = new ArrayList<Text>();
     1244               
    11921245                if (currentTextItems.contains(current)) {
    11931246                        toCheck.addAll(currentTextItems);
     
    11951248                        toCheck.addAll(getTextItems());
    11961249                }
     1250               
    11971251                // Make sure the items are sorted
    11981252                Collections.sort(toCheck);
    11991253
    12001254                int ind = toCheck.indexOf(current);
    1201                 if (ind == -1)
    1202                         return null;
     1255                if (ind == -1) return null;
    12031256
    12041257                // loop through all items above this one, return the first match
    12051258                for (int i = ind - 1; i >= 0; i--) {
    12061259                        Text check = toCheck.get(i);
    1207                         if (FrameUtils.inSameColumn(check, current))
    1208                                 return check;
     1260                        if (FrameUtils.inSameColumn(check, current)) return check;
    12091261                }
    12101262
    12111263                return null;
    12121264        }
    1213 
    1214         /**
    1215          * Updates any Images that require it from their ImageObserver (Principally
    1216          * Animated GIFs)
    1217          */
    1218         public boolean imageUpdate(Image img, int infoflags, int x, int y,
    1219                         int width, int height) {
    1220                 FrameGraphics.ForceRepaint();
    1221 
    1222                 if (DisplayIO.getCurrentFrame() == this)
    1223                         return true;
    1224 
    1225                 return false;
    1226         }
    1227 
     1265       
    12281266        /**
    12291267         * Gets the text items that are in the same column and below a specified
     
    12331271         *            The Item to get the column for.
    12341272         */
    1235         public List<Text> getColumn(Item from) {
     1273        public List<Text> getColumn(Item from)
     1274        {
    12361275                // Check that this item is on the current frame
    1237                 if (!_body.contains(from))
    1238                         return null;
     1276                if (!_body.contains(from)) return null;
    12391277
    12401278                if (from == null) {
     
    12421280                }
    12431281
    1244                 if (from == null)
    1245                         return null;
     1282                if (from == null) return null;
    12461283
    12471284                // Get the enclosedItems
    12481285                Collection<Text> enclosed = FrameUtils.getCurrentTextItems();
    12491286                List<Text> toCheck = null;
     1287               
    12501288                if (enclosed.contains(from)) {
    12511289                        toCheck = new ArrayList<Text>();
     
    12561294
    12571295                List<Text> column = new ArrayList<Text>();
     1296               
    12581297                if (toCheck.size() > 0) {
    1259 
    12601298                        // Make sure the items are sorted
    12611299                        Collections.sort(toCheck);
     
    12661304
    12671305                        // If its the title index will be 0
    1268                         if (index < 0)
    1269                                 index = 0;
     1306                        if (index < 0) index = 0;
    12701307
    12711308                        for (int i = index; i < toCheck.size(); i++) {
    12721309                                Text item = toCheck.get(i);
    1273                                 if (FrameUtils.inSameColumn(from, item))
    1274                                         column.add(item);
     1310                                if (FrameUtils.inSameColumn(from, item)) column.add(item);
    12751311                        }
    12761312                }
     
    12891325         *             If overlay is null.
    12901326         */
    1291         protected boolean addVector(Vector toAdd) {
     1327        protected boolean addVector(Vector toAdd)
     1328        {
    12921329                // make sure we dont add this frame as an overlay of itself
    1293                 if (toAdd.Frame == this)
    1294                         return false;
     1330                if (toAdd.Frame == this) return false;
     1331               
    12951332                _vectors.add(toAdd);
     1333               
    12961334                // Items must be notified that they have been added or removed from this
    12971335                // frame via the vector...
    12981336                int maxX = 0;
    12991337                int maxY = 0;
     1338               
    13001339                HighlightMode mode = toAdd.Source.getHighlightMode();
    1301                 if (mode != HighlightMode.None)
    1302                         mode = HighlightMode.Connected;
    1303                 Color highlightColor = toAdd.Source.getHighlightColor();
     1340                if (mode != HighlightMode.None) mode = HighlightMode.Connected;
     1341               
     1342                Colour highlightColor = toAdd.Source.getHighlightColor();
     1343               
    13041344                for (Item i : ItemUtils.CopyItems(toAdd.Frame.getVectorItems(), toAdd)) {
    1305                         i.onParentStateChanged(new ItemParentStateChangedEvent(this,
    1306                                         ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY,
    1307                                         toAdd.permission));
     1345                        i.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, toAdd.permission));
    13081346                        i.setEditTarget(toAdd.Source);
    1309                         i.setHighlightMode(mode, highlightColor);
     1347                        i.setHighlightModeAndColour(mode, highlightColor);
    13101348                        _vectorItems.add(i);
    13111349                        i.invalidateAll();
    13121350                        i.invalidateFill();
     1351                       
    13131352                        // Get the right most x and bottom most y pos
    13141353                        int itemRight = i.getX() + i.getBoundsWidth();
    1315                         if (itemRight > maxX)
    1316                                 maxX = itemRight;
     1354                        if (itemRight > maxX) maxX = itemRight;
     1355                       
    13171356                        int itemBottom = i.getY() + i.getBoundsHeight();
    1318                         if (itemBottom > maxY)
    1319                                 maxY = itemBottom;
    1320                 }
     1357                        if (itemBottom > maxY) maxY = itemBottom;
     1358                }
     1359               
    13211360                toAdd.setSize(maxX, maxY);
     1361               
    13221362                return true;
    13231363        }
    13241364
    1325         public Collection<Vector> getVectors() {
     1365        public Collection<Vector> getVectors()
     1366        {
    13261367                Collection<Vector> l = new LinkedList<Vector>();
    13271368                l.addAll(_vectors);
     
    13291370        }
    13301371
    1331         public Collection<Overlay> getOverlays() {
     1372        public Collection<Overlay> getOverlays()
     1373        {
    13321374                return new LinkedList<Overlay>(_overlays.keySet());
    13331375        }
    13341376
    13351377        /**
    1336          * @return All vectosr seen by this frame (including its vector's vectors).
    1337          */
    1338         public List<Vector> getVectorsDeep() {
     1378         * @return All vectors seen by this frame (including its vector's vectors).
     1379         */
     1380        public List<Vector> getVectorsDeep()
     1381        {
    13391382                List<Vector> l = new LinkedList<Vector>();
    13401383                getVectorsDeep(l, this, new LinkedList<Frame>());
     
    13421385        }
    13431386
    1344         private boolean getVectorsDeep(List<Vector> vectors, Frame vector,
    1345                         List<Frame> seenVectors) {
    1346 
    1347                 if (seenVectors.contains(vector))
    1348                         return false;
     1387        private boolean getVectorsDeep(List<Vector> vectors, Frame vector, List<Frame> seenVectors)
     1388        {
     1389                if (seenVectors.contains(vector)) return false;
    13491390
    13501391                seenVectors.add(vector);
    13511392
    1352                 for (Vector o : vector.getVectors()) {
    1353                         if (getVectorsDeep(vectors, o.Frame, seenVectors)) {
    1354                                 vectors.add(o);
     1393                for (Vector v : vector.getVectors()) {
     1394                        if (getVectorsDeep(vectors, v.Frame, seenVectors)) {
     1395                                vectors.add(v);
    13551396                        }
    13561397                }
     
    13591400        }
    13601401
    1361         // private boolean getOverlaysDeep(List<Overlay> overlays, Frame overlay,
    1362         // List<Frame> seenOverlays) {
    1363         //
    1364         // if (seenOverlays.contains(overlay))
    1365         // return false;
    1366         //
    1367         // seenOverlays.add(overlay);
    1368         //
    1369         // for (Overlay o : overlay.getOverlays()) {
    1370         // if (getOverlaysDeep(overlays, o.Frame, seenOverlays)) {
    1371         // overlays.add(o);
    1372         // }
    1373         // }
    1374         //
    1375         // return true;
    1376         // }
     1402        public List<Overlay> getOverlaysDeep()
     1403        {
     1404                List<Overlay> ret = new LinkedList<Overlay>();
     1405               
     1406                getOverlaysDeep(ret, new LinkedList<Frame>());
     1407               
     1408                return ret;
     1409        }
     1410       
     1411        private boolean getOverlaysDeep(List<Overlay> overlays, List<Frame> seenOverlays)
     1412        {
     1413                if (seenOverlays.contains(this)) return false;
     1414               
     1415                seenOverlays.add(this);
     1416               
     1417                for (Overlay o : this.getOverlays()) {
     1418                        if (o.Frame.getOverlaysDeep(overlays, seenOverlays)) {
     1419                                overlays.add(o);
     1420                        }
     1421                }
     1422                return true;
     1423        }
     1424       
     1425        /**
     1426         * Recursive function similar to AddAllOverlayItems.
     1427         *
     1428         * @param widgets
     1429         *            The collection the widgets will be added to
     1430         * @param overlay
     1431         *            An "overlay" frame - this initially will be the parent frame
     1432         * @param seenOverlays
     1433         *            Used for state in the recursion stack. Pass as an empty
     1434         *            (non-null) list.
     1435         */
     1436        public List<Widget> getAllOverlayWidgets()
     1437        {
     1438                List<Widget> widgets = new LinkedList<Widget>();
     1439               
     1440                for (Overlay o : getOverlaysDeep()) widgets.addAll(o.Frame.getInteractiveWidgets());
     1441               
     1442                return widgets;
     1443        }
    13771444
    13781445        /**
     
    13811448         * @param item
    13821449         *            The item - must not be null.
    1383          * @return The overlay that contains the itm. Null if no overlay owns the
     1450         * @return The overlay that contains the item. Null if no overlay owns the
    13841451         *         item.
    13851452         */
    1386         public Overlay getOverlayOwner(Item item) {
    1387                 if (item == null)
    1388                         throw new NullPointerException("item");
     1453        public Overlay getOverlayOwner(Item item)
     1454        {
     1455                if (item == null) throw new NullPointerException("item");
    13891456
    13901457                for (Overlay l : getOverlays()) {
    1391                         if (item.getParent() == l.Frame)
    1392                                 return l;
     1458                        if (item.getParent() == l.Frame) return l;
    13931459                }
    13941460
    13951461                // TODO return the correct vector... not just the first vector matching
    1396                 // the vectorFrame
     1462                // the vector frame
    13971463                for (Vector v : getVectors()) {
    1398                         if (item.getParent() == v.Frame)
    1399                                 return v;
     1464                        if (item.getParent() == v.Frame) return v;
    14001465                }
    14011466
     
    14031468        }
    14041469
    1405         public void clearVectors() {
     1470        public void clearVectors()
     1471        {
    14061472                _vectors.clear();
    14071473
     
    14141480        }
    14151481
    1416         protected boolean removeVector(Vector toRemove) {
    1417                 if (!_vectors.remove(toRemove))
    1418                         return false;
     1482        protected boolean removeVector(Vector toRemove)
     1483        {
     1484                if (!_vectors.remove(toRemove)) return false;
     1485               
    14191486                for (Item i : toRemove.Frame.getVectorItems()) {
    14201487                        i.invalidateAll();
     
    14261493
    14271494                }
     1495               
    14281496                return true;
    14291497        }
    14301498
    1431         public void clearOverlays() {
     1499        public void clearOverlays()
     1500        {
    14321501                for (Overlay o : _overlays.keySet()) {
    14331502                        for (Item i : o.Frame.getItems()) {
    1434                                 i
    1435                                                 .onParentStateChanged(new ItemParentStateChangedEvent(
     1503                                i.onParentStateChanged(new ItemParentStateChangedEvent(
    14361504                                                                this,
    14371505                                                                ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY,
     
    14441512        }
    14451513
    1446         protected boolean removeOverlay(Frame f) {
     1514        protected boolean removeOverlay(Frame f)
     1515        {
    14471516                for (Overlay o : _overlays.keySet()) {
    14481517                        if (o.Frame == f) {
    14491518                                _overlays.remove(o);
     1519                               
    14501520                                for (Item i : f.getItems()) {
    14511521                                        _overlayItems.remove(i);
    1452                                         i
    1453                                                         .onParentStateChanged(new ItemParentStateChangedEvent(
     1522                                        i.onParentStateChanged(new ItemParentStateChangedEvent(
    14541523                                                                        this,
    14551524                                                                        ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY,
    14561525                                                                        o.permission));
    14571526                                }
     1527                               
    14581528                                return true;
    14591529                        }
    14601530                }
     1531               
    14611532                return false;
    14621533        }
    14631534
    1464         public void addAllVectors(List<Vector> vectors) {
     1535        public void addAllVectors(List<Vector> vectors)
     1536        {
    14651537                for (Vector v : vectors) {
    14661538                        addVector(v);
     
    14681540        }
    14691541
    1470         public void addAllOverlays(Collection<Overlay> overlays) {
     1542        public void addAllOverlays(Collection<Overlay> overlays)
     1543        {
    14711544                for (Overlay o : overlays) {
    14721545                        addOverlay(o);
     
    14741547        }
    14751548
    1476         protected boolean addOverlay(Overlay toAdd) {
     1549        protected boolean addOverlay(Overlay toAdd)
     1550        {
    14771551                // make sure we dont add this frame as an overlay of itself
    1478                 if (toAdd.Frame == this)
    1479                         return false;
     1552                if (toAdd.Frame == this) return false;
     1553               
    14801554                // Dont add the overlay if there is already one for this frame
    1481                 if (_overlays.values().contains(toAdd.Frame))
    1482                         return false;
     1555                if (_overlays.values().contains(toAdd.Frame)) return false;
     1556               
    14831557                // Add the overlay to the map of overlays on this frame
    14841558                _overlays.put(toAdd, toAdd.Frame);
     1559               
    14851560                // Add all the overlays from the overlay frame to this frame
    1486                 for (Overlay o : toAdd.Frame.getOverlays())
    1487                         addOverlay(o);
     1561                // TODO: Can this cause a recursion loop? If A and B are overlays of each other? cts16
     1562                for (Overlay o : toAdd.Frame.getOverlays()) addOverlay(o);
    14881563
    14891564                // Add all the vectors from the overlay frame to this frame
    1490                 for (Vector v : toAdd.Frame.getVectors())
    1491                         addVector(v);
     1565                for (Vector v : toAdd.Frame.getVectors()) addVector(v);
    14921566
    14931567                // Now add the items for this overlay
    1494                 UserAppliedPermission permission = UserAppliedPermission.min(toAdd.Frame.getUserAppliedPermission(),toAdd.permission);
     1568                UserAppliedPermission permission = UserAppliedPermission.min(toAdd.Frame.getUserAppliedPermission(), toAdd.permission);
    14951569
    14961570                // Items must be notified that they have been added or removed from this
    14971571                // frame via the overlay...
    14981572                for (Item i : toAdd.Frame.getVisibleItems()) {
    1499                         i.onParentStateChanged(new ItemParentStateChangedEvent(this,
    1500                                         ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY,
    1501                                         permission));
    1502                         // i.setPermission(permission);
     1573                        i.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, permission));
    15031574                        _overlayItems.add(i);
    15041575                }
     
    15081579
    15091580        @Override
    1510         public boolean equals(Object o) {
     1581        public boolean equals(Object o)
     1582        {
    15111583                if (o instanceof String) {
    1512                         return (String.CASE_INSENSITIVE_ORDER
    1513                                         .compare((String) o, getName()) == 0);
     1584                        return (String.CASE_INSENSITIVE_ORDER.compare((String) o, getName()) == 0);
    15141585                }
    15151586
     
    15261597         * @param toMergeWith
    15271598         */
    1528         private void merge(Frame toMergeWith) {
    1529                 if (toMergeWith == null)
    1530                         return;
     1599        private void merge(Frame toMergeWith)
     1600        {
     1601                if (toMergeWith == null) return;
    15311602
    15321603                List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems());
     
    15481619         * @return the items that cant be merged
    15491620         */
    1550         public List<Item> merge(List<Item> toMerge) {
     1621        public List<Item> merge(List<Item> toMerge)
     1622        {
    15511623                ArrayList<Item> remain = new ArrayList<Item>(0);
    15521624
    15531625                for (Item i : toMerge) {
    1554                         if (!(i instanceof Text))
     1626                        if (!(i instanceof Text)) {
    15551627                                remain.add(i);
    1556                         else {
     1628                        } else {
    15571629                                if (!AttributeUtils.setAttribute(this, (Text) i)) {
    1558                                         if (i.getLink() != null)
     1630                                        if (i.getLink() != null) {
    15591631                                                merge(FrameIO.LoadFrame(i.getAbsoluteLink()));
    1560                                         else if (FrameIO
    1561                                                         .isValidFrameName(((Text) i).getFirstLine())) {
     1632                                        } else if (FrameIO.isValidFrameName(((Text) i).getFirstLine())) {
    15621633                                                // If we get hear we are merging frames
    15631634                                                merge(FrameIO.LoadFrame(((Text) i).getFirstLine()));
     
    15741645         * items are added to the backup-stack.
    15751646         */
    1576         public void clear(boolean keepAnnotations) {
     1647        public void clear(boolean keepAnnotations)
     1648        {
    15771649                List<Item> newBody = new ArrayList<Item>(0);
     1650               
    15781651                Item title = getTitleItem();
     1652               
    15791653                if (title != null) {
    15801654                        newBody.add(title);
    15811655                        _body.remove(title);
    15821656                }
     1657               
    15831658                if (keepAnnotations) {
    15841659                        for (Item i : _body) {
    1585                                 if (i.isAnnotation())
    1586                                         newBody.add(i);
    1587                         }
    1588                 }
     1660                                if (i.isAnnotation()) newBody.add(i);
     1661                        }
     1662                }
     1663               
    15891664                _body.removeAll(newBody);
    15901665                addToUndoDelete(_body);
     
    15921667                change();
    15931668
    1594                 if (!keepAnnotations && _annotations != null)
    1595                         _annotations.clear();
     1669                if (!keepAnnotations && _annotations != null) _annotations.clear();
    15961670        }
    15971671
     
    16021676         * @return
    16031677         */
    1604         public Text createNewText(String text) {
     1678        public Text createNewText(String text)
     1679        {
    16051680                Text t = createBlankText(text);
    16061681                t.setText(text);
     
    16151690         * @return The newly created Text Item
    16161691         */
    1617         public Text createBlankText(String templateType) {
     1692        public Text createBlankText(String templateType)
     1693        {
    16181694                SessionStats.CreatedText();
    16191695                Text t;
    1620                 if (templateType.length() == 0)
     1696               
     1697                if (templateType.length() == 0) {
    16211698                        t = getItemTemplate().copy();
    1622                 else
     1699                } else {
    16231700                        t = getItemTemplate(templateType.charAt(0));
    1624 
     1701                }
     1702               
    16251703                // reset attributes
    16261704                t.setID(getNextItemID());
    1627                 t.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
     1705                t.setPosition(DisplayController.getMousePosition());
    16281706                t.setText("");
    16291707                t.setParent(this);
     
    16481726        }
    16491727
    1650         public Item createDot() {
    1651                 Item dot = new Dot(DisplayIO.getMouseX(), FrameMouseActions.getY(),
    1652                                 getNextItemID());
     1728        public Item createDot()
     1729        {
     1730                Item dot = new Dot(DisplayController.getMouseX(), DisplayController.getMouseY(), getNextItemID());
    16531731
    16541732                Item template = getTemplate(_dotTemplate, ItemUtils.TAG_DOT_TEMPLATE);
    16551733                float thickness = template.getThickness();
    1656                 if (thickness > 0)
    1657                         dot.setThickness(template.getThickness());
    1658                 if (template.getLinePattern() != null)
    1659                         dot.setLinePattern(template.getLinePattern());
     1734                if (thickness > 0) dot.setThickness(template.getThickness());
     1735                if (template.getLinePattern() != null) dot.setLinePattern(template.getLinePattern());
    16601736                dot.setColor(template.getColor());
    16611737                dot.setFillColor(template.getFillColor());
     
    16651741        }
    16661742
    1667         private Text getTemplate(Text defaultTemplate, int templateTag) {
     1743        private Text getTemplate(Text defaultTemplate, int templateTag)
     1744        {
    16681745                Text t = null;
    16691746
     
    16771754
    16781755                if (t == null) {
    1679                         if (defaultTemplate == null) {
    1680                                 return null;
    1681                         }
     1756                        if (defaultTemplate == null) return null;
     1757                       
    16821758                        t = defaultTemplate;
    16831759                }
     
    16851761                // If the item is linked apply any attribute pairs on the child frame
    16861762                String link = t.getAbsoluteLink();
     1763               
    16871764                // need to get link first because copy doesnt copy the link
    16881765                t = t.copy();
     
    17011778        }
    17021779
    1703         public Text getItemTemplate(char firstChar) {
     1780        /**
     1781         * TODO: Comment. cts16
     1782         * TODO: Remove magic constants. cts16
     1783         */
     1784        public Text getItemTemplate(char firstChar)
     1785        {
    17041786                switch (firstChar) {
    1705                 case '@':
    1706                         return getAnnotationTemplate();
    1707                 case '/':
    1708                 case '#':
    1709                         return getCodeCommentTemplate();
    1710                 default:
    1711                         return getItemTemplate();
    1712                 }
    1713         }
    1714 
    1715         public Text createNewText() {
     1787                        case '@':
     1788                                return getAnnotationTemplate();
     1789                        case '/':
     1790                        case '#':
     1791                                return getCodeCommentTemplate();
     1792                        default:
     1793                                return getItemTemplate();
     1794                }
     1795        }
     1796
     1797        public Text createNewText()
     1798        {
    17161799                return createNewText("");
    17171800        }
    17181801
    1719         public Text addText(int x, int y, String text, String action) {
     1802        public Text addText(int x, int y, String text, String action)
     1803        {
    17201804                Text t = createNewText(text);
    17211805                t.setPosition(x, y);
     
    17241808        }
    17251809
    1726         public Item addText(int x, int y, String text, String action, String link) {
    1727                 Item t = addText(x, y, text, action);
     1810        public Text addText(int x, int y, String text, String action, String link)
     1811        {
     1812                Text t = addText(x, y, text, action);
    17281813                t.setLink(link);
    17291814                return t;
    17301815        }
    17311816
    1732         public Item addDot(int x, int y) {
    1733                 Item d = new Dot(x, y, getNextItemID());
     1817        public Dot addDot(int x, int y)
     1818        {
     1819                Dot d = new Dot(x, y, getNextItemID());
    17341820                addItem(d);
    17351821                return d;
     
    17541840         *            Color to fill the rectangle with
    17551841         */
    1756         public List<Item> addRectangle(int x, int y, int width, int height, float borderThickness, Color borderColor, Color fillColor) {
     1842        public List<Item> addRectangle(int x, int y, int width, int height, float borderThickness, Colour borderColor, Colour fillColor)
     1843        {
    17571844                List<Item> rectComponents = new ArrayList<Item>();
    17581845                Item[] corners = new Item[4];
     
    17961883                List<Item> rect = new ArrayList<Item>(rectComponents);
    17971884                this.addAllItems(rectComponents);
    1798                 FrameMouseActions.anchor(rectComponents);
     1885                StandardGestureActions.anchor(rectComponents);
    17991886                return rect;
    1800                 // rectComponents.clear();
    1801         }
    1802 
    1803         public boolean isSaved() {
     1887        }
     1888
     1889        public boolean isSaved()
     1890        {
    18041891                return _saved;
    18051892        }
    18061893
    1807         public void setSaved() {
    1808                 // System.out.println(getName() + " saved");
     1894        public void setSaved()
     1895        {
    18091896                _saved = true;
    18101897                _change = false;
    18111898        }
    18121899
    1813         public static boolean rubberbandingLine() {
    1814                 return FreeItems.getInstance().size() == 2
    1815                                 && (FreeItems.getInstance().get(0) instanceof Line || FreeItems
    1816                                                 .getInstance().get(1) instanceof Line);
     1900        public static boolean rubberbandingLine()
     1901        {
     1902                return  FreeItems.getInstance().size() == 2 &&
     1903                                (FreeItems.getInstance().get(0) instanceof Line || FreeItems.getInstance().get(1) instanceof Line);
    18171904        }
    18181905
     
    18251912         * @return true if the item is a normal text item
    18261913         */
    1827         public boolean isNormalTextItem(Item it) {
    1828                 if (it instanceof Text && it != getTitleItem() && it != _frameName
    1829                                 && !((Text) it).isSpecialAnnotation()) {
     1914        public boolean isNormalTextItem(Item it)
     1915        {
     1916                if (it instanceof Text && it != getTitleItem() && it != _frameName && !((Text) it).isSpecialAnnotation()) {
    18301917                        return true;
    18311918                }
     
    18391926         * @param index
    18401927         */
    1841         public boolean moveMouseToTextItem(int index) {
     1928        public boolean moveMouseToTextItem(int index)
     1929        {
    18421930                List<Item> items = getItems();
    18431931                int itemsFound = 0;
    18441932                for (int i = 0; i < items.size(); i++) {
    18451933                        Item it = items.get(i);
    1846                         if (isNormalTextItem(it))
    1847                                 itemsFound++;
     1934                        if (isNormalTextItem(it)) itemsFound++;
    18481935                        if (itemsFound > index) {
    1849                                 DisplayIO.setCursorPosition(((Text) it)
    1850                                                 .getParagraphEndPosition().x, it.getY());
    1851                                 DisplayIO.resetCursorOffset();
    1852                                 FrameGraphics.Repaint();
     1936                                DisplayController.setCursorPosition(((Text) it).getParagraphEndPosition().x, it.getY());
     1937                                DisplayController.resetCursorOffset();
     1938                                DisplayController.requestRefresh(true);
    18531939                                return true;
    18541940                        }
     
    18571943                return false;
    18581944        }
    1859 
    1860         /*
    1861          * public boolean moveMouseToNextTextItem(int index) { List<Item> items =
    1862          * getItems(); int itemsFound = 0; for (int i = 0; i < items.size(); i++) {
    1863          * Item it = items.get(i); if ( isNormalTextItem(it)) itemsFound++; if
    1864          * (itemsFound > index) {
    1865          * DisplayIO.setCursorPosition(((Text)it).getEndParagraphPosition().x,
    1866          * it.getY()); DisplayIO.resetCursorOffset(); FrameGraphics.Repaint();
    1867          * return true; } }
    1868          *
    1869          * return false; }
    1870          */
    18711945
    18721946        /**
    18731947         * Searches for an annotation item called start to be used as the default
    18741948         * cursor location when TDFC occurs.
    1875          */
    1876         public boolean moveMouseToDefaultLocation() {
     1949         *
     1950         * TODO: Remove magic constants. cts16
     1951         */
     1952        public boolean moveMouseToDefaultLocation()
     1953        {
    18771954                List<Item> items = getItems();
    18781955
     
    18801957                        if (it instanceof Text) {
    18811958                                Text t = (Text) it;
    1882                                 if (t.getText().toLowerCase().startsWith("@start")
    1883                                                 || t.getText().toLowerCase().equals("@start:")) {
     1959                                if (t.getText().toLowerCase().startsWith("@start") || t.getText().toLowerCase().equals("@start:")) {
    18841960                                        // Used to allow users the option of putting an initial
    18851961                                        // bullet after the @start
     
    18881964                                        t.setText("");
    18891965
    1890                                         if (t.getText().equals(""))
    1891                                                 DisplayIO.getCurrentFrame().removeItem(t);
    1892                                         if (!FreeItems.itemsAttachedToCursor()) {
    1893                                                 DisplayIO.setCursorPosition(((Text) it)
    1894                                                                 .getParagraphEndPosition());
    1895                                                 DisplayIO.resetCursorOffset();
     1966                                        if (t.getText().equals("")) DisplayController.getCurrentFrame().removeItem(t);
     1967                                       
     1968                                        if (!FreeItems.hasItemsAttachedToCursor()) {
     1969                                                DisplayController.setCursorPosition(((Text) it).getParagraphEndPosition());
     1970                                                DisplayController.resetCursorOffset();
    18961971                                        }
    1897                                         FrameGraphics.Repaint();
     1972                                       
     1973                                        DisplayController.requestRefresh(true);
     1974                                       
    18981975                                        return true;
    18991976                                }
     
    19111988         *         name of the frame if the tag isnt on the frame.
    19121989         */
    1913         public String getExportFileName() {
     1990        public String getExportFileName()
     1991        {
    19141992                String fileName = getExportFileTagValue();
    19151993
     
    19252003        }
    19262004
    1927         public void toggleBackgroundColor() {
    1928                 setBackgroundColor(ColorUtils.getNextColor(_background,
    1929                                 TemplateSettings.BackgroundColorWheel.get(), null));
    1930         }
    1931 
    1932         public void setName(String frameset, int i) {
     2005        public void toggleBackgroundColor()
     2006        {
     2007                setBackgroundColor(ColorUtils.getNextColor(_background, TemplateSettings.BackgroundColorWheel.get(), null));
     2008        }
     2009
     2010        public void setName(String frameset, int i)
     2011        {
    19332012                setFrameset(frameset);
    19342013                setFrameNumber(i);
     
    19402019         *
    19412020         */
    1942         public void refreshItemPermissions(UserAppliedPermission maxPermission) {
    1943                 if(_frameName == null)
    1944                         return;
     2021        public void refreshItemPermissions(UserAppliedPermission maxPermission)
     2022        {
     2023                if(_frameName == null) return;
    19452024               
    19462025                UserAppliedPermission permission = UserAppliedPermission.min(maxPermission, getUserAppliedPermission());
     
    19482027                switch (permission) {
    19492028                case none:
    1950                         _frameName.setBackgroundColor(new Color(255, 220, 220));
     2029                        _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_NONE);
    19512030                        break;
    19522031                case followLinks:
    1953                         _frameName.setBackgroundColor(new Color(255, 230, 135));
     2032                        _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FOLLOW_LINKS);
    19542033                        break;
    19552034                case copy:
    1956                         _frameName.setBackgroundColor(new Color(255, 255, 155));
     2035                        _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_COPY);
    19572036                        break;
    19582037                case createFrames:
    1959                         _frameName.setBackgroundColor(new Color(220, 255, 220));
     2038                        _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_CREATE_FRAMES);
    19602039                        break;
    19612040                case full:
    1962                         _frameName.setBackgroundColor(null);
     2041                        _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FULL);
    19632042                        break;
    19642043                default:
     
    19752054        }
    19762055
    1977         public boolean isTestFrame() {
     2056        public boolean isTestFrame()
     2057        {
    19782058                Text title = getTitleItem();
    1979                 if (title == null)
    1980                         return false;
     2059                if (title == null) return false;
    19812060                String action = title.getFirstAction();
    1982                 if (action == null)
    1983                         return false;
     2061                if (action == null) return false;
    19842062                action = action.toLowerCase();
    1985                 return action.startsWith(Simple.RUN_FRAME_ACTION)
    1986                                 || action.startsWith(Simple.DEBUG_FRAME_ACTION);
    1987         }
    1988 
    1989         public void setActiveTime(String activeTime) {
     2063                return action.startsWith(Simple.RUN_FRAME_ACTION) || action.startsWith(Simple.DEBUG_FRAME_ACTION);
     2064        }
     2065
     2066        public void setActiveTime(String activeTime)
     2067        {
    19902068                try {
    1991                         _activeTime = new Time(Time.valueOf(activeTime).getTime() + 12 * 60
    1992                                         * 60 * 1000);
     2069                        _activeTime = new Time(Time.valueOf(activeTime).getTime() + 12 * 60 * 60 * 1000);
    19932070                } catch (Exception e) {
    19942071                        _activeTime = new Time(0);
     
    19962073        }
    19972074
    1998         public void setActiveTime(Time activeTime) {
     2075        public void setActiveTime(Time activeTime)
     2076        {
    19992077                _activeTime = activeTime;
    20002078        }
    20012079
    2002         public void setDarkTime(Time darkTime) {
     2080        public void setDarkTime(Time darkTime)
     2081        {
    20032082                _darkTime = darkTime;
    20042083        }
    20052084
    2006         public void setDarkTime(String darkTime) {
     2085        public void setDarkTime(String darkTime)
     2086        {
    20072087                try {
    2008                         _darkTime = new Time(Time.valueOf(darkTime).getTime() + 12 * 60
    2009                                         * 60 * 1000);
     2088                        _darkTime = new Time(Time.valueOf(darkTime).getTime() + 12 * 60 * 60 * 1000);
    20102089                } catch (Exception e) {
    20112090                        _darkTime = new Time(0);
     
    20182097         * @return the backup frame for this frame
    20192098         */
    2020         public Frame getBackupFrame() {
     2099        public Frame getBackupFrame()
     2100        {
    20212101                Text backupTag = _annotations.get("old");
    2022                 if (backupTag == null)
    2023                         return null;
     2102                if (backupTag == null) return null;
     2103               
    20242104                // TODO want another way to deal with updating of annotations items
    20252105                // without F12 refresh
     
    20312111                        return getBackupFrame();
    20322112                }
     2113               
    20332114                // Now return the name of the backed up frame
    20342115                String link = backupTag.getAbsoluteLink();
    2035                 if (link == null || link.equalsIgnoreCase(getName()))
    2036                         return null;
     2116                if (link == null || link.equalsIgnoreCase(getName())) return null;
    20372117
    20382118                Frame backup = FrameIO.LoadFrame(link);
     
    20402120        }
    20412121
    2042         public Time getDarkTime() {
     2122        public Time getDarkTime()
     2123        {
    20432124                return _darkTime;
    20442125        }
    20452126
    2046         public Time getActiveTime() {
     2127        public Time getActiveTime()
     2128        {
    20472129                return _activeTime;
    20482130        }
     
    20542136         * @return the number of frames in the backed up comet
    20552137         */
    2056         public int getCometLength() {
     2138        public int getCometLength()
     2139        {
    20572140                Frame backup = getBackupFrame();
    20582141                return 1 + (backup == null ? 0 : backup.getCometLength());
    20592142        }
    20602143
    2061         public void addAnnotation(Text item) {
     2144        public void addAnnotation(Text item)
     2145        {
    20622146                if (_annotations == null) {
    20632147                        _annotations = new HashMap<String, Text>();
    20642148                }
     2149               
    20652150                // Check if this item has already been processed
    20662151                String[] tokens = item.getProcessedText();
     
    20742159                String text = item.getText().trim();
    20752160                assert (text.charAt(0) == '@');
     2161               
    20762162                // Ignore annotations with spaces after the tag symbol
    20772163                if (text.length() < 2 || !Character.isLetter(text.charAt(1))) {
     
    20792165                        return;
    20802166                }
     2167               
    20812168                // The separator char must come before the first non letter otherwise we
    20822169                // ignore the annotation item
     
    21012188                        }
    21022189                }
     2190               
    21032191                // If it was nothing but letters and digits save the tag
    21042192                String lowerCaseText = text.substring(1).toLowerCase();
     
    21072195        }
    21082196
    2109         public boolean hasAnnotation(String annotation) {
    2110                 if (_annotations == null)
    2111                         refreshAnnotationList();
     2197        public boolean hasAnnotation(String annotation)
     2198        {
     2199                if (_annotations == null) refreshAnnotationList();
     2200               
    21122201                return _annotations.containsKey(annotation.toLowerCase());
    21132202        }
     
    21212210         *         is not on the frame or has no value.
    21222211         */
    2123         public String getAnnotationValue(String annotation) {
    2124                 if (_annotations == null)
    2125                         refreshAnnotationList();
     2212        public String getAnnotationValue(String annotation)
     2213        {
     2214                if (_annotations == null) refreshAnnotationList();
    21262215
    21272216                Text text = _annotations.get(annotation.toLowerCase());
    2128                 if (text == null)
    2129                         return null;
     2217                if (text == null) return null;
    21302218
    21312219                String[] tokens = text.getProcessedText();
    2132                 if (tokens != null && tokens.length > 1)
    2133                         return tokens[1];
     2220               
     2221                if (tokens != null && tokens.length > 1) return tokens[1];
     2222               
    21342223                return null;
    21352224        }
    21362225
    2137         Map<String, Text> _annotations = null;
    2138 
    2139         private Collection<FrameObserver> _observers = new HashSet<FrameObserver>();
    2140 
    2141         public void clearAnnotations() {
     2226        public void clearAnnotations()
     2227        {
    21422228                _annotations = null;
    21432229        }
    21442230
    2145         public List<Item> getVisibleItems() {
     2231        public List<Item> getVisibleItems()
     2232        {
    21462233                return getItems(true);
    21472234        }
    21482235
    2149         private void refreshAnnotationList() {
    2150                 if (_annotations == null)
     2236        private void refreshAnnotationList()
     2237        {
     2238                if (_annotations == null) {
    21512239                        _annotations = new HashMap<String, Text>();
    2152                 else
     2240                } else {
    21532241                        _annotations.clear();
     2242                }
     2243               
    21542244                for (Text text : getTextItems()) {
    21552245                        if (text.isAnnotation()) {
     
    21592249        }
    21602250
    2161         public Collection<Text> getAnnotationItems() {
     2251        public Collection<Text> getAnnotationItems()
     2252        {
    21622253                if (_annotations == null) {
    21632254                        refreshAnnotationList();
    21642255                }
     2256               
    21652257                return _annotations.values();
    21662258        }
     
    21712263         * @return the list of items to be saved to a text file
    21722264         */
    2173         public List<Item> getItemsToSave() {
    2174 
     2265        public List<Item> getItemsToSave()
     2266        {
    21752267                if (!_sorted) {
    21762268                        Collections.sort(_body);
     
    21792271
    21802272                // iWidgets are handled specially since 8 items are written as one
    2181                 Collection<InteractiveWidget> seenWidgets = new LinkedHashSet<InteractiveWidget>();
     2273                Collection<Widget> seenWidgets = new LinkedHashSet<Widget>();
    21822274
    21832275                List<Item> toSave = new ArrayList<Item>();
    21842276
    21852277                for (Item i : _body) {
    2186                         if (i == null || i.dontSave()) {
    2187                                 continue;
    2188                         }
     2278                        if (i == null || i.dontSave()) continue;
    21892279
    21902280                        // Ensure only one of the WidgetCorners represent a single widget
    21912281                        if (i instanceof WidgetCorner) {
    2192                                 InteractiveWidget iw = ((WidgetCorner) i).getWidgetSource();
    2193                                 if (seenWidgets.contains(iw))
    2194                                         continue;
     2282                                Widget iw = ((WidgetCorner) i).getWidgetSource();
     2283                                if (seenWidgets.contains(iw)) continue;
    21952284                                seenWidgets.add(iw);
    21962285                                toSave.add(iw.getSource());
     
    21982287                                XRayable x = (XRayable) i;
    21992288                                toSave.addAll(x.getItemsToSave());
    2200                         }// Circle centers are items with attached enclosures
    2201                         else if (i.hasEnclosures()) {
     2289                        // Circle centers are items with attached enclosures
     2290                        } else if (i.hasEnclosures()) {
    22022291                                continue;
    22032292                        } else {
     
    22132302        }
    22142303
    2215         public Collection<Item> getOverlayItems() {
     2304        public Collection<Item> getOverlayItems()
     2305        {
    22162306                return _overlayItems;
    22172307        }
     
    22232313         * @return
    22242314         */
    2225         public boolean hasOverlay(Frame frame) {
     2315        public boolean hasOverlay(Frame frame)
     2316        {
    22262317                return _overlays.containsValue(frame);
    22272318        }
    22282319
    2229         public Collection<Item> getAllItems() {
     2320        public Collection<Item> getAllItems()
     2321        {
    22302322                Collection<Item> allItems = new LinkedHashSet<Item>(_body);
    22312323                allItems.addAll(_overlayItems);
     
    22342326        }
    22352327
    2236         public Collection<Item> getVectorItems() {
     2328        public Collection<Item> getVectorItems()
     2329        {
    22372330                Collection<Item> vectorItems = new LinkedHashSet<Item>(_vectorItems);
    22382331                vectorItems.addAll(getNonAnnotationItems(false));
     
    22452338         * @return
    22462339         */
    2247         public Collection<Text> getTextItems() {
     2340        public Collection<Text> getTextItems()
     2341        {
    22482342                Collection<Text> textItems = new ArrayList<Text>();
     2343               
    22492344                for (Item i : getItems(true)) {
    22502345                        // only add up normal body text items
     
    22532348                        }
    22542349                }
     2350               
    22552351                return textItems;
    22562352        }
    22572353
    2258         public Text getAnnotation(String annotation) {
    2259                 if (_annotations == null)
    2260                         refreshAnnotationList();
     2354        public Text getAnnotation(String annotation)
     2355        {
     2356                if (_annotations == null) refreshAnnotationList();
    22612357
    22622358                return _annotations.get(annotation.toLowerCase());
    22632359        }
    22642360
    2265         public void recalculate() {
    2266 
     2361        public void recalculate()
     2362        {
    22672363                for (Item i : getItems()) {
    22682364                        if (i.hasFormula() && !i.isAnnotation()) {
     
    22722368        }
    22732369
    2274         public void removeObserver(FrameObserver observer) {
     2370        public void removeObserver(FrameObserver observer)
     2371        {
    22752372                _observers.remove(observer);
    22762373        }
    22772374
    2278         public void addObserver(FrameObserver observer) {
     2375        public void addObserver(FrameObserver observer)
     2376        {
    22792377                _observers.add(observer);
    22802378        }
    22812379
    2282         public void clearObservers() {
     2380        public void clearObservers()
     2381        {
    22832382                for (FrameObserver fl : _observers) {
    22842383                        fl.removeSubject(this);
    22852384                }
     2385               
    22862386                // The frame listener will call the frames removeListener method
    22872387                assert (_observers.size() == 0);
    22882388        }
    22892389
    2290         public Collection<Text> getNonAnnotationText(boolean removeTitle) {
     2390        public Collection<Text> getNonAnnotationText(boolean removeTitle)
     2391        {
    22912392                Collection<Text> items = new LinkedHashSet<Text>();
     2393               
    22922394                for (Item i : getItems(true)) {
    22932395                        // only add up normal body text items
     
    22962398                        }
    22972399                }
     2400               
    22982401                if (removeTitle) {
    22992402                        items.remove(getTitleItem());
    23002403                }
     2404               
    23012405                return items;
    23022406        }
    23032407
    2304         public void dispose() {
     2408        public void dispose()
     2409        {
    23052410                clearObservers();
     2411               
    23062412                for (Item i : _body) {
    23072413                        i.dispose();
    23082414                }
     2415               
    23092416                _frameName.dispose();
    23102417                _body = null;
     
    23122419        }
    23132420
    2314         public void parse() {
     2421        public void parse()
     2422        {
    23152423                for (Overlay o : getOverlays()) {
    23162424                        o.Frame.parse();
    23172425                }
     2426               
    23182427                // Must parse the frame AFTER the overlays
    23192428                FrameUtils.Parse(this);
    23202429        }
    23212430
    2322         public void setPath(String path) {
     2431        public void setPath(String path)
     2432        {
    23232433                this.path = path;
    23242434        }
    23252435
    2326         public String getPath() {
     2436        public String getPath()
     2437        {
    23272438                return path;
    23282439        }
    23292440
    2330         public void setLocal(boolean isLocal) {
     2441        public void setLocal(boolean isLocal)
     2442        {
    23312443                this._isLocal = isLocal;
    23322444        }
    23332445
    2334         public boolean isLocal() {
     2446        public boolean isLocal()
     2447        {
    23352448                return _isLocal;
    23362449        }
    23372450
    2338         public String getExportFileTagValue() {
     2451        public String getExportFileTagValue()
     2452        {
    23392453                return getAnnotationValue("file");
    23402454        }
    23412455
    2342         public void assertEquals(Frame frame2) {
     2456        public void assertEquals(Frame frame2)
     2457        {
    23432458                // Check that all the items on the frame are the same
    23442459                List<Item> items1 = getVisibleItems();
    23452460                List<Item> items2 = frame2.getVisibleItems();
     2461               
    23462462                if (items1.size() != items2.size()) {
    2347                         throw new UnitTestFailedException(items1.size() + " items", items2
    2348                                         .size()
    2349                                         + " items");
     2463                        throw new UnitTestFailedException(items1.size() + " items", items2.size() + " items");
    23502464                } else {
    23512465                        for (int i = 0; i < items1.size(); i++) {
     
    23612475        }
    23622476
    2363         public boolean hasObservers() {
     2477        public boolean hasObservers()
     2478        {
    23642479                return _observers != null && _observers.size() > 0;
    23652480        }
    23662481
    2367         public Collection<? extends Item> getInteractableItems() {
     2482        public Collection<? extends Item> getInteractableItems()
     2483        {
    23682484                /*
    23692485                 * TODO: Cache the interactableItems list so we dont have to recreate it
    23702486                 * every time this method is called
    23712487                 */
    2372                 if (_interactableItems.size() > 0)
    2373                         return _interactableItems;
     2488                if (_interactableItems.size() > 0) return _interactableItems;
    23742489
    23752490                for (Item i : _body) {
    2376                         if (i == null) {
    2377                                 continue;
    2378                         }
     2491                        if (i == null) continue;
    23792492                        if (i.isVisible()) {
    23802493                                _interactableItems.add(i);
     
    23862499                                _interactableItems.add(i);     
    23872500                        }
    2388                        
    2389                        
    23902501                }
    23912502
     
    23982509                return _interactableItems;
    23992510        }
     2511
     2512        private static final class History {
     2513               
     2514                public enum Type {
     2515                        deletion,
     2516                        movement
     2517                }
     2518               
     2519                public final List<Item> items;
     2520               
     2521                public final Type type;
     2522               
     2523                public History(Collection<Item> items, Type type)
     2524                {
     2525                        this.items = new LinkedList<Item>(items);
     2526                        this.type = type;
     2527                }
     2528               
     2529                public String toString()
     2530                {
     2531                        return this.type.toString() + ":\n" + this.items.toString();
     2532                }
     2533        }
    24002534}
Note: See TracChangeset for help on using the changeset viewer.