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

Added calculate action

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.