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/io
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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        {
Note: See TracChangeset for help on using the changeset viewer.