Changeset 156


Ignore:
Timestamp:
07/25/08 09:24:45 (16 years ago)
Author:
ra33
Message:

Added calculate action

Location:
trunk/src/org/expeditee
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Actions.java

    r154 r156  
    2222import org.expeditee.gui.FrameIO;
    2323import org.expeditee.gui.FrameUtils;
     24import org.expeditee.gui.FreeItems;
    2425import org.expeditee.gui.MessageBay;
    2526import org.expeditee.io.Conversion;
     
    3839 * When adding an action to a class in the actions folder the following must be
    3940 * considered:
    40  * <li> If the first parameter is of type Frame or Item they will be called with
    41  * the current frame and the item used to execute the action.</li>
    42  * <li> If the second item is also of type Frame or Item it will be set to the
    43  * current frame or item.</li>
     41 * <li> If the first parameter is of type Frame, the current frame will be
     42 * passed as a parameter.
     43 * <li> If the next param is of type Item the item on the end of the cursor will
     44 * be passed or the item that was clicked to execute the action if nothing is on
     45 * the end of the cursor. current frame or item.</li>
    4446 * <li> If there are multiple overloads for the same method they should be
    4547 * declared in order of the methods with the most parameteres to least
     
    383385         *            The starting Frame that the JAG is being launched on
    384386         */
    385         private static void LaunchAgent(String name, String parameters, Frame source, Item clicked) {
     387        private static void LaunchAgent(String name, String parameters,
     388                        Frame source, Item clicked) {
    386389                // Use the correct case version for printing error messages
    387390                String nameWithCorrectCase = name;
     
    444447                        t.setPriority(Thread.MIN_PRIORITY);
    445448
     449                        Item itemParam = clicked;
     450                        if (FreeItems.textAttachedToCursor()) {
     451                                itemParam = FreeItems.getItemAttachedToCursor();
     452                        }
     453
    446454                        // check for errors during initialisation
    447                         if (!_Agent.initialise(source, clicked)) {
     455                        if (!_Agent.initialise(source, itemParam)) {
    448456                                MessageBay.errorMessage("Error initialising agent: "
    449457                                                + nameWithCorrectCase);
     
    521529                Class[] paramTypes = method.getParameterTypes();
    522530
     531                int paramCount = paramTypes.length;
    523532                // if the method has no parameters
    524                 if (paramTypes.length == 0)
     533                if (paramCount == 0)
    525534                        return new Object[0];
    526535
    527                 Object[] objects = new Object[paramTypes.length];
     536                Object[] objects = new Object[paramCount];
    528537                int ind = 0;
    529538
     
    531540                // or launcher
    532541                // length must be at least one if we are still running
    533                 if (paramTypes[0] == Frame.class) {
    534                         objects[0] = source;
    535                         ind = 1;
    536                 } else if (Item.class.isAssignableFrom(paramTypes[0])) {
    537                         objects[0] = launcher;
    538                         ind = 1;
    539                 }
    540 
    541                 // if the first class was a frame or item, the second class might be the
    542                 // other
    543                 if (paramTypes.length > 1 && objects[0] != null) {
    544                         if (paramTypes[1] == Frame.class) {
    545                                 objects[1] = source;
    546                                 ind = 2;
    547                         } else if (Item.class.isAssignableFrom(paramTypes[1])) {
    548                                 objects[1] = launcher;
    549                                 ind = 2;
    550                         }
     542                if (paramTypes[ind] == Frame.class) {
     543                        objects[ind] = source;
     544                        ind++;
     545                }
     546
     547                if (paramCount > ind && Item.class.isAssignableFrom(paramTypes[ind])) {
     548                        objects[ind] = launcher;
     549                        ind++;
    551550                }
    552551
     
    670669         */
    671670        public static String getCapitalizedFontName(String fontName) {
    672                 //Initialize the fonts if they have not already been loaded
     671                // Initialize the fonts if they have not already been loaded
    673672                initFonts();
    674673                return _Fonts.get(fontName.toLowerCase());
     
    688687                }
    689688        }
    690        
    691         public static HashMap<String, String> getFonts(){
     689
     690        public static HashMap<String, String> getFonts() {
    692691                initFonts();
    693692                return _Fonts;
  • trunk/src/org/expeditee/actions/Misc.java

    r154 r156  
    99import java.io.IOException;
    1010import java.lang.reflect.Method;
     11import java.text.NumberFormat;
    1112import java.util.ArrayList;
    1213import java.util.Collection;
    1314import java.util.List;
     15import java.util.Observable;
     16import java.util.Observer;
    1417
    1518import javax.imageio.ImageIO;
    1619
     20import org.expeditee.gui.AttributeUtils;
     21import org.expeditee.gui.AttributeValuePair;
    1722import org.expeditee.gui.DisplayIO;
    1823import org.expeditee.gui.Frame;
     
    2833import org.expeditee.stats.StatsLogger;
    2934import org.expeditee.stats.TreeStats;
     35import org.nfunk.jep.Node;
     36import org.nfunk.jep.Variable;
    3037
    3138/**
     
    8895                                                action);
    8996                        }
     97                } else {
     98                        MessageBay.errorMessage("Item must be a text item.");
    9099                }
    91100        }
     
    106115                        if (deletedFrameName != null) {
    107116                                DisplayIO.Back();
    108                                 //Remove any links on the previous frame to the one being deleted
     117                                // Remove any links on the previous frame to the one being
     118                                // deleted
    109119                                Frame current = DisplayIO.getCurrentFrame();
    110120                                for (Item i : current.getItems())
     
    116126                                MessageBay.displayMessage(deletedFrame + " renamed "
    117127                                                + deletedFrameName);
    118                                 //FrameGraphics.Repaint();
     128                                // FrameGraphics.Repaint();
    119129                                return;
    120130                        }
     
    645655                return item;
    646656        }
     657
     658        public static void calculate(Frame frame, Item toCalculate) {
     659                if (toCalculate instanceof Text) {
     660                        Text text = (Text) toCalculate;
     661                        org.nfunk.jep.JEP myParser = new org.nfunk.jep.JEP();
     662                        myParser.addStandardFunctions();
     663                        myParser.addStandardConstants();
     664                        myParser.setImplicitMul(true);
     665
     666                        Observer observer = new Observer() {
     667                                private String _attribute = "";
     668                                public void update(Observable ob, Object o) {
     669                                        _attribute = ((Variable)o).getName() + ": ";
     670                                }
     671                               
     672                                @Override
     673                                public String toString() {
     674                                        return _attribute;
     675                                }
     676                        };
     677
     678                        // Check for variables
     679                        for (Text t : frame.getTextItems()) {
     680                                AttributeValuePair avp = AttributeUtils.getPair(t.getText());
     681                                if (avp != null) {
     682                                        myParser.addVariable(avp.getAttribute(), avp
     683                                                        .getDoubleValue());
     684                                }
     685                        }
     686                       
     687                        myParser.getSymbolTable().addObserver(observer);
     688                        myParser.setAllowAssignment(true);
     689                        myParser.setAllowUndeclared(true);
     690                       
     691                        // Do the calculation
     692                        Node node = myParser.parseExpression(text.getText());
     693                        if (node == null) {
     694                                for (String s : myParser.getErrorInfo().split("\n")) {
     695                                        MessageBay.errorMessage(s);
     696                                }
     697                        } else {
     698                                Double result = myParser.getValue();
     699                                NumberFormat nf = NumberFormat.getInstance();
     700                                nf.setMinimumFractionDigits(0);
     701                                nf.setMaximumFractionDigits(15);
     702                                text.setText(observer.toString() + nf.format(result));
     703                                text.setPosition(FrameMouseActions.MouseX,
     704                                                FrameMouseActions.MouseY);
     705                                FrameMouseActions.resetOffset();
     706                        }
     707
     708                }
     709        }
    647710}
  • trunk/src/org/expeditee/actions/Simple.java

    r154 r156  
    2424import org.expeditee.agents.WriteTree;
    2525import org.expeditee.gui.AttributeUtils;
     26import org.expeditee.gui.Browser;
    2627import org.expeditee.gui.DisplayIO;
    2728import org.expeditee.gui.Frame;
     
    312313                        t.start();
    313314                } else {
    314                         assert (testSuite.runSuite());
     315                        if (!testSuite.runSuite()){
     316                                throw new RuntimeException(frameset + " failed");
     317                        }
    315318                }
    316319
     
    826829                                                .getVariable(tokens[1]).getValue();
    827830                                boolean bFound = false;
    828                                 for (Text itemToSearch : frameToSearch.getBodyTextItems(true,
    829                                                 true)) {
     831                                for (Text itemToSearch : frameToSearch.getTextItems()) {
    830832                                        bFound = context.searchItem(itemToSearch, context
    831833                                                        .getPrimitives().getStringValue(tokens[2]),
     
    862864                                                tokens[2]);
    863865                                SearchAgent searchAgent = new SearchFrameset();
    864                                 searchAgent.initialise(frameset, resultsFrameset,
     866                                searchAgent.initialise(null, null, frameset, resultsFrameset,
    865867                                                replacementString, pattern);
    866868                                _agent = searchAgent;
     
    899901                                SearchAgent searchAgent = new SearchTree();
    900902                                _agent = searchAgent;
    901                                 searchAgent.initialise(topFrameName, resultsFrameset,
     903                                searchAgent.initialise(null, null, topFrameName, resultsFrameset,
    902904                                                replacementString, pattern);
    903905                                searchAgent.run();
     
    962964                                Item valueItem = null;
    963965                                // Begin the search
    964                                 for (Text text : targetFrame.getBodyTextItems(true)) {
     966                                for (Text text : targetFrame.getTextItems()){
    965967                                        String s = text.getText().toLowerCase();
    966968
     
    978980                                                        .getParagraphEndPosition();
    979981
    980                                         for (Text text : targetFrame.getBodyTextItems(true)) {
     982                                        for (Text text : targetFrame.getTextItems()) {
    981983                                                Point startPoint = text.getPosition();
    982984                                                if (Math.abs(startPoint.y - endPoint.y) < 10
     
    11961198                                        Item valueItem = null;
    11971199                                        // Begin the search
    1198                                         for (Text text : targetFrame.getBodyTextItems(true)) {
     1200                                        for (Text text : targetFrame.getTextItems()) {
    11991201                                                String s = text.getText().toLowerCase();
    12001202                                                if (s.startsWith(targetAttribute)) {
     
    12131215                                                                .getParagraphEndPosition();
    12141216
    1215                                                 for (Text text : targetFrame.getBodyTextItems(true)) {
     1217                                                for (Text text : targetFrame.getTextItems()) {
    12161218                                                        Point startPoint = text.getPosition();
    12171219                                                        if (Math.abs(startPoint.y - endPoint.y) < 10
     
    12541256                                        context.getPrimitives().setValue(frameNameVar,
    12551257                                                        frame.getName());
    1256                                 } else if (tokens[0].startsWith("getframefilepath")) {
     1258                                } else if (tokens[0].startsWith("getframetitle")) {
     1259                                        String frameTitleVar = DEFAULT_ITEM;
     1260                                        String frameVar = DEFAULT_FRAME;
     1261
     1262                                        if (tokens.length > 1) {
     1263                                                assertExactParametreCount(tokens, 2);
     1264                                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     1265                                                assertVariableType(tokens[2], 2, SPointer.itemPrefix);
     1266                                                frameTitleVar = tokens[2];
     1267                                                frameVar = tokens[1];
     1268                                        }
     1269                                        Frame frame = (Frame) context.getPointers().getVariable(
     1270                                                        frameVar).getValue();
     1271                                        context.getPointers().setObject(frameTitleVar,
     1272                                                        frame.getTitleItem());
     1273                                }else if (tokens[0].startsWith("getframefilepath")) {
    12571274                                        assertExactParametreCount(tokens, 2);
    12581275                                        String frameName = context.getPrimitives().getStringValue(
     
    13711388                                        // assertPrimitiveType(tokens[2], 2);
    13721389                                        String link = ((Item) context.getPointers().getVariable(
    1373                                                         tokens[1]).getValue()).getLink();
     1390                                                        tokens[1]).getValue()).getAbsoluteLink();
    13741391                                        context.getPrimitives().setValue(tokens[2],
    13751392                                                        new SString(link));
     
    16451662                        } else if (ifStatement.equals("ifdefined")) {
    16461663                                result = context.isDefined(tokens[1]);
    1647                         } else if (ifStatement.equals("ifnotdef")) {
     1664                        } else if (ifStatement.equals("ifnotdefined")) {
    16481665                                result = !context.isDefined(tokens[1]);
    16491666                        } else if (ifStatement.equals("ifzero")) {
     
    19821999                        } else
    19832000                                context.readFrame(frameName, frameVar, null);
    1984                 } else if (tokens[0].equals("readkbdcond")) {
     2001                }else if (tokens[0].equals("exitexpeditee")) {
     2002                        Browser._theBrowser.exit();
     2003                }else if (tokens[0].equals("readkbdcond")) {
    19852004
    19862005                        String nextCharVarName = DEFAULT_CHAR;
  • trunk/src/org/expeditee/agents/ComputeTree.java

    r154 r156  
    55import org.expeditee.gui.AttributeUtils;
    66import org.expeditee.gui.Frame;
    7 import org.expeditee.gui.FrameGraphics;
    87import org.expeditee.gui.FrameIO;
    98import org.expeditee.items.Item;
  • trunk/src/org/expeditee/agents/DisplayTree.java

    r154 r156  
    33import org.expeditee.gui.DisplayIO;
    44import org.expeditee.gui.Frame;
    5 import org.expeditee.gui.FrameUtils;
    65import org.expeditee.gui.MessageBay;
    76import org.expeditee.items.Item;
  • trunk/src/org/expeditee/agents/Format.java

    r154 r156  
    5252                ArrayList<Item> columnHeads = new ArrayList<Item>();
    5353
    54                 ArrayList<ArrayList<Item>> columns = new ArrayList<ArrayList<Item>>();
     54                ArrayList<ArrayList<Text>> columns = new ArrayList<ArrayList<Text>>();
    5555
    56                 for (Item t : itemsToFormat) {
     56                for (Text t : itemsToFormat) {
    5757                        int col = findColumn(columnHeads, t);
    5858                        // if this is the head of a new column
    5959                        if (col < 0) {
    6060                                columnHeads.add(t);
    61                                 columns.add(new ArrayList<Item>());
     61                                columns.add(new ArrayList<Text>());
    6262                                // otherwise the column for this item has already been
    6363                                // found set the column to be the one we just added...
     
    9292
    9393                // sort lists by their X axis
    94                 Collections.sort(columns, new Comparator<ArrayList<Item>>() {
    95                         public int compare(ArrayList<Item> o1, ArrayList<Item> o2) {
     94                Collections.sort(columns, new Comparator<ArrayList<Text>>() {
     95                        public int compare(ArrayList<Text> o1, ArrayList<Text> o2) {
    9696                                if (o2.size() == 0)
    9797                                        return -10;
     
    112112
    113113                for (int i = 0; i < columns.size() - 1; i++) {
    114                         List<Item> list = columns.get(i);
     114                        List<Text> list = columns.get(i);
    115115
    116116                        int maxX = 0;
  • trunk/src/org/expeditee/agents/SearchAgent.java

    r143 r156  
    55import org.expeditee.gui.FrameGraphics;
    66import org.expeditee.gui.FrameIO;
    7 import org.expeditee.gui.FreeItems;
    8 import org.expeditee.gui.MessageBay;
    97import org.expeditee.io.Conversion;
    108import org.expeditee.items.Item;
     
    2321        @Override
    2422        public boolean initialise(Frame frame, Item item) {
    25                 if (FreeItems.getInstance().size() != 1) {
    26                         MessageBay
    27                                         .displayMessage("Attach search pattern to the end of the cursor");
    28                         return false;
    29                 }
    30                 Item cursorItem = Frame.getItemAttachedToCursor();
    31                 if (!(cursorItem instanceof Text))
    32                         return false;
    33 
    34                 String pattern = ((Text) cursorItem).getText();
     23                String pattern = item.getText();
    3524                String resultFrameset = null;
     25               
     26                //TODO use a results frame specified on the profile frame
    3627                if (item.getLink() == null) {
    3728                        resultFrameset = frame.getFramesetName();
     
    4031                                        false);
    4132                }
    42                 return initialise(frame.getFramesetName(), resultFrameset, null, pattern);
     33                return initialise(frame, item, frame.getFramesetName(), resultFrameset, null, pattern);
    4334        }
    4435
    45         public boolean initialise(String startName, String resultsFrameset,
     36        public boolean initialise(Frame frame, Item item, String startName, String resultsFrameset,
    4637                        String replacementString, String pattern) {
    4738                _pattern = pattern;
     
    5748                _end = _results.getFirstFrame();
    5849               
    59                 return super.initialise(null, null);
     50                return super.initialise(frame, item);
    6051        }
    6152       
     
    8677                if (frameToSearch == null)
    8778                        return false;
    88                 for (Text itemToSearch : frameToSearch.getVisibleTextItems()) {
     79                for (Text itemToSearch : frameToSearch.getTextItems()) {
    8980                        // Search for the item and add it to the results page if
    9081                        // it is found
  • trunk/src/org/expeditee/agents/SearchTree.java

    r134 r156  
    4242                overwriteMessage("Searching " + frameName);
    4343
    44                 for (Text itemToSearch : frameToSearch.getVisibleTextItems()) {
     44                for (Text itemToSearch : frameToSearch.getTextItems()) {
    4545                        // Search for the item and add it to the results page if
    4646                        // it is found
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r154 r156  
    9595                        _GetMethods.add(Item.class.getMethod("getLink", param));
    9696                        _GetMethods.add(Item.class.getMethod("getFillColor", param));
     97                        _GetMethods.add(Item.class.getMethod("getGradientColor", param));
    9798                        _GetMethods.add(Item.class.getMethod("getFillPattern", param));
    9899                        _GetMethods.add(Item.class.getMethod("getThickness", param));
     
    709710                return null;
    710711        }
     712
     713        public static AttributeValuePair getPair(String text) {
     714                //TODO Make this more efficient
     715                String attribute = AttributeUtils.getAttribute(text);
     716                String value = AttributeUtils.getValue(text);
     717                if(attribute == null || value == null)
     718                        return null;
     719                return new AttributeValuePair(attribute, value);
     720        }
    711721}
  • trunk/src/org/expeditee/gui/Browser.java

    r154 r156  
    102102        }
    103103
    104         public static boolean isInitComplete() {
     104        private static boolean isInitComplete() {
    105105                return _initComplete;
    106106        }
     
    428428        }
    429429
     430        public static Browser initialize(){
     431                if (Browser._theBrowser == null) {
     432                        Browser.main(null);
     433                        try {
     434                                while (!isInitComplete()) {
     435                                        Thread.sleep(10);
     436                                }
     437                        } catch (Exception e) {
     438                        }
     439                }
     440                return _theBrowser;
     441        }
     442
    430443}
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r154 r156  
    6262         * The title to display in the Title bar.
    6363         */
    64         public static final String TITLE = "Exp18Jul2008A";
     64        public static final String TITLE = "Exp22Jul2008A";
    6565
    6666        private DisplayIO() {
     
    207207                FrameMouseActions.setLastRobotMove(x, y);
    208208
    209                 if (Frame.itemAttachedToCursor()) {
     209                if (FreeItems.itemAttachedToCursor()) {
    210210                        List<Item> toMove = FreeItems.getInstance();
    211211                        for (Item move : toMove) {
  • trunk/src/org/expeditee/gui/Frame.java

    r154 r156  
    237237        }
    238238
    239         public List<Text> getVisibleTextItems() {
    240                 List<Text> textItems = new ArrayList<Text>();
    241                 for (Item i : getItems(true)) {
    242                         // only add up normal body text items
    243                         if (i instanceof Text) {
    244                                 textItems.add((Text) i);
    245                         }
    246                 }
    247                 return textItems;
    248         }
    249 
    250239        public List<Item> getItems() {
    251240                return getItems(false);
     
    264253
    265254        /**
    266          * Gets a list of all the non annotation text items on the frame, excluding
    267          * the title and frame name.
     255         * Returns a list of all the non annotation text items on the frame which
     256         * are not the title or frame name or special annotation items.
    268257         *
    269258         * @param includeAnnotations
    270          *            true if annotations should be included in the list
    271          * @return list of text items
    272          */
    273         public List<Text> getBodyTextItems(boolean includeAnnotations) {
    274                 return getBodyTextItems(includeAnnotations, false);
    275         }
    276 
    277         /**
    278          * Returns a list of all the non annotation text items on the frame which
    279          * are not the title or frame name.
    280          *
     259         *            true if annotation items without special meaning should be
     260         *            included
    281261         * @param includeLineEnds
    282262         *            true if text on the end of lines should be included in the
     
    284264         * @return the list of body text items.
    285265         */
    286         public List<Text> getBodyTextItems(boolean includeAnnotations,
    287                         boolean includeLineEnds) {
     266        public List<Text> getBodyTextItems(boolean includeAnnotations) {
    288267                List<Text> bodyTextItems = new ArrayList<Text>();
    289268                for (Item i : getItems(true)) {
    290269                        // only add up normal body text items
    291270                        if ((i instanceof Text)
    292                                         && (includeAnnotations || !i.isAnnotation())
    293                                         && (includeLineEnds || !i.isLineEnd())) {
     271                                        && ((includeAnnotations && !((Text) i)
     272                                                        .isSpecialAnnotation()) || !i.isAnnotation())
     273                                        && !i.isLineEnd()) {
    294274                                bodyTextItems.add((Text) i);
    295275                        }
     
    617597        public void resetDateCreated() {
    618598                setDateCreated(Logger.EasyDateFormat("ddMMMyyyy:HHmm"));
     599                setActiveTime(new Time(0));
     600                setDarkTime(new Time(0));
     601                setVersion(0);
    619602        }
    620603
     
    662645                if (item == null || item.equals(_frameName) || _body.contains(item))
    663646                        return;
     647
     648                // When an annotation item is anchored the annotation list must be
     649                // refreshed
     650                if (item.isAnnotation()) {
     651                        clearAnnotations();
     652                }
    664653
    665654                if (item instanceof Line)
     
    706695                        if (anchorRight != null) {
    707696                                i.setX(width - anchorRight);
    708                                 if(i.hasVector()){
     697                                if (i.hasVector()) {
    709698                                        bReparse = true;
    710699                                }
     
    712701                        if (anchorBottom != null) {
    713702                                i.setY(height - anchorBottom);
    714                                 if(i.hasVector()){
     703                                if (i.hasVector()) {
    715704                                        bReparse = true;
    716705                                }
    717706                        }
    718707                }
    719                 if(bReparse){
     708                if (bReparse) {
    720709                        FrameUtils.Parse(this, false);
    721710                }
     
    725714
    726715        public void addAllItems(Collection<Item> toAdd) {
    727                 for (Item i : toAdd)
     716                for (Item i : toAdd) {
     717                        // If an annotation is being deleted clear the annotation list
     718                        if (i.isAnnotation())
     719                                i.getParentOrCurrentFrame().clearAnnotations();
    728720                        addItem(i);
     721                }
    729722        }
    730723
    731724        public void removeAllItems(Collection<Item> toRemove) {
    732                 for (Item i : toRemove)
     725                for (Item i : toRemove) {
     726                        // If an annotation is being deleted clear the annotation list
     727                        if (i.isAnnotation())
     728                                i.getParentOrCurrentFrame().clearAnnotations();
    733729                        removeItem(i);
     730                }
    734731        }
    735732
    736733        public void removeItem(Item item) {
     734                // If an annotation is being deleted clear the annotation list
     735                if (item.isAnnotation())
     736                        item.getParentOrCurrentFrame().clearAnnotations();
     737
    737738                if (_body.remove(item)) {
    738739                        change();
     
    954955        }
    955956
    956         public Item getItemAbove(Item current) {
     957        public Text getTextAbove(Text current) {
     958                Collection<Text> currentTextItems = FrameUtils.getCurrentTextItems();
     959                List<Text> toCheck = new ArrayList<Text>();
     960                if (currentTextItems.contains(current)) {
     961                        toCheck.addAll(currentTextItems);
     962                } else {
     963                        toCheck.addAll(getTextItems());
     964                }
    957965                // Make sure the items are sorted
    958                 Collections.sort(_body);
    959                 int ind = _body.indexOf(current);
     966                Collections.sort(toCheck);
     967
     968                int ind = toCheck.indexOf(current);
    960969                if (ind == -1)
    961970                        return null;
     
    963972                // loop through all items above this one, return the first match
    964973                for (int i = ind - 1; i >= 0; i--) {
    965                         Item check = _body.get(i);
    966                         if (check.isVisible() && FrameUtils.inSameColumn(check, current))
     974                        Text check = toCheck.get(i);
     975                        if (FrameUtils.inSameColumn(check, current))
    967976                                return check;
    968977                }
     
    9921001         *            The Item to get the column for.
    9931002         */
    994         public List<Item> getColumn(Item from) {
     1003        public List<Text> getColumn(Item from) {
    9951004                // Check that this item is on the current frame
    9961005                if (!_body.contains(from))
    9971006                        return null;
    9981007
    999                 // Make sure the items are sorted
    1000                 Collections.sort(_body);
    1001 
    10021008                if (from == null) {
    10031009                        from = getLastNonAnnotationTextItem();
     
    10071013                        return null;
    10081014
    1009                 List<Item> column = new ArrayList<Item>();
     1015                // Get the enclosedItems
     1016                Collection<Text> enclosed = FrameUtils.getCurrentTextItems();
     1017                List<Text> toCheck = null;
     1018                if (enclosed.contains(from)) {
     1019                        toCheck = new ArrayList<Text>();
     1020                        toCheck.addAll(enclosed);
     1021                } else {
     1022                        toCheck = getBodyTextItems(true);
     1023                }
     1024
     1025                // Make sure the items are sorted
     1026                Collections.sort(toCheck);
     1027
     1028                List<Text> column = new ArrayList<Text>();
    10101029
    10111030                // Create a list of items consisting of the item 'from' and all the
    10121031                // items below it which are also in the same column as it
    1013                 for (int i = _body.indexOf(from); i < _body.size(); i++) {
    1014                         Item item = _body.get(i);
    1015                         if (item.isVisible() && isNormalTextItem(item)) {
    1016                                 if (FrameUtils.inSameColumn(from, item))
    1017                                         column.add(item);
    1018                         }
     1032                for (int i = toCheck.indexOf(from); i < toCheck.size(); i++) {
     1033                        Text item = toCheck.get(i);
     1034                        if (FrameUtils.inSameColumn(from, item))
     1035                                column.add(item);
    10191036                }
    10201037
     
    13141331                _body = newBody;
    13151332                change();
     1333
     1334                if (!keepAnnotations)
     1335                        _annotations.clear();
    13161336        }
    13171337
     
    13521372                // Make it the width of the page
    13531373                // t.setMaxWidth(FrameGraphics.getMaxFrameSize().width);
    1354                 //if (t.getWidth() <= 0) {
    1355                         t.setRightMargin(FrameGraphics.getMaxFrameSize().width);
    1356                 //}
     1374                // if (t.getWidth() <= 0) {
     1375                t.setRightMargin(FrameGraphics.getMaxFrameSize().width);
     1376                // }
    13571377                addItem(t);
    13581378                return t;
     
    14601480                                && (FreeItems.getInstance().get(0) instanceof Line || FreeItems
    14611481                                                .getInstance().get(1) instanceof Line);
    1462         }
    1463 
    1464         public static boolean itemAttachedToCursor() {
    1465                 return FreeItems.getInstance().size() > 0;
    1466         }
    1467 
    1468         public static boolean textItemAttachedToCursor() {
    1469                 return itemAttachedToCursor()
    1470                                 && FreeItems.getInstance().get(0) instanceof Text;
    1471         }
    1472 
    1473         // TODO move this method to FreeItems
    1474         public static Item getItemAttachedToCursor() {
    1475                 if (itemAttachedToCursor())
    1476                         return FreeItems.getInstance().get(0);
    1477 
    1478                 return null;
    14791482        }
    14801483
     
    15481551                                        if (t.getText().equals(""))
    15491552                                                DisplayIO.getCurrentFrame().removeItem(t);
    1550                                         if (!Frame.itemAttachedToCursor()) {
     1553                                        if (!FreeItems.itemAttachedToCursor()) {
    15511554                                                DisplayIO.setCursorPosition(((Text) it)
    15521555                                                                .getParagraphEndPosition());
     
    17101713
    17111714        public void addAnnotation(Text item) {
     1715                if (_annotations == null) {
     1716                        _annotations = new HashMap<String, Text>();
     1717                }
    17121718                // Check if this item has already been processed
    17131719                String[] tokens = item.getProcessedText();
     
    17551761
    17561762        public boolean hasAnnotation(String annotation) {
     1763                if (_annotations == null)
     1764                        refreshAnnotationList();
    17571765                return _annotations.containsKey(annotation.toLowerCase());
    17581766        }
    17591767
    17601768        public String getAnnotationValue(String annotation) {
     1769                if (_annotations == null)
     1770                        refreshAnnotationList();
     1771
    17611772                Text text = _annotations.get(annotation.toLowerCase());
    17621773                if (text == null)
     
    17691780        }
    17701781
    1771         Map<String, Text> _annotations = new HashMap<String, Text>();
     1782        Map<String, Text> _annotations = null;
    17721783
    17731784        public void clearAnnotations() {
    1774                 _annotations.clear();
     1785                _annotations = null;
    17751786        }
    17761787
     
    17791790        }
    17801791
     1792        private void refreshAnnotationList() {
     1793                if (_annotations == null)
     1794                        _annotations = new HashMap<String, Text>();
     1795                else
     1796                        _annotations.clear();
     1797                for (Text text : getTextItems()) {
     1798                        if (text.isAnnotation()) {
     1799                                addAnnotation(text);
     1800                        }
     1801                }
     1802        }
     1803
    17811804        public Collection<Text> getAnnotationItems() {
     1805                if (_annotations == null) {
     1806                        refreshAnnotationList();
     1807                }
    17821808                return _annotations.values();
    17831809        }
     
    18511877                return vectorItems;
    18521878        }
     1879
     1880        /**
     1881         * Gets a list of all the text items on the frame.
     1882         *
     1883         * @return
     1884         */
     1885        public Collection<Text> getTextItems() {
     1886                Collection<Text> textItems = new ArrayList<Text>();
     1887                for (Item i : getItems(true)) {
     1888                        // only add up normal body text items
     1889                        if ((i instanceof Text)) {
     1890                                textItems.add((Text) i);
     1891                        }
     1892                }
     1893                return textItems;
     1894        }
    18531895}
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r154 r156  
    658658                        if (toDisconnect != null && !(i instanceof WidgetEdge)) {
    659659                                Item.HighlightMode newMode = toDisconnect.getHighlightMode();
    660                                 if (Frame.itemAttachedToCursor())
     660                                if (FreeItems.itemAttachedToCursor())
    661661                                        newMode = Item.HighlightMode.Normal;
    662662                                // unhighlight all the other dots
  • trunk/src/org/expeditee/gui/FrameIO.java

    r154 r156  
    567567                        }
    568568                }
    569 
    570569                return template;
    571570        }
     
    947946
    948947                Frame newFrame = FrameIO.CreateFrame(frameset, title, templateLink);
    949 
    950948                return newFrame;
    951949        }
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r154 r156  
    1212import java.util.ArrayList;
    1313import java.util.Collection;
     14import java.util.Collections;
    1415import java.util.HashSet;
    1516import java.util.LinkedList;
     
    444445                Frame current = DisplayIO.getCurrentFrame();
    445446                Item title = current.getTitleItem();
    446                 List<Text> textItems = current.getBodyTextItems(false);
     447
     448                Collection<Text> currentItems = FrameUtils.getCurrentTextItems();
     449                List<Text> textItems = new ArrayList<Text>();
     450                // Move to the next text item in the box if
     451                if (currentItems.contains(currentItem)) {
     452                        textItems.addAll(currentItems);
     453                } else {
     454                        textItems.add(current.getTitleItem());
     455                        textItems.addAll(current.getBodyTextItems(true));
     456                }
     457
     458                Collections.sort(textItems);
     459
    447460                if (textItems.size() == 0) {
    448461                        // If there are no text items on the frame its a NoOp
     
    484497                        return;
    485498                }
    486                 // If the user is on the title item
    487                 if (current != null && title != null && title == currentItem) {
    488                         if (down) {
    489                                 // Move to the first item
    490                                 DisplayIO.MoveCursorToEndOfItem(textItems.get(0));
    491                                 FrameGraphics.Repaint();
    492                         }
    493                         return;
    494                 }
    495499
    496500                // Find the current item... then move to the next item
     
    498502
    499503                int nextIndex = i + (down ? 1 : -1);
    500                 if (nextIndex >= 0) {
    501                         if (nextIndex < textItems.size()) {
    502                                 DisplayIO.MoveCursorToEndOfItem(textItems.get(nextIndex));
    503                         }
    504                 } else if (title != null) {
    505                         DisplayIO.MoveCursorToEndOfItem(title);
     504                if (nextIndex >= 0 && nextIndex < textItems.size()) {
     505                        DisplayIO.MoveCursorToEndOfItem(textItems.get(nextIndex));
     506                } else {
     507                        DisplayIO.MoveCursorToEndOfItem(currentItem);
    506508                }
    507509                FrameGraphics.Repaint();
     
    894896                // get whatever the user is pointing at
    895897                Item on = FrameUtils.getCurrentItem();
     898               
    896899                // check for enclosed mode
    897900                if (on == null && key.ordinal() < FunctionKey.AudienceMode.ordinal()) {
    898901                        Collection<Item> enclosed = FrameUtils.getCurrentItems(on);
    899 
     902                       
    900903                        if (enclosed != null && enclosed.size() > 0) {
    901904                                // ensure only one dot\line is present in the list
     
    10541057
    10551058                        // Get the list of items that must be dropped
    1056                         List<Item> column = DisplayIO.getCurrentFrame().getColumn(
     1059                        List<Text> column = DisplayIO.getCurrentFrame().getColumn(
    10571060                                        toDropFrom);
    10581061
     
    10711074                        Text dummyItem = null;
    10721075
    1073                         if (Frame.textItemAttachedToCursor()) {
    1074                                 dummyItem = (Text) Frame.getItemAttachedToCursor();
     1076                        if (FreeItems.textAttachedToCursor()) {
     1077                                dummyItem = (Text) FreeItems.getItemAttachedToCursor();
    10751078                                String autoBullet = getAutoBullet(dummyItem.getText());
    10761079
     
    10801083                        }
    10811084                        dummyItem = createText();
    1082                         if (Frame.textItemAttachedToCursor()) {
    1083                                 Text t = (Text) Frame.getItemAttachedToCursor();
     1085                        if (FreeItems.textAttachedToCursor()) {
     1086                                Text t = (Text) FreeItems.getItemAttachedToCursor();
    10841087                                dummyItem.setSize(t.getSize());
    10851088                                int lines = t.getTextList().size();
     
    11441147                                        }
    11451148                                }
    1146                                 if (!Frame.textItemAttachedToCursor() && !dummyItem.isEmpty()) {
     1149                                if (!FreeItems.textAttachedToCursor() && !dummyItem.isEmpty()) {
    11471150                                        DisplayIO.getCurrentFrame().addItem(dummyItem);
    11481151                                }
    11491152
    11501153                                // Move the item to the cursor position
    1151                                 if (Frame.itemAttachedToCursor()) {
     1154                                if (FreeItems.itemAttachedToCursor()) {
    11521155                                        DisplayIO.setCursorPosition(dummyItem.getX(), dummyItem
    11531156                                                        .getY());
    1154                                         Item firstItem = Frame.getItemAttachedToCursor();
     1157                                        Item firstItem = FreeItems.getItemAttachedToCursor();
    11551158                                        int deltaX = firstItem.getX() - dummyItem.getX();
    11561159                                        int deltaY = firstItem.getY() - dummyItem.getY();
     
    11641167                        }
    11651168                        if (dummyItem.getText().length() == 0
    1166                                         || Frame.itemAttachedToCursor())
     1169                                        || FreeItems.itemAttachedToCursor())
    11671170                                dummyItem.getParentOrCurrentFrame().removeItem(dummyItem);
    11681171                        dummyItem.setRightMargin(FrameGraphics.getMaxFrameSize().width);
     
    13491352                // if the user is not pointing to any item
    13501353                if (item == null) {
    1351                         if (Frame.itemAttachedToCursor())
     1354                        if (FreeItems.itemAttachedToCursor())
    13521355                                toSize.addAll(FreeItems.getInstance());
    13531356                        else {
     
    15321535                Frame currentFrame = DisplayIO.getCurrentFrame();
    15331536                if (item == null) {
    1534                         if (Frame.itemAttachedToCursor()) {
     1537                        if (FreeItems.itemAttachedToCursor()) {
    15351538                                color = FreeItems.getInstance().get(0).getColor();
    15361539                        } else {
     
    15961599
    15971600                if (setBackgroundColor) {
    1598                         if (item == null && Frame.itemAttachedToCursor()) {
     1601                        if (item == null && FreeItems.itemAttachedToCursor()) {
    15991602                                for (Item i : FreeItems.getInstance())
    16001603                                        i.setBackgroundColor(color);
     
    16041607                        }
    16051608                } else {
    1606                         if (item == null && Frame.itemAttachedToCursor()) {
     1609                        if (item == null && FreeItems.itemAttachedToCursor()) {
    16071610                                for (Item i : FreeItems.getInstance())
    16081611                                        i.setColor(color);
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r147 r156  
    246246                NavigationActions.ResetLastAddToBack();
    247247                // System.out.println(modifiersEx);
     248                if (_mouseDown == 0)
     249                        _lastMouseClickDate = new Date();
     250
    248251                int buttonPressed = e.getButton();
    249252                _mouseDown += buttonPressed;
    250 
    251                 _lastMouseClickDate = new Date();
    252253                _lastClickedOn = FrameUtils.getCurrentItem();
    253254                // load any frame if necessary
     
    321322                if (buttonPressed != MouseEvent.BUTTON1
    322323                                && (_context == CONTEXT_FREESPACE || _context == CONTEXT_AT_ENCLOSURE)
    323                                 && Frame.itemAttachedToCursor()) {
     324                                && FreeItems.itemAttachedToCursor()) {
    324325                        FrameGraphics.changeHighlightMode(_lastHighlightedItem,
    325326                                        Item.HighlightMode.None);
    326327
    327                         _lastHighlightedItem = Frame.getItemAttachedToCursor();
     328                        _lastHighlightedItem = FreeItems.getItemAttachedToCursor();
    328329                        for (Item i : FreeItems.getInstance()) {
    329330                                i.setHighlightColor(Item.DEPRESSED_HIGHLIGHT);
     
    444445                                                Item.HighlightMode.None);
    445446
    446                         if (Frame.itemAttachedToCursor()) {
     447                        if (FreeItems.itemAttachedToCursor()) {
    447448                                move(FreeItems.getInstance());
    448449                        }
     
    461462                        if (lastRanged != null) {
    462463
    463                                 Item i = Frame.getItemAttachedToCursor();
     464                                Item i = FreeItems.getItemAttachedToCursor();
    464465                                if (i != null && i instanceof Text) {
    465466                                        lastRanged.replaceSelectedText(((Text) i).getText());
     
    518519                                        return;
    519520                                }
    520                                 // if the entire text is selected then pickup the item
    521                                 if (lastRanged.getSelectionSize() == lastRanged.getLength()) {
     521                                // if the entire text is selected and its not a line end then
     522                                // pickup the item
     523                                boolean entireText = lastRanged.getSelectionSize() == lastRanged
     524                                                .getLength();
     525                                if (entireText && !lastRanged.isLineEnd()) {
    522526                                        pickup(lastRanged);
    523527                                        lastRanged.clearSelection();
    524                                         FrameGraphics.Repaint();
     528                                        FrameGraphics.refresh(true);
    525529                                        return;
    526530                                } else {
    527531                                        ranged.setText(lastRanged.cutSelectedText());
     532                                        ranged.setWidth(lastRanged.getWidth());
     533                                        // If its the whole text then replace last ranged with a dot
     534                                        if (entireText) {
     535                                                Item dot = FrameKeyboardActions.replaceText(lastRanged);
     536                                                dot.setHighlightMode(HighlightMode.None);
     537                                        }
    528538                                }
    529539                                // if the user is copying text from the item
     
    539549                                }
    540550                                ranged.setText(lastRanged.copySelectedText());
     551                                ranged.setWidth(lastRanged.getWidth());
    541552                        }
    542553
     
    545556                        ranged.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
    546557                        pickup(ranged);
    547 
    548558                        lastRanged.clearSelection();
    549                         FrameGraphics.Repaint();
     559                        lastRanged.setHighlightMode(HighlightMode.None);
     560                        refreshHighlights();
     561                        FrameGraphics.refresh(false);
    550562                        return;
    551563                }
     
    591603                if (e.getButton() == MouseEvent.BUTTON2) {
    592604                        SessionStats.AddFrameEvent("Mu");
    593                         middleButton(clickedOn, clickedIn);
     605                        middleButton(clickedOn, clickedIn, e.isShiftDown());
    594606                        return;
    595607                }
     
    609621         * This method handles all left-click actions
    610622         */
    611         private static void leftButton(Item clicked, Collection<Item> clickedIn) {
     623        private void leftButton(Item clicked, Collection<Item> clickedIn) {
    612624                // if the user is pointing at something then either follow the link or
    613625                // do TDFC
     
    710722                        if (clicked.isLineEnd()
    711723                                        || clicked.getAllConnected().contains(
    712                                                         Frame.getItemAttachedToCursor())) {
     724                                                        FreeItems.getItemAttachedToCursor())) {
    713725                                return true;
    714726                        }
     
    718730                        return false;
    719731
    720                 Item attachedToCursor = Frame.getItemAttachedToCursor();
     732                Item attachedToCursor = FreeItems.getItemAttachedToCursor();
    721733
    722734                if (clicked instanceof Text
     
    731743        public static void middleButton() {
    732744                Item currentItem = FrameUtils.getCurrentItem();
    733                 middleButton(currentItem, FrameUtils.getCurrentItems(currentItem));
     745                getInstance().middleButton(currentItem,
     746                                FrameUtils.getCurrentItems(currentItem), false);
    734747                updateCursor();
    735748        }
     
    737750        public static void rightButton() {
    738751                Item currentItem = FrameUtils.getCurrentItem();
    739                 rightButton(currentItem, FrameUtils.getCurrentItems(currentItem));
     752                getInstance().rightButton(currentItem,
     753                                FrameUtils.getCurrentItems(currentItem));
    740754                updateCursor();
    741755        }
     
    743757        public static void leftButton() {
    744758                Item currentItem = FrameUtils.getCurrentItem();
    745                 leftButton(currentItem, FrameUtils.getCurrentItems(currentItem));
     759                getInstance().leftButton(currentItem,
     760                                FrameUtils.getCurrentItems(currentItem));
    746761                updateCursor();
    747762        }
     
    750765         * This method handles all middle-click actions
    751766         */
    752         private static void middleButton(Item clicked, Collection<Item> clickedIn) {
     767        private void middleButton(Item clicked, Collection<Item> clickedIn,
     768                        boolean isShiftDown) {
    753769                // if the cursor has Items attached
    754                 if (Frame.itemAttachedToCursor()) {
     770                if (FreeItems.itemAttachedToCursor()) {
    755771                        // if the user is pointing at something, merge the items (if
    756772                        // possible)
     
    763779                                        return;
    764780                                }
    765                                 Item merger = Frame.getItemAttachedToCursor();
     781                                Item merger = FreeItems.getItemAttachedToCursor();
    766782                                assert (merger != null);
    767                                 Collection<Item> left = merge(FreeItems.getInstance(), clicked);
     783                                Collection<Item> left = null;
     784                                // when anchoring a line end onto a text line end, holding shift
     785                                // prevents the line ends from being merged
     786                                if (isShiftDown) {
     787                                        left = FreeItems.getInstance();
     788                                } else {
     789                                        left = merge(FreeItems.getInstance(), clicked);
     790                                }
    768791                                anchor(left);
    769792                                FreeItems.getInstance().clear();
    770                                 FrameGraphics.Repaint();
    771793                                updateCursor();
     794                                // Make sure the dot goes away when anchoring a line end behind
     795                                // a text line end
     796                                if (isShiftDown) {
     797                                        refreshHighlights();
     798                                }
    772799                                return;
    773800                                // otherwise, anchor the items
    774801                        } else {
    775                                 if(clickedIn != null && FreeItems.getInstance().size() == 1){
    776                                         Item item = Frame.getItemAttachedToCursor();
    777                                         if(item instanceof Text){
    778                                                 Text text = (Text)item;
    779                                                 if(AttributeUtils.setAttribute(text, text)){
    780                                                         clickedIn.removeAll(FrameUtils.getEnclosingLineEnds().iterator().next().getAllConnected());
    781                                                         for(Item i: clickedIn){
     802                                if (clickedIn != null && FreeItems.getInstance().size() == 1) {
     803                                        Item item = FreeItems.getItemAttachedToCursor();
     804                                        if (item instanceof Text) {
     805                                                Text text = (Text) item;
     806                                                if (AttributeUtils.setAttribute(text, text)) {
     807                                                        clickedIn.removeAll(FrameUtils
     808                                                                        .getEnclosingLineEnds().iterator().next()
     809                                                                        .getAllConnected());
     810                                                        for (Item i : clickedIn) {
    782811                                                                AttributeUtils.setAttribute(i, text);
    783812                                                        }
     
    786815                                        }
    787816                                }
    788                                
     817
    789818                                // if a line is being rubber-banded, check for auto
    790819                                // straightening
     
    9741003         * This method handles all right-click action
    9751004         */
    976         private static void rightButton(Item clicked, Collection<Item> clickedIn) {
     1005        private void rightButton(Item clicked, Collection<Item> clickedIn) {
    9771006                // if the cursor has Items attached, then anchor a copy of them
    9781007
    9791008                List<Item> copies = null;
    980                 if (Frame.itemAttachedToCursor()) {
     1009                if (FreeItems.itemAttachedToCursor()) {
    9811010                        // if the user is clicking on something, merge the items
    9821011                        // unless it is a point onto somethin other than a lineEnd or a dot
    9831012                        if (clicked != null
    9841013                        // TODO Change the items merge methods so the logic is simplified
    985                                         && (!(Frame.getItemAttachedToCursor() instanceof Dot)
     1014                                        && (!(FreeItems.getItemAttachedToCursor() instanceof Dot)
    9861015                                                        || clicked instanceof Dot || clicked.isLineEnd())) {
    9871016                                // check permissions
     
    16731702                refreshHighlights();
    16741703
    1675                 if (Frame.itemAttachedToCursor()) {
     1704                if (FreeItems.itemAttachedToCursor()) {
    16761705                        move(FreeItems.getInstance());
    16771706                        // System.out.println(FreeItems.getInstance().size());
     
    17671796
    17681797                // disable cursor changes when the cursor has items attached
    1769                 if (Frame.itemAttachedToCursor()
     1798                if (FreeItems.itemAttachedToCursor()
    17701799                                && DisplayIO.getCursor() != Item.TEXT_CURSOR)
    17711800                        _forceArrowCursor = false;
     
    18491878
    18501879        public static void resetOffset() {
    1851                 if (Frame.itemAttachedToCursor()) {
     1880                if (FreeItems.itemAttachedToCursor()) {
    18521881                        _offX = DisplayIO.getMouseX()
    18531882                                        - FreeItems.getInstance().get(0).getX()
     
    18911920
    18921921                // repaint things if necessary
    1893                 if (Frame.itemAttachedToCursor())
     1922                if (FreeItems.itemAttachedToCursor())
    18941923                        move(FreeItems.getInstance());
    18951924        }
     
    19181947                linker.setLink("" + next.getNumber());
    19191948
    1920                 for (Item i : next.getBodyTextItems(true)) {
     1949                for (Item i : next.getTextItems()) {
    19211950                        // Set the link for @Parent annotation item if one
    19221951                        if (ItemUtils.startsWithTag(i, ItemUtils.TAG_PARENT)
     
    19551984                        return;
    19561985
    1957                 if (Frame.itemAttachedToCursor())
     1986                if (FreeItems.itemAttachedToCursor())
    19581987                        return;
    19591988
     
    19832012                _offX = _offY = 0;
    19842013
     2014                Frame current = DisplayIO.getCurrentFrame();
    19852015                // check if the user is pointing at the frame's framename
    19862016                if (toDelete != null
    1987                                 && toDelete == DisplayIO.getCurrentFrame().getNameItem()) {
    1988                         DisplayIO.getCurrentFrame().clear(false);
     2017                                && toDelete == current.getNameItem()) {
     2018                        current.clear(false);
    19892019                        FrameGraphics.Repaint();
    19902020                        return;
     
    19922022
    19932023                // if the user is deleting items attached to the cursor
    1994                 if (Frame.itemAttachedToCursor()) {
     2024                if (FreeItems.itemAttachedToCursor()) {
    19952025                        // if this is an item-swap
    19962026                        if (FreeItems.getInstance().size() == 1
     
    20852115                        }
    20862116
    2087                         Frame current = toDelete.getParent();
    2088                         if (current != null) {
    2089                                 current.setChanged(true);
     2117                        Frame parent = toDelete.getParent();
     2118                        if (parent != null) {
     2119                                parent.setChanged(true);
    20902120                        }
    20912121                        Collection<Item> toUndo = null;
     
    21142144                        }
    21152145                        SessionStats.DeletedItems(toUndo);
    2116                         if (current != null) {
    2117                                 current.addAllToUndo(toUndo);
    2118                                 current.removeAllItems(toUndo); // toDelete.getConnected()
     2146                        if (parent != null) {
     2147                                parent.addAllToUndo(toUndo);
     2148                                parent.removeAllItems(toUndo); // toDelete.getConnected()
    21192149                        }
    21202150                        // reset the mouse cursor
    21212151                        updateCursor();
    2122                         ItemUtils.EnclosedCheck(current.getItems());
     2152                        ItemUtils.EnclosedCheck(parent.getItems());
    21232153                        if (toDelete.hasOverlay()) {
    2124                                 FrameUtils.Parse(current, false);
     2154                                FrameUtils.Parse(parent, false);
    21252155                                FrameGraphics.requestRefresh(false);
    21262156                        }
     
    25702600                Set<Frame> checkEnclosure = new HashSet<Frame>();
    25712601                for (Item i : toAnchor) {
    2572                         //if (!i.hasVector())
    2573                                 anchor(i, false);
     2602                        // if (!i.hasVector())
     2603                        anchor(i, false);
    25742604                        checkEnclosure.add(i.getParentOrCurrentFrame());
    25752605                        bReparse |= i.hasOverlay();
     
    27372767                // TODO: Check why the new constrained line is not repainted immediately
    27382768                FrameGraphics.requestRefresh(true);
     2769                FrameGraphics.refresh(true);
    27392770        }
    27402771
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r154 r156  
    140140         * @return
    141141         */
    142         public static int Align(List<Item> toAlign, boolean moveAll, int adjust) {
     142        public static int Align(List<Text> toAlign, boolean moveAll, int adjust) {
    143143                Collections.sort(toAlign);
    144144
     
    148148
    149149                // get the first item
    150                 Item from = toAlign.get(0);
     150                Text from = toAlign.get(0);
    151151                if (from.getParent() == null)
    152152                        from = toAlign.get(1);
     
    154154
    155155                Frame curr = from.getParent();
    156                 Item above = curr.getItemAbove(from);
     156                Text above = curr.getTextAbove(from);
    157157
    158158                String lastBullet = "";
    159159
    160160                if (above != null && curr.isNormalTextItem(above))
    161                         lastBullet = FrameKeyboardActions.getAutoBullet(((Text) above)
    162                                         .getText());
     161                        lastBullet = FrameKeyboardActions.getAutoBullet(above.getText());
    163162                else {
    164                         lastBullet = FrameKeyboardActions.getBullet(((Text) toAlign.get(0))
     163                        lastBullet = FrameKeyboardActions.getBullet(toAlign.get(0)
    165164                                        .getText());
    166165                }
     
    168167                        // renumber...
    169168                        for (int i = 0; i < toAlign.size(); i++) {
    170                                 assert toAlign.get(i) instanceof Text;
    171 
    172                                 Text currentText = ((Text) toAlign.get(i));
     169
     170                                Text currentText = toAlign.get(i);
    173171                                String currentBullet = FrameKeyboardActions
    174172                                                .getAutoBullet(currentText.getText());
     
    329327
    330328                // move any anchored connected items
    331                 if (Frame.itemAttachedToCursor()) {
     329                if (FreeItems.itemAttachedToCursor()) {
    332330                        List<Item> toAdd = new ArrayList<Item>();
    333331                        List<Item> toCheck = new ArrayList<Item>(FreeItems.getInstance());
     
    531529                UserSettings.TitleTemplate = profile.getTitleItem();
    532530
    533                 List<Text> items = profile.getBodyTextItems(true, true);
    534 
    535531                // check for all tags setting user values
    536                 for (Text item : items) {
     532                for (Text item : profile.getTextItems()) {
    537533                        if (!item.isAnnotation())
    538534                                continue;
     
    14641460                }
    14651461                LastEdited = lastEdited;
    1466                
     1462
    14671463                if (toReparse != null) {
    14681464                        Parse(toReparse, false);
     
    14751471
    14761472        public static Collection<Text> getCurrentTextItems() {
    1477                 Collection<Text> currentTextItems = new LinkedList<Text>();
     1473                Collection<Text> currentTextItems = new LinkedHashSet<Text>();
    14781474                Collection<Item> currentItems = getCurrentItems(null);
    14791475                if (currentItems != null) {
  • trunk/src/org/expeditee/gui/FreeItems.java

    r123 r156  
    44
    55import org.expeditee.items.Item;
     6import org.expeditee.items.Text;
    67
    78public class FreeItems extends ArrayList<Item> {
     
    4344        }
    4445
     46        public static boolean itemAttachedToCursor() {
     47                return getInstance().size() > 0;
     48        }
     49
     50        public static boolean textAttachedToCursor() {
     51                return itemAttachedToCursor()
     52                                && getInstance().get(0) instanceof Text;
     53        }
     54
     55        public static Item getItemAttachedToCursor() {
     56                if (itemAttachedToCursor())
     57                        return getInstance().get(0);
     58                return null;
     59        }
     60
     61        public static Text getTextAttachedToCursor() {
     62                if(textAttachedToCursor())
     63                        return (Text)getInstance().get(0);
     64                return null;
     65        }
     66
    4567        //     
    4668        // @Override
  • trunk/src/org/expeditee/items/Item.java

    r154 r156  
    3131import org.expeditee.gui.FrameKeyboardActions;
    3232import org.expeditee.gui.FrameUtils;
     33import org.expeditee.gui.FreeItems;
    3334import org.expeditee.gui.MessageBay;
    3435import org.expeditee.gui.Overlay;
     
    988989        public void performActions() {
    989990                Frame sourceFrame = null;
     991                Item sourceItem = FreeItems.getItemAttachedToCursor();
     992                if(sourceItem == null){
     993                        sourceItem = this;
     994                }
     995               
    990996                // if a link exists make it the source frame for this action
    991997                if (getLink() != null) {
     
    10001006
    10011007                for (String s : getAction()) {
    1002                         Actions.PerformAction(sourceFrame, this, s);
     1008                        Actions.PerformAction(sourceFrame, sourceItem, s);
    10031009                }
    10041010        }
     
    10641070                        Simple.ProgramFinished();
    10651071                }
     1072                //Need to repaint any highlights etc
     1073                FrameGraphics.requestRefresh(true);
    10661074        }
    10671075
     
    23782386                return _anchorBottom;
    23792387        }
     2388       
     2389        public String getText() {
     2390                return toString();
     2391        }
    23802392}
  • trunk/src/org/expeditee/items/ItemUtils.java

    r154 r156  
    9191         * @return True if an Item was found that is the given Tag, False otherwise.
    9292         */
    93         public static boolean ContainsTag(List<Item> items, int tag) {
     93        public static boolean ContainsTag(Collection<Item> items, int tag) {
    9494                return ContainsTag(items, GetTag(tag));
    9595        }
    9696
    97         public static boolean ContainsTag(List<Item> items, String tag) {
     97        public static boolean ContainsTag(Collection<Item> items, String tag) {
    9898                return (FindTag(items, tag) != null);
    9999        }
    100100
    101         public static boolean ContainsExactTag(List<Item> items, int tag) {
     101        public static boolean ContainsExactTag(Collection<Item> items, int tag) {
    102102                return ContainsExactTag(items, GetTag(tag));
    103103        }
    104104
    105         public static boolean ContainsExactTag(List<Item> items, String tag) {
     105        public static boolean ContainsExactTag(Collection<Item> items, String tag) {
    106106                return (FindExactTag(items, tag) != null);
    107107        }
     
    133133         *         is found
    134134         */
    135         public static Text FindTag(List<Item> items, String toFind) {
     135        public static Text FindTag(Collection<Item> items, String toFind) {
    136136                for (Item i : items) {
    137137                        if (i instanceof Text && i.isAnnotation())
     
    142142        }
    143143
    144         public static Item FindExactTag(List<Item> items, String toFind) {
     144        public static Item FindExactTag(Collection<Item> items, String toFind) {
    145145                for (Item i : items) {
    146146                        if (i instanceof Text && i.isAnnotation())
  • trunk/src/org/expeditee/items/Text.java

    r154 r156  
    2525
    2626import org.expeditee.gui.DisplayIO;
     27import org.expeditee.gui.Frame;
    2728import org.expeditee.gui.FrameGraphics;
    2829import org.expeditee.gui.FrameKeyboardActions;
     
    11651166        // This needs to be fixed!!
    11661167        private void rebuild(boolean limitWidth) {
     1168                // TODO make this more efficient so it only clears annotation list when
     1169                // it really has to
     1170                if (isAnnotation()) {
     1171                        Frame parent = getParent();
     1172                        //parent can be null when running tests
     1173                        if (parent != null) {
     1174                                parent.clearAnnotations();
     1175                        }
     1176                }
     1177
    11671178                // if there is no text, there is nothing to do
    11681179                if (_text == null || _text.length() == 0) {
     
    17551766                clearSelection();
    17561767                setAlpha(0);
     1768                if (isLineEnd())
     1769                        DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    17571770        }
    17581771
     
    18011814                String text = getText().toLowerCase();
    18021815                // TODO make it so can just check the _overlay variable
    1803                 //Mike cant remember the reason _overlay var cant be use! opps
    1804                 if(!text.startsWith("@"))
     1816                // Mike cant remember the reason _overlay var cant be use! opps
     1817                if (!text.startsWith("@"))
    18051818                        return false;
    18061819                return text.startsWith("@o") || text.startsWith("@ao")
  • trunk/src/org/expeditee/items/XRayable.java

    r154 r156  
    164164                        return;
    165165                }
    166                 if(action.size() == 0)
     166                if(action == null || action.size() == 0)
    167167                        invalidateAll();
    168168                _source.setActions(action);
Note: See TracChangeset for help on using the changeset viewer.