Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

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

    r919 r1102  
    1919package org.expeditee.items;
    2020
    21 import java.awt.BasicStroke;
    22 import java.awt.Color;
    23 import java.awt.Graphics2D;
    24 import java.awt.Point;
    25 import java.awt.Polygon;
    26 import java.awt.Rectangle;
    27 import java.awt.RenderingHints;
    28 import java.awt.Shape;
    29 import java.awt.Stroke;
    30 import java.awt.geom.AffineTransform;
    31 import java.awt.geom.Point2D;
    3221import java.util.ArrayList;
    3322import java.util.Collection;
     
    3726import java.util.List;
    3827
    39 import org.expeditee.gui.DisplayIO;
     28import org.expeditee.core.Colour;
     29import org.expeditee.core.Dimension;
     30import org.expeditee.core.Fill;
     31import org.expeditee.core.Point;
     32import org.expeditee.core.Stroke;
     33import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     34import org.expeditee.core.bounds.CombinationBoxBounds;
     35import org.expeditee.core.bounds.PolygonBounds;
     36import org.expeditee.gio.EcosystemManager;
     37import org.expeditee.gio.GraphicsManager;
     38import org.expeditee.gui.DisplayController;
    4039import org.expeditee.gui.Frame;
    4140import org.expeditee.gui.FrameGraphics;
     
    5958
    6059       
    61         public static Polygon createArrowheadPolygon(double x0, double y0, float arrowLength0, double arrowRatio0, double arrowNibPerc0)
     60        public static PolygonBounds createArrowheadPolygon(double x0, double y0, float arrowLength0, double arrowRatio0, double arrowNibPerc0)
    6261        {
    63                
    64                 Polygon arrowhead = new Polygon();
     62                PolygonBounds arrowhead = new PolygonBounds();
    6563           
    6664                int ix0 = (int)Math.round(x0);
     
    7371                int flange_iy_left = (int) Math.round((y0 - flange_y_width));
    7472                int flange_iy_right = (int) Math.round((y0 + flange_y_width));
    75                                
    76                
    77                 arrowhead.addPoint(ix0, iy0);
    78                 arrowhead.addPoint(flange_ix_project, flange_iy_left);
    79                
    80                 arrowhead.addPoint(ix_nib, iy0);
    81                
    82                 arrowhead.addPoint(flange_ix_project, flange_iy_right);
     73               
     74                arrowhead.addPoint(new Point(ix0, iy0));
     75                arrowhead.addPoint(new Point(flange_ix_project, flange_iy_left));
     76                arrowhead.addPoint(new Point(ix_nib, iy0));
     77                arrowhead.addPoint(new Point(flange_ix_project, flange_iy_right));
    8378               
    8479                return arrowhead;
     
    9590
    9691        // brush strokes used for painting this line and highlighting
    97         private Stroke _lineStroke = new BasicStroke(DEFAULT_THICKNESS, CAP, JOIN, 4.0F);
     92        private Stroke _lineStroke = new Stroke(DEFAULT_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN);
    9893
    9994        Stroke getStroke() {
     
    143138                        for (int i = 0; i < pattern.length; i++)
    144139                                dash[i] = (float) pattern[i];
    145                         _lineStroke = new BasicStroke(Math.max(thick,
    146                                         MINIMUM_PAINT_THICKNESS), CAP, JOIN, 10f, dash, 0.0f);
     140                        _lineStroke = new Stroke(Math.max(thick, MINIMUM_PAINT_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN, dash, 0.0f);
    147141                } else {
    148                         _lineStroke = new BasicStroke(Math.max(thick,
    149                                         MINIMUM_PAINT_THICKNESS), CAP, JOIN);
    150                 }
    151 
    152                 updatePolygon();
     142                        _lineStroke = new Stroke(Math.max(thick, MINIMUM_PAINT_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN);
     143                }
     144
     145                invalidateBounds();
    153146        }
    154147
     
    240233                        _start = start;
    241234                        _start.addLine(this);
    242                         updatePolygon();
     235                        invalidateBounds();
    243236                }
    244237        }
     
    258251                        _end = end;
    259252                        _end.addLine(this);
    260                         updatePolygon();
     253                        invalidateBounds();
    261254                }
    262255        }
     
    317310                        for (int i = 0; i < pattern.length; i++)
    318311                                dash[i] = (float) pattern[i];
    319                         _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS),
    320                                         CAP, JOIN, 10f, dash, 0.0f);
     312                        _lineStroke = new Stroke(Math.max(thick, MINIMUM_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN, dash, 0.0f);
    321313                } else
    322                         _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS),
    323                                         CAP, JOIN);
     314                        _lineStroke = new Stroke(Math.max(thick, MINIMUM_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN);
    324315
    325316                if (_start.getLinePattern() != pattern)
     
    333324
    334325        @Override
    335         public void paint(Graphics2D g) {
    336                 if (!isVisible())
    337                         return;
    338 
    339                 // Dont paint lines with thickness 0 if they are the border on a filled
    340                 // shape
    341                 if (dontPaint())
    342                         return;
    343 
    344                 g.setColor(getPaintColor());
     326        public void paint()
     327        {
     328                if (!isVisible()) return;
     329
     330                // Dont paint lines with thickness 0 if they are the border on a filled shape
     331                if (dontPaint()) return;
    345332
    346333                // if (this._mode == Item.SelectedMode.Disconnect)
    347334                // System.out.println("Disconnect mode!");
    348                 g.setStroke(_lineStroke);
    349335                // Get a path of points
    350                 int[][][] paths = getPaths();
    351                 for (int i = 0; i < paths.length; i++) {
    352                         int[][] path = paths[i];
    353                         int last = path[0].length - 1;
    354                         if (path[0][0] == path[0][last] && path[1][0] == path[1][last]) {
    355                                 g.drawPolygon(path[0], path[1], last);
    356                         } else {
    357                                 g.drawPolyline(path[0], path[1], last + 1);
    358                         }
    359                 }
     336                PolygonBounds[] paths = getPaths();
     337                for (PolygonBounds path : paths) {
     338                        EcosystemManager.getGraphicsManager().drawPolygon(path, null, null, 0.0f, null, getPaintColor(), _lineStroke);
     339                }
     340               
    360341                // paint the arrowhead (if necessary)
    361                 paintArrows(g);
    362 
    363                 if (showLineHighlight() && isHighlighted()) {
    364                         g.setColor(getHighlightColor());
    365                         g.setStroke(HIGHLIGHT_STROKE);
    366                         ((Graphics2D) g).draw(this.getArea());
     342                paintArrows();
     343
     344                if (shouldShowLineHighlight() && isHighlighted()) {
     345                        PolygonBounds poly = (PolygonBounds) getBounds();
     346                        EcosystemManager.getGraphicsManager().drawPolygon(poly, null, null, 0.0f, null, getHighlightColor(), HIGHLIGHT_STROKE);
    367347                }
    368348        }
     
    371351                // enable invisible shapes (for web browser divs) only when XRayMode is off
    372352                return getThickness() <= 0 && _start.isEnclosed()
    373                                 && (_start.getFillColor() != null || !FrameGraphics.isXRayMode());
    374         }
    375 
    376         protected int[][][] getPaths() {
     353                                && (_start.getFillColor() != null || !DisplayController.isXRayMode());
     354        }
     355
     356        protected PolygonBounds[] getPaths() {
    377357                List<List<Point>> pointPaths = new LinkedList<List<Point>>();
    378358                Collection<Line> visited = new HashSet<Line>();
     
    388368                }
    389369                // Put the paths into int arrays
    390                 int[][][] paths = new int[pointPaths.size()][][];
     370                PolygonBounds[] paths = new PolygonBounds[pointPaths.size()];
    391371                Iterator<List<Point>> iter = pointPaths.iterator();
    392372
    393373                for (int i = 0; i < paths.length; i++) {
    394374                        List<Point> pointPath = iter.next();
    395                         int[][] path = new int[2][pointPath.size()];
     375                        PolygonBounds path = new PolygonBounds();
    396376                        paths[i] = path;
    397377                        // Add all the x and y's to the array
    398                         for (int j = 0; j < path[0].length; j++) {
    399                                 path[0][j] = pointPath.get(j).x;
    400                                 path[1][j] = pointPath.get(j).y;
    401                         }
    402                 }
     378                        for (int j = 0; j < pointPath.size(); j++) {
     379                                path.addPoint(pointPath.get(j).x, pointPath.get(j).y);
     380                        }
     381                }
     382               
    403383                return paths;
    404384        }
    405385
    406         protected List<Point> getPath(Collection<Line> visited,
    407                         LinkedList<Line> toExplore) {
     386        protected List<Point> getPath(Collection<Line> visited, LinkedList<Line> toExplore)
     387        {
    408388                LinkedList<Point> points = new LinkedList<Point>();
    409389                // put the start item points into our list
     
    417397        }
    418398
    419         public void paintArrows(Graphics2D g) {
    420                 if (dontPaint())
    421                         return;
    422 
    423                 g.setColor(getPaintColor());
    424                 g.setStroke(new BasicStroke(getPaintThickness(), CAP,
    425                                 BasicStroke.JOIN_MITER));
    426                 paintArrow(g, getStartArrow());
    427                 paintArrow(g, getEndArrow());
    428 
     399        public void paintArrows()
     400        {
     401                if (dontPaint()) return;
     402
     403                paintArrow(getStartArrow());
     404                paintArrow(getEndArrow());
     405
     406                // TODO: What is a virtual spot? cts16
    429407                if (_virtualSpot != null) {
    430                         _virtualSpot.paint(g);
     408                        _virtualSpot.paint();
    431409                        invalidateVirtualSpot();
    432410                        _virtualSpot = null;
     
    456434         * @return
    457435         */
    458         private Shape getArrow(Item withArrow, Point startOffset, Point endOffset) {
    459                 boolean disconnectMode = withArrow._mode == Item.HighlightMode.Disconnect;
     436        private PolygonBounds getArrow(Item withArrow, Point startOffset, Point endOffset)
     437        {
     438                boolean disconnectMode = withArrow._highlightMode == Item.HighlightMode.Disconnect;
     439               
    460440                // only draw an arrowhead if necessary
    461                 if (!(this._mode == Item.HighlightMode.Disconnect && disconnectMode)
    462                                 && (!withArrow.hasVisibleArrow() || withArrow.getLines().size() > 1))
     441                if (    !(this._highlightMode == Item.HighlightMode.Disconnect && disconnectMode) &&
     442                                (!withArrow.hasVisibleArrow() || withArrow.getLines().size() > 1))
     443                {
    463444                        return null;
    464 
     445                }
     446               
    465447                int x0, x1, y0, y1;
    466448
     
    475457               
    476458                // set the size of the disconnect indicator arrowhead
    477                 if (this._mode == Item.HighlightMode.Disconnect) {
     459                if (this._highlightMode == Item.HighlightMode.Disconnect) {
    478460                        arrowLength  = 15;
    479461                        arrowRatio   = 0.3;
     
    494476                // The length of the line must at least be as long as the arrow or we
    495477                // wont show the arrow
    496                 if (length <= MINIMUM_ARROW_HEAD_LENGTH)
    497                         return null;
     478                if (length <= MINIMUM_ARROW_HEAD_LENGTH) return null;
     479               
    498480                if (arrowLength == AUTO_ARROWHEAD_LENGTH) {
    499481                        arrowLength = getAutoArrowheadLength(length);
     
    508490
    509491                // only calculate the arrowhead polygon if necessary
    510                 Polygon arrowhead = withArrow.getArrowhead();
     492                PolygonBounds arrowhead = withArrow.getArrowhead();
    511493                if (arrowhead == null || disconnectMode) {
    512                         arrowhead = createArrowheadPolygon(x0,y0,arrowLength,arrowRatio,arrowNibPerc);
     494                        arrowhead = createArrowheadPolygon(x0, y0, arrowLength, arrowRatio, arrowNibPerc);
    513495                       
    514496                        if (!disconnectMode)
    515                                 withArrow.setArrowhead(arrowhead);
    516                 }
     497                                withArrow.setArrowhead(new PolygonBounds(arrowhead));
     498                }
     499                arrowhead = arrowhead.clone();
    517500                double rad = calcAngle((float) x0, (float) y0, (float) x1, (float) y1);
    518                 arrowhead.translate((x0 + length) - arrowhead.xpoints[0], y0
    519                                 - arrowhead.ypoints[0]);
    520                 AffineTransform tx = AffineTransform.getRotateInstance(rad, x0, y0);
    521                
    522         int[] rx = new int[arrowhead.npoints];
    523         int[] ry = new int[arrowhead.npoints];
    524        
    525         for(int i = 0; i < arrowhead.npoints; i++){
    526             Point2D p = new Point2D.Double(arrowhead.xpoints[i], arrowhead.ypoints[i]);
    527             tx.transform(p,p);
    528             rx[i] = (int) p.getX();
    529             ry[i] = (int) p.getY();
    530         }
    531        
    532         return new Polygon(rx, ry, arrowhead.npoints);
     501                arrowhead.translate((x0 + length) - arrowhead.toArray()[0].x, y0 - arrowhead.toArray()[0].y);
     502                arrowhead.rotate(rad, x0, y0);
     503               
     504                return arrowhead;
    533505        }
    534506       
    535         public Polygon getStartArrow() {
    536                 return (Polygon) getArrow(_start, _startOffset, _endOffset);
     507        public PolygonBounds getStartArrow() {
     508                return getArrow(_start, _startOffset, _endOffset);
    537509        }
    538510       
    539         public Polygon getEndArrow() {
    540                 return (Polygon) getArrow(_end, _endOffset, _startOffset);
     511        public PolygonBounds getEndArrow() {
     512                return getArrow(_end, _endOffset, _startOffset);
    541513        }
    542514
     
    544516         * Based on code from DeSL (Arrow2D) http://sourceforge.net/projects/desl/
    545517         */
    546         private void paintArrow(Graphics2D g, Shape arrow) {
     518        private void paintArrow(PolygonBounds arrow)
     519        {
     520                Colour arrowColour = getPaintColor();
     521                Fill arrowFill = new Fill(arrowColour);
     522                Stroke arrowStroke = new Stroke(getPaintThickness(), DEFAULT_CAP, Stroke.JOIN.MITER);
    547523               
    548524                if(arrow == null) {
     
    557533                // ****
    558534               
    559                 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    560                
    561                 g.draw(arrow);
    562                 g.fill(arrow);
     535                GraphicsManager g = EcosystemManager.getGraphicsManager();
     536               
     537                g.setAntialiasing(true);
     538                g.drawPolygon(arrow.close(), null, null, 0.0f, arrowFill, arrowColour, arrowStroke);
    563539       
    564540        }
     
    630606                return temp;
    631607        }
     608       
     609        public Item getEndPointToDisconnect(Point p)
     610        {
     611                return getEndPointToDisconnect(p.x, p.y);
     612        }
    632613
    633614        public Item getEndPointToDisconnect(int x, int y) {
     
    653634
    654635                if (distStart < NORMAL_THRESHHOLD) {
    655                         start._mode = Item.HighlightMode.Normal;
     636                        start._highlightMode = Item.HighlightMode.Normal;
    656637                        return start;
    657638                } else if (distEnd < NORMAL_THRESHHOLD) {
    658                         end._mode = Item.HighlightMode.Normal;
     639                        end._highlightMode = Item.HighlightMode.Normal;
    659640                        return end;
    660641                } else if (distStart < DISCONNECT_THRESHHOLD) {
    661642                        if (start.getLines().size() > 1
    662643                                        || start.getConstraints().size() > 0)
    663                                 start._mode = Item.HighlightMode.Disconnect;
     644                                start._highlightMode = Item.HighlightMode.Disconnect;
    664645                        else
    665                                 start._mode = Item.HighlightMode.Normal;
     646                                start._highlightMode = Item.HighlightMode.Normal;
    666647                        return start;
    667648                } else if (distEnd < DISCONNECT_THRESHHOLD) {
    668649                        if (end.getLines().size() > 1 || end.getConstraints().size() > 0)
    669                                 end._mode = Item.HighlightMode.Disconnect;
     650                                end._highlightMode = Item.HighlightMode.Disconnect;
    670651                        else
    671                                 end._mode = Item.HighlightMode.Normal;
     652                                end._highlightMode = Item.HighlightMode.Normal;
    672653                        return end;
    673654                }
     
    677658
    678659        @Override
    679         public int setHighlightColor() {
    680                 super.setHighlightColor();
    681 
    682                 return Item.UNCHANGED_CURSOR;
     660        public void setHighlightColorToDefault() {
     661                super.setHighlightColorToDefault();
     662
     663                //return Item.UNCHANGED_CURSOR;
    683664        }
    684665
     
    690671         */
    691672        @Override
    692         public void setColor(Color c) {
     673        public void setColor(Colour c) {
    693674                super.setColor(c);
    694675
     
    698679
    699680        @Override
    700         public Color getFillColor() {
     681        public Colour getFillColor() {
    701682                return _start.getFillColor();
    702683        }
     
    882863        private Item _virtualSpot = null;
    883864
    884         public void showVirtualSpot(Item orig, int mouseX, int mouseY) {
    885                 if (orig.getLines().size() != 1)
    886                         return;
     865        public void showVirtualSpot(Item orig, int mouseX, int mouseY)
     866        {
     867                if (orig.getLines().size() != 1) return;
    887868
    888869                // lines that are in 'connected' mode, also cannot be attached
    889                 if (orig.getLines().get(0).getOppositeEnd(orig).isFloating())
    890                         return;
     870                if (orig.getLines().get(0).getOppositeEnd(orig).isFloating()) return;
    891871
    892872                Item spot = new Dot(-1, orig.getX(), orig.getY());
    893873                Item.DuplicateItem(orig, spot);
    894874                spot.setThickness(Math.max(this.getThickness(), 5));
    895                 if (this.getColor() != Color.RED)
    896                         spot.setColor(Color.RED);
    897                 else
    898                         spot.setColor(Color.BLUE);
    899 
     875                if (!this.getColor().equals(Colour.RED)) {
     876                        spot.setColor(Colour.RED);
     877                } else {
     878                        spot.setColor(Colour.BLUE);
     879                }
     880               
    900881                // unhighlight all the dots
    901882                for (Item conn : getAllConnected()) {
    902883                        conn.setHighlightMode(Item.HighlightMode.None);
    903                 }
     884                        conn.setHighlightColorToDefault();
     885                }
     886
     887                // calculate nearest point on line from spot
     888                org.expeditee.core.Line line = new org.expeditee.core.Line(_start.getPosition(), _end.getPosition());
     889                Point nearest = line.getPointNearestTo(spot.getPosition());
     890
     891                // position spot on the line
     892                spot.setPosition(nearest);
     893                _virtualSpot = spot;
     894                invalidateVirtualSpot();
     895        }
     896
     897        public void showVirtualSpot(int mouseX, int mouseY) {
     898                Item spot = new Dot(mouseX, mouseY, -1);
     899                spot.setThickness(Math.max(this.getThickness(), 5));
     900                if (DEFAULT_HIGHLIGHT.equals(this.getColor()))
     901                        spot.setColor(ALTERNATE_HIGHLIGHT);
     902                else
     903                        spot.setColor(DEFAULT_HIGHLIGHT);
     904
     905
     906                // calculate nearest point on line from spot
     907                org.expeditee.core.Line line = new org.expeditee.core.Line(_start.getPosition(), _end.getPosition());
     908                Point nearest = line.getPointNearestTo(spot.getPosition());
     909
     910                // position spot on the line
     911                spot.setPosition(nearest);
     912                _virtualSpot = spot;
     913                invalidateVirtualSpot();
     914        }
     915
     916        public Item forceMerge(Item spot, int mouseX, int mouseY) {
    904917
    905918                // calculate nearest point on line from spot
     
    930943                // position spot on the line
    931944                spot.setPosition((int) x, (int) y);
    932                 _virtualSpot = spot;
    933                 invalidateVirtualSpot();
    934         }
    935 
    936         public void showVirtualSpot(int mouseX, int mouseY) {
    937                 Item spot = new Dot(mouseX, mouseY, -1);
    938                 spot.setThickness(Math.max(this.getThickness(), 5));
    939                 if (DEFAULT_HIGHLIGHT.equals(this.getColor()))
    940                         spot.setColor(ALTERNATE_HIGHLIGHT);
    941                 else
    942                         spot.setColor(DEFAULT_HIGHLIGHT);
    943 
    944                 // calculate nearest point on line from spot
    945                 double slope1;
    946                 double slope2;
    947                 double x, y;
    948 
    949                 slope1 = (_start.getY() - _end.getY() * 1.0)
    950                                 / (_start.getX() - _end.getX());
    951                 slope2 = -1 / slope1;
    952 
    953                 // if the line is horizontal
    954                 if (slope1 == 0) {
    955                         x = spot.getX();
    956                         y = _start.getY();
    957                         // if the line is vertical
    958                 } else if (slope2 == 0) {
    959                         x = _start.getX();
    960                         y = spot.getY();
    961                         // otherwise, the line is sloped
    962                 } else {
    963                         x = (-1 * slope2 * spot.getX() + spot.getY() - _start.getY() + slope1
    964                                         * _start.getX())
    965                                         / (slope1 - slope2);
    966                         y = slope1 * (x - _start.getX()) + _start.getY();
    967                 }
    968 
    969                 // position spot on the line
    970                 spot.setPosition((int) x, (int) y);
    971                 _virtualSpot = spot;
    972                 invalidateVirtualSpot();
    973         }
    974 
    975         public Item forceMerge(Item spot, int mouseX, int mouseY) {
    976 
    977                 // calculate nearest point on line from spot
    978                 double slope1;
    979                 double slope2;
    980                 double x, y;
    981 
    982                 slope1 = (_start.getY() - _end.getY() * 1.0)
    983                                 / (_start.getX() - _end.getX());
    984                 slope2 = -1 / slope1;
    985 
    986                 // if the line is horizontal
    987                 if (slope1 == 0) {
    988                         x = spot.getX();
    989                         y = _start.getY();
    990                         // if the line is vertical
    991                 } else if (slope2 == 0) {
    992                         x = _start.getX();
    993                         y = spot.getY();
    994                         // otherwise, the line is sloped
    995                 } else {
    996                         x = (-1 * slope2 * spot.getX() + spot.getY() - _start.getY() + slope1
    997                                         * _start.getX())
    998                                         / (slope1 - slope2);
    999                         y = slope1 * (x - _start.getX()) + _start.getY();
    1000                 }
    1001 
    1002                 // position spot on the line
    1003                 spot.setPosition((int) x, (int) y);
    1004945
    1005946                // Keep constraints
     
    1018959                Line temp = copy();
    1019960
    1020                 Frame currentFrame = DisplayIO.getCurrentFrame();
     961                Frame currentFrame = DisplayController.getCurrentFrame();
    1021962                temp.setID(currentFrame.getNextItemID());
    1022963                temp.setEndItem(_end);
     
    11011042
    11021043        @Override
    1103         public void updatePolygon() {
    1104                 _poly = new Polygon();
    1105 
    1106                 Rectangle one;
    1107                 Rectangle two;
     1044        public PolygonBounds updateBounds() {
     1045                PolygonBounds ret = new PolygonBounds();
     1046
     1047                AxisAlignedBoxBounds one;
     1048                AxisAlignedBoxBounds two;
    11081049
    11091050                /**
     
    11211062                        Item e = new Dot(_end.getX(), _end.getY(), -1);
    11221063
    1123                         one = s.getPolygon().getBounds();
    1124                         two = e.getPolygon().getBounds();
     1064                        one = AxisAlignedBoxBounds.getEnclosing(s.getBounds());
     1065                        two = AxisAlignedBoxBounds.getEnclosing(e.getBounds());
    11251066                } else {
    11261067                        Item s = new Dot(_start.getX(), _start.getY(), -1);
    11271068                        Item e = new Dot(_end.getX(), _end.getY(), -1);
    11281069
    1129                         one = e.getPolygon().getBounds();
    1130                         two = s.getPolygon().getBounds();
     1070                        one = AxisAlignedBoxBounds.getEnclosing(e.getBounds());
     1071                        two = AxisAlignedBoxBounds.getEnclosing(s.getBounds());
    11311072                        /*
    11321073                         * one = _end.getPolygon().getBounds(); two =
     
    11361077
    11371078                // if one is above two
    1138                 if (one.getY() < two.getY()) {
    1139                         _poly.addPoint((int) one.getMaxX(), (int) one.getMinY());
    1140                         _poly.addPoint((int) two.getMaxX(), (int) two.getMinY());
    1141                         _poly.addPoint((int) two.getMinX(), (int) two.getMaxY());
    1142                         _poly.addPoint((int) one.getMinX(), (int) one.getMaxY());
     1079                if (one.getMinY() < two.getMinY()) {
     1080                        ret.addPoint(one.getMaxX(), one.getMinY());
     1081                        ret.addPoint(two.getMaxX(), two.getMinY());
     1082                        ret.addPoint(two.getMinX(), two.getMaxY());
     1083                        ret.addPoint(one.getMinX(), one.getMaxY());
    11431084                        // if one is below two
    11441085                } else {
    1145                         _poly.addPoint((int) one.getMinX(), (int) one.getMinY());
    1146                         _poly.addPoint((int) two.getMinX(), (int) two.getMinY());
    1147                         _poly.addPoint((int) two.getMaxX(), (int) two.getMaxY());
    1148                         _poly.addPoint((int) one.getMaxX(), (int) one.getMaxY());
    1149                 }
    1150 
     1086                        ret.addPoint(one.getMinX(), one.getMinY());
     1087                        ret.addPoint(two.getMinX(), two.getMinY());
     1088                        ret.addPoint(two.getMaxX(), two.getMaxY());
     1089                        ret.addPoint(one.getMaxX(), one.getMaxY());
     1090                }
     1091               
     1092                return ret.close();
    11511093        }
    11521094
     
    11991141
    12001142        public double getLength() {
    1201                 return getLength(_start.getPosition(), _end.getPosition());
     1143                return Point.distanceBetween(_start.getPosition(), _end.getPosition());
    12021144        }
    12031145
     
    12101152        }
    12111153
    1212         public static double getLength(Point p1, Point p2) {
    1213                 return Point.distance(p1.x, p1.y, p2.x, p2.y);
    1214         }
    1215 
    1216         @Override
    1217         public Rectangle[] getDrawingArea() { // TODO: CACHE - LIKE UPDATE POLYGON
     1154/*      public static double getLength(Point p1, Point p2) {
     1155                return Point.distance(p1, p2);
     1156        }*/
     1157
     1158        @Override
     1159        public AxisAlignedBoxBounds getDrawingArea() { // TODO: CACHE - LIKE UPDATE POLYGON
    12181160
    12191161                float currentThickness = this.getThickness() + 4;
     
    12361178                y -= halfThickness;
    12371179
    1238                 Rectangle bounds = new Rectangle(x, y, w, h);
     1180                AxisAlignedBoxBounds bounds = new AxisAlignedBoxBounds(x, y, w, h);
    12391181
    12401182                // TODO: Cap bounds
     
    12571199                         overall as opposed to advanced/expensive calculations for getting exact
    12581200                         bounding box */
    1259                         Rectangle arrowBounds = new Rectangle(_end.getX() - nArrowLength,
     1201                        AxisAlignedBoxBounds arrowBounds = new AxisAlignedBoxBounds(_end.getX() - nArrowLength,
    12601202                                        _end.getY() - nArrowLength, 2 * nArrowLength,
    12611203                                        2 * nArrowLength);
     
    12631205                        if (currentThickness > 0.0f) {
    12641206
    1265                                 arrowBounds = new Rectangle(arrowBounds.x - halfThickness,
    1266                                                 arrowBounds.y - halfThickness, arrowBounds.width
    1267                                                                 + thickness, arrowBounds.height + thickness);
    1268                         }
    1269 
    1270                         return new Rectangle[] { bounds, arrowBounds };
     1207                                arrowBounds = new AxisAlignedBoxBounds(arrowBounds.getMinX() - halfThickness,
     1208                                                arrowBounds.getMinY() - halfThickness, arrowBounds.getWidth()
     1209                                                                + thickness, arrowBounds.getHeight() + thickness);
     1210                        }
     1211
     1212                        return bounds.combineWith(arrowBounds);
    12711213                } else {
    1272                         return new Rectangle[] { bounds };
     1214                        return bounds;
    12731215                }
    12741216
     
    12941236        public void scale(Float scale, int originX, int originY) {
    12951237        }
     1238
     1239        @Override
     1240        public float getSize()
     1241        {
     1242                return getThickness();
     1243        }
    12961244}
Note: See TracChangeset for help on using the changeset viewer.