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...

File:
1 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:
Note: See TracChangeset for help on using the changeset viewer.