Changeset 943


Ignore:
Timestamp:
12/16/14 15:03:11 (9 years ago)
Author:
bln4
Message:

Implementation of IndirectMouseActions. Programmers are now able to intercept actions relating to mouse input events and make them act as they please.

Beginnings of IndirectKeyboardActions...

Location:
trunk/src/org/expeditee/gui
Files:
3 added
4 edited

Legend:

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

    r941 r943  
    3737import org.expeditee.actions.Navigation;
    3838import org.expeditee.actions.Simple;
     39import org.expeditee.gui.indirect.keyboard.IndirectKeyboardActions;
     40import org.expeditee.gui.indirect.keyboard.KeyboardAction;
     41import org.expeditee.gui.indirect.keyboard.KeyboardAction.KeyboardInfo;
    3942import org.expeditee.io.ItemSelection;
    4043import org.expeditee.items.Circle;
     
    6063
    6164        protected FrameKeyboardActions() {
     65                IndirectKeyboardActions.getInstance().setDropDownAction(new KeyboardAction() {
     66                        @Override
     67                        public void exec(KeyboardInfo info) {
     68                                // Get the last text item and drop from in
     69                                Item lastText = null;
     70                                for (Item i : info.enclosed) {
     71                                        if (i instanceof Text) {
     72                                                lastText = i;
     73                                        }
     74                                }
     75                                // Drop from the item if there was a text item in the box
     76                                if (lastText != null) {
     77                                        Drop(lastText, false);
     78                                } else {
     79                                        // Move to the top of the box
     80                                        Rectangle rect = info.firstConnected.getEnclosedShape()
     81                                                        .getBounds();
     82                                        int newX = rect.x + Text.MARGIN_LEFT;
     83                                        int newY = Text.MARGIN_LEFT
     84                                                        + rect.y
     85                                                        + DisplayIO.getCurrentFrame().getItemTemplate()
     86                                                                        .getBoundsHeight();
     87                                        moveCursorAndFreeItems(newX, newY);
     88                                        // TODO can resetOffset be put inside
     89                                        // moveCursorAndFreeItems
     90                                        FrameMouseActions.resetOffset();
     91                                }
     92                        } 
     93                });
     94                IndirectKeyboardActions.getInstance().setSizeUpAction(new KeyboardAction() {
     95                        @Override
     96                        public void exec(final KeyboardInfo info) {
     97                                SetSize(info.firstConnected, info.repeat, false, true, info.isControlDown);
     98                        }               
     99                });
     100                IndirectKeyboardActions.getInstance().setSizeDownAction(new KeyboardAction() {
     101                        @Override
     102                        public void exec(final KeyboardInfo info) {
     103                                SetSize(info.firstConnected, -info.repeat, false, true, info.isControlDown);
     104                        }               
     105                });
     106                IndirectKeyboardActions.getInstance().setChangeColorAction(new KeyboardAction() {
     107                        @Override
     108                        public void exec(final KeyboardInfo info) {
     109                                if (info.connected.size() > 0) {
     110                                        for (Item d : info.lineEnds) {
     111                                                if (info.isControlDown)
     112                                                        SetGradientColor(d, info.isShiftDown);
     113                                                else
     114                                                        SetFillColor(d, info.isShiftDown);
     115                                                break;
     116                                        }
     117                                }
     118                        }
     119                });
    62120        }
    63121
     
    9871045                                switch (key) {
    9881046                                case DropDown:
    989                                         // Get the last text item and drop from in
    990                                         Item lastText = null;
    991                                         for (Item i : enclosed) {
    992                                                 if (i instanceof Text) {
    993                                                         lastText = i;
    994                                                 }
    995                                         }
    996                                         // Drop from the item if there was a text item in the box
    997                                         if (lastText != null) {
    998                                                 Drop(lastText, false);
    999                                         } else {
    1000                                                 // Move to the top of the box
    1001                                                 Rectangle rect = firstConnected.getEnclosedShape()
    1002                                                                 .getBounds();
    1003                                                 int newX = rect.x + Text.MARGIN_LEFT;
    1004                                                 int newY = Text.MARGIN_LEFT
    1005                                                                 + rect.y
    1006                                                                 + DisplayIO.getCurrentFrame().getItemTemplate()
    1007                                                                                 .getBoundsHeight();
    1008                                                 moveCursorAndFreeItems(newX, newY);
    1009                                                 // TODO can resetOffset be put inside
    1010                                                 // moveCursorAndFreeItems
    1011                                                 FrameMouseActions.resetOffset();
    1012                                         }
     1047                                        IndirectKeyboardActions.getInstance().getDropDownAction().exec(
     1048                                                        new KeyboardInfo(key, repeat, isShiftDown, isControlDown, enclosed, firstConnected, connected, lineEnds));
    10131049                                        break;
    10141050                                case SizeUp:
    1015                                         SetSize(firstConnected, repeat, false, true, isControlDown);
     1051                                        IndirectKeyboardActions.getInstance().getSizeUpAction().exec(
     1052                                                        new KeyboardInfo(key, repeat, isShiftDown, isControlDown, enclosed, firstConnected, connected, lineEnds));
    10161053                                        break;
    10171054                                case SizeDown:
    1018                                         SetSize(firstConnected, -repeat, false, true, isControlDown);
     1055                                        IndirectKeyboardActions.getInstance().getSizeDownAction().exec(
     1056                                                        new KeyboardInfo(key, repeat, isShiftDown, isControlDown, enclosed, firstConnected, connected, lineEnds));
    10191057                                        break;
    10201058                                case ChangeColor:
    1021                                         if (connected.size() > 0) {
    1022                                                 for (Item d : lineEnds) {
    1023                                                         if (isControlDown)
    1024                                                                 SetGradientColor(d, isShiftDown);
    1025                                                         else
    1026                                                                 SetFillColor(d, isShiftDown);
    1027                                                         break;
    1028                                                 }
    1029                                         }
     1059                                        IndirectKeyboardActions.getInstance().getChangeColorAction().exec(
     1060                                                        new KeyboardInfo(key, repeat, isShiftDown, isControlDown, enclosed, firstConnected, connected, lineEnds));
    10301061                                        break;
    10311062                                case ToggleAnnotation:
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r942 r943  
    8787                IndirectMouseActions.getInstance().setBackAction(new MouseAction() {
    8888                        @Override
    89                         public void exec(MouseInfo info) {
     89                        public List<Item> exec(MouseInfo info) {
    9090                                //if user is not pointing at something,this is a back
    9191                                if (info.isControlDown || info.isShiftDown)
     
    9393                                else
    9494                                        back();
    95                         }
     95                                return null;
     96                        }
     97                });
     98                IndirectMouseActions.getInstance().setTDFCAction(new MouseAction() {
     99                        @Override
     100                        public List<Item> exec(final MouseInfo info) {
     101                                // check for TDFC permission
     102                                if (!info.clicked.hasPermission(UserAppliedPermission.createFrames)) {
     103                                        MessageBay
     104                                                        .displayMessage("Insufficient permission to TDFC (Top Down Frame Creation) from that item");
     105                                        return null;
     106                                }
     107
     108                                if (info.clicked.isOldTag())
     109                                        return null;
     110
     111                                try {
     112                                        tdfc(info.clicked);
     113                                } catch (RuntimeException e) {
     114                                        e.printStackTrace();
     115                                        MessageBay.errorMessage("Top Down Frame Creation (TDFC) error: " + e.getMessage());
     116                                }
     117                                return null;
     118                        }
     119                });
     120                IndirectMouseActions.getInstance().setRespondToFrameNameClickAction(new MouseAction() {
     121                        @Override
     122                        public List<Item> exec(MouseInfo info) {
     123                                if (info.isControlDown)
     124                                        Navigation.PreviousFrame(false);
     125                                else
     126                                        Navigation.NextFrame(false);
     127                                return null;
     128                        }               
     129                });
     130                IndirectMouseActions.getInstance().setFollowLinkAction(new MouseAction() {
     131                        @Override
     132                        public List<Item> exec(MouseInfo info) {
     133                                /*
     134                                 * Dont save the frame if we are moving to an old version of
     135                                 * this frame because everytime we save with the old tag... the
     136                                 * frame is backed up
     137                                 */
     138                                if (!info.clicked.isOldTag())
     139                                        FrameIO.SaveFrame(DisplayIO.getCurrentFrame());
     140
     141                                Navigation.setLastNavigationItem(info.clicked);
     142                                load(info.clicked.getAbsoluteLink(), info.clicked.getLinkHistory());
     143                                // DisplayIO.UpdateTitle();
     144                                return null;
     145                        }
     146                });
     147                IndirectMouseActions.getInstance().setExecuteActionAction(new MouseAction() {
     148                        @Override
     149                        public List<Item> exec(MouseInfo info) {
     150                                info.clicked.performActions();
     151                                info.clicked.setHighlightMode(HighlightMode.None);
     152                                getInstance().refreshHighlights();
     153                                return null;
     154                        }
     155                });
     156                IndirectMouseActions.getInstance().setCreateRectangleAction(new MouseAction() {
     157                        @Override
     158                        public List<Item> exec(MouseInfo info) {
     159                                final List<Item> copies = new ArrayList<Item>();
     160                                Item[] d = new Item[RECTANGLE_CORNERS];
     161                                // create dots
     162                                Frame current = DisplayIO.getCurrentFrame();
     163                                for (int i = 0; i < d.length; i++) {
     164                                        d[i] = current.createDot();
     165                                        copies.add(d[i]);
     166                                }
     167
     168                                current.nextDot();
     169
     170                                // create lines
     171                                copies.add(new Line(d[0], d[1], current.getNextItemID()));
     172                                copies.add(new Line(d[1], d[2], current.getNextItemID()));
     173                                copies.add(new Line(d[2], d[3], current.getNextItemID()));
     174                                copies.add(new Line(d[3], d[0], current.getNextItemID()));
     175
     176                                new Constraint(d[0], d[1], current.getNextItemID(),
     177                                                Constraint.HORIZONTAL);
     178                                new Constraint(d[2], d[3], current.getNextItemID(),
     179                                                Constraint.HORIZONTAL);
     180                                new Constraint(d[1], d[2], current.getNextItemID(),
     181                                                Constraint.VERTICAL);
     182                                new Constraint(d[3], d[0], current.getNextItemID(),
     183                                                Constraint.VERTICAL);
     184
     185                                anchor(new ArrayList<Item>(copies));
     186                                pickup(d[3]);
     187                                d[3].setHighlightMode(HighlightMode.Normal);
     188
     189                                SessionStats.CreatedItems(copies);
     190                                copies.clear();
     191                                return copies;
     192                        }
     193                });
     194                IndirectMouseActions.getInstance().setExtendLineAction(new MouseAction() {
     195                        @Override
     196                        public List<Item> exec(final MouseInfo info) {
     197                                Line onLine = (Line) info.clicked;
     198                                Line newLine = onLine.copy();
     199                                Item end = newLine.getEndItem();
     200                                Item start = newLine.getStartItem();
     201                                end.setPosition(MouseX, MouseY);
     202                                start.setPosition(MouseX, MouseY);
     203                                onLine.autoArrowheadLength();
     204                                // anchor the start
     205                                anchor(start);
     206                                // attach the line to the cursor
     207                                pickup(end);
     208
     209                                List<Item> toMerge = new LinkedList<Item>();
     210                                toMerge.add(newLine.getStartItem());
     211                                toMerge.add(newLine);
     212
     213                                // Make sure the highlighting is shown when the end is
     214                                // anchored
     215                                end.setHighlightMode(Item.HighlightMode.Normal);
     216                                merge(toMerge, info.clicked);
     217                                // anchor(left);
     218                                // FreeItems.getInstance().clear();
     219                                FrameGraphics.Repaint();
     220                                updateCursor();
     221                                return null;
     222                        }
     223                });
     224                IndirectMouseActions.getInstance().setMakeGroupCopyAction(new MouseAction() {
     225                        @Override
     226                        public List<Item> exec(final MouseInfo info) {
     227                                List<Item> copies = new ArrayList<Item>();
     228                                // Set the selection mode for the items that were clicked in
     229                                Collection<Item> enclosed = getFullyEnclosedItems(info.clickedIn);
     230                                if (enclosed.size() == 0) {
     231                                        MessageBay
     232                                                        .displayMessage("Insufficient permission to copy items");
     233                                } else {
     234                                        copies = copy(enclosed);
     235                                        clearParent(copies);
     236                                        ItemUtils.Justify(copies);
     237                                        pickup(copies);
     238                                        for (Item i : info.clickedIn) {
     239                                                i.setHighlightMode(HighlightMode.None);
     240                                        }
     241                                }
     242                                return copies;
     243                        }
     244                });
     245                IndirectMouseActions.getInstance().setMakeCopyAction(new MouseAction() {
     246                        @Override
     247                        public List<Item> exec(MouseInfo info) {
     248                                List<Item> copies = ItemUtils.UnreelLine(info.clicked, _controlDown);
     249                                // Copies will NOT be null if the user right clicked on a point
     250                                if (copies == null) {
     251                                        Collection<Item> originals = info.clicked.getConnected();
     252                                        copies = ItemUtils.CopyItems(originals, _extrude);
     253                                        // if this is the title of the frame, link it to the frame
     254                                        if (originals.size() == 1 && copies.size() == 1) {
     255                                                Item copy = copies.get(0);
     256                                                Item original = originals.iterator().next();
     257                                                if (original.getLink() == null
     258                                                                && original.isFrameTitle()) {
     259                                                        // save the frame after copying
     260                                                        // i.getParent().setChanged(true);
     261                                                        copy.setLink(original.getParentOrCurrentFrame()
     262                                                                        .getName());
     263                                                }
     264                                        }
     265
     266                                        FrameGraphics.changeHighlightMode(info.clicked,
     267                                                        HighlightMode.None);
     268
     269                                        if (!_extrude)
     270                                                clearParent(copies);
     271                                }
     272                               
     273                                ItemUtils.Justify(copies);
     274
     275                                pickup(copies);
     276                                return copies;
     277                        }       
     278                });
     279                IndirectMouseActions.getInstance().setExtrudeAction(new MouseAction() {
     280                        @Override
     281                        public List<Item> exec(MouseInfo info) {
     282                                List<Item> copies = null;
     283                                List<Item> originals = new ArrayList<Item>();
     284                                // remove any lines that dont have both endpoints
     285                                // floating
     286                                for (Item i : FreeItems.getInstance()) {
     287                                        if (i.isFloating())
     288                                                originals.add(i);
     289                                }
     290                                if (copies == null)
     291                                        copies = ItemUtils.CopyItems(originals, _extrude);
     292                                for (Item i : copies)
     293                                        i.setOffset(0, 0);
     294                                anchor(FreeItems.getInstance());
     295                                // Move isnt working right for extruding!!
     296                                // move(copies);
     297                                pickup(copies);
     298                                return copies;
     299                        }       
     300                });
     301                IndirectMouseActions.getInstance().setRubberBandingCopyAction(new MouseAction() {
     302                        @Override
     303                        public List<Item> exec(MouseInfo info) {
     304                                List<Item> copies = new ArrayList<Item>();
     305                                if (info.clicked != null) {
     306                                        Collection<Item> leftOver = merge(FreeItems
     307                                                        .getInstance(), info.clicked);
     308                                        anchor(leftOver);
     309                                }
     310                                // This is executed when the user is putting down a line
     311                                // endpoint and unreeling. ie. Normal unreeling
     312                                copies = ItemUtils.UnreelLine(FreeItems.getInstance(),
     313                                                _controlDown);
     314
     315                                if (copies == null)
     316                                        copies = copy(FreeItems.getInstance());
     317                                anchor(FreeItems.getInstance());
     318                                for (Item i : copies)
     319                                        i.setOffset(0, 0);
     320                                // need to move to prevent cursor dislocation
     321                                move(copies);
     322                                pickup(copies);
     323                                return copies;
     324                        }               
     325                });
     326                IndirectMouseActions.getInstance().setRubberBandingCornerAction(new MouseAction() {
     327                        @Override
     328                        public List<Item> exec(final MouseInfo info) {
     329                                List<Item> copies = new ArrayList<Item>();
     330                                Item d = getFirstFreeLineEnd();
     331                                // anchor the points
     332                                anchor(FreeItems.getInstance());
     333                                FreeItems.getInstance().clear();
     334                                updateCursor();
     335                                // pick up a copy of all enclosed items
     336                                Collection<Item> enclosedItems = FrameUtils
     337                                                .getItemsEnclosedBy(DisplayIO.getCurrentFrame(), d
     338                                                                .getEnclosedShape());
     339                                if (enclosedItems != null) {
     340                                        enclosedItems.removeAll(d.getAllConnected());
     341                                        Collection<Item> toCopy = getFullyEnclosedItems(enclosedItems);
     342
     343                                        if (toCopy.size() > 0) {
     344                                                // Find the closest item to the mouse cursor
     345                                                double currentX = DisplayIO.getMouseX();
     346                                                double currentY = FrameMouseActions.getY();
     347                                                Item closest = null;
     348                                                double shortestDistance = Double.MAX_VALUE;
     349                                                for (Item next : toCopy) {
     350                                                        if (next instanceof Line)
     351                                                                continue;
     352                                                        double distance = Point.distance(currentX,
     353                                                                        currentY, next.getX(), next.getY());
     354                                                        if (distance < shortestDistance) {
     355                                                                shortestDistance = distance;
     356                                                                closest = next;
     357                                                        }
     358                                                }
     359                                                // Move the cursor to closest item
     360                                                DisplayIO.setCursorPosition(closest.getPosition());
     361                                                // Pickup copy of the stuff inside the rectange
     362                                                copies = copy(toCopy);
     363                                                pickup(copies);
     364                                                // Remove the rectangle
     365                                                d.getParentOrCurrentFrame().removeAllItems(
     366                                                                d.getAllConnected());
     367                                        } else {
     368                                                // Pick up a copy of the rectangle
     369                                                copies = copy(d.getAllConnected());
     370                                                pickup(copies);
     371                                        }
     372                                }
     373                                return copies;
     374                        }               
     375                });
     376                IndirectMouseActions.getInstance().setStampAction(new MouseAction() {
     377                        @Override
     378                        public List<Item> exec(MouseInfo info) {
     379                                List<Item> copies = new ArrayList<Item>();
     380                                stampItemsOnCursor(true);
     381                                copies = FreeItems.getInstance();
     382                                return copies;
     383                        }       
     384                });
     385                IndirectMouseActions.getInstance().setMergeSingleItemAction(new MouseAction() {
     386                        @Override
     387                        public List<Item> exec(final MouseInfo info) {
     388                                List<Item> copies = new ArrayList<Item>();
     389                                copies = copy(FreeItems.getInstance());
     390                                Collection<Item> remain = merge(copies, info.clicked);
     391
     392                                // ignore items that could not be merged.
     393                                anchor(remain);
     394                                return copies;
     395                        } 
     396                });
     397                IndirectMouseActions.getInstance().setMergeTwoItemsAction(new MouseAction() {
     398                        @Override
     399                        public List<Item> exec(MouseInfo info) {
     400                                List<Item> copies = new ArrayList<Item>();
     401                                copies = ItemUtils.UnreelLine(FreeItems.getInstance(),
     402                                                _controlDown);
     403                                Collection<Item> leftOver = merge(FreeItems
     404                                                .getInstance(), info.clicked);
     405                                anchor(leftOver);
     406                                if (copies == null)
     407                                        copies = copy(FreeItems.getInstance());
     408                                FreeItems.getInstance().clear();
     409                                for (Item i : copies)
     410                                        i.setOffset(0, 0);
     411                                // need to move to prevent cursor dislocation
     412                                move(copies);
     413                                pickup(copies);
     414                                // point onto point
     415                                return copies;
     416                        }               
     417                });
     418                IndirectMouseActions.getInstance().setMergeGroupAction(new MouseAction() {
     419                        @Override
     420                        public List<Item> exec(final MouseInfo info) {
     421                                List<Item> copies = new ArrayList<Item>();
     422                                // Move the cursor so that the copy is exactly the
     423                                // same as the shape that was anchored
     424                                DisplayIO.setCursorPosition(info.clicked.getPosition());
     425                                Item d = getFirstFreeLineEnd();
     426                                // get a copy of all enclosed items before merging
     427                                // lineEnds
     428                                Collection<Item> items = FrameUtils.getItemsEnclosedBy(
     429                                                DisplayIO.getCurrentFrame(), d
     430                                                                .getEnclosedShape());
     431                                // If its not an enclosed shape then pick up the
     432                                // connected shape
     433                                if (items == null || items.size() == 0) {
     434                                        items = d.getAllConnected();
     435                                } else {
     436                                        // For some reason the item that was clicked ends up
     437                                        // in the enclosure and needs to be removed
     438                                        items.removeAll(info.clicked.getConnected());
     439                                        // the item that was the origin of the enclosed
     440                                        // shape used to create the enclosure does not get
     441                                        // returned from getItemsEnclosedBy to the enclosure
     442                                        // so it must be added
     443                                        items.addAll(d.getConnected());
     444                                }
     445
     446                                Collection<Item> toCopy = new LinkedHashSet<Item>();
     447
     448                                for (Item ip : items) {
     449                                        if (ip.hasPermission(UserAppliedPermission.copy))
     450                                                toCopy.add(ip);
     451                                }
     452                                copies = copy(toCopy);
     453                                // Now do the merging
     454                                Collection<Item> remain = merge(
     455                                                FreeItems.getInstance(), info.clicked);
     456                                // anchor the points
     457                                anchor(remain);
     458                                FreeItems.getInstance().clear();
     459                                pickup(copies);
     460                                return copies;
     461                        }               
     462                });
     463                IndirectMouseActions.getInstance().setNewLineAction(new MouseAction() {
     464                        @Override
     465                        public List<Item> exec(MouseInfo info) {
     466                                List<Item> copies = new ArrayList<Item>();
     467                                Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), Math
     468                                                .round(MouseX), Math.round(MouseY), true);
     469                                // If we have permission to copy this item then pick it up
     470                                if (on != null && on.isLineEnd()
     471                                                && on.hasPermission(UserAppliedPermission.full)) {
     472                                        on.removeAllConstraints();
     473                                        pickup(on);
     474                                        return copies;
     475                                }
     476
     477                                if (on instanceof WidgetEdge) {
     478                                        // Don't allow the user to break widget edges.
     479                                        // Note: had to return here because random dots would
     480                                        // appear otherwise... cannot understand code below
     481                                        // with create line.
     482                                        return copies;
     483                                }
     484
     485                                // if its on a line then split the line and put a point on it and
     486                                // pick that point up. Only if it is not a widget line
     487                                if (on instanceof Line && on.hasPermission(UserAppliedPermission.full)) {
     488                                        Frame current = DisplayIO.getCurrentFrame();
     489                                        // create the two endpoints
     490                                        Line oldLine = (Line) info.clicked;
     491                                        Item newPoint = oldLine.getStartItem().copy();
     492                                        newPoint.setPosition(MouseX, MouseY);
     493
     494                                        Item end = oldLine.getEndItem();
     495                                        // create the Line
     496                                        Line newLine = new Line(newPoint, end, current.getNextItemID());
     497                                        oldLine.replaceLineEnd(end, newPoint);
     498                                        newPoint.removeAllConstraints();
     499                                        pickup(newPoint);
     500                                        // Update the stats
     501                                        Collection<Item> created = new LinkedList<Item>();
     502                                        created.add(newPoint);
     503                                        created.add(newLine);
     504                                        SessionStats.CreatedItems(newLine.getAllConnected());
     505                                        return copies;
     506                                }
     507                                Line newLine = createLine();
     508                                SessionStats.CreatedItems(newLine.getAllConnected());
     509                                return copies;
     510                        }
     511                });
     512                IndirectMouseActions.getInstance().setGroupPickupAction(new MouseAction() {
     513                        @Override
     514                        public List<Item> exec(final MouseInfo info) {
     515                                List<Item> copies = new ArrayList<Item>();
     516                                ArrayList<Item> toPickup = new ArrayList<Item>(info.clickedIn.size());
     517                                for (Item ip : info.clickedIn)
     518                                        if (ip.hasPermission(UserAppliedPermission.full))
     519                                                toPickup.add(ip);
     520                                pickup(toPickup);
     521                                // otherwise the user is creating a line
     522                                return copies;
     523                        }
     524                });
     525                IndirectMouseActions.getInstance().setDetachLineAction(new MouseAction() {
     526                        @Override
     527                        public List<Item> exec(final MouseInfo info) {
     528                                List<Item> items = new ArrayList<Item>();
     529                                // BROOK: WIDGET RECTANGLES DONT ALLOW DISCONNECTION
     530                                if (info.clicked instanceof Line && !(info.clicked instanceof WidgetEdge)) {
     531                                        // Check if within 20% of the end of the line
     532                                        Line l = (Line) info.clicked;
     533                                        Item toDisconnect = l.getEndPointToDisconnect(_lastMouseClick
     534                                                        .getX(), _lastMouseClick.getY());
     535
     536                                        if (toDisconnect == null) {
     537                                                pickup(info.clicked);
     538                                        } else {
     539                                                if (toDisconnect.getHighlightMode() == Item.HighlightMode.Normal) {
     540                                                        DisplayIO.setCursorPosition(toDisconnect.getPosition(),
     541                                                                        false);
     542                                                        pickup(toDisconnect);
     543                                                } else {
     544                                                        List<Line> lines = toDisconnect.getLines();
     545                                                        // This is to remove constraints from single lines
     546                                                        // with constraints...
     547                                                        // ie. partially deleted rectangles
     548                                                        if (lines.size() == 1) {
     549                                                                toDisconnect.removeAllConstraints();
     550
     551                                                                DisplayIO.setCursorPosition(toDisconnect
     552                                                                                .getPosition(), false);
     553                                                                // This is to ensure the selected mode will be set
     554                                                                // to Normal rather than disconnect when the line is
     555                                                                // anchored
     556                                                                toDisconnect
     557                                                                                .setHighlightMode(Item.HighlightMode.Normal);
     558                                                                pickup(toDisconnect);
     559                                                        } else {
     560                                                                // If we are then detatch the line and pick up its
     561                                                                // end point...
     562                                                                Frame currentFrame = DisplayIO.getCurrentFrame();
     563                                                                Item newPoint = null;
     564
     565                                                                // If the point we are disconnecting is text...
     566                                                                // Then we want to leave the text behind
     567                                                                // And disconnect a point
     568                                                                if (toDisconnect instanceof Text) {
     569                                                                        newPoint = new Dot(toDisconnect.getX(),
     570                                                                                        toDisconnect.getY(), -1);
     571                                                                        Item.DuplicateItem(toDisconnect, newPoint);
     572                                                                } else {
     573                                                                        newPoint = toDisconnect.copy();
     574                                                                }
     575
     576                                                                currentFrame.addItem(newPoint);
     577                                                                // remove the current item from the connected
     578                                                                // list for this item
     579                                                                l.replaceLineEnd(toDisconnect, newPoint);
     580                                                                // remove unneeded constrains
     581                                                                newPoint.removeAllConstraints();
     582
     583                                                                // Set the new points mode to normal before picking
     584                                                                // it up so it will be restored correctly when
     585                                                                // anchored
     586                                                                newPoint
     587                                                                                .setHighlightMode(Item.HighlightMode.Normal);
     588                                                                toDisconnect
     589                                                                                .setHighlightMode(Item.HighlightMode.None);
     590                                                                DisplayIO.setCursorPosition(toDisconnect
     591                                                                                .getPosition(), false);
     592                                                                pickup(newPoint);
     593                                                                ItemUtils.EnclosedCheck(toDisconnect
     594                                                                                .getParentOrCurrentFrame().getItems());
     595                                                        }
     596                                                }
     597                                        }
     598                                } else {
     599                                        if (info.clicked.isLineEnd()) {
     600                                                DisplayIO.setCursorPosition(info.clicked.getPosition(), false);
     601                                        }
     602                                        pickup(info.clicked);
     603                                }
     604                                return items;
     605                        }
     606                });
     607                IndirectMouseActions.getInstance().setAnchorFreeItemsAction(new MouseAction() {
     608                        @Override
     609                        public List<Item> exec(MouseInfo info) {
     610                                List<Item> items = new ArrayList<Item>();
     611                                if (info.clickedIn != null && FreeItems.getInstance().size() == 1) {
     612                                        Item item = FreeItems.getItemAttachedToCursor();
     613                                        if (item instanceof Text) {
     614                                                Text text = (Text) item;
     615                                                if (AttributeUtils.setAttribute(text, text, 2)) {
     616                                                        info.clickedIn.removeAll(FrameUtils
     617                                                                        .getEnclosingLineEnds().iterator().next()
     618                                                                        .getAllConnected());
     619                                                        for (Item i : info.clickedIn) {
     620                                                                AttributeUtils.setAttribute(i, text);
     621                                                        }
     622                                                        FreeItems.getInstance().clear();
     623                                                }
     624                                        }
     625                                }
     626
     627                                // if a line is being rubber-banded, check for auto
     628                                // straightening
     629                                anchor(FreeItems.getInstance());
     630                                FreeItems.getInstance().clear();
     631                                updateCursor();
     632                                _offX = _offY = 0;
     633                                return items;
     634                        } 
     635                });
     636                IndirectMouseActions.getInstance().setDeleteItemsAction(new MouseAction() {
     637                        @Override
     638                        public List<Item> exec(final MouseInfo info) {
     639                                List<Item> items = new ArrayList<Item>();
     640                                // check permissions
     641                                if (!info.clicked.hasPermission(UserAppliedPermission.full)) {
     642                                        //Items on the message box have parent == null
     643                                        if (info.clicked.getParent() != null) {
     644                                                if (!info.clicked.isFrameName()) {
     645                                                        Item editTarget = info.clicked.getEditTarget();
     646                                                        if (editTarget != info.clicked
     647                                                                        && editTarget
     648                                                                                        .hasPermission(UserAppliedPermission.full)) {
     649                                                                info.clicked = editTarget;
     650                                                        } else {
     651                                                                MessageBay
     652                                                                                .displayMessage("Insufficient permission");
     653                                                                return items;
     654                                                        }
     655                                                }
     656                                               
     657                                        } else /*Its in the message area*/ {
     658                                                MessageBay.displayMessage("Insufficient permission");
     659                                                return items;
     660                                        }
     661                                }
     662                                Item merger = FreeItems.getItemAttachedToCursor();
     663                                assert (merger != null);
     664                                Collection<Item> left = null;
     665                                // when anchoring a line end onto a text line end, holding shift
     666                                // prevents the line ends from being merged
     667                                if (info.isShiftDown) {
     668                                        left = FreeItems.getInstance();
     669                                } else {
     670                                        left = merge(FreeItems.getInstance(), info.clicked);
     671                                }
     672                                Collection<Item> toDelete = new LinkedList<Item>();
     673                                toDelete.addAll(FreeItems.getInstance());
     674                                toDelete.removeAll(left);
     675                                anchor(left);
     676                                FreeItems.getInstance().clear();
     677                                DisplayIO.getCurrentFrame().removeAllItems(toDelete);
     678                                updateCursor();
     679                                // Make sure the dot goes away when anchoring a line end behind
     680                                // a text line end
     681                                if (info.isShiftDown) {
     682                                        refreshHighlights();
     683                                }
     684                                FrameGraphics.requestRefresh(true);
     685                                return items;
     686                                // otherwise, anchor the items
     687                        }               
    96688                });
    97689        }
     
    8541446                        if (_lastMouseClick != null && !_lastMouseClick.isControlDown()
    8551447                                        && clickedOn.hasAction()) {
    856                                 clickedOn.performActions();
    857                                 clickedOn.setHighlightMode(HighlightMode.None);
    858                                 getInstance().refreshHighlights();
    859                                 return;
     1448                                IndirectMouseActions.getInstance().getExecuteActionAction().exec(new MouseInfo(clicked, clickedIn, isShiftDown, isControlDown));
    8601449                        } else if (clickedOn.getLink() != null) {
    861                                 /*
    862                                  * Dont save the frame if we are moving to an old version of
    863                                  * this frame because everytime we save with the old tag... the
    864                                  * frame is backed up
    865                                  */
    866                                 if (!clickedOn.isOldTag())
    867                                         FrameIO.SaveFrame(DisplayIO.getCurrentFrame());
    868 
    869                                 Navigation.setLastNavigationItem(clickedOn);
    870                                 load(clickedOn.getAbsoluteLink(), clickedOn.getLinkHistory());
    871                                 // DisplayIO.UpdateTitle();
    872                                 return;
     1450                                IndirectMouseActions.getInstance().getFollowLinkAction().exec(new MouseInfo(clicked, clickedIn, isShiftDown, isControlDown));
    8731451                                // no link is found, perform TDFC
    8741452                        } else {
     
    8791457                                 */
    8801458                                if (clickedOn.isFrameName()) {
    881                                         if (isControlDown)
    882                                                 Navigation.PreviousFrame(false);
    883                                         else
    884                                                 Navigation.NextFrame(false);
    885                                         return;
    886                                 }
    887 
    888                                 // check for TDFC permission
    889                                 if (!clicked.hasPermission(UserAppliedPermission.createFrames)) {
    890                                         MessageBay
    891                                                         .displayMessage("Insufficient permission to TDFC (Top Down Frame Creation) from that item");
    892                                         return;
    893                                 }
    894 
    895                                 if (clickedOn.isOldTag())
    896                                         return;
    897 
    898                                 try {
    899                                         tdfc(clickedOn);
    900                                 } catch (RuntimeException e) {
    901                                         e.printStackTrace();
    902                                         MessageBay.errorMessage("Top Down Frame Creation (TDFC) error: " + e.getMessage());
    903                                 }
    904                                 return;
     1459                                        IndirectMouseActions.getInstance().getRespondToFrameNameClickAction().exec(new MouseInfo(clicked, clickedIn, isShiftDown, isControlDown));
     1460                                }
     1461                               
     1462                                IndirectMouseActions.getInstance().getTDFCAction().exec(new MouseInfo(clicked, clickedIn, isShiftDown, isControlDown));
    9051463                        }
    9061464
    9071465                } else {
    9081466                        IndirectMouseActions.getInstance().getBackAction().exec(new MouseInfo(clicked, clickedIn, isShiftDown, isControlDown));
    909                         // if user is not pointing at something,this is a back
    910 //                      if (isShiftDown || isControlDown)
    911 //                              forward();
    912 //                      else
    913 //                              back();
    9141467                }
    9151468        }
     
    10081561                        // possible)
    10091562                        if (doMerging(clicked)) {
    1010                                 // check permissions
    1011                                 if (!clicked.hasPermission(UserAppliedPermission.full)) {
    1012                                         //Items on the message box have parent == null
    1013                                         if (clicked.getParent() != null) {
    1014                                                 if (!clicked.isFrameName()) {
    1015                                                         Item editTarget = clicked.getEditTarget();
    1016                                                         if (editTarget != clicked
    1017                                                                         && editTarget
    1018                                                                                         .hasPermission(UserAppliedPermission.full)) {
    1019                                                                 clicked = editTarget;
    1020                                                         } else {
    1021                                                                 MessageBay
    1022                                                                                 .displayMessage("Insufficient permission");
    1023                                                                 return;
    1024                                                         }
    1025                                                 }
    1026                                                
    1027                                         } else /*Its in the message area*/ {
    1028                                                 MessageBay.displayMessage("Insufficient permission");
    1029                                                 return;
    1030                                         }
    1031                                 }
    1032                                 Item merger = FreeItems.getItemAttachedToCursor();
    1033                                 assert (merger != null);
    1034                                 Collection<Item> left = null;
    1035                                 // when anchoring a line end onto a text line end, holding shift
    1036                                 // prevents the line ends from being merged
    1037                                 if (isShiftDown) {
    1038                                         left = FreeItems.getInstance();
    1039                                 } else {
    1040                                         left = merge(FreeItems.getInstance(), clicked);
    1041                                 }
    1042                                 Collection<Item> toDelete = new LinkedList<Item>();
    1043                                 toDelete.addAll(FreeItems.getInstance());
    1044                                 toDelete.removeAll(left);
    1045                                 anchor(left);
    1046                                 FreeItems.getInstance().clear();
    1047                                 DisplayIO.getCurrentFrame().removeAllItems(toDelete);
    1048                                 updateCursor();
    1049                                 // Make sure the dot goes away when anchoring a line end behind
    1050                                 // a text line end
    1051                                 if (isShiftDown) {
    1052                                         refreshHighlights();
    1053                                 }
    1054                                 FrameGraphics.requestRefresh(true);
    1055                                 return;
    1056                                 // otherwise, anchor the items
     1563                                IndirectMouseActions.getInstance().getDeleteItemsAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    10571564                        } else {
    1058                                 if (clickedIn != null && FreeItems.getInstance().size() == 1) {
    1059                                         Item item = FreeItems.getItemAttachedToCursor();
    1060                                         if (item instanceof Text) {
    1061                                                 Text text = (Text) item;
    1062                                                 if (AttributeUtils.setAttribute(text, text, 2)) {
    1063                                                         clickedIn.removeAll(FrameUtils
    1064                                                                         .getEnclosingLineEnds().iterator().next()
    1065                                                                         .getAllConnected());
    1066                                                         for (Item i : clickedIn) {
    1067                                                                 AttributeUtils.setAttribute(i, text);
    1068                                                         }
    1069                                                         FreeItems.getInstance().clear();
    1070                                                 }
    1071                                         }
    1072                                 }
    1073 
    1074                                 // if a line is being rubber-banded, check for auto
    1075                                 // straightening
    1076                                 anchor(FreeItems.getInstance());
    1077                                 FreeItems.getInstance().clear();
    1078                                 updateCursor();
    1079                                 _offX = _offY = 0;
    1080                                 return;
     1565                                IndirectMouseActions.getInstance().getAnchorFreeItemsAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    10811566                        }
    10821567                        // otherwise if the user is pointing at something, pick it up unless shift is down
     
    10951580                                }
    10961581                        }
    1097 
    1098                         // BROOK: WIDGET RECTANGLES DONT ALLOW DISCONNECTION
    1099                         if (clicked instanceof Line && !(clicked instanceof WidgetEdge)) {
    1100                                 // Check if within 20% of the end of the line
    1101                                 Line l = (Line) clicked;
    1102                                 Item toDisconnect = l.getEndPointToDisconnect(_lastMouseClick
    1103                                                 .getX(), _lastMouseClick.getY());
    1104 
    1105                                 if (toDisconnect == null) {
    1106                                         pickup(clicked);
    1107                                 } else {
    1108                                         if (toDisconnect.getHighlightMode() == Item.HighlightMode.Normal) {
    1109                                                 DisplayIO.setCursorPosition(toDisconnect.getPosition(),
    1110                                                                 false);
    1111                                                 pickup(toDisconnect);
    1112                                         } else {
    1113                                                 List<Line> lines = toDisconnect.getLines();
    1114                                                 // This is to remove constraints from single lines
    1115                                                 // with constraints...
    1116                                                 // ie. partially deleted rectangles
    1117                                                 if (lines.size() == 1) {
    1118                                                         toDisconnect.removeAllConstraints();
    1119 
    1120                                                         DisplayIO.setCursorPosition(toDisconnect
    1121                                                                         .getPosition(), false);
    1122                                                         // This is to ensure the selected mode will be set
    1123                                                         // to Normal rather than disconnect when the line is
    1124                                                         // anchored
    1125                                                         toDisconnect
    1126                                                                         .setHighlightMode(Item.HighlightMode.Normal);
    1127                                                         pickup(toDisconnect);
    1128                                                 } else {
    1129                                                         // If we are then detatch the line and pick up its
    1130                                                         // end point...
    1131                                                         Frame currentFrame = DisplayIO.getCurrentFrame();
    1132                                                         Item newPoint = null;
    1133 
    1134                                                         // If the point we are disconnecting is text...
    1135                                                         // Then we want to leave the text behind
    1136                                                         // And disconnect a point
    1137                                                         if (toDisconnect instanceof Text) {
    1138                                                                 newPoint = new Dot(toDisconnect.getX(),
    1139                                                                                 toDisconnect.getY(), -1);
    1140                                                                 Item.DuplicateItem(toDisconnect, newPoint);
    1141                                                         } else {
    1142                                                                 newPoint = toDisconnect.copy();
    1143                                                         }
    1144 
    1145                                                         currentFrame.addItem(newPoint);
    1146                                                         // remove the current item from the connected
    1147                                                         // list for this item
    1148                                                         l.replaceLineEnd(toDisconnect, newPoint);
    1149                                                         // remove unneeded constrains
    1150                                                         newPoint.removeAllConstraints();
    1151 
    1152                                                         // Set the new points mode to normal before picking
    1153                                                         // it up so it will be restored correctly when
    1154                                                         // anchored
    1155                                                         newPoint
    1156                                                                         .setHighlightMode(Item.HighlightMode.Normal);
    1157                                                         toDisconnect
    1158                                                                         .setHighlightMode(Item.HighlightMode.None);
    1159                                                         DisplayIO.setCursorPosition(toDisconnect
    1160                                                                         .getPosition(), false);
    1161                                                         pickup(newPoint);
    1162                                                         ItemUtils.EnclosedCheck(toDisconnect
    1163                                                                         .getParentOrCurrentFrame().getItems());
    1164                                                 }
    1165                                         }
    1166                                 }
    1167                         } else {
    1168                                 if (clicked.isLineEnd()) {
    1169                                         DisplayIO.setCursorPosition(clicked.getPosition(), false);
    1170                                 }
    1171                                 pickup(clicked);
    1172                         }
     1582                        IndirectMouseActions.getInstance().getDetachLineAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    11731583                        // if we're inside a shape, pick it up unless shift is down
    11741584                } else if (clickedIn != null && !isShiftDown) {
    1175                         ArrayList<Item> toPickup = new ArrayList<Item>(clickedIn.size());
    1176                         for (Item ip : clickedIn)
    1177                                 if (ip.hasPermission(UserAppliedPermission.full))
    1178                                         toPickup.add(ip);
    1179                         pickup(toPickup);
    1180                         // otherwise the user is creating a line
     1585                        IndirectMouseActions.getInstance().getGroupPickupAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    11811586                } else {
    1182                         Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), Math
    1183                                         .round(MouseX), Math.round(MouseY), true);
    1184                         // If we have permission to copy this item then pick it up
    1185                         if (on != null && on.isLineEnd()
    1186                                         && on.hasPermission(UserAppliedPermission.full)) {
    1187                                 on.removeAllConstraints();
    1188                                 pickup(on);
    1189                                 return;
    1190                         }
    1191 
    1192                         if (on instanceof WidgetEdge) {
    1193                                 // Don't allow the user to break widget edges.
    1194                                 // Note: had to return here because random dots would
    1195                                 // appear otherwise... cannot understand code below
    1196                                 // with create line.
    1197                                 return;
    1198                         }
    1199 
    1200                         // if its on a line then split the line and put a point on it and
    1201                         // pick that point up. Only if it is not a widget line
    1202                         if (on instanceof Line && on.hasPermission(UserAppliedPermission.full)) {
    1203                                 Frame current = DisplayIO.getCurrentFrame();
    1204                                 // create the two endpoints
    1205                                 Line oldLine = (Line) on;
    1206                                 Item newPoint = oldLine.getStartItem().copy();
    1207                                 newPoint.setPosition(MouseX, MouseY);
    1208 
    1209                                 Item end = oldLine.getEndItem();
    1210                                 // create the Line
    1211                                 Line newLine = new Line(newPoint, end, current.getNextItemID());
    1212                                 oldLine.replaceLineEnd(end, newPoint);
    1213                                 newPoint.removeAllConstraints();
    1214                                 pickup(newPoint);
    1215                                 // Update the stats
    1216                                 Collection<Item> created = new LinkedList<Item>();
    1217                                 created.add(newPoint);
    1218                                 created.add(newLine);
    1219                                 SessionStats.CreatedItems(newLine.getAllConnected());
    1220                                 return;
    1221                         }
    1222                         Line newLine = createLine();
    1223                         SessionStats.CreatedItems(newLine.getAllConnected());
    1224                         return;
     1587                        IndirectMouseActions.getInstance().getNewLineAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    12251588                }
    12261589                SessionStats.MovedItems(FreeItems.getInstance());
     
    13291692                                                || clicked instanceof XRayable) {
    13301693                                        if (isRubberBandingCorner()) {
    1331                                                 // Move the cursor so that the copy is exactly the
    1332                                                 // same as the shape that was anchored
    1333                                                 DisplayIO.setCursorPosition(clicked.getPosition());
    1334                                                 Item d = getFirstFreeLineEnd();
    1335                                                 // get a copy of all enclosed items before merging
    1336                                                 // lineEnds
    1337                                                 Collection<Item> items = FrameUtils.getItemsEnclosedBy(
    1338                                                                 DisplayIO.getCurrentFrame(), d
    1339                                                                                 .getEnclosedShape());
    1340                                                 // If its not an enclosed shape then pick up the
    1341                                                 // connected shape
    1342                                                 if (items == null || items.size() == 0) {
    1343                                                         items = d.getAllConnected();
    1344                                                 } else {
    1345                                                         // For some reason the item that was clicked ends up
    1346                                                         // in the enclosure and needs to be removed
    1347                                                         items.removeAll(clicked.getConnected());
    1348                                                         // the item that was the origin of the enclosed
    1349                                                         // shape used to create the enclosure does not get
    1350                                                         // returned from getItemsEnclosedBy to the enclosure
    1351                                                         // so it must be added
    1352                                                         items.addAll(d.getConnected());
    1353                                                 }
    1354 
    1355                                                 Collection<Item> toCopy = new LinkedHashSet<Item>();
    1356 
    1357                                                 for (Item ip : items) {
    1358                                                         if (ip.hasPermission(UserAppliedPermission.copy))
    1359                                                                 toCopy.add(ip);
    1360                                                 }
    1361                                                 copies = copy(toCopy);
    1362                                                 // Now do the merging
    1363                                                 Collection<Item> remain = merge(
    1364                                                                 FreeItems.getInstance(), clicked);
    1365                                                 // anchor the points
    1366                                                 anchor(remain);
    1367                                                 FreeItems.getInstance().clear();
    1368                                                 pickup(copies);
     1694                                                copies = IndirectMouseActions.getInstance().getMergeGroupAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    13691695                                                // line onto something
    13701696                                        } else if (FreeItems.getInstance().size() == 2
    13711697                                        /* && clicked instanceof XRayable */) {
    1372                                                 copies = ItemUtils.UnreelLine(FreeItems.getInstance(),
    1373                                                                 _controlDown);
    1374                                                 Collection<Item> leftOver = merge(FreeItems
    1375                                                                 .getInstance(), clicked);
    1376                                                 anchor(leftOver);
    1377                                                 if (copies == null)
    1378                                                         copies = copy(FreeItems.getInstance());
    1379                                                 FreeItems.getInstance().clear();
    1380                                                 for (Item i : copies)
    1381                                                         i.setOffset(0, 0);
    1382                                                 // need to move to prevent cursor dislocation
    1383                                                 move(copies);
    1384                                                 pickup(copies);
    1385                                                 // point onto point
     1698                                                copies = IndirectMouseActions.getInstance().getMergeTwoItemsAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    13861699                                        } else if (FreeItems.getInstance().size() == 1) {
    1387                                                 copies = copy(FreeItems.getInstance());
    1388                                                 Collection<Item> remain = merge(copies, clicked);
    1389 
    1390                                                 // ignore items that could not be merged.
    1391                                                 anchor(remain);
     1700                                                copies = IndirectMouseActions.getInstance().getMergeSingleItemAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    13921701                                        } else {
    1393                                                 stampItemsOnCursor(true);
    1394                                                 copies = FreeItems.getInstance();
     1702                                                copies = IndirectMouseActions.getInstance().getStampAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    13951703                                        }
    13961704                                } else {
     
    14101718                                // check if this is anchoring a rectangle
    14111719                                if (isRubberBandingCorner()) {
    1412                                         Item d = getFirstFreeLineEnd();
    1413                                         // anchor the points
    1414                                         anchor(FreeItems.getInstance());
    1415                                         FreeItems.getInstance().clear();
    1416                                         updateCursor();
    1417                                         // pick up a copy of all enclosed items
    1418                                         Collection<Item> enclosedItems = FrameUtils
    1419                                                         .getItemsEnclosedBy(DisplayIO.getCurrentFrame(), d
    1420                                                                         .getEnclosedShape());
    1421                                         if (enclosedItems != null) {
    1422                                                 enclosedItems.removeAll(d.getAllConnected());
    1423                                                 Collection<Item> toCopy = getFullyEnclosedItems(enclosedItems);
    1424 
    1425                                                 if (toCopy.size() > 0) {
    1426                                                         // Find the closest item to the mouse cursor
    1427                                                         double currentX = DisplayIO.getMouseX();
    1428                                                         double currentY = FrameMouseActions.getY();
    1429                                                         Item closest = null;
    1430                                                         double shortestDistance = Double.MAX_VALUE;
    1431                                                         for (Item next : toCopy) {
    1432                                                                 if (next instanceof Line)
    1433                                                                         continue;
    1434                                                                 double distance = Point.distance(currentX,
    1435                                                                                 currentY, next.getX(), next.getY());
    1436                                                                 if (distance < shortestDistance) {
    1437                                                                         shortestDistance = distance;
    1438                                                                         closest = next;
    1439                                                                 }
    1440                                                         }
    1441                                                         // Move the cursor to closest item
    1442                                                         DisplayIO.setCursorPosition(closest.getPosition());
    1443                                                         // Pickup copy of the stuff inside the rectange
    1444                                                         copies = copy(toCopy);
    1445                                                         pickup(copies);
    1446                                                         // Remove the rectangle
    1447                                                         d.getParentOrCurrentFrame().removeAllItems(
    1448                                                                         d.getAllConnected());
    1449                                                 } else {
    1450                                                         // Pick up a copy of the rectangle
    1451                                                         copies = copy(d.getAllConnected());
    1452                                                         pickup(copies);
    1453                                                 }
    1454                                         }
     1720                                        copies = IndirectMouseActions.getInstance().getRubberBandingCornerAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    14551721                                } else {
    14561722                                        if (rubberBanding()) {
    1457                                                 if (clicked != null) {
    1458                                                         Collection<Item> leftOver = merge(FreeItems
    1459                                                                         .getInstance(), clicked);
    1460                                                         anchor(leftOver);
    1461                                                 }
    1462                                                 // This is executed when the user is putting down a line
    1463                                                 // endpoint and unreeling. ie. Normal unreeling
    1464                                                 copies = ItemUtils.UnreelLine(FreeItems.getInstance(),
    1465                                                                 _controlDown);
    1466 
    1467                                                 if (copies == null)
    1468                                                         copies = copy(FreeItems.getInstance());
    1469                                                 anchor(FreeItems.getInstance());
    1470                                                 for (Item i : copies)
    1471                                                         i.setOffset(0, 0);
    1472                                                 // need to move to prevent cursor dislocation
    1473                                                 move(copies);
    1474                                                 pickup(copies);
     1723                                                copies = IndirectMouseActions.getInstance().getRubberBandingCopyAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    14751724                                        } else if (_extrude) {
    1476                                                 List<Item> originals = new ArrayList<Item>();
    1477                                                 // remove any lines that dont have both endpoints
    1478                                                 // floating
    1479                                                 for (Item i : FreeItems.getInstance()) {
    1480                                                         if (i.isFloating())
    1481                                                                 originals.add(i);
    1482                                                 }
    1483                                                 if (copies == null)
    1484                                                         copies = ItemUtils.CopyItems(originals, _extrude);
    1485                                                 for (Item i : copies)
    1486                                                         i.setOffset(0, 0);
    1487                                                 anchor(FreeItems.getInstance());
    1488                                                 // Move isnt working right for extruding!!
    1489                                                 // move(copies);
    1490                                                 pickup(copies);
     1725                                                copies = IndirectMouseActions.getInstance().getExtrudeAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    14911726                                        } else {
    14921727                                                stampItemsOnCursor(true);
     
    15161751                                        }
    15171752                                }
    1518 
    1519                                 copies = ItemUtils.UnreelLine(clicked, _controlDown);
    1520                                 // Copies will NOT be null if the user right clicked on a point
    1521                                 if (copies == null) {
    1522                                         Collection<Item> originals = clicked.getConnected();
    1523                                         copies = ItemUtils.CopyItems(originals, _extrude);
    1524                                         // if this is the title of the frame, link it to the frame
    1525                                         if (originals.size() == 1 && copies.size() == 1) {
    1526                                                 Item copy = copies.get(0);
    1527                                                 Item original = originals.iterator().next();
    1528                                                 if (original.getLink() == null
    1529                                                                 && original.isFrameTitle()) {
    1530                                                         // save the frame after copying
    1531                                                         // i.getParent().setChanged(true);
    1532                                                         copy.setLink(original.getParentOrCurrentFrame()
    1533                                                                         .getName());
    1534                                                 }
    1535                                         }
    1536 
    1537                                         FrameGraphics.changeHighlightMode(clicked,
    1538                                                         HighlightMode.None);
    1539 
    1540                                         if (!_extrude)
    1541                                                 clearParent(copies);
    1542                                 }
    15431753                               
    1544                                 ItemUtils.Justify(copies);
    1545 
    1546                                 pickup(copies);
     1754                                copies = IndirectMouseActions.getInstance().getMakeCopyAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    15471755                        } else {
    15481756                                // if user is pointing in a closed shape and shift isn't down, make a copy of the items inside
    15491757                                if (clickedIn != null && !isShiftDown()) {
    1550                                         // Set the selection mode for the items that were clicked in
    1551                                         Collection<Item> enclosed = getFullyEnclosedItems(clickedIn);
    1552                                         if (enclosed.size() == 0) {
    1553                                                 MessageBay
    1554                                                                 .displayMessage("Insufficient permission to copy items");
    1555                                         } else {
    1556                                                 copies = copy(enclosed);
    1557                                                 clearParent(copies);
    1558                                                 ItemUtils.Justify(copies);
    1559                                                 pickup(copies);
    1560                                                 for (Item i : clickedIn) {
    1561                                                         i.setHighlightMode(HighlightMode.None);
    1562                                                 }
    1563                                         }
     1758                                        IndirectMouseActions.getInstance().getMakeGroupCopyAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    15641759                                        // otherwise, create a rectangle
    15651760                                } else {
     
    15681763                                        // if its on a line then create a line from that line
    15691764                                        if (on instanceof Line && on.hasPermission(UserAppliedPermission.full)) {
    1570 
    1571                                                 Line onLine = (Line) on;
    1572                                                 Line newLine = onLine.copy();
    1573                                                 Item end = newLine.getEndItem();
    1574                                                 Item start = newLine.getStartItem();
    1575                                                 end.setPosition(MouseX, MouseY);
    1576                                                 start.setPosition(MouseX, MouseY);
    1577                                                 onLine.autoArrowheadLength();
    1578                                                 // anchor the start
    1579                                                 anchor(start);
    1580                                                 // attach the line to the cursor
    1581                                                 pickup(end);
    1582 
    1583                                                 List<Item> toMerge = new LinkedList<Item>();
    1584                                                 toMerge.add(newLine.getStartItem());
    1585                                                 toMerge.add(newLine);
    1586 
    1587                                                 // Make sure the highlighting is shown when the end is
    1588                                                 // anchored
    1589                                                 end.setHighlightMode(Item.HighlightMode.Normal);
    1590                                                 merge(toMerge, on);
    1591                                                 // anchor(left);
    1592                                                 // FreeItems.getInstance().clear();
    1593                                                 FrameGraphics.Repaint();
    1594                                                 updateCursor();
    1595                                                 return;
     1765                                                IndirectMouseActions.getInstance().getExtendLineAction().exec(new MouseInfo(on, clickedIn, false, false));
    15961766                                        }
    1597 
    1598                                         copies = new ArrayList<Item>();
    1599                                         Item[] d = new Item[RECTANGLE_CORNERS];
    1600                                         // create dots
    1601                                         Frame current = DisplayIO.getCurrentFrame();
    1602                                         for (int i = 0; i < d.length; i++) {
    1603                                                 d[i] = current.createDot();
    1604                                                 copies.add(d[i]);
    1605                                         }
    1606 
    1607                                         current.nextDot();
    1608 
    1609                                         // create lines
    1610                                         copies.add(new Line(d[0], d[1], current.getNextItemID()));
    1611                                         copies.add(new Line(d[1], d[2], current.getNextItemID()));
    1612                                         copies.add(new Line(d[2], d[3], current.getNextItemID()));
    1613                                         copies.add(new Line(d[3], d[0], current.getNextItemID()));
    1614 
    1615                                         new Constraint(d[0], d[1], current.getNextItemID(),
    1616                                                         Constraint.HORIZONTAL);
    1617                                         new Constraint(d[2], d[3], current.getNextItemID(),
    1618                                                         Constraint.HORIZONTAL);
    1619                                         new Constraint(d[1], d[2], current.getNextItemID(),
    1620                                                         Constraint.VERTICAL);
    1621                                         new Constraint(d[3], d[0], current.getNextItemID(),
    1622                                                         Constraint.VERTICAL);
    1623 
    1624                                         anchor(new ArrayList<Item>(copies));
    1625                                         pickup(d[3]);
    1626                                         d[3].setHighlightMode(HighlightMode.Normal);
    1627 
    1628                                         SessionStats.CreatedItems(copies);
    1629                                         copies.clear();
     1767                                        copies = IndirectMouseActions.getInstance().getCreateRectangleAction().exec(new MouseInfo(clicked, clickedIn, false, false));                                   
    16301768                                }
    16311769                        }
  • trunk/src/org/expeditee/gui/indirect/mouse/IndirectMouseActions.java

    r942 r943  
    22
    33public class IndirectMouseActions {
    4         private static final int ACTIONQUANTITY = 100;
     4       
     5        private enum Action {
     6                //Left Mouse
     7                BACK, TDFC, FRAMENAMECLICK, FOLLOWLINK, EXECUTEACTION,
     8                //Right Mouse
     9                CREATERECTANGLE, EXTENDLINE, MAKEGROUPCOPY, MAKECOPY, EXTRUDE, RUBBERBANDCOPY,
     10                RUBBERBANDCORNERCOPY, STAMP, MERGESINGLE, MERGETWO, MERGEGROUP,
     11                //Middle Mouse
     12                NEWLINE, GROUPPICKUP, DETACHLINE, ANCHORFREEITEMS, DELETEITEMS
     13        }
     14       
     15        private static final int ACTIONQUANTITY = Action.values().length;
    516       
    617        private static IndirectMouseActions instance = new IndirectMouseActions();
     
    1223        public MouseAction[] actions = new MouseAction[ACTIONQUANTITY];
    1324       
    14         private int back = 0;
    15         public MouseAction getBackAction() { return actions[back]; }
    16         public MouseAction setBackAction(final MouseAction action) { actions[back] = action; return action; }
     25        public MouseAction getBackAction() { return actions[Action.BACK.ordinal()]; }
     26        public MouseAction setBackAction(final MouseAction action) { actions[Action.BACK.ordinal()] = action; return action; }
     27
     28        public MouseAction getTDFCAction() { return actions[Action.TDFC.ordinal()]; }
     29        public MouseAction setTDFCAction(final MouseAction action) { actions[Action.TDFC.ordinal()] = action; return action; }
     30
     31        public MouseAction getRespondToFrameNameClickAction() { return actions[Action.FRAMENAMECLICK.ordinal()]; }
     32        public MouseAction setRespondToFrameNameClickAction(final MouseAction action) { actions[Action.FRAMENAMECLICK.ordinal()] = action; return action; }
     33
     34        public MouseAction getFollowLinkAction() { return actions[Action.FOLLOWLINK.ordinal()]; }
     35        public MouseAction setFollowLinkAction(final MouseAction action) { actions[Action.FOLLOWLINK.ordinal()] = action; return action; }
     36
     37        public MouseAction getExecuteActionAction() { return actions[Action.EXECUTEACTION.ordinal()]; }
     38        public MouseAction setExecuteActionAction(final MouseAction action) { actions[Action.EXECUTEACTION.ordinal()] = action; return action; }
     39
     40        public MouseAction getCreateRectangleAction() { return actions[Action.CREATERECTANGLE.ordinal()]; }
     41        public MouseAction setCreateRectangleAction(final MouseAction action) { actions[Action.CREATERECTANGLE.ordinal()] = action; return action; }
     42
     43        public MouseAction getExtendLineAction() { return actions[Action.EXTENDLINE.ordinal()]; }
     44        public MouseAction setExtendLineAction(final MouseAction action) { actions[Action.EXTENDLINE.ordinal()] = action; return action; }
     45
     46        public MouseAction getMakeGroupCopyAction() { return actions[Action.MAKEGROUPCOPY.ordinal()]; }
     47        public MouseAction setMakeGroupCopyAction(final MouseAction action) { actions[Action.MAKEGROUPCOPY.ordinal()] = action; return action; }
     48
     49        public MouseAction getMakeCopyAction() { return actions[Action.MAKECOPY.ordinal()]; }
     50        public MouseAction setMakeCopyAction(final MouseAction action) { actions[Action.MAKECOPY.ordinal()] = action; return action; }
     51       
     52        public MouseAction getExtrudeAction() { return actions[Action.EXTRUDE.ordinal()]; }
     53        public MouseAction setExtrudeAction(final MouseAction action) { actions[Action.EXTRUDE.ordinal()] = action; return action; }
     54
     55        public MouseAction getRubberBandingCopyAction() { return actions[Action.RUBBERBANDCOPY.ordinal()]; }
     56        public MouseAction setRubberBandingCopyAction(final MouseAction action) { actions[Action.RUBBERBANDCOPY.ordinal()] = action; return action; }
     57
     58        public MouseAction getRubberBandingCornerAction() { return actions[Action.RUBBERBANDCORNERCOPY.ordinal()]; }
     59        public MouseAction setRubberBandingCornerAction(final MouseAction action) { actions[Action.RUBBERBANDCORNERCOPY.ordinal()] = action; return action; }
     60
     61        public MouseAction getStampAction() { return actions[Action.STAMP.ordinal()]; }
     62        public MouseAction setStampAction(final MouseAction action) { actions[Action.STAMP.ordinal()] = action; return action; }
     63
     64        public MouseAction getMergeSingleItemAction() { return actions[Action.MERGESINGLE.ordinal()]; }
     65        public MouseAction setMergeSingleItemAction(final MouseAction action) { actions[Action.MERGESINGLE.ordinal()] = action; return action; }
     66
     67        public MouseAction getMergeTwoItemsAction() { return actions[Action.MERGETWO.ordinal()]; }
     68        public MouseAction setMergeTwoItemsAction(final MouseAction action) { actions[Action.MERGETWO.ordinal()] = action; return action; }
     69
     70        public MouseAction getMergeGroupAction() { return actions[Action.MERGEGROUP.ordinal()]; }
     71        public MouseAction setMergeGroupAction(final MouseAction action) { actions[Action.MERGEGROUP.ordinal()] = action; return action; }
     72
     73        public MouseAction getNewLineAction() { return actions[Action.NEWLINE.ordinal()]; }
     74        public MouseAction setNewLineAction(final MouseAction action) { actions[Action.NEWLINE.ordinal()] = action; return action; }
     75
     76        public MouseAction getGroupPickupAction() { return actions[Action.GROUPPICKUP.ordinal()]; }
     77        public MouseAction setGroupPickupAction(final MouseAction action) { actions[Action.GROUPPICKUP.ordinal()] = action; return action; }
     78
     79        public MouseAction getDetachLineAction() { return actions[Action.DETACHLINE.ordinal()]; }
     80        public MouseAction setDetachLineAction(final MouseAction action) { actions[Action.DETACHLINE.ordinal()] = action; return action; }
     81       
     82        public MouseAction getAnchorFreeItemsAction() { return actions[Action.ANCHORFREEITEMS.ordinal()]; }
     83        public MouseAction setAnchorFreeItemsAction(final MouseAction action) { actions[Action.ANCHORFREEITEMS.ordinal()] = action; return action; }
     84
     85        public MouseAction getDeleteItemsAction() { return actions[Action.DELETEITEMS.ordinal()]; }
     86        public MouseAction setDeleteItemsAction(final MouseAction action) { actions[Action.DELETEITEMS.ordinal()] = action; return action; }
    1787}
  • trunk/src/org/expeditee/gui/indirect/mouse/MouseAction.java

    r942 r943  
    22
    33import java.util.Collection;
     4import java.util.List;
    45
    56import org.expeditee.items.Item;
     
    78public interface MouseAction {
    89       
    9         public void exec(MouseInfo info);
     10        public List<Item> exec(MouseInfo info);
    1011       
    1112       
Note: See TracChangeset for help on using the changeset viewer.