Ignore:
Timestamp:
08/22/08 10:54:44 (16 years ago)
Author:
ra33
Message:

Added more import and mail stuff... including text importer

File:
1 edited

Legend:

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

    r242 r247  
    55import java.awt.Dimension;
    66import java.awt.Font;
     7import java.awt.GradientPaint;
    78import java.awt.Graphics2D;
    89import java.awt.Point;
    910import java.awt.Polygon;
    1011import java.awt.Rectangle;
     12import java.awt.Shape;
    1113import java.awt.Stroke;
    1214import java.awt.event.KeyEvent;
     
    3335import org.expeditee.gui.FrameKeyboardActions;
    3436import org.expeditee.gui.FrameMouseActions;
     37import org.expeditee.gui.FrameUtils;
    3538import org.expeditee.math.ExpediteeJEP;
    3639import org.nfunk.jep.Node;
     
    255258                        invalidateAll();
    256259                _text = new StringBuffer(text);
    257                 rebuild(false);
     260                rebuild(true);
    258261                invalidateAll();
    259262        }
     
    283286         */
    284287        public void prependText(String text) {
     288               
    285289                _text.insert(0, text);
    286290                rebuild(false);
     
    295299         */
    296300        public void removeText(String text) {
    297 
    298301                if (_text.length() > 0 && _text.indexOf(text) == 0) {
    299                         // invalidateAll();
     302                        //Need the invalidate all for dateStamp toggling
     303                        invalidateAll();
    300304                        _text.delete(0, text.length());
    301305                }
     
    13891393                if (getBackgroundColor() != null) {
    13901394                        Color bgc = getBackgroundColor();
    1391                         if (_alpha > 0)
     1395                        if (_alpha > 0){
    13921396                                bgc = new Color(bgc.getRed(), bgc.getGreen(), bgc.getBlue(),
    13931397                                                _alpha);
     1398                        }
    13941399                        g.setColor(bgc);
    1395                         g.fill(getPolygon());
    1396                 }
    1397                
     1400                       
     1401                        Color gradientColor = getGradientColor();
     1402                        if (gradientColor != null) {
     1403                                // The painting is not efficient enough for gradients...
     1404                                Shape s = getPolygon();
     1405                                if (s != null) {
     1406                                        Rectangle b = s.getBounds();
     1407                                        GradientPaint gp = new GradientPaint(
     1408                                                        (int) (b.x + b.width * 0.3), b.y, bgc,
     1409                                                        (int) (b.x + b.width * 1.3), b.y, gradientColor);
     1410                                        g.setPaint(gp);
     1411                                }
     1412                        }
     1413                       
     1414                        g.fillPolygon(getPolygon());
     1415                }
     1416
    13981417                if (hasVisibleBorder()) {
    13991418                        g.setColor(getPaintBorderColor());
     
    14021421                        g.drawPolygon(getPolygon());
    14031422                }
    1404                
     1423
    14051424                if (isHighlighted()) {
    14061425                        g.setColor(getPaintHighlightColor());
     
    15671586                        }
    15681587                }
     1588                FrameUtils.setLastEdited(this);
    15691589                rebuild(true);
    15701590                DisplayIO.setCursorPosition(newPoint.x, newPoint.y, false);
     
    18311851        }
    18321852
    1833         public void setRightMargin(int i) {
    1834                 setWidth(i - getX() - Item.MARGIN_LEFT);
    1835         }
    1836 
    18371853        @Override
    18381854        public void calculate(String formula) {
     
    18461862                String lowercaseFormula = formula.toLowerCase();
    18471863                ExpediteeJEP myParser = new ExpediteeJEP();
     1864               
     1865                int nextVarNo = 1;
     1866               
    18481867                // Add variables from the containing rectangle if the item being
    18491868                // calculated is inside the enclosing rectangle
    18501869                Collection<Item> enclosed = getItemsInSameEnclosure();
    18511870                for (Item i : enclosed) {
    1852                         if (i instanceof Text) {
     1871                        if(i == this)
     1872                                continue;
     1873                        if (i instanceof Text && !i.isAnnotation()) {
    18531874                                AttributeValuePair pair = new AttributeValuePair(i.getText());
    18541875                                if (pair.hasPair()) {
    18551876                                        try {
    1856                                                 myParser.addVariable(pair.getAttribute(), pair
    1857                                                                 .getDoubleValue());
     1877                                                double value = pair
     1878                                                .getDoubleValue();
     1879                                                myParser.addVariable(pair.getAttribute(), value);
     1880                                                //myParser.addVariable("$" + nextVarNo++, value);
     1881                                        } catch (NumberFormatException nfe) {
     1882                                                continue;
     1883                                        } catch (Exception e) {
     1884                                                e.printStackTrace();
     1885                                        }
     1886                                }else{
     1887                                        try {
     1888                                                double value = pair
     1889                                                .getDoubleValue();
     1890                                                myParser.addVariable("$" + nextVarNo++, value);
     1891                                        } catch (NumberFormatException nfe) {
     1892                                                continue;
    18581893                                        } catch (Exception e) {
    18591894                                                e.printStackTrace();
     
    18981933
    18991934        /**
    1900          * Gets items which are in the same enclosure as this item.
    1901          * TODO: Improve the efficiency of this method
     1935         * Gets items which are in the same enclosure as this item. TODO: Improve
     1936         * the efficiency of this method
     1937         *
    19021938         * @return
    19031939         */
     
    19101946                        // Go through all the enclosures looking for one that includes this
    19111947                        // shape
    1912                         if (!seen.contains(i) &&  i.isEnclosed()) {
     1948                        if (!seen.contains(i) && i.isEnclosed()) {
    19131949                                seen.addAll(i.getEnclosingDots());
    19141950                                Collection<Item> enclosed = i.getEnclosedItems();
    1915                                 //Check if we have found an enclosure containing this item
    1916                                 //Check it is smaller than any other enclosure found containing this item
    1917                                 if(enclosed.contains(this) && i.getEnclosedArea() < enclosureArea){
     1951                                // Check if we have found an enclosure containing this item
     1952                                // Check it is smaller than any other enclosure found containing
     1953                                // this item
     1954                                if (enclosed.contains(this)
     1955                                                && i.getEnclosedArea() < enclosureArea) {
    19181956                                        sameEnclosure = enclosed;
    19191957                                }
     
    19211959                }
    19221960
    1923                 if(sameEnclosure == null)
     1961                if (sameEnclosure == null)
    19241962                        return new LinkedList<Item>();
    1925                
     1963
    19261964                return sameEnclosure;
    19271965        }
    19281966
    19291967        /**
    1930          * Returns true if this text item should be recalculated when t is modified
     1968         * Returns true if this text item should be recalculated when it is modified
    19311969         */
    19321970        public boolean recalculateWhenChanged() {
    1933                 if (!isAnnotation()
    1934                                 && (hasFormula() || getText().contains(":") || isLineEnd()))
     1971                if (/*!isAnnotation()
     1972                                && */(hasFormula() || getText().contains(":") || isLineEnd()))
    19351973                        return true;
    19361974                try {
Note: See TracChangeset for help on using the changeset viewer.