Ignore:
Timestamp:
08/07/08 11:44:58 (16 years ago)
Author:
ra33
Message:

Added Frame and Box variables to the Math calculations

File:
1 edited

Legend:

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

    r190 r196  
    2121import java.awt.geom.Rectangle2D;
    2222import java.text.AttributedString;
     23import java.util.Collection;
    2324import java.util.LinkedList;
    2425import java.util.List;
     
    3031import org.expeditee.gui.FrameKeyboardActions;
    3132import org.expeditee.gui.FrameMouseActions;
     33import org.expeditee.gui.FrameUtils;
    3234import org.expeditee.math.ExpediteeJEP;
    3335import org.nfunk.jep.Node;
     
    569571                        // otherwise, we are inserting text
    570572                } else {
    571                         _processedText = null;
     573                        setProcessedText(null);
     574                        setFormula(null);
    572575                        // determine what line is being pointed to
    573576                        line = getLinePosition(mouseY);
     
    18721875                        return;
    18731876                }
    1874 
     1877                String lowercaseFormula = formula.toLowerCase();
    18751878                ExpediteeJEP myParser = new ExpediteeJEP();
    18761879                myParser.addVariables(this.getParentOrCurrentFrame());
    18771880                String linkedFrame = getAbsoluteLink();
     1881                //Add the relative frame variable if the item is linked
    18781882                if (linkedFrame != null) {
    1879                         myParser.addVariables(FrameIO.LoadFrame(linkedFrame));
     1883                        Frame frame = FrameIO.LoadFrame(linkedFrame);
     1884                        myParser.addVariables(frame);
     1885                        //If the frame is linked add vector variable for the frame
     1886                        if(lowercaseFormula.contains("$frame")){
     1887                                myParser.addVectorVariable(frame.getNonAnnotationItems(true), "$frame");
     1888                        }
     1889                }
     1890                //Add the relative box variable if this item is a line end
     1891                if (this.isLineEnd()){
     1892                        //if its a line end add the enclosed stuff as an @variable
     1893                        if(lowercaseFormula.contains("$box")){
     1894                                Collection<Item> enclosed = FrameUtils.getItemsEnclosedBy(
     1895                                                this.getParentOrCurrentFrame(), this.getEnclosedShape());
     1896                                myParser.addVectorVariable(enclosed, "$box");
     1897                        }
    18801898                }
    18811899                myParser.resetObserver();
    18821900                try {
    1883                         Node node = myParser.parse(formula.toLowerCase());
     1901                        Node node = myParser.parse(lowercaseFormula);
    18841902                        String result = myParser.evaluate(node);
    18851903                        if (result != null) {
    18861904                                this.setText(result);
    1887                         }
    1888                 } catch (Exception e) {
     1905                                this.setFormula(formula);
     1906                        }
     1907                } catch (Throwable e) {
    18891908                        this.setText(getFormula());
    1890                 }
    1891 
     1909                        //this.setFormula(null);
     1910                }
    18921911        }
    18931912
Note: See TracChangeset for help on using the changeset viewer.