Changeset 10


Ignore:
Timestamp:
05/01/08 17:02:40 (16 years ago)
Author:
ra33
Message:

Added Interactive Widget Items

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

Legend:

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

    r8 r10  
    11package org.expeditee.gui;
    22
     3import java.awt.Color;
    34import java.awt.Dimension;
    45import java.awt.Graphics;
     
    1516import javax.swing.JFrame;
    1617
     18import org.expeditee.AbsoluteLayout;
    1719import org.expeditee.actions.Actions;
    1820import org.expeditee.actions.Misc;
     
    3032public class Browser extends JFrame implements ComponentListener,
    3133                WindowListener, WindowStateListener {
     34       
    3235        /**
    3336         * Default version - just to stop eclipse from complaining about it.
     
    3841
    3942        public static Browser _theBrowser;
    40 
     43       
    4144        /**
    4245         * Constructs a new Browser object, then launches it
     
    5154                // FrameGraphics.ForceRepaint();
    5255        }
    53 
     56       
    5457        public void setSizes(Dimension size) {
    5558                setSize(size);
     
    9194                                UserSettings.InitialHeight));
    9295
     96                //set the layout to absolute layout for widgets
     97                this.getContentPane().setLayout(new AbsoluteLayout());
     98                //enable the glasspane-for capturing all mouse events
     99                this.setGlassPane(new MouseEventRouter(getJMenuBar(), getContentPane()));
     100                this.getGlassPane().setVisible(true);
     101                this.getContentPane().setBackground(Color.white);
     102               
    93103                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    94104
     
    127137                DisplayIO.setCurrentFrame(firstFrame);
    128138
    129                 // Create the action handler for the
    130                 FrameMouseActions mouse = new FrameMouseActions();
    131 
    132                 this.getContentPane().addMouseListener(mouse);
    133                 this.getContentPane().addMouseMotionListener(mouse);
    134                 this.addKeyListener(new FrameKeyboardActions());
    135                 this.getContentPane().addMouseWheelListener(mouse);
     139                FrameKeyboardActions keyboardListner = new FrameKeyboardActions();
     140                this.getContentPane().addKeyListener(keyboardListner);
     141                this.addKeyListener(keyboardListner);
    136142        }
    137143
     
    145151        }
    146152
    147         /*
    148          * public void loadedMenu(String menu) { if (g == null) return;
    149          *
    150          * g.setColor(this.getBackground()); g.fillRect(0, 0, this.getWidth(),
    151          * this.getHeight()); g.setColor(Color.BLACK); g.drawString("Loading Menu... " +
    152          * menu, this.getWidth() / 2 - 200, this .getHeight() / 2); }
    153          */
    154 
    155153        @Override
    156154        public void paint(Graphics g) {
    157155                super.paint(g);
    158156                FrameGraphics.Repaint();
    159                 // System.out.print('p');
    160157        }
    161158
     
    167164                setupGraphics();
    168165                repaint();
    169                 // System.out.println("Resize");
    170166        }
    171167
     
    218214         */
    219215        public void windowStateChanged(WindowEvent e) {
    220                 // FrameGraphics.Repaint();
    221                 // System.out.println('C');
     216                //FrameGraphics.Repaint();
     217                //System.out.println('C');
    222218        }
    223219
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r7 r10  
    330330                                FrameIO.ResumeCache();
    331331                        }
    332 
     332                       
     333                        // If the frames are the same then the items for the
     334                        // frame that is just about to hide will still be in view
     335                        // so only notify items that they are hidden if the
     336                        // frames differ.
     337                        if (_CurrentFrames[getCurrentSide()] != null &&
     338                                _CurrentFrames[0] != _CurrentFrames[1]) {
     339                                for (Item i : _CurrentFrames[getCurrentSide()].getItems()) {
     340                                        i.onParentFameHidden();
     341                                }
     342                        }
    333343                        _CurrentFrames[getCurrentSide()] = frame;
     344                       
     345                        // BROOK
     346                        for (Item i : _CurrentFrames[getCurrentSide()].getItems()) {
     347                                i.onParentFameShown();
     348                        }
    334349                } else {
     350                        // Notifying items on the frame being hidden that they
     351                        // are about to be hidden.
     352                        // ie. Widgets use this method to remove themselves from
     353                        //the JPanel
     354                        if (_CurrentFrames[getCurrentSide()] != null) {
     355                                for (Item i : _CurrentFrames[getCurrentSide()].getItems()) {
     356                                        i.onParentFameHidden();
     357                                }
     358                        }
     359                       
    335360                        _CurrentFrames[getCurrentSide()] = frame;
    336361                        frame.setMaxSize(FrameGraphics.getMaxFrameSize());
     362               
     363                        // Notify items on the frame being displayed that they are in view
     364                        //ie. widgets use this method to add themselves to the content pane
     365                        for (Item i : _CurrentFrames[getCurrentSide()].getItems()) {
     366                                i.onParentFameShown();
     367                        }
    337368                }
    338369
  • trunk/src/org/expeditee/gui/Frame.java

    r7 r10  
    88import java.awt.image.VolatileImage;
    99import java.util.ArrayList;
     10import java.util.Collection;
    1011import java.util.Collections;
    1112import java.util.LinkedList;
     
    1617import org.expeditee.io.Logger;
    1718import org.expeditee.items.Dot;
     19import org.expeditee.items.InteractiveWidget;
    1820import org.expeditee.items.Item;
    1921import org.expeditee.items.ItemUtils;
    2022import org.expeditee.items.Line;
    2123import org.expeditee.items.Text;
     24import org.expeditee.items.WidgetCorner;
    2225
    2326/**
     
    8689
    8790        public static List<Item> FreeItems = new ArrayList<Item>();
     91       
     92        // for drawing purposes
     93        private List<InteractiveWidget> _iWidgets = new ArrayList<InteractiveWidget>();
    8894
    8995        private int _lineCount = 0;
     
    140146                                i.setID(++_lineCount);
    141147        }
     148       
     149        /**
     150         *
     151         * @return The interactive widgets that are currently ancored in this frame.
     152         * Hence it exlcudes free-widgets.
     153         */
     154        public List<InteractiveWidget> getInteractiveWidgets() {
     155                return Collections.unmodifiableList(this._iWidgets);
     156                // return       this._iWidgets; // faster
     157        }
    142158
    143159        /**
     
    163179                _change = value;
    164180
    165                 if (_change) {
     181                if (_change){
    166182                        setBufferValid(false);
    167183                        _saved = false;
     
    186202                        _sorted = true;
    187203                }
    188 
     204               
    189205                List<Item> visibleItems = new ArrayList<Item>();
    190 
    191                 for (Item i : _body) {
     206               
     207                for(Item i: _body) {
    192208                        if (i.isVisible())
    193209                                visibleItems.add(i);
    194210                }
    195 
     211               
    196212                return visibleItems;
    197213        }
     
    214230                }
    215231
    216                 return bodyTextItems;
    217 
     232                return bodyTextItems;           
    218233        }
    219234
     
    289304                        if (autoBulletText.length() > 0)
    290305                                frameTitle.stripFirstWord();
     306                }
     307                //TODO Widgets... check this out
     308                // Brook: Cannot figure what is going on above... widget  annot titles should be stripped always
     309                if (ItemUtils.isTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) {
     310                        frameTitle.stripFirstWord();
    291311                }
    292312
     
    452472                if (_frameName != null) {
    453473                        id = _frameName.getID();
    454                 } else {
     474                } else{
    455475                        id = -1 * getNextItemID();
    456476                }
     
    575595                if (item != null) {
    576596                        if (_body.contains(item)) {
    577                                 // System.out.println("Item (" + item.getClass().getSimpleName()
    578                                 // + ") with ID " + item.getID() + " already in body.");
     597                                //System.out.println("Item (" + item.getClass().getSimpleName()
     598                                //              + ") with ID " + item.getID() + " already in body.");
    579599                                return;
    580600                        }
     
    582602                        if (item instanceof Line)
    583603                                _lineCount++;
    584 
     604                       
    585605                        _itemCount = Math.max(_itemCount, item.getID());
    586606
     
    591611
    592612                        item.setMaxSize(FrameGraphics.getMaxFrameSize());
     613                        //add widget items to the list of widgets
     614                        if (item instanceof WidgetCorner) {
     615                                InteractiveWidget iw = ((WidgetCorner)item).getWidgetSource();
     616                                if (!this._iWidgets.contains(iw)) { // A set would have been best
     617                                        _iWidgets.add(iw);
     618                                }
     619                        }
     620                       
     621                        item.onAddedToFrame();
     622
    593623                        change();
    594624                }
     
    608638        }
    609639
    610         public void addAllItems(List<Item> toAdd) {
     640        public void addAllItems(Collection<Item> toAdd) {
    611641                for (Item i : toAdd)
    612642                        addItem(i);
    613643        }
    614644
    615         public void removeAllItems(List<Item> toRemove) {
     645        public void removeAllItems(Collection<Item> toRemove) {
    616646                for (Item i : toRemove)
    617647                        removeItem(i);
     
    621651                if (_body.remove(item))
    622652                        change();
     653               
     654                //Remove widgets from the widget list
     655                if (item != null) {
     656                        item.onRemovedFromFrame();
     657                        if (item instanceof WidgetCorner) {
     658                                _iWidgets.remove(((WidgetCorner)item).getWidgetSource());
     659                        }
     660                }
     661               
    623662        }
    624663
     
    951990                List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems());
    952991                copies.remove(toMergeWith.getFrameNameItem());
    953 
     992               
    954993                for (Item i : copies) {
    955994                        if (i.getID() >= 0) {
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r7 r10  
    22
    33import java.awt.Color;
     4import java.awt.Component;
     5import java.awt.Container;
    46import java.awt.Dimension;
    57import java.awt.Font;
     
    79import java.awt.Graphics2D;
    810import java.awt.GraphicsEnvironment;
     11import java.awt.Point;
    912import java.awt.RenderingHints;
    1013import java.awt.image.VolatileImage;
     
    1215import java.util.List;
    1316
     17import javax.swing.JPopupMenu;
     18import javax.swing.SwingUtilities;
     19
    1420import org.expeditee.actions.Misc;
    1521import org.expeditee.items.Dot;
     22import org.expeditee.items.InteractiveWidget;
    1623import org.expeditee.items.Item;
    1724import org.expeditee.items.Line;
    1825import org.expeditee.items.Picture;
    1926import org.expeditee.items.Text;
     27import org.expeditee.items.WidgetEdge;
    2028
    2129public class FrameGraphics {
     
    247255                                paintItems.addAll(toPaint.getItems());
    248256                        }
     257                        // FIRST: Paint widgets swing gui (not expeditee gui) .
     258                        // Note that these are the ancored widgets
     259                        for (InteractiveWidget iw : toPaint.getInteractiveWidgets()) {
     260                                iw.paint(bg);
     261                        }
     262                       
    249263                        PaintPictures(bg, paintItems);
    250264
     
    300314                                PaintLines(bg, Frame.FreeItems);
    301315                        }
     316                       
    302317                        if (paintOverlay) {
    303318                                PaintItem(bg, toPaint.getFrameNameItem());
    304319                        }
     320                       
     321                        // BROOK: Ensure popups are repainted
     322                        if (Browser._theBrowser != null)
     323                                repaintPopups(Browser._theBrowser.getLayeredPane(), bg);
     324
    305325                        bg.dispose();
    306326                }
     
    388408                g.drawImage(_MessageBuffer, 0, _MaxSize.height, null);
    389409                g.dispose();
    390         }
     410               
     411        }
     412       
     413
    391414
    392415        private static void paintMessage(Graphics2D g, Color background) {
     
    481504                                        FrameMouseActions.MouseX, FrameMouseActions.MouseY);
    482505
    483                         if (toDisconnect != null) {
    484                                 if (Frame.itemAttachedToCursor())
     506                        // Brook: Widget Edges do not have such a context
     507                        if (toDisconnect != null && !(i instanceof WidgetEdge)) {
     508                                if(Frame.itemAttachedToCursor())
    485509                                        return;
    486 
    487                                 // unhighlight all the other dots
     510                               
     511                                //unhighlight all the other dots
    488512                                for (Item conn : toDisconnect.getAllConnected()) {
    489513                                        conn.showHighlight(false);
    490514                                }
    491                                 // highlight the dot that will be in disconnect mode
     515                                //highlight the dot that will be in disconnect mode
    492516                                toDisconnect.showDisconnectHighlight(val);
    493517                                toDisconnect.setFilledHighlight(true);
     
    724748                _SupressErrors = val;
    725749        }
     750       
     751
     752        private static void repaintPopups(Container parent, Graphics g) {
     753                for (Component c : parent.getComponents()) {
     754                        if (c instanceof JPopupMenu && ((JPopupMenu)c).isVisible()) {
     755                               
     756                                Point p = SwingUtilities.convertPoint(c, c.getLocation(), Browser._theBrowser.getContentPane());
     757                               
     758                                g.translate(p.x, p.y);
     759                                c.paint(g);
     760                                g.translate(-p.x, -p.y);
     761                        } else if (c instanceof Container &&
     762                                        c != Browser._theBrowser.getContentPane()) {
     763                                repaintPopups((Container)c, g);
     764                        }
     765                }
     766        }
    726767}
  • trunk/src/org/expeditee/gui/FrameIO.java

    r8 r10  
    822822                Text titleItem = newFrame.getTitle();
    823823
    824                 while (titleItem.getBoundsWidth() + titleItem.getX() > newFrame
    825                                 .getFrameNameItem().getX()) {
    826                         titleItem.setSize(titleItem.getSize() - 1);
     824                // BROOK: This had recursion!! Changed to avoid...
     825                if ((titleItem.getX() + 1) < newFrame.getFrameNameItem().getX()) {
     826                        while (titleItem.getBoundsWidth() + titleItem.getX() > newFrame
     827                                        .getFrameNameItem().getX()) {
     828                                titleItem.setSize(titleItem.getSize() - 1);
     829                        }
     830                } else {
     831                        System.out.println("Bad title x position: " + titleItem.getX());
    827832                }
    828833
     
    965970                if (!FrameIO.DoesFramesetExist(framesetName))
    966971                        return false;
    967 
     972               
    968973                for (String path : UserSettings.FrameDirs) {
    969974                        String source = path + framesetName.toLowerCase() + File.separator;
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r7 r10  
    2020import org.expeditee.items.Constraint;
    2121import org.expeditee.items.Dot;
     22import org.expeditee.items.InteractiveWidgetNotAvailableException;
    2223import org.expeditee.items.Item;
    2324import org.expeditee.items.ItemUtils;
     
    2526import org.expeditee.items.Picture;
    2627import org.expeditee.items.Text;
     28import org.expeditee.items.WidgetCorner;
     29import org.expeditee.items.WidgetEdge;
    2730import org.expeditee.stats.SessionStats;
    2831
    2932public class FrameMouseActions implements MouseListener, MouseMotionListener,
    3033                MouseWheelListener {
     34       
     35
     36        private FrameMouseActions() {}
     37       
     38        private static FrameMouseActions _instance = null;
     39       
     40        public static FrameMouseActions getInstance() {
     41                if (_instance == null) _instance = new FrameMouseActions();
     42                return _instance;
     43        }
    3144
    3245        // TODO say where/how used
     
    185198        public void mouseClicked(MouseEvent e) {
    186199        }
    187 
     200       
    188201        /**
    189202         * Each Item on the Frame is checked to determine if the mouse x,y
     
    193206         */
    194207        public void mousePressed(MouseEvent e) {
     208                ProccessMousePressedEvent(e, e.getModifiersEx());
     209        }
     210
     211        public void ProccessMousePressedEvent(MouseEvent e, int modifiersEx) {
     212
    195213                _mouseDown += e.getButton();
    196214                _lastMouseClickDate = new Date();
     
    238256
    239257                // check for delete command
    240                 if (isDelete(e)) {
     258                if (isDelete(modifiersEx)) {
    241259                        _isDelete = true;
    242260                        // _lastRanged = null;
     
    244262                        _wasDouble = false;
    245263                        // check for attributes command
    246                 } else if (isGetAttributes(e)) {
     264                } else if (isGetAttributes(modifiersEx)) {
    247265                        _isAttribute = true;
    248266                        _wasDouble = false;
    249                 } else if (isTwoClickNoOp(e)) {
     267                } else if (isTwoClickNoOp(modifiersEx)) {
    250268                        _isAttribute = false;
    251269                        _wasDouble = false;
     
    442460                }
    443461
    444                 // if the user has cropped an image, either the above happend or this is
     462                // if the user has cropped an imate, either the above happend or this is
    445463                // a no-op
    446464                if (_lastCropped != null && _lastCropped.getCroppedSize() > 0) {
     
    560578                if (clicked == null)
    561579                        return false;
     580               
     581                // Brook: widgets do not merge
     582                if (clicked instanceof WidgetCorner) return false;
     583               
     584                // Brook: widgets do not merge
     585                if (clicked instanceof WidgetEdge) return false;
    562586
    563587                // System.out.println(Frame.FreeItems.size());
     
    623647                                }
    624648
    625                                 // TODO remove rectangle constraints?
    626                                 if (clicked instanceof Line) {
     649                                // BROOK: WIDGET RECTANGLES DONT ALLOW DISCONNECTION
     650                                if (clicked instanceof Line && !(clicked instanceof WidgetEdge)) {
    627651                                        // Check if within 20% of the end of the line
    628652                                        Line l = (Line) clicked;
     
    683707                                        }
    684708                                }
    685 
     709                               
    686710                                pickup(clicked);
    687711                                return;
     
    13201344               
    13211345                DisplayIO.Back();
    1322                
     1346
    13231347                // repaint things if necessary
    13241348                if (Frame.itemAttachedToCursor())
     
    15131537                List<Item> toUndo = new LinkedList<Item>();
    15141538                List<Item> seen = new LinkedList<Item>();
    1515 
     1539               
    15161540                // disconnect any connected items
    15171541                for (Item i : itemList) {
     
    15801604
    15811605        private static List<Item> deleteDot(Dot dot) {
    1582                 // create a backup copy of the dot
    1583                 List<Item> copy = copy(dot.getConnected());
    1584                 // remove lines that are connected to anchored dots
    1585                 // note: the line is kept so that it can be properly restored
    1586                 for (Item ic : copy) {
    1587                         if (ic instanceof Line) {
    1588                                 Line line = (Line) ic;
    1589                                 if (!copy.contains(line.getStartItem()))
    1590                                         line.getStartItem().removeLine(line);
    1591                                 if (!copy.contains(line.getEndItem()))
    1592                                         line.getEndItem().removeLine(line);
    1593                         }
    1594                 }
    1595 
    1596                 // remove all lines being deleted
    1597                 for (Item ic : dot.getConnected()) {
    1598                         if (ic instanceof Line && ((Line) ic).getOppositeEnd(dot) != null) {
    1599                                 Line line = (Line) ic;
    1600 
    1601                                 Item d = line.getOppositeEnd(dot);
    1602                                 d.removeLine(line);
    1603 
    1604                                 // if the dot was only part of one line, it can be
    1605                                 // removed
    1606                                 if (d.getLines().size() == 0) {
    1607                                         if (d.getParent() != null)
    1608                                                 d.getParent().removeItem(d);
    1609                                         if (!copy.contains(d))
    1610                                                 copy.add(d);
    1611                                 }
    1612 
    1613                                 if (dot.getParent() != null)
    1614                                         dot.getParent().removeItem(ic);
    1615                         }
    1616                 }
    1617                 return copy;
     1606               
     1607                if (dot instanceof WidgetCorner) { // Brook
     1608                       
     1609                        WidgetCorner wc = (WidgetCorner)dot;
     1610                        List<Item> wccopy;
     1611                       
     1612                        try {
     1613                                wccopy = wc.getWidgetSource().copy().getItems();
     1614                        } catch (InteractiveWidgetNotAvailableException e) {
     1615                                e.printStackTrace();
     1616                                return new LinkedList<Item>();
     1617                        }
     1618                       
     1619                        if (dot.getParent() != null) {
     1620                                dot.getParent().removeAllItems(wc.getWidgetSource().getItems());
     1621                        }
     1622                        return wccopy;
     1623                } else {
     1624                       
     1625                        // create a backup copy of the dot
     1626                        List<Item> copy = copy(dot.getConnected());
     1627                        // remove lines that are connected to anchored dots
     1628                        // note: the line is kept so that it can be properly restored
     1629                        for (Item ic : copy) {
     1630                                if (ic instanceof Line) {
     1631                                        Line line = (Line) ic;
     1632                                        if (!copy.contains(line.getStartItem()))
     1633                                                line.getStartItem().removeLine(line);
     1634                                        if (!copy.contains(line.getEndItem()))
     1635                                                line.getEndItem().removeLine(line);
     1636                                }
     1637                        }
     1638       
     1639                        // remove all lines being deleted
     1640                        for (Item ic : dot.getConnected()) {
     1641                                if (ic instanceof Line && ((Line) ic).getOppositeEnd(dot) != null) {
     1642                                        Line line = (Line) ic;
     1643       
     1644                                        Item d = line.getOppositeEnd(dot);
     1645                                        d.removeLine(line);
     1646       
     1647                                        // if the dot was only part of one line, it can be
     1648                                        // removed
     1649                                        if (d.getLines().size() == 0) {
     1650                                                if (d.getParent() != null)
     1651                                                        d.getParent().removeItem(d);
     1652                                                if (!copy.contains(d))
     1653                                                        copy.add(d);
     1654                                        }
     1655       
     1656                                        if (dot.getParent() != null)
     1657                                                dot.getParent().removeItem(ic);
     1658                                }
     1659                        }
     1660                        return copy;
     1661                }
    16181662        }
    16191663
     
    17631807         */
    17641808        public static void pickup(Item toGrab) {
     1809               
     1810                // Brook: If the widget corner is being picked up. Instead refer to picking
     1811                // up the edge for fixed-sized widgets so it is not so confusing
     1812                if (toGrab instanceof WidgetCorner) {
     1813                        WidgetCorner wc = (WidgetCorner) toGrab;
     1814                        if (wc.getWidgetSource().isFixedSize()) {
     1815                                toGrab = toGrab.getConnected().get(1);
     1816                        }
     1817                }
     1818               
    17651819                pickup(toGrab.getConnected());
    17661820        }
     
    19742028        }
    19752029
    1976         public static boolean isDelete(MouseEvent e) {
    1977                 if (e == null)
    1978                         return false;
     2030        public static boolean isDelete(int modifiersEx) {
     2031               
    19792032                int onMask = MouseEvent.BUTTON3_DOWN_MASK
    19802033                                | MouseEvent.BUTTON2_DOWN_MASK;
    1981                 return (e.getModifiersEx() & onMask) == onMask;
    1982         }
    1983 
    1984         public static boolean isGetAttributes(MouseEvent e) {
    1985                 if (e == null)
    1986                         return false;
     2034                return (modifiersEx & onMask) == onMask;
     2035        }
     2036
     2037        public static boolean isGetAttributes(int modifiersEx) {
    19872038                int onMask = MouseEvent.BUTTON3_DOWN_MASK
    19882039                                | MouseEvent.BUTTON1_DOWN_MASK;
    1989                 return (e.getModifiersEx() & onMask) == onMask;
    1990         }
    1991 
    1992         public static boolean isTwoClickNoOp(MouseEvent e) {
    1993                 if (e == null)
    1994                         return false;
     2040                return (modifiersEx & onMask) == onMask;
     2041        }
     2042
     2043        public static boolean isTwoClickNoOp(int modifiersEx) {
    19952044                int onMask = MouseEvent.BUTTON2_DOWN_MASK
    19962045                                | MouseEvent.BUTTON1_DOWN_MASK;
    1997                 return (e.getModifiersEx() & onMask) == onMask;
     2046                return (modifiersEx & onMask) == onMask;
    19982047        }
    19992048
    20002049        public static boolean wasDeleteClicked() {
    2001                 return isDelete(_lastMouseClick);
     2050                if (_lastMouseClick == null) return false;
     2051                return isDelete(_lastMouseClick.getModifiersEx());
    20022052        }
    20032053
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r7 r10  
    1111import org.expeditee.io.Logger;
    1212import org.expeditee.items.Dot;
     13import org.expeditee.items.InteractiveWidget;
     14import org.expeditee.items.InteractiveWidgetNotAvailableException;
    1315import org.expeditee.items.Item;
    1416import org.expeditee.items.ItemUtils;
     
    1618import org.expeditee.items.Picture;
    1719import org.expeditee.items.Text;
     20import org.expeditee.items.WidgetCorner;
     21import org.expeditee.items.WidgetEdge;
    1822
    1923public class FrameUtils {
     
    447451                frame.removeItem(txt);
    448452                frame.addItem(pic);
     453
     454                return true;
     455        }
     456       
     457        /**
     458         * Creates an interactive widget and adds it to a frame.
     459         * If txt has no parent the parent will be set to frame.
     460         *
     461         * @param frame
     462         *              Frame to add widget to. Must not be null.
     463         *
     464         * @param txt
     465         *              Text to create the widget from. Must not be null.
     466         *
     467         * @return True if created/added. False if coul not create.
     468         *
     469         * @author Brook Novak
     470         */
     471        private static boolean createWidget(Frame frame, Text txt) {
     472
     473                if (frame == null) throw new NullPointerException("frame");
     474                if (txt == null) throw new NullPointerException("txt");
     475               
     476                // Safety
     477                if (txt.getParent() == null) txt.setParent(frame);
     478               
     479                InteractiveWidget iw = null;
     480               
     481                try {
     482                       
     483                        iw = InteractiveWidget.CreateWidget(txt);
     484                       
     485                } catch (InteractiveWidgetNotAvailableException e) {
     486                        e.printStackTrace();
     487                        FrameGraphics.ErrorMessage("Cannot create iWidget: " + e.getMessage());
     488                       
     489                }  catch (IllegalArgumentException e) {
     490                        e.printStackTrace();
     491                        FrameGraphics.ErrorMessage("Cannot create iWidget: " + e.getMessage());
     492                }
     493               
     494                if (iw == null) return false;
     495
     496                frame.removeItem(txt);
     497               
     498                frame.addAllItems(iw.getItems());
    449499
    450500                return true;
     
    628678                        ItemUtils.EnclosedCheck(toParse.getItems());
    629679
    630                 ArrayList<Item> items = new ArrayList<Item>();
    631                 items.addAll(toParse.getItems());
     680                List<Item> items = toParse.getItems();
    632681
    633682                // if XRayMode is on, replace pictures with their underlying text
    634683                if (FrameGraphics.isXRayMode()) {
     684                       
     685                        // BROOK: Must handle these a little different
     686                        //List<InteractiveWidget> widgets = toParse.getInteractiveWidgets();
     687                        ArrayList<InteractiveWidget> widgets = new ArrayList<InteractiveWidget>();
     688                        /*
    635689                        for (Item i : items) {
    636690                                if (i instanceof Picture) {
    637691                                        toParse.removeItem(i);
    638692                                        toParse.addItem(((Picture) i).getText());
    639                                 }
    640                         }
    641 
     693                                } else if (i instanceof WidgetCorner) {
     694                                        toParse.removeItem(i);
     695                                } else if (i instanceof WidgetEdge) {
     696                                        toParse.removeItem(i);
     697                                }
     698                        }*/
     699                        for (Item i : items) {
     700                                if (i instanceof Picture) {
     701                                        toParse.removeItem(i);
     702                                        toParse.addItem(((Picture) i).getText());
     703                                } else if (i instanceof WidgetCorner) {
     704                                        toParse.removeItem(i);
     705                                        InteractiveWidget iw = ((WidgetCorner)i).getWidgetSource();
     706                                        if (!widgets.contains(iw)) { // hmmm I should be using a set... meh
     707                                                widgets.add(iw);
     708                                        }
     709                                } else if (i instanceof WidgetEdge) toParse.removeItem(i);
     710                        }
     711
     712
     713                        for (InteractiveWidget iw : widgets) {
     714                                toParse.addItem(iw.getSource());
     715                        }
     716                       
    642717                        // update the list of items
    643718                        items.clear();
     
    691766                                }
    692767
    693                                 // check for Images
     768                                // check for Images and widgets
    694769                                if (!FrameGraphics.isXRayMode()) {
    695770                                        if (ItemUtils.isTag(i, ItemUtils.TAG_IMAGE))
     
    699774                                                        && ItemUtils.isTag(i, ItemUtils.TAG_FRAME_IMAGE))
    700775                                                createFramePicture(toParse, (Text) i);
     776                                        // Check for interactive widgets
     777                                        else if (ItemUtils.isTag(i, ItemUtils.TAG_IWIDGET)) {
     778                                                createWidget(toParse, (Text) i);
     779                                        }
    701780                                }
    702781
  • trunk/src/org/expeditee/io/ExpWriter.java

    r4 r10  
    1313import org.expeditee.items.Constraint;
    1414import org.expeditee.items.Dot;
     15import org.expeditee.items.InteractiveWidget;
    1516import org.expeditee.items.Item;
    1617import org.expeditee.items.Line;
    1718import org.expeditee.items.Picture;
    1819import org.expeditee.items.Text;
     20import org.expeditee.items.WidgetCorner;
     21import org.expeditee.items.WidgetEdge;
    1922import org.expeditee.stats.SessionStats;
    2023
     
    145148                // write out each Item in the Frame.
    146149                List<Item> items = frame.getItems();
     150               
     151                // iWidgets are handled specially since 8 items are written as one
     152                List<InteractiveWidget> seenWidgets = new LinkedList<InteractiveWidget>();
    147153
    148154                // do not write items with ID -1, also skip any lines
    149155                for (Item i : items) {
    150                         if (i.getID() >= 0 && !(i instanceof Line))
     156                       
     157                        // Ensure only one of the WidgetCorners represent a single widget
     158                        if (i instanceof WidgetCorner) {
     159                                InteractiveWidget iw = ((WidgetCorner)i).getWidgetSource();
     160                                if (seenWidgets.contains(iw)) continue;
     161                                seenWidgets.add(iw);
     162                        }
     163       
     164                        if (i.getID() >= 0 && !(i instanceof Line)) {
    151165                                writeItem(i);
    152                 }
    153 
     166                        }
     167                }
     168               
    154169                // write any lines or constraints
    155170                writeTerminator();
     
    210225                if (item instanceof Picture)
    211226                        item = ((Picture) item).getText();
    212 
     227                else if (item instanceof WidgetCorner)
     228                        item = ((WidgetCorner) item).getWidgetSource().getSource();
     229               
    213230                if (item.getLines().size() > 0)
    214231                        writePoint(item);
     
    242259                        if (lines != null && lines.size() > 0) {
    243260                                for (Line line : lines) {
     261                                       
     262                                        // Brook: widget edges are not saved
     263                                        if (line instanceof WidgetEdge) {
     264                                                seen.add(line);
     265                                                continue;
     266                                        }
    244267
    245268                                        // only output new lines that have not yet been output
  • trunk/src/org/expeditee/items/Item.java

    r7 r10  
    4040        public static int PERMISSION_TDFC = 3;
    4141        public static int PERMISSION_FULL = 4;
    42 
     42       
    4343        public static final int NEAR_DISTANCE = 15;
    4444       
     
    14141414                return _visible;
    14151415        }
     1416       
     1417       
     1418       
     1419        // BROOK: Overrideable
     1420        public void onRemovedFromFrame() {}
     1421        public void onAddedToFrame() {}
     1422        public void onParentFameHidden() {} // because of caching
     1423        public void onParentFameShown() {} // because of caching
    14161424}
  • trunk/src/org/expeditee/items/ItemUtils.java

    r7 r10  
    6363
    6464        public static final int TAG_MAX = 15;
     65       
     66        // Brook: Im claiming this number!
     67        public static final int TAG_IWIDGET = 16;
     68       
    6569
    6670        /**
     
    276280                case TAG_POINTTYPE:
    277281                        return "@pointtype:";
     282                case TAG_IWIDGET:
     283                        return "@iw";
    278284                default:
    279285                        return null;
     
    418424                List<Item> seen = new ArrayList<Item>();
    419425               
     426                // Widgets are super special
     427                List<InteractiveWidget> widgets = new ArrayList<InteractiveWidget>();
     428               
    420429                for (Item i : toCopy) {
     430                       
     431//                      BROOK
     432                        if (i instanceof WidgetCorner) { // dont add these
     433
     434                                if (!widgets.contains(((WidgetCorner)i).getWidgetSource()))
     435                                        widgets.add(((WidgetCorner)i).getWidgetSource());
     436                               
     437//                      BROOK
     438                        } else if (i instanceof WidgetEdge) { // dont add these
     439
    421440                        // lines are recreated later
    422                         if (i instanceof Line) {
     441                        } else if (i instanceof Line) {
    423442                                Line line = (Line) i;
    424443                                lines.add(line);
     
    529548                }
    530549
     550                // BROOK
     551                for (InteractiveWidget iw : widgets) {
     552                        try {
     553                               
     554                                InteractiveWidget icopy = iw.copy();
     555                                copies.addAll(icopy.getItems());
     556                               
     557                        } catch (InteractiveWidgetNotAvailableException e) {
     558                                e.printStackTrace();
     559                        }
     560                }
     561               
    531562                return copies;
    532563        }
Note: See TracChangeset for help on using the changeset viewer.