Ignore:
Timestamp:
05/19/08 12:03:18 (16 years ago)
Author:
ra33
Message:

Fixed a bunch of problems with rectangles and resizing the window, as well as adding some more unit tests etc.

File:
1 edited

Legend:

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

    r58 r67  
    11package org.expeditee.gui;
    22
     3import java.awt.Point;
    34import java.awt.event.ActionEvent;
    45import java.awt.event.ActionListener;
     
    261262                // pre-cache the frame if it is linked
    262263                if (on != null && on.getLink() != null && on.isLinkValid()) {
    263                         FrameIO.Precache(on.getLink());
     264                        FrameIO.Precache(on.getAbsoluteLink());
    264265                }
    265266
     
    739740                                                                        .getPosition(), false);
    740741                                                        pickup(newPoint);
    741                                                         ItemUtils.EnclosedCheck(toDisconnect.getCurrentFrame().getItems());
     742                                                        ItemUtils.EnclosedCheck(toDisconnect
     743                                                                        .getParentOrCurrentFrame().getItems());
    742744                                                        return;
    743745                                                }
     
    913915
    914916                                                if (toCopy.size() > 0) {
     917                                                        //Find the closest item to the mouse cursor
     918                                                        double currentX = DisplayIO.getMouseX();
     919                                                        double currentY = DisplayIO.getMouseY();
     920                                                        Item closest = null;
     921                                                        double shortestDistance = Double.MAX_VALUE;
     922                                                        for(int i = 0; i < toCopy.size(); i++) {
     923                                                                Item next = toCopy.get(i);
     924                                                                if (next instanceof Line)
     925                                                                        continue;
     926                                                                double distance = Point.distance(currentX, currentY, next.getX(), next.getY());
     927                                                                if (distance  < shortestDistance) {
     928                                                                        shortestDistance = distance;
     929                                                                        closest = next;
     930                                                                }
     931                                                        }
     932                                                        //Move the cursor to closest item
     933                                                        DisplayIO.setCursorPosition(closest.getPosition());
     934                                                        //Pickup copy of the stuff inside the rectange
    915935                                                        pickup(copy(toCopy));
     936                                                        //Remove the rectangle
    916937                                                        DisplayIO.getCurrentFrame().removeAllItems(
    917938                                                                        d.getAllConnected());
    918939                                                } else {
     940                                                        //Pick up a copy of the rectangle
    919941                                                        pickup(copy(d.getAllConnected()));
    920942                                                }
     
    14431465                setTdfcItem(linker);
    14441466
    1445                 // Set the link for an @Parent annotation item if one is on the frame
    1446                 for (Item i : next.getItems()) {
    1447                         if ((i instanceof Text) && ItemUtils.isTag(i, ItemUtils.TAG_PARENT)
    1448                                         && i.getLink() == null)
    1449                                 i.setLink(DisplayIO.getCurrentFrame().getFrameName());
     1467                for (Text i : next.getBodyTextItems(true)) {
     1468                        // Set the link for @Parent annotation item if one
     1469                        if (ItemUtils.isTag(i, ItemUtils.TAG_PARENT) && i.getLink() == null) {
     1470                                Frame parent = linker.getParentOrCurrentFrame();
     1471                                i.setLink(parent.getFrameName());
     1472                        } else if (ItemUtils.isTag(i, ItemUtils.TAG_BACKUP)) {
     1473                                // Delink backup tag if it is on the frame
     1474                                i.setLink(null);
     1475                        }
    14501476                }
    14511477
     
    15941620                        // reset the mouse cursor
    15951621                        updateCursor();
    1596                         FrameGraphics.Repaint();
    1597 
    15981622                        ItemUtils.EnclosedCheck(current.getItems());
    15991623                        FrameGraphics.Repaint();
     
    16041628
    16051629        private static void deleteItems(List<Item> itemList) {
    1606                 Frame current = DisplayIO.getCurrentFrame();
     1630                List<Frame> modifiedFrames = new LinkedList<Frame>();
     1631                // Get a list of all the modified frames
     1632                for (Item i : itemList) {
     1633                        Frame parent = i.getParent();
     1634                        if (parent != null)
     1635                                modifiedFrames.add(parent);
     1636                }
     1637
    16071638                List<Item> toUndo = new LinkedList<Item>();
    16081639                List<Item> seen = new LinkedList<Item>();
    1609 
    1610                 // Mike: Removed code that checked for rectangles and removed them
    1611                 // completely!!
    16121640
    16131641                // disconnect any connected items
     
    16231651                                        toUndo.addAll(copy(i));
    16241652                        }
    1625 
    16261653                        seen.add(i);
    16271654                }
    1628 
    1629                 // Mike: What is the point of the code below
    1630                 // It causes problems when deleting three items off the cursor which
    1631                 // include a non dot or line item
    1632                 /*
    1633                  * // check for rectangle deletion if (itemList.size() == 3) { boolean
    1634                  * rectangle = false; Dot dot = null; // check that this is indeed a
    1635                  * rectangle for (Item check : itemList) { if (dot == null && check
    1636                  * instanceof Dot) dot = (Dot) check; else if (check != dot &&
    1637                  * !dot.getLines().contains(check)) { rectangle = false; break; } else
    1638                  * rectangle = true; } // if this is a rectangle, remove the entire
    1639                  * rectangle if (rectangle) { // List<Item> copy =
    1640                  * copy(dot.getAllConnected());
    1641                  * current.addAllToUndo(dot.getAllConnected());
    1642                  * current.removeAllItems(dot.getAllConnected()); itemList.clear(); //
    1643                  * reset the mouse cursor updateCursor(); FrameGraphics.Repaint();
    1644                  * return; } }
    1645                  */
    1646 
    1647                 current.removeAllItems(itemList);
    1648                 current.addAllToUndo(itemList);
     1655                for (Frame f : modifiedFrames) {
     1656                        f.removeAllItems(itemList);
     1657                        ItemUtils.EnclosedCheck(f.getItems());
     1658                }
     1659                // TODO: How should undelete deal with undo when items are removed from
     1660                // the current frame as well as the overlay frame
     1661                DisplayIO.getCurrentFrame().addAllToUndo(itemList);
    16491662                itemList.clear();
    16501663        }
     
    19641977
    19651978                FrameGraphics.Repaint();
    1966                 ItemUtils.EnclosedCheck(toAnchor.getCurrentFrame().getItems());
     1979                ItemUtils.EnclosedCheck(toAnchor.getParentOrCurrentFrame().getItems());
    19671980        }
    19681981
Note: See TracChangeset for help on using the changeset viewer.