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/MagneticConstraint/Utilities/Paragraph.java

    r962 r1102  
    11package org.expeditee.items.MagneticConstraint.Utilities;
    22
    3 import java.awt.*;
    43import java.util.LinkedList;
     4
     5import org.expeditee.core.Point;
     6import org.expeditee.core.bounds.AxisAlignedBoxBounds;
    57import org.expeditee.items.Text;
    68
     
    3032        }
    3133       
    32         public Rectangle getBoundingBox() {
    33                 final Rectangle rect = new Rectangle();
    34                 for(final Line ln : this) rect.add(ln.getBoundingBox());
     34        public AxisAlignedBoxBounds getBoundingBox() {
     35                AxisAlignedBoxBounds rect = null;
     36                for(final Line ln : this) {
     37                        if (rect == null) rect = ln.getBoundingBox();
     38                        else rect.combineWith(ln.getBoundingBox());
     39                }
    3540                return rect;
    3641        }
     
    5055                if(nextLine == null) {
    5156                        //2a. No; then we simply need to calculate the position of where it would be and return that.
    52                         final Rectangle boundingBox = splitAt.getBoundingBox();
    53                         return new Point((int)boundingBox.getX(), (int)boundingBox.getMaxY() + lineHeight);
     57                        final AxisAlignedBoxBounds boundingBox = splitAt.getBoundingBox();
     58                        return new Point((int)boundingBox.getMinX(), (int)boundingBox.getMaxY() + lineHeight);
    5459                }
    5560                //3. Get paragraph starting from the next line
     
    5863                if(!this.containsAll(paragraphStartingAtNextLine)) {
    5964                        //4b. No; then we simply need to calculate the position of the next line and return that.
    60                         final Rectangle boundingBox = splitAt.getBoundingBox();
     65                        final AxisAlignedBoxBounds boundingBox = splitAt.getBoundingBox();
    6166                        return new Point(((Text) splitAt.getFirst()).getX(), (int)boundingBox.getMaxY() + lineHeight);
    6267                }
     
    6671                //6. Return the position of the new line we have made space for.
    6772               
    68                 final Rectangle boundingBox = splitAt.getBoundingBox();
     73                final AxisAlignedBoxBounds boundingBox = splitAt.getBoundingBox();
    6974                final int x = ((Text) splitAt.getFirst()).getX();
    7075                return new Point(x, (int)boundingBox.getMaxY() + lineHeight);
     
    7277       
    7378        private static int getLineHeight(final Line line) {
    74                 return (int) (line.get(0).getArea().getBounds().getHeight() * 1.2);
     79                return (int) (line.get(0).getBoundingBox().getHeight() * 1.2);
    7580        }
    7681       
     
    8994        private static boolean isInSameParagraph(final Line thisLine, final Line nextLine, final int lineHeight) {
    9095                if(!XGroupLogic.areInSameXGroup(thisLine.get(0), nextLine.get(0))) return false;
    91                 final Rectangle thisLineBoundingBox = thisLine.getBoundingBox();
    92                 final Rectangle nextLineBoundingBox = nextLine.getBoundingBox();
    93                 final Point toAdd = new Point(Math.min((int)thisLineBoundingBox.getX(),(int) nextLineBoundingBox.getX()), (int)thisLineBoundingBox.getMaxY() + lineHeight);
    94                 final Rectangle overlappingSection = new Rectangle(thisLineBoundingBox);
    95                 overlappingSection.add(toAdd);
     96                final AxisAlignedBoxBounds thisLineBoundingBox = thisLine.getBoundingBox();
     97                final AxisAlignedBoxBounds nextLineBoundingBox = nextLine.getBoundingBox();
     98                final Point toAdd = new Point(Math.min((int)thisLineBoundingBox.getMinX(),(int) nextLineBoundingBox.getMinX()), (int)thisLineBoundingBox.getMaxY() + lineHeight);
     99                final AxisAlignedBoxBounds overlappingSection = new AxisAlignedBoxBounds(thisLineBoundingBox);
     100                overlappingSection.combineWith(toAdd);
    96101                return overlappingSection.intersects(nextLineBoundingBox);
    97102        }
Note: See TracChangeset for help on using the changeset viewer.