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/ItemUtils.java

    r922 r1102  
    1919package org.expeditee.items;
    2020
    21 import java.awt.Color;
    22 import java.awt.Rectangle;
    23 import java.awt.image.ImageObserver;
    2421import java.io.File;
    2522import java.io.UnsupportedEncodingException;
     
    3431import java.util.Map;
    3532
    36 import org.expeditee.gui.DisplayIO;
     33import org.expeditee.core.Colour;
     34import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     35import org.expeditee.gui.DisplayController;
     36import org.expeditee.gui.DisplayController.TwinFramesSide;
    3737import org.expeditee.gui.Frame;
    3838import org.expeditee.gui.FrameUtils;
     
    4040import org.expeditee.gui.Vector;
    4141import org.expeditee.items.Item.HighlightMode;
    42 import org.expeditee.items.widgets.InteractiveWidget;
     42import org.expeditee.items.widgets.Widget;
    4343import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException;
    4444import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException;
     
    360360         *
    361361         * @param source
    362          *            The Text file containing the Picture infomation
     362         *            The Text file containing the Picture information
    363363         * @return The Picture object representing the file, or Null if the file is
    364364         *         not found.
    365365         */
    366         public static Picture CreatePicture(Text source, ImageObserver observer, boolean tryRemote) {
     366        public static Picture CreatePicture(Text source, boolean tryRemote) {
    367367                String text = source.getText();
    368368                String path = "";
     
    424424                                // call CreatePicture again, but with tryRemote set to false so we won't get into an infinite loop
    425425                                // if something goes wrong with finding the downloaded image
    426                                 return CreatePicture(source, observer, false);
     426                                return CreatePicture(source, false);
    427427                        }
    428428                                return null;
     
    434434
    435435                try {
    436                         Picture pic = new Picture(source, fileName, path, size, observer);
     436                        Picture pic = new Picture(source, fileName, path, size);
    437437
    438438                        return pic;
     
    444444        }
    445445       
    446         public static Picture CreatePicture(Text source, ImageObserver observer) {
    447                 return CreatePicture(source, observer, true);
     446        public static Picture CreatePicture(Text source) {
     447                return CreatePicture(source, true);
    448448        }
    449449
     
    483483
    484484                // Widgets are super special
    485                 List<InteractiveWidget> widgets = new ArrayList<InteractiveWidget>();
     485                List<Widget> widgets = new ArrayList<Widget>();
    486486
    487487                for (Item i : toCopy) {
     
    596596                        Item start = lineEndMap.get(c.getStart());
    597597                        Item end = lineEndMap.get(c.getEnd());
    598                         int id = DisplayIO.getCurrentFrame().getNextItemID();
     598                        int id = DisplayController.getCurrentFrame().getNextItemID();
    599599                        if (start != null && end != null) {
    600600                                new Constraint(start, end, id, c.getType());
     
    603603
    604604                // BROOK
    605                 for (InteractiveWidget iw : widgets) {
     605                for (Widget iw : widgets) {
    606606                        try {
    607607
    608                                 InteractiveWidget icopy = iw.copy();
     608                                Widget icopy = iw.copy();
    609609                                copies.addAll(icopy.getItems());
    610610
     
    680680                Item copy = origEnd.copy();
    681681                origEnd.setHighlightMode(HighlightMode.None);
     682                origEnd.setHighlightColorToDefault();
    682683                copy.removeAllLines();
    683684                copy.removeAllConstraints();
     
    688689
    689690                // create a new line
    690                 Frame currentFrame = DisplayIO.getCurrentFrame();
     691                Frame currentFrame = DisplayController.getCurrentFrame();
    691692                Line line = new Line(origEnd, copy, currentFrame.getNextItemID());
    692693                // if the previous line was constrained then make the new line
     
    694695                // TODO add later a diagonal constraint if getLines() == 3 or 4
    695696                Collection<Constraint> constraints = origEnd.getConstraints();
    696                 if (constrain && constraints.size() > 0
    697                                 && origEnd.getLines().size() == 2) {
     697                if (constrain && constraints.size() > 0 && origEnd.getLines().size() == 2) {
    698698                        Integer type = null;
    699699                        for (Constraint c : constraints) {
     
    710710                        }
    711711                        if (type != null) {
    712                                 new Constraint(origEnd, copy, currentFrame.getNextItemID(),
    713                                                 type);
     712                                new Constraint(origEnd, copy, currentFrame.getNextItemID(), type);
    714713                        }
    715714                }
     
    726725
    727726        public static void New() {
    728                 EnclosedCheck(DisplayIO.getCurrentFrame().getItems());
     727                EnclosedCheck(DisplayController.getCurrentFrame().getItems());
    729728        }
    730729
    731730        public static void Old() {
    732                 OldEnclosedCheck(DisplayIO.getCurrentFrame().getItems());
     731                OldEnclosedCheck(DisplayController.getCurrentFrame().getItems());
    733732        }
    734733
     
    902901         */
    903902        public static boolean isVisible(Item i) {
    904                 if (DisplayIO.isTwinFramesOn()) {
    905                         if (!isVisible(DisplayIO.getFrames()[0], i)) {
    906                                 return isVisible(DisplayIO.getFrames()[1], i);
     903                if (DisplayController.isTwinFramesOn()) {
     904                        if (!isVisible(DisplayController.getFrameOnSide(TwinFramesSide.LEFT), i)) {
     905                                return isVisible(DisplayController.getFrameOnSide(TwinFramesSide.RIGHT), i);
    907906                        } else {
    908907                                return true;
    909908                        }
    910909                } else {
    911                         return isVisible(DisplayIO.getCurrentFrame(), i);
     910                        return isVisible(DisplayController.getCurrentFrame(), i);
    912911                }
    913912        }
     
    923922         * @return True if visible/free from given frame.
    924923         */
    925         public static boolean isVisible(Frame fromFrame, Item i) {
    926                 if (fromFrame == null)
    927                         return false;
     924        public static boolean isVisible(Frame fromFrame, Item i)
     925        {
     926                if (fromFrame == null) return false;
    928927
    929928                Frame parent = i.getParent();
    930929
    931                 if (parent == fromFrame)
     930                if (parent == fromFrame) {
    932931                        return true;
     932                } else if (parent == null) {
     933                        return FreeItems.getInstance().contains(i) || FreeItems.getCursor().contains(i);
     934                }
    933935               
    934                 else if (parent == null)
    935                         return FreeItems.getInstance().contains(i)
    936                                         || FreeItems.getCursor().contains(i);
    937 
    938936                return fromFrame.getAllItems().contains(i) && i.isVisible();
    939937        }
    940938
    941         public static Rectangle expandRectangle(Rectangle r, int n) {
    942                 return new Rectangle(r.x - (n >> 1), r.y - (n >> 1), r.width + n,
    943                                 r.height + n);
     939        public static AxisAlignedBoxBounds expandRectangle(AxisAlignedBoxBounds r, int n)
     940        {
     941                if (r == null) return null;
     942               
     943                return new AxisAlignedBoxBounds(r.getMinX() - (n >> 1), r.getMinY() - (n >> 1), r.getWidth() + n, r.getHeight() + n);
    944944        }
    945945
     
    973973                int originX = v.Origin.x;
    974974                int originY = v.Origin.y;
    975                 Color defaultForeground = v.Foreground;
    976                 Color defaultBackground = v.Background;
     975                Colour defaultForeground = v.Foreground;
     976                Colour defaultBackground = v.Background;
    977977                UserAppliedPermission permission = v.permission;
    978978                // TODO should this be checking if the frame has the
     
    10141014         * @return List of (unique)widgets in items. Never null.
    10151015         */
    1016         public static List<InteractiveWidget> extractWidgets(List<Item> items) {
     1016        public static List<Widget> extractWidgets(List<Item> items) {
    10171017                assert (items != null);
    10181018
    1019                 List<InteractiveWidget> iWidgets = new LinkedList<InteractiveWidget>();
     1019                List<Widget> iWidgets = new LinkedList<Widget>();
    10201020
    10211021                for (Item i : items) {
     
    10531053         * @param frame
    10541054         */
    1055         public static void Justify(Frame frame) {
     1055        public static void Justify(Frame frame)
     1056        {
     1057                if (frame == null) return;
    10561058                EnclosedCheck(frame.getItems());
    10571059                Justify(frame.getItems());
Note: See TracChangeset for help on using the changeset viewer.