Changeset 906 for trunk/src


Ignore:
Timestamp:
04/15/14 12:56:30 (10 years ago)
Author:
bln4
Message:

Added Magnetic Constraints

Magnetic Constraints are a new type of constraint between items; particularly text. Items can have their neighbours set (for example: who is to my right) and then have custom actions run when a item and its neighbour interact in a defined way. For example: one text item grows enough for hits its right neighbour; so its right neighbour moves over to compensate.
Files changed: org.expeditee.{ gui.DisplayIO, io.DefaultFrameReader, io.DefaultFrameWriter, items.Item, items.Text }

Added ability to have 'delayed' properties on items. With the invention of Magnetic Constraints it was found that the saving and loading of properties now required (greatly benifited from) a way to set a property after all items have been loaded in; rather than as the perticular item was being loaded in. This is that ability.

Files changed: org.expeditee.io.{ DefaultFrameReader, ExpReader }

Let through some non letter characters as names of properties. The tokens ',', '', and '_' have been used as property names to describe neighbors. In order to do this the isValidLine(String) method was altered to let these through. This is not the ideal solution, and should be looked at later.

Files changed: org.expeditee.io.ExpReader

Bug fix: setting a custom title support was added previously. If a custom title had been set the title was: [Your Custom Title] ~ [Expeditee Title]. However the tildas where showing up even without a custom title set. This is now fixed.

Location:
trunk/src/org/expeditee
Files:
10 added
8 edited

Legend:

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

    r730 r906  
    2626import org.expeditee.items.Picture;
    2727import org.expeditee.items.Text;
     28import org.expeditee.items.MagneticConstraint.MagneticConstraints;
    2829import org.expeditee.settings.UserSettings;
    2930import org.expeditee.stats.SessionStats;
     
    157158                                .getFloatMouseX(), FrameMouseActions.MouseY, isShiftDown,
    158159                                isCtrlDown);
     160                               
     161                if(isCtrlDown || DisplayIO.getFloatMouseX() + 1 >= newMouse.x && DisplayIO.getFloatMouseX() <= newMouse.x) {
     162                        if(cursorMovement == Text.RIGHT && !MagneticConstraints.getInstance().rightBorderHit(text)) {
     163                                MagneticConstraints.getInstance().endOfLineHit(text);
     164                        } else {
     165                                if(cursorMovement == Text.LEFT && !MagneticConstraints.getInstance().leftBorderHit(text)) {
     166                                        MagneticConstraints.getInstance().startOfLineHit(text);
     167                                }
     168                        }
     169                        newMouse.x = DisplayIO.getFloatMouseX();
     170                        newMouse.y = DisplayIO.getFloatMouseY();
     171                }               
    159172
    160173                if (!newSize && cursorType == Item.TEXT_CURSOR) {
     
    577590                        title.append(" [").append(SessionStats.getShortStats()).append(']');
    578591
    579                 _Browser.setTitle(DisplayIO.title + " ~~~ " + title.toString());
     592                if(DisplayIO.title != "")
     593                        _Browser.setTitle(DisplayIO.title + " ~~~ " + title.toString());
     594                else _Browser.setTitle(title.toString());
    580595        }
    581596       
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r843 r906  
    17951795                                final java.lang.reflect.Method toInvoke = c.getMethod("getFileURL");
    17961796                                final URL fileURL = (URL)toInvoke.invoke(urlConnection);
    1797                                 BryceSaysPleaseNameMe(new File(fileURL.getPath()));
     1797                                extractResourcesFromFolder(new File(fileURL.getPath()));
    17981798                        } else {
    17991799                                File folder = new File(docURL.toURI().getPath());
    1800                                 BryceSaysPleaseNameMe(folder);
     1800                                extractResourcesFromFolder(folder);
    18011801                        }
    18021802                }
     
    18061806        }
    18071807
    1808     private static void BryceSaysPleaseNameMe(File folder) throws IOException {
     1808    private static void extractResourcesFromFolder(File folder) throws IOException {
    18091809        LinkedList<File> items = new LinkedList<File>();
    18101810        items.addAll(Arrays.asList(folder.listFiles()));
  • trunk/src/org/expeditee/io/DefaultFrameReader.java

    r737 r906  
    1212import java.util.LinkedHashMap;
    1313import java.util.List;
     14import java.util.LinkedList;
    1415
    1516import org.expeditee.gui.Frame;
     
    2425public abstract class DefaultFrameReader implements FrameReader {
    2526        protected static LinkedHashMap<Character, Method> _ItemTags = null;
     27       
     28        protected static List<Character> _DelayedItemTags = null;
    2629
    2730        protected static LinkedHashMap<Character, Method> _FrameTags = null;
     
    4952                _ItemTags = new LinkedHashMap<Character, Method>();
    5053                _FrameTags = new LinkedHashMap<Character, Method>();
     54                _DelayedItemTags = new LinkedList<Character>();
    5155
    5256                try {
     
    139143                        _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem));
    140144                        _ItemTags.put('C', Constraint.class.getMethod("getID", (Class[]) null));
     145                       
     146                        _ItemTags.put('[', Item.class.getMethod("setMagnetizedItemLeft", pInt));
     147                        _DelayedItemTags.add('[');
     148                        _ItemTags.put(']', Item.class.getMethod("setMagnetizedItemRight", pInt));
     149                        _DelayedItemTags.add(']');
     150                        _ItemTags.put('^', Item.class.getMethod("setMagnetizedItemTop", pInt));
     151                        _DelayedItemTags.add('^');
     152                        _ItemTags.put('_', Item.class.getMethod("setMagnetizedItemBottom", pInt));
     153                        _DelayedItemTags.add('_');
    141154                } catch (Exception e) {
    142155                        e.printStackTrace();
  • trunk/src/org/expeditee/io/DefaultFrameWriter.java

    r874 r906  
    123123                        _ItemTags.put('p', Item.class.getMethod("getPermission"));
    124124
     125                        _ItemTags.put('[', Item.class.getMethod("getMagnetizedItemLeft"));
     126                        _ItemTags.put(']', Item.class.getMethod("getMagnetizedItemRight"));
     127                        _ItemTags.put('^', Item.class.getMethod("getMagnetizedItemTop"));
     128                        _ItemTags.put('_', Item.class.getMethod("getMagnetizedItemBottom"));
    125129                } catch (Exception e) {
    126130                        e.printStackTrace();
  • trunk/src/org/expeditee/io/ExpReader.java

    r659 r906  
    66import java.lang.reflect.Method;
    77import java.util.HashMap;
     8import java.util.LinkedList;
     9import java.util.List;
    810
    911import org.expeditee.gui.Frame;
     
    4850        protected static boolean isValidLine(String s) {
    4951                return s.length() >= 2 && s.charAt(1) == ' '
    50                                 && Character.isLetter(s.charAt(0));
     52                                && (Character.isLetter(s.charAt(0)) || s.charAt(0) == '[' || s.charAt(0) == ']' || s.charAt(0) == '^' || s.charAt(0) == '_');
    5153        }
    5254
     
    6971                        newFrame.setName(_frameName);
    7072
     73                        final List<DelayedAction> delayedActions = new LinkedList<DelayedAction>();
     74                       
    7175                        // First read all the header lines
    7276                        while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) {
     
    9599                                                _linePoints.put(currentItem.getID(), currentItem);
    96100                                                newFrame.addItem(currentItem);
     101                                        } else if (currentItem != null && actionShouldBeDelayed(getTag(next))) {
     102                                                delayedActions.add(new DelayedAction(currentItem, next));
    97103                                        } else if (currentItem != null) {
    98104                                                processBodyLine(currentItem, next);
     105                                        } else {
     106                                                System.err.println("Error while reading in frame (ExpReader): Found body line but no current item to apply it to.");
    99107                                        }
    100108                                }
     
    140148                                }
    141149                        }
     150                       
     151                        for(DelayedAction action: delayedActions)
     152                                action.exec();
    142153
    143154                        // Read the stats
     
    173184        }
    174185
     186        private class DelayedAction {
     187                private Item theItem;
     188                private String theLine;
     189
     190                DelayedAction(final Item theItem, final String theLine) {
     191                        this.theItem = theItem;
     192                        this.theLine = theLine;
     193                }
     194               
     195                void exec() {
     196                        processBodyLine(theItem, theLine);
     197                }
     198        }
     199       
    175200        // Stores points used when constructing lines
    176201        private HashMap<Integer, Item> _linePoints = new HashMap<Integer, Item>();
     
    213238                else
    214239                        return "";
     240        }
     241       
     242        protected static boolean actionShouldBeDelayed(Character c) {
     243                return _DelayedItemTags.contains(c);
    215244        }
    216245
  • trunk/src/org/expeditee/io/flowlayout/XGroupItem.java

    r904 r906  
    213213        }
    214214       
     215        public int getItemSpanLength() {
     216                return yitems_span_array.length;
     217        }
     218       
    215219        public YOverlappingItemsSpan getYOverlappingItemsSpan(int y)
    216220        {
  • trunk/src/org/expeditee/items/Item.java

    r851 r906  
    31973197                return _filled;
    31983198        }
     3199               
     3200        private Item _magnetizedItemLeft = null;
     3201        private Item _magnetizedItemRight = null;
     3202        private Item _magnetizedItemTop = null;
     3203        private Item _magnetizedItemBottom = null;
     3204       
     3205        public int getMagnetizedItemLeft() {
     3206                if(_magnetizedItemLeft != null) return _magnetizedItemLeft.getID();
     3207                else return -1;
     3208        }
     3209       
     3210        public void setMagnetizedItemLeft(final Item item) {
     3211                _magnetizedItemLeft = item;
     3212        }
     3213       
     3214        public void setMagnetizedItemLeft(final int id) {
     3215                setMagnetizedItemLeft(this.getParent().getItemWithID(id));
     3216        }
     3217       
     3218        public int getMagnetizedItemRight() {
     3219                if(_magnetizedItemRight != null) return _magnetizedItemRight.getID();
     3220                else return -1;
     3221        }
     3222       
     3223        public void setMagnetizedItemRight(final Item item) {
     3224                _magnetizedItemRight = item;
     3225        }
     3226       
     3227        public void setMagnetizedItemRight(final int id) {
     3228                setMagnetizedItemRight(this.getParent().getItemWithID(id));
     3229        }
     3230       
     3231        public int getMagnetizedItemTop() {
     3232                if(_magnetizedItemTop != null) return _magnetizedItemTop.getID();
     3233                else return -1;
     3234        }
     3235       
     3236        public void setMagnetizedItemTop(final Item item) {
     3237                _magnetizedItemTop = item;
     3238        }
     3239       
     3240        public void setMagnetizedItemTop(final int id) {
     3241                setMagnetizedItemTop(this.getParent().getItemWithID(id));
     3242        }
     3243       
     3244        public int getMagnetizedItemBottom() {
     3245                if(_magnetizedItemBottom != null) return _magnetizedItemBottom.getID();
     3246                else return -1;
     3247        }
     3248       
     3249        public void setMagnetizedItemBottom(final Item item) {
     3250                _magnetizedItemBottom = item;
     3251        }
     3252       
     3253        public void setMagnetizedItemBottom(final int id) {
     3254                setMagnetizedItemBottom(this.getParent().getItemWithID(id));
     3255        }
    31993256}
  • trunk/src/org/expeditee/items/Text.java

    r905 r906  
    2424import java.awt.geom.Rectangle2D;
    2525import java.io.File;
    26 import java.io.IOException;
     26
    2727import java.text.AttributedString;
    2828import java.util.Collection;
     
    4141import org.expeditee.gui.FrameUtils;
    4242import org.expeditee.gui.FreeItems;
     43import org.expeditee.items.MagneticConstraint.MagneticConstraints;
    4344import org.expeditee.math.ExpediteeJEP;
    4445import org.expeditee.settings.experimental.ExperimentalFeatures;
     
    691692         */
    692693        public Point2D.Float insertText(String text, float mouseX, float mouseY) {
    693                 return insertText(text, mouseX, mouseY, -1);
     694                final Point2D.Float newPos = insertText(text, mouseX, mouseY, -1);
     695                return newPos;
    694696        }
    695697
     
    14091411                        return;
    14101412
     1413                int preChangeWidth = 0;
     1414                if (_poly != null)
     1415                        preChangeWidth = _poly.getBounds().width;
     1416
    14111417                _poly = new Polygon();
    14121418
     
    14571463
    14581464                _poly.translate(getX(), getY());
     1465                                               
     1466                if(preChangeWidth != 0 && preChangeWidth != _poly.getBounds().width)
     1467                        if(_poly.getBounds().width > preChangeWidth) MagneticConstraints.getInstance().textGrown(this, _poly.getBounds().width - preChangeWidth);
     1468                        else MagneticConstraints.getInstance().textShrunk(this, preChangeWidth - _poly.getBounds().width);
    14591469        }
    14601470
Note: See TracChangeset for help on using the changeset viewer.