Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Simple.java

    r947 r1102  
    1919package org.expeditee.actions;
    2020
    21 import java.awt.Color;
    22 import java.awt.Point;
    23 import java.awt.event.InputEvent;
    24 import java.awt.geom.Point2D;
     21//import java.awt.event.InputEvent;
    2522import java.io.BufferedReader;
    2623import java.io.InputStreamReader;
     
    4744import org.expeditee.agents.SearchTree;
    4845import org.expeditee.agents.WriteTree;
     46import org.expeditee.core.Colour;
     47import org.expeditee.core.Point;
     48import org.expeditee.gio.gesture.StandardGestureActions;
    4949import org.expeditee.gui.AttributeUtils;
    5050import org.expeditee.gui.AttributeValuePair;
    5151import org.expeditee.gui.Browser;
    52 import org.expeditee.gui.DisplayIO;
     52import org.expeditee.gui.DisplayController;
    5353import org.expeditee.gui.Frame;
    54 import org.expeditee.gui.FrameGraphics;
    5554import org.expeditee.gui.FrameIO;
    56 import org.expeditee.gui.FrameMouseActions;
    5755import org.expeditee.gui.FrameUtils;
    5856import org.expeditee.gui.FreeItems;
     
    156154        private static int _stepPause = -1;
    157155
    158         private static Color _stepColor;
     156        private static Colour _stepColor;
    159157
    160158        private static boolean _nextStatement;
     
    173171
    174172        public static void NewSimpleTest() {
    175                 Frame newSimpleTest = FrameIO.CreateFrame(DisplayIO.getCurrentFrame()
     173                Frame newSimpleTest = FrameIO.CreateFrame(DisplayController.getCurrentFrame()
    176174                                .getFramesetName(), "Test", null);
    177175                List<String> actions = new ArrayList<String>();
     
    183181
    184182        public static void NextTest() {
    185                 Frame next = DisplayIO.getCurrentFrame();
     183                Frame next = DisplayController.getCurrentFrame();
    186184                do {
    187185                        next = FrameIO.LoadNext(next);
     
    191189
    192190        public static void PreviousTest() {
    193                 Frame prev = DisplayIO.getCurrentFrame();
     191                Frame prev = DisplayController.getCurrentFrame();
    194192                do {
    195193                        prev = FrameIO.LoadPrevious(prev);
     
    240238                int testsFailed = 0;
    241239
    242                 FrameIO.SaveFrame(DisplayIO.getCurrentFrame(), false);
     240                FrameIO.SaveFrame(DisplayController.getCurrentFrame(), false);
    243241                MessageBay.displayMessage("Starting test suite: " + _frameset,
    244                                 Color.CYAN);
     242                                Colour.CYAN);
    245243
    246244                // Get the next number in the inf file for the _frameset
     
    312310                // Report the number of test passed and failed
    313311                MessageBay.displayMessage(
    314                                 "Total tests: " + (testsPassed + testsFailed), Color.CYAN);
     312                                "Total tests: " + (testsPassed + testsFailed), Colour.CYAN);
    315313                if (testsPassed > 0)
    316314                        MessageBay.displayMessage("Passed: " + testsPassed, Item.GREEN);
    317315                if (testsFailed > 0)
    318                         MessageBay.displayMessage("Failed: " + testsFailed, Color.RED);
     316                        MessageBay.displayMessage("Failed: " + testsFailed, Colour.RED);
    319317                // Remove items from the cursor...
    320318                FreeItems.getInstance().clear();
     
    350348        //Have changed parameters, so it takes an Item, not just a Text item.
    351349        private static void RunFrame(Frame frame, Item current,
    352                         boolean acceptKeyboardInput, boolean step, int pause, Color color) {
     350                        boolean acceptKeyboardInput, boolean step, int pause, Colour color) {
    353351                try {
    354352                        if (current != null) {
     
    358356                                 */
    359357                                // DisplayIO.addToBack(current.getParent());
    360                                 DisplayIO.addToBack(DisplayIO.getCurrentFrame());
     358                                DisplayController.addToBack(DisplayController.getCurrentFrame());
    361359                        } else {
    362360                                /* TODO we should not have to pass an item just to run a frame! */
     
    365363                        }
    366364
    367                         _stepColor = color == null ? Color.green : color;
    368                         _stepColor = new Color(_stepColor.getRed(), _stepColor.getGreen(),
    369                                         _stepColor.getBlue(), 50);
     365                        _stepColor = color == null ? Colour.GREEN : color;
     366                        _stepColor = new Colour(_stepColor.getRed(), _stepColor.getGreen(),
     367                                        _stepColor.getBlue(), Colour.FromComponent255(50));
    370368                        _stepPause = pause;
    371369                        _step = step;
     
    429427         */
    430428        public static void DebugFrame(Frame frame, Text current, float pause,
    431                         Color color) {
     429                        Colour color) {
    432430                if (isProgramRunning()) {
    433431                        stop();
     
    454452                FrameUtils.DisplayFrame(item.getParent().getName(), true, true);
    455453                item.setHighlightMode(HighlightMode.Normal);
    456                 item.setHighlightColor(Color.CYAN);
     454                item.setHighlightColor(Colour.CYAN);
    457455                FrameIO.SaveFrame(item.getParent());
    458456        }
     
    499497
    500498                if (_step) {
    501                         if (child != DisplayIO.getCurrentFrame()) {
    502                                 DisplayIO.setCurrentFrame(child, true);
    503                         }
    504                         DisplayIO.addToBack(child);
     499                        if (child != DisplayController.getCurrentFrame()) {
     500                                DisplayController.setCurrentFrame(child, true);
     501                        }
     502                        DisplayController.addToBack(child);
    505503                }
    506504
     
    524522                        AgentStats.ItemExecuted();
    525523                        try {
    526                                 Color oldColor = item.getBackgroundColor();
     524                                Colour oldColor = item.getBackgroundColor();
    527525                                if (_step) {
    528526                                        pause(item);
     
    534532                                        } else {
    535533                                                item.setHighlightMode(Item.HighlightMode.None);
     534                                                item.setHighlightColorToDefault();
    536535                                        }
    537536                                }
     
    541540                                                        && lastItemStatus != Status.FalseIf) {
    542541                                                if (_step) {
    543                                                         DisplayIO.removeFromBack();
     542                                                        DisplayController.removeFromBack();
    544543                                                }
    545544                                                return lastItemStatus;
     
    565564
    566565                if (_step) {
    567                         DisplayIO.removeFromBack();
    568                         if (DisplayIO.getCurrentFrame() != current.getParent())
    569                                 DisplayIO.setCurrentFrame(current.getParent(), true);
     566                        DisplayController.removeFromBack();
     567                        if (DisplayController.getCurrentFrame() != current.getParent())
     568                                DisplayController.setCurrentFrame(current.getParent(), true);
    570569                }
    571570
     
    583582                        return;
    584583
    585                 Color oldColor = item.getBackgroundColor();
     584                Colour oldColor = item.getBackgroundColor();
    586585                item.setBackgroundColor(_stepColor);
    587586                item.setHighlightMode(Item.HighlightMode.None);
     587                item.setHighlightColorToDefault();
    588588
    589589                // Make sure we are on the frame with this item
    590590                Frame parent = item.getParentOrCurrentFrame();
    591                 if (!parent.equals(DisplayIO.getCurrentFrame())) {
    592                         DisplayIO.setCurrentFrame(parent, true);
     591                if (!parent.equals(DisplayController.getCurrentFrame())) {
     592                        DisplayController.setCurrentFrame(parent, true);
    593593                }
    594594
    595                 FrameGraphics.Repaint();
     595                DisplayController.requestRefresh(true);
    596596
    597597                int timeRemaining;
     
    604604                        if (_stop) {
    605605                                item.setBackgroundColor(oldColor);
    606                                 item.setHighlightMode(HighlightMode.Normal, _stepColor);
     606                                item.setHighlightModeAndColour(HighlightMode.Normal, _stepColor);
    607607                                throw new Exception("Program terminated");
    608608                        }
     
    11251125                                // attribute without the value in the same item
    11261126                                if (!found && attributeItem != null) {
    1127                                         Point2D.Float endPoint = attributeItem
    1128                                                         .getParagraphEndPosition();
     1127                                        Point endPoint = attributeItem.getParagraphEndPosition();
    11291128
    11301129                                        for (Text text : targetFrame.getTextItems()) {
     
    12171216                                        String stringColor = context.getPrimitives().getVariable(
    12181217                                                        tokens[2]).stringValue();
    1219                                         item.setBackgroundColor((Color) Conversion.Convert(
    1220                                                         Color.class, stringColor));
     1218                                        item.setBackgroundColor((Colour) Conversion.Convert(
     1219                                                        Colour.class, stringColor));
    12211220                                } else if (tokens[0].equals("setitemcolor")) {
    12221221                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     
    12261225                                        String stringColor = context.getPrimitives().getVariable(
    12271226                                                        tokens[2]).stringValue();
    1228                                         item.setColor((Color) Conversion.Convert(Color.class,
     1227                                        item.setColor((Colour) Conversion.Convert(Colour.class,
    12291228                                                        stringColor, item.getColor()));
    12301229                                       
     
    13771376                                        // attribute without the value in the same item
    13781377                                        if (!found && attributeItem != null) {
    1379                                                 Point2D.Float endPoint = attributeItem
    1380                                                                 .getParagraphEndPosition();
     1378                                                Point endPoint = attributeItem.getParagraphEndPosition();
    13811379
    13821380                                                for (Text text : targetFrame.getTextItems()) {
     
    14841482                                        assertVariableType(tokens[1], 1, SPointer.framePrefix);
    14851483
    1486                                         Frame currentFrame = DisplayIO.getCurrentFrame();
     1484                                        Frame currentFrame = DisplayController.getCurrentFrame();
    14871485                                        context.getPointers().setObject(tokens[1], currentFrame);
    14881486
     
    15041502                                                        && tokens.length > 2) {
    15051503                                                Text text = (Text) currentItem;
    1506                                                 int cursorLinePos = text
    1507                                                                 .getLinePosition(FrameMouseActions.getY());
     1504                                                int cursorLinePos = text.getLinePosition(DisplayController.getMouseY());
    15081505                                                context.getPrimitives().setValue(tokens[2],
    15091506                                                                new SInteger(cursorLinePos + 1));
    15101507                                                if (tokens.length > 3) {
    15111508                                                        int cursorCharPos = text.getCharPosition(
    1512                                                                         cursorLinePos, DisplayIO.getMouseX())
     1509                                                                        cursorLinePos, DisplayController.getMouseX())
    15131510                                                                        .getCharIndex();
    15141511                                                        context.getPrimitives().setValue(tokens[3],
     
    15321529                   
    15331530                    //no frame specified by user so use current frame.
    1534                     getFrameName = DisplayIO.getCurrentFrame().getName();
     1531                    getFrameName = DisplayController.getCurrentFrame().getName();
    15351532                    getItem = Misc.getItemContainingData(data, FrameUtils.getFrame(getFrameName));
    15361533                }
     
    15691566                                               
    15701567                                                //no frame specified by user so use current frame.
    1571                                                 getFrameName = DisplayIO.getCurrentFrame().getName();
     1568                                                getFrameName = DisplayController.getCurrentFrame().getName();
    15721569                                                getItem = Misc.getItemAtPosition(x, y, FrameUtils.getFrame(getFrameName));
    15731570                                        }
     
    16621659                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    16631660                                        // assertPrimitiveType(tokens[2], 2);
    1664                                         Color itemColor = ((Item) context.getPointers()
     1661                                        Colour itemColor = ((Item) context.getPointers()
    16651662                                                        .getVariable(tokens[1]).getValue())
    16661663                                                        .getPaintBackgroundColor();
     
    16721669                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    16731670                                        // assertPrimitiveType(tokens[2], 2);
    1674                                         Color itemColor = ((Item) context.getPointers()
     1671                                        Colour itemColor = ((Item) context.getPointers()
    16751672                                                        .getVariable(tokens[1]).getValue()).getPaintColor();
    16761673                                        String color = itemColor.getRed() + " "
     
    18341831                        double delay = context.getPrimitives().getDoubleValue(tokens[1]);
    18351832                        String s = getMessage(tokens, context, code.toString(), " ", 2);
    1836                         DisplayIO.typeStringDirect(delay, s);
     1833                        DisplayController.typeStringDirect(delay, s);
    18371834                } else if (tokens[0].equals("type") || tokens[0].equals("typenospaces")) {
    18381835
     
    18401837                                        .equals("type") ? " " : "", 1);
    18411838
    1842                         DisplayIO.typeStringDirect(0.025, s);
     1839                        DisplayController.typeStringDirect(0.025, s);
    18431840                } else if (tokens[0].equals("runstring")) {
    18441841                        String codeText = getMessage(tokens, context, code.toString(), " ",
     
    18581855                                // Process p = Runtime.getRuntime().exec(new String[]{"date",
    18591856                                // ">", "test.date"});
    1860                                 MessageBay.displayMessage(command, Color.darkGray);
     1857                                MessageBay.displayMessage(command, Colour.DARK_GREY);
    18611858
    18621859                                BufferedReader stdInput = new BufferedReader(
     
    20282025                        Item item = (Item) context.getPointers().getVariable(itemVar)
    20292026                                        .getValue();
    2030                         item
    2031                                         .setPosition(FrameMouseActions.MouseX,
    2032                                                         FrameMouseActions.MouseY);
    2033                         FrameMouseActions.pickup(item);
     2027                        item.setPosition(DisplayController.getMouseX(), DisplayController.getMouseY());
     2028                        StandardGestureActions.pickup(item);
    20342029                } else if (tokens[0].equals("attachstrtocursor")) {
    20352030                        String stringVar = DEFAULT_STRING;
     
    20402035                        }
    20412036                        String s = context.getPrimitives().getStringValue(stringVar);
    2042                         Frame frame = DisplayIO.getCurrentFrame();
     2037                        Frame frame = DisplayController.getCurrentFrame();
    20432038                        Item item = frame.createNewText(s);
    2044                         item
    2045                                         .setPosition(FrameMouseActions.MouseX,
    2046                                                         FrameMouseActions.MouseY);
    2047                         FrameMouseActions.pickup(item);
     2039                        item.setPosition(DisplayController.getMouseX(), DisplayController.getMouseY());
     2040                        StandardGestureActions.pickup(item);
    20482041                } else if (tokens[0].equals("additemtoframe")) {
    20492042                        String itemVar = DEFAULT_ITEM;
     
    24102403                                                }
    24112404                                        }
    2412                                         DisplayIO.setCurrentFrame(frame, false);
     2405                                        DisplayController.setCurrentFrame(frame, false);
    24132406                                        pause(thisFramesPause);
    24142407
     
    26292622                                                tokens[3]) * 1000);
    26302623
    2631                         int initialX = DisplayIO.getMouseX();
    2632                         int initialY = FrameMouseActions.getY();
     2624                        int initialX = DisplayController.getMouseX();
     2625                        int initialY = DisplayController.getMouseY();
    26332626
    26342627                        final int timeInterval = 40;
     
    26432636                                Thread.yield();
    26442637                                Thread.sleep(timeInterval);
    2645                                 DisplayIO.setCursorPosition(newX, newY);
     2638                                DisplayController.setCursorPosition(newX, newY);
    26462639                                // DisplayIO.repaint();
    26472640                        }
    26482641                        // Thread.yield();
    26492642                        Thread.sleep(milliseconds % timeInterval);
    2650                         DisplayIO.setCursorPosition(finalX, finalY);
     2643                        DisplayController.setCursorPosition(finalX, finalY);
    26512644                } else if (tokens[0].equals("glideitemto")) {
    26522645                        assertMinParametreCount(tokens, 3);
     
    26862679
    26872680                                item.setPosition(newX, newY);
    2688                                 FrameGraphics.Repaint();
     2681                                DisplayController.requestRefresh(true);
    26892682                        }
    26902683                        // Thread.yield();
     
    26922685                        item.setPosition(finalX, finalY);
    26932686                        // DisplayIO.setCursorPosition(finalX, finalY);
    2694                         FrameMouseActions.anchor(item);
     2687                        StandardGestureActions.anchor(item);
    26952688                        FreeItems.getInstance().clear();
    2696                         FrameGraphics.Repaint();
     2689                        DisplayController.requestRefresh(true);
    26972690                        // FrameMouseActions.updateCursor();
    26982691                }
     
    27402733                } else if (tokens[0].equals("pressleftbutton")) {
    27412734                        assertExactParametreCount(tokens, 0);
    2742                         DisplayIO.pressMouse(InputEvent.BUTTON1_MASK);
     2735                        //DisplayIO.pressMouse(InputEvent.BUTTON1_MASK); TODO: Reinstate. cts16
    27432736                } else if (tokens[0].equals("pressmiddlebutton")) {
    27442737                        assertExactParametreCount(tokens, 0);
    2745                         DisplayIO.pressMouse(InputEvent.BUTTON2_MASK);
     2738                        //DisplayIO.pressMouse(InputEvent.BUTTON2_MASK); TODO: Reinstate. cts16
    27462739                } else if (tokens[0].equals("pressrightbutton")) {
    27472740                        assertExactParametreCount(tokens, 0);
    2748                         DisplayIO.pressMouse(InputEvent.BUTTON3_MASK);
     2741                        //DisplayIO.pressMouse(InputEvent.BUTTON3_MASK); TODO: Reinstate. cts16
    27492742                } else if (tokens[0].equals("releaseleftbutton")) {
    27502743                        assertExactParametreCount(tokens, 0);
    2751                         DisplayIO.releaseMouse(InputEvent.BUTTON1_MASK);
     2744                        //DisplayIO.releaseMouse(InputEvent.BUTTON1_MASK); TODO: Reinstate. cts16
    27522745                } else if (tokens[0].equals("releasemiddlebutton")) {
    27532746                        assertExactParametreCount(tokens, 0);
    2754                         DisplayIO.releaseMouse(InputEvent.BUTTON2_MASK);
     2747                        //DisplayIO.releaseMouse(InputEvent.BUTTON2_MASK); TODO: Reinstate. cts16
    27552748                } else if (tokens[0].equals("releaserightbutton")) {
    27562749                        assertExactParametreCount(tokens, 0);
    2757                         DisplayIO.releaseMouse(InputEvent.BUTTON3_MASK);
     2750                        //DisplayIO.releaseMouse(InputEvent.BUTTON3_MASK); TODO: Reinstate. cts16
    27582751                } else if (tokens[0].equals("clickleftbutton")) {
    27592752                        assertExactParametreCount(tokens, 0);
    2760                         FrameMouseActions.leftButton();
     2753                        // FrameMouseActions.leftButton(); TODO: Reinstate. cts16
    27612754                        // DisplayIO.clickMouse(InputEvent.BUTTON1_MASK);
    27622755                } else if (tokens[0].equals("clickmiddlebutton")) {
    27632756                        assertExactParametreCount(tokens, 0);
    2764                         FrameMouseActions.middleButton();
     2757                        // FrameMouseActions.middleButton(); TODO: Reinstate. cts16
    27652758                        // DisplayIO.clickMouse(InputEvent.BUTTON2_MASK);
    27662759                } else if (tokens[0].equals("clickrightbutton")) {
    27672760                        assertExactParametreCount(tokens, 0);
    2768                         FrameMouseActions.rightButton();
     2761                        // FrameMouseActions.rightButton(); TODO: Reinstate. cts16
    27692762                        // DisplayIO.clickMouse(InputEvent.BUTTON3_MASK);
    27702763                } else if (tokens[0].equals("repaint")) {
    27712764                        assertExactParametreCount(tokens, 0);
    27722765                        // FrameGraphics.Repaint();
    2773                         FrameGraphics.requestRefresh(true);
     2766                        DisplayController.requestRefresh(true);
    27742767                } else if (tokens[0].equals("add")) {
    27752768                        assertMaxParametreCount(tokens, 3);
     
    29312924                        int x = (int) context.getPrimitives().getIntegerValue(tokens[1]);
    29322925                        int y = (int) context.getPrimitives().getIntegerValue(tokens[2]);
    2933                         DisplayIO.setCursorPosition(x, y);
     2926                        DisplayController.setCursorPosition(x, y);
    29342927                       
    29352928                       
     
    29812974
    29822975                if (source == null)
    2983                         source = DisplayIO.getCurrentFrame();
     2976                        source = DisplayController.getCurrentFrame();
    29842977                int lastParam = tokens.length - 1;
    29852978                String resultVarName = null;
     
    31023095                _programsRunning++;
    31033096                AgentStats.reset();
    3104                 MessageBay.displayMessage("Running SimpleProgram...", Color.BLUE);
     3097                MessageBay.displayMessage("Running SimpleProgram...", Colour.BLUE);
    31053098        }
    31063099
Note: See TracChangeset for help on using the changeset viewer.