Changeset 124


Ignore:
Timestamp:
07/03/08 18:18:19 (16 years ago)
Author:
ra33
Message:

Repaint now works with cropping and changing color of @b and @v

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/ExpediteeRepaintManager.java

    r122 r124  
    11package org.expeditee.gui;
    22
    3 import java.applet.Applet;
    43import java.awt.Component;
    54import java.awt.Point;
    65import java.awt.Rectangle;
    7 import java.awt.Window;
    86
    97import javax.swing.JComponent;
     
    4846    }
    4947   
    50         @Override
     48        /*@Override
    5149        public void addDirtyRegion(Applet applet, int x, int y, int w, int h) {
    5250                // Ignore
     
    5654        public void addDirtyRegion(Window window, int x, int y, int w, int h) {
    5755                // Ignore
    58         }
     56        }*/
    5957   
    6058    /**
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r121 r124  
    799799                                damagedAreas.clear();
    800800                        }
    801                         System.out.println("FULLSCREEN REFRESH"); // TODO: REMOVE
     801                        //System.out.println("FULLSCREEN REFRESH"); // TODO: REMOVE
    802802                }
    803803
  • trunk/src/org/expeditee/items/Item.java

    r123 r124  
    2828import org.expeditee.gui.FrameGraphics;
    2929import org.expeditee.gui.FrameIO;
     30import org.expeditee.gui.FrameKeyboardActions;
    3031import org.expeditee.gui.FrameUtils;
    3132import org.expeditee.gui.MessageBay;
     
    186187                if (parent != null) {
    187188                        dest.setID(source.getParentOrCurrentFrame().getNextItemID());
    188                 } 
    189 //              else {
    190 //                      dest.setID(source.getID());
    191 //              }
     189                }
     190                // else {
     191                // dest.setID(source.getID());
     192                // }
    192193        }
    193194
     
    947948                        g.setColor(fillColor);
    948949                        // The painting is not efficient enough for gradients...
    949 //                      Polygon s = getEnclosedShape();
    950 //                      Rectangle b = s.getBounds();
    951 //                      GradientPaint gp = new GradientPaint((int) (b.x + b.width * 0.3),
    952 //                      b.y, getFillColor(), (int) (b.x + b.width * 1.3), b.y,
    953 //                      Color.white);
    954 //                      g.setPaint(gp);
    955 //                      g.fillPolygon(s);
     950                        // Polygon s = getEnclosedShape();
     951                        // Rectangle b = s.getBounds();
     952                        // GradientPaint gp = new GradientPaint((int) (b.x + b.width * 0.3),
     953                        // b.y, getFillColor(), (int) (b.x + b.width * 1.3), b.y,
     954                        // Color.white);
     955                        // g.setPaint(gp);
     956                        // g.fillPolygon(s);
    956957                        g.fillPolygon(getEnclosedShape());
    957958                }
     
    10231024         */
    10241025        public void removeLine(Line line) {
    1025                 if (_lines.remove(line)) 
     1026                if (_lines.remove(line))
    10261027                        line.invalidateAll();
    10271028        }
     
    11771178                        _color = c;
    11781179                        invalidateCommonTrait(ItemAppearence.ForegroundColorChanged);
     1180                        if (hasVector()) {
     1181                                //TODO make this more efficient so it only repaints the items for this vector
     1182                                FrameKeyboardActions.Refresh();
     1183                        }
    11791184                }
    11801185        }
     
    12131218                                other.setFillColor(c);
    12141219                }
    1215                
     1220
    12161221                invalidateCommonTrait(ItemAppearence.FillColor);
    12171222                invalidateFill();
     
    12641269                for (Line line : lines)
    12651270                        line.setLinePattern(getLinePattern());
    1266                
    1267                
     1271
    12681272        }
    12691273
     
    12761280         */
    12771281        public void setLink(String frameName) {
    1278                 if (FrameIO.isValidLink(frameName)) 
     1282                if (FrameIO.isValidLink(frameName))
    12791283                        _link = frameName;
    12801284                else
     
    12821286                                        + "] is not a valid frame name");
    12831287                // TODO make this throw exceptions etc...
    1284                
     1288
    12851289                invalidate(getLinkDrawArea());
    12861290        }
     
    13411345        /**
    13421346         * Invalidates this, connected lines and fill
     1347         *
    13431348         * @param trait
    13441349         */
    13451350        private void invalidateCommonTraitForAll(ItemAppearence trait) {
    13461351                invalidateCommonTrait(trait);
    1347                 for (Line line : getLines()) 
     1352                for (Line line : getLines())
    13481353                        line.invalidateCommonTrait(trait);
    13491354                if (_colorFill != null) {
    13501355                        invalidateFill(); // only invalidates if has fill
    13511356                }
    1352                 for(XRayable x: getEnclosures()){
     1357                for (XRayable x : getEnclosures()) {
    13531358                        x.invalidateCommonTrait(trait);
    13541359                }
    13551360
    13561361        }
    1357        
    1358        
     1362
    13591363        /**
    13601364         * Sets the position of this item on the screen
     
    13681372                float deltaX = x - _x;
    13691373                float deltaY = y - _y;
    1370                
    1371                 if (deltaX == 0 && deltaY == 0) return;
    1372                
     1374
     1375                if (deltaX == 0 && deltaY == 0)
     1376                        return;
     1377
    13731378                invalidateCommonTraitForAll(ItemAppearence.PreMoved);
    13741379
     
    14601465
    14611466                for (Line line : getLines()) {
    1462                         line.updatePolygon();   
    1463                 }
    1464                
     1467                        line.updatePolygon();
     1468                }
     1469
    14651470                invalidateCommonTraitForAll(ItemAppearence.PostMoved);
    1466                
     1471
    14671472        }
    14681473
     
    15131518         */
    15141519        public void setThickness(float thick, boolean setConnectedThickness) {
    1515                
    1516                 if (thick == _thickness) return;
     1520
     1521                if (thick == _thickness)
     1522                        return;
    15171523                boolean bigger = thick > _thickness;
    1518                
    1519                 if (!bigger) invalidateCommonTrait(ItemAppearence.Thickness);
    1520                
     1524
     1525                if (!bigger)
     1526                        invalidateCommonTrait(ItemAppearence.Thickness);
     1527
    15211528                _thickness = thick;
    15221529                // update the size of any lines
     
    15241531                        line.setThickness(thick, setConnectedThickness);
    15251532
    1526                 if (bigger) invalidateCommonTrait(ItemAppearence.Thickness);
     1533                if (bigger)
     1534                        invalidateCommonTrait(ItemAppearence.Thickness);
    15271535        }
    15281536
     
    15921600
    15931601        public int setHighlightColor(Color c) {
    1594                
     1602
    15951603                _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;
    1596                
     1604
    15971605                Color selColor = (c != null) ? c : DEFAULT_HIGHLIGHT;
    15981606                if (_highlightColor != c) {
     
    16021610
    16031611                return Item.UNCHANGED_CURSOR;
    1604                
     1612
    16051613        }
    16061614
     
    17201728         */
    17211729        public void setEnclosedList(Collection<Item> enclosed) {
    1722                
     1730
    17231731                boolean changed = (_enclosure == null && enclosed != null);
    1724                
     1732
    17251733                if (_enclosure != null && enclosed == null) {
    17261734                        invalidateFill();
    17271735                }
    1728                
     1736
    17291737                _enclosure = enclosed;
    1730                
     1738
    17311739                if (changed) {
    1732                         invalidateFill();;
     1740                        invalidateFill();
     1741                        ;
    17331742                }
    17341743        }
     
    18581867                return 0;
    18591868        }
    1860        
     1869
    18611870        protected Rectangle getLinkDrawArea() { // TODO: Revise
    1862                 return new Rectangle(getX() - LEFT_MARGIN - 3, getY() + getLinkYOffset() - 3, 6, 6);
     1871                return new Rectangle(getX() - LEFT_MARGIN - 3, getY()
     1872                                + getLinkYOffset() - 3, 6, 6);
    18631873        }
    18641874
     
    20542064         */
    20552065        public void translate(Point2D origin, double ratio) {
    2056                
     2066
    20572067                invalidateCommonTraitForAll(ItemAppearence.PreMoved);
    2058                
     2068
    20592069                _x = (float) (origin.getX() + ratio * (_x - origin.getX()));
    20602070                _y = (float) (origin.getY() + ratio * (_y - origin.getY()));
     
    20622072                for (Line line : getLines())
    20632073                        line.updatePolygon();
    2064                
     2074
    20652075                invalidateCommonTraitForAll(ItemAppearence.PostMoved);
    2066                
     2076
    20672077        }
    20682078
     
    20922102                                        setLinePattern(new int[] { LinePatterns[i], LinePatterns[i] });
    20932103                                }
    2094                                
     2104
    20952105                                invalidateCommonTrait(ItemAppearence.ToggleDashed);
    20962106                                return;
    20972107                        }
    20982108                }
    2099                
    2100                
     2109
    21012110        }
    21022111
     
    21292138                return _deleted;
    21302139        }
    2131        
    2132         /**
    2133          * @return The full canvas that this item draws to. Must include highlighting bounds
     2140
     2141        /**
     2142         * @return The full canvas that this item draws to. Must include
     2143         *         highlighting bounds
    21342144         */
    21352145        public Rectangle[] getDrawingArea() {
    2136                
    2137                 return new Rectangle[] {
    2138                                 ItemUtils.expandRectangle(getPolygon().getBounds(),
    2139                                 _highlightThickness)
    2140                         };
    2141                
    2142         }
    2143        
     2146
     2147                return new Rectangle[] { ItemUtils.expandRectangle(getPolygon()
     2148                                .getBounds(), _highlightThickness) };
     2149
     2150        }
     2151
    21442152        /**
    21452153         *
     
    21492157        public final boolean isInDrawingArea(Area area) {
    21502158                for (Rectangle r : getDrawingArea()) {
    2151                         if (area.intersects(r)) return true;
     2159                        if (area.intersects(r))
     2160                                return true;
    21522161                }
    21532162                return false;
    21542163        }
    2155        
    2156         /**
    2157          * Completetly invalidates the item - so that it should be redrawed.
    2158          * Note: This is handled internally, it should be reare to invoke this
    2159          * externally
     2164
     2165        /**
     2166         * Completetly invalidates the item - so that it should be redrawed. Note:
     2167         * This is handled internally, it should be reare to invoke this externally
    21602168         */
    21612169        public final void invalidateAll() {
    21622170                invalidate(getDrawingArea());
    21632171        }
    2164        
    2165         /**
    2166          * Invalidates areas on the parent frame.
    2167          * Purpose: to be called on specific areas of the item that needs redrawing.
     2172
     2173        /**
     2174         * Invalidates areas on the parent frame. Purpose: to be called on specific
     2175         * areas of the item that needs redrawing.
     2176         *
    21682177         * @param damagedAreas
    21692178         */
    21702179        protected final void invalidate(Rectangle[] damagedAreas) {
    2171                 for (Rectangle r : damagedAreas) invalidate(r);
    2172         }
    2173        
    2174         /**
    2175          * Invalidates areas on the parent frame.
    2176          * Purpose: to be called on specific areas of the item that needs redrawing.
     2180                for (Rectangle r : damagedAreas)
     2181                        invalidate(r);
     2182        }
     2183
     2184        /**
     2185         * Invalidates areas on the parent frame. Purpose: to be called on specific
     2186         * areas of the item that needs redrawing.
     2187         *
    21772188         * @param damagedAreas
    21782189         */
     
    21802191                FrameGraphics.invalidateItem(this, damagedArea);
    21812192        }
    2182        
     2193
    21832194        /**
    21842195         * Used to invalidate visual traits commonly shared by all items.
     2196         *
    21852197         * @param trait
    21862198         */
    21872199        public final void invalidateCommonTrait(ItemAppearence trait) {
    21882200                invalidate(getDamagedArea(trait));
    2189                
    2190                 if (_colorFill != null && (
    2191                                 trait == ItemAppearence.Added
    2192                                 || trait == ItemAppearence.Removed)
    2193                                 ) {
     2201
     2202                if (_colorFill != null
     2203                                && (trait == ItemAppearence.Added || trait == ItemAppearence.Removed)) {
    21942204                        invalidateFill();
    21952205                }
    21962206        }
    2197        
     2207
    21982208        /**
    21992209         * Invalidates fill if has one, even if no color is set.
     
    22042214                }
    22052215        }
    2206        
    2207         /**
    2208          * Default implementation always uses drawing area except for links,
    2209          * where the link drawing area is used. Override to make item
    2210          * drawing more efficient - defining only parts of the item that needs
    2211          * redrawing.
     2216
     2217        /**
     2218         * Default implementation always uses drawing area except for links, where
     2219         * the link drawing area is used. Override to make item drawing more
     2220         * efficient - defining only parts of the item that needs redrawing.
    22122221         *
    22132222         * @see Item.getDrawingArea
    22142223         *
    2215          * @param trait The visual trait that has changed.
     2224         * @param trait
     2225         *            The visual trait that has changed.
    22162226         *
    22172227         * @return The damaged area according to the visual trait that has changed.
    22182228         */
    22192229        protected Rectangle[] getDamagedArea(ItemAppearence trait) {
    2220                
    2221                 if (trait == ItemAppearence.LinkChanged)
    2222                         return new Rectangle[] {getLinkDrawArea()}; // Invalidate area where link is drawn
    2223                        
     2230
     2231                if (trait == ItemAppearence.LinkChanged)
     2232                        return new Rectangle[] { getLinkDrawArea() }; // Invalidate area
     2233                                                                                                                        // where link is
     2234                                                                                                                        // drawn
     2235
    22242236                return getDrawingArea();
    22252237
     
    22292241                return _overlay instanceof Vector;
    22302242        }
    2231        
     2243
    22322244        public boolean hasOverlay() {
    22332245                return _overlay != null;
  • trunk/src/org/expeditee/items/Picture.java

    r121 r124  
    112112                String size = _source.getFirstLine();
    113113                size = AttributeUtils.getValue(size);
    114                
    115                 if(_end.x != 0 || _end.y != 0)
     114
     115                if (_end.x != 0 || _end.y != 0)
    116116                        return;
    117                
     117
    118118                // set the default values for start and end
    119119                _start.setLocation(0, 0);
     
    163163
    164164        public void setStartCrop(int x, int y) {
     165                invalidateCroppedArea();
    165166                _cropStart = new Point(x - getX(), y - getY());
     167                invalidateCroppedArea();
    166168        }
    167169
    168170        public void setEndCrop(int x, int y) {
     171                invalidateCroppedArea();
    169172                _cropEnd = new Point(x - getX(), y - getY());
     173                invalidateCroppedArea();
     174        }
     175
     176        private void invalidateCroppedArea() {
     177                if (_cropStart != null && _cropEnd != null) {
     178                        Point topLeft = getTopLeftCrop();
     179                        Point bottomRight = getBottomRightCrop();
     180                        int startX = getX() + topLeft.x - _highlightThickness;
     181                        int startY = getY() + topLeft.y - _highlightThickness;
     182                        int border = 2 * _highlightThickness;
     183                        invalidate(new Rectangle(startX, startY, bottomRight.x - topLeft.x
     184                                        + 2 * border, bottomRight.y - topLeft.y + 2 * border));
     185                        invalidateAll();
     186                } else {
     187                        invalidateAll();
     188                }
    170189        }
    171190
     
    181200
    182201        public void setShowCrop(boolean value) {
     202                //invalidateCroppedArea();
    183203                _showCropping = value;
     204                invalidateCroppedArea();
    184205        }
    185206
     
    195216
    196217        public void clearCropping() {
     218                invalidateCroppedArea();
    197219                _cropStart = null;
    198220                _cropEnd = null;
     
    391413                return _scale;
    392414        }
    393        
    394         public void setScale(float scale){
     415
     416        public void setScale(float scale) {
    395417                _scale = scale;
    396418        }
    397        
     419
    398420        @Override
    399421        public float getSize() {
     
    519541                _source.setText(newText.toString());
    520542        }
    521        
    522         @Override
    523         public void translate(Point2D origin, double ratio){
     543
     544        @Override
     545        public void translate(Point2D origin, double ratio) {
    524546                _scale *= ratio;
    525547                updateSource();
     
    529551        @Override
    530552        public Rectangle[] getDrawingArea() {
    531                
     553
    532554                Rectangle[] da = super.getDrawingArea();
    533                
     555
    534556                if (getLink() != null || getAction() != null) {
    535557                        Rectangle[] da2 = new Rectangle[da.length + 1];
    536558                        System.arraycopy(da, 0, da2, 0, da.length);
    537559                        da2[da.length] = getLinkPoly().getBounds();
    538                         da2[da.length].translate(getX() - LEFT_MARGIN, getY() + getLinkYOffset());
     560                        da2[da.length].translate(getX() - LEFT_MARGIN, getY()
     561                                        + getLinkYOffset());
    539562                        da2[da.length].width += 2;
    540563                        da2[da.length].height += 2;
    541564                        da = da2;
    542                 } 
    543                
     565                }
     566
    544567                return da;
    545                
    546         }
    547        
    548        
     568
     569        }
     570
    549571}
  • trunk/src/org/expeditee/items/XRayable.java

    r121 r124  
    8888        public void setColor(Color c) {
    8989                _source.setColor(c);
     90                invalidateCommonTrait(ItemAppearence.ForegroundColorChanged);
    9091        }
    9192       
Note: See TracChangeset for help on using the changeset viewer.