Ignore:
Timestamp:
06/27/08 16:44:21 (16 years ago)
Author:
ra33
Message:

Heaps of changes!!!!
Added circles...
Better drawing of lines etc etc

File:
1 edited

Legend:

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

    r107 r108  
    44import java.awt.Point;
    55import java.awt.event.InputEvent;
     6import java.awt.geom.Point2D;
    67import java.io.BufferedReader;
    78import java.io.InputStreamReader;
     
    188189        private String _frameset;
    189190
    190         private boolean _verbose;
     191        private static boolean _verbose = false;
    191192
    192193        public Simple(String frameset, boolean verbose) {
     
    216217                        if (nextFrame == null)
    217218                                continue;
    218                         Item frameTitle = nextFrame.getTitleItem();
     219                        Text frameTitle = nextFrame.getTitleItem();
    219220                        if (frameTitle == null)
    220221                                continue;
    221222                        // Run the frames with the RunFrame action on the title
    222                         Item title = frameTitle.copy();
     223                        Text title = frameTitle.copy();
    223224                        List<String> actions = title.getAction();
    224225                        if (actions == null || title.isAnnotation())
     
    235236                                        _KeyStrokes.clear();
    236237                                        _programsRunning++;
    237                                         RunFrameAndReportError(title, new Context());
     238                                        Context context = new Context();
     239                                        RunFrameAndReportError(title, context);
    238240                                        _programsRunning--;
    239241                                        // if the throws exception annotation is on the frame then
     
    306308        }
    307309
    308         private static void RunFrame(Item current, boolean acceptKeyboardInput,
     310        private static void RunFrame(Text current, boolean acceptKeyboardInput,
    309311                        boolean step, int pause, Color color) {
    310312                try {
     
    321323                        // an item without a link signals to run the current frame
    322324                        if (current.getLink() == null) {
     325                                //Make a copy but hide it
    323326                                current = current.copy();
    324327                                current.setLink(DisplayIO.getCurrentFrame().getName());
     
    334337        }
    335338
    336         public static void RunFrame(Item current, boolean acceptKeyboardInput) {
     339        public static void RunFrame(Text current, boolean acceptKeyboardInput) {
    337340                RunFrame(current, acceptKeyboardInput, false, 0, null);
    338341        }
    339342
    340         public static void RunFrame(Item current) {
     343        public static void RunFrame(Text current) {
    341344                RunFrame(current, false);
    342345        }
     
    348351         * @param pause
    349352         */
    350         public static void DebugFrame(Item current, float pause, Color color) {
     353        public static void DebugFrame(Text current, float pause, Color color) {
     354                if(isProgramRunning()){
     355                        stop();
     356                }
    351357                RunFrame(current, false, true, Math.round(pause * 1000), color);
    352358        }
     
    359365         *            the time to pause between
    360366         */
    361         public static void DebugFrame(Item current, float pause) {
     367        public static void DebugFrame(Text current, float pause) {
    362368                DebugFrame(current, pause, null);
    363369        }
    364370
    365         public static void DebugFrame(Item current) {
     371        public static void DebugFrame(Text current) {
    366372                DebugFrame(current, -1.0F, null);
    367373        }
     
    391397                Frame child = FrameIO.LoadFrame(current.getAbsoluteLink());
    392398
     399                // Create frame variables for each linked annotation item on the frame
     400                // which has a single word of text corresponding to the variable name
     401                for (Text text : child.getAnnotationItems()) {
     402                        String link = text.getAbsoluteLink();
     403                        if (link == null)
     404                                continue;
     405                        Frame frame = FrameIO.LoadFrame(link);
     406                        if (frame == null)
     407                                continue;
     408                        // Now save the frame as a variable
     409                        String varName = text.getText().substring(1).trim();
     410                        if (varName.indexOf(' ') > 0)
     411                                continue;
     412                        context.getPointers().setObject(SPointer.framePrefix + varName,
     413                                        frame);
     414                        context.getPrimitives().add(SString.prefix + varName,
     415                                        new SString(frame.getName()));
     416                }
     417
    393418                if (_step) {
    394419                        if (child != DisplayIO.getCurrentFrame()) {
     
    419444                                Color oldColor = item.getBackgroundColor();
    420445                                if (_step) {
    421                                         if (item.getLink() != null) {
    422                                                 pause(item);
    423                                                 item.setSelectedMode(Item.SelectedMode.Normal,
    424                                                                 _stepColor);
    425                                         } else {
    426                                                 item.setBackgroundColor(_stepColor);
    427                                         }
    428                                         FrameGraphics.Repaint();
     446                                        pause(item);
    429447                                }
    430448                                lastItemStatus = RunItem(item, context, lastItemStatus);
     
    432450                                        if (item.getLink() == null) {
    433451                                                item.setBackgroundColor(oldColor);
    434                                                 pause(item);
    435452                                        } else {
    436453                                                item.setSelectedMode(Item.SelectedMode.None);
     
    464481                if (_step) {
    465482                        DisplayIO.removeFromBack();
    466                         DisplayIO.setCurrentFrame(current.getParent());
     483                        if(DisplayIO.getCurrentFrame() != current.getParent())
     484                                DisplayIO.setCurrentFrame(current.getParent());
    467485                }
    468486
     
    776794                                assertExactParametreCount(tokens, 3);
    777795
    778                                 Map map = (Map) context.getPointers().getVariable(tokens[1])
     796                                Map<String,String> map = (Map<String,String>) context.getPointers().getVariable(tokens[1])
    779797                                                .getValue();
    780798                                String attribute = context.getPrimitives().getStringValue(
     
    812830                                // attribute without the value in the same item
    813831                                if (!found && attributeItem != null) {
    814                                         Point endPoint = attributeItem.getEndParagraphPosition();
     832                                        Point2D.Float endPoint = attributeItem
     833                                                        .getEndParagraphPosition();
    815834
    816835                                        for (Text text : targetFrame.getBodyTextItems(true)) {
     
    10501069                                        // attribute without the value in the same item
    10511070                                        if (!found && attributeItem != null) {
    1052                                                 Point endPoint = attributeItem
     1071                                                Point2D.Float endPoint = attributeItem
    10531072                                                                .getEndParagraphPosition();
    10541073
     
    11121131                                                        .getValue();
    11131132                                        t.setText(log);
     1133                                } else if (tokens[0].equals("getframeitemcount")) {
     1134                                        String frameVar = DEFAULT_FRAME;
     1135                                        String countVar = DEFAULT_INTEGER;
     1136                                        if (tokens.length > 1) {
     1137                                                assertExactParametreCount(tokens, 2);
     1138                                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     1139                                                frameVar = tokens[1];
     1140                                                countVar = tokens[2];
     1141                                        }
     1142                                        Frame frame = (Frame) context.getPointers().getVariable(
     1143                                                        frameVar).getValue();
     1144                                        Integer count = frame.getItems(true).size();
     1145                                        context.getPrimitives().setValue(countVar,
     1146                                                        new SInteger(count));
    11141147                                }
    11151148                        } else if (tokens[0].equals("getassociation")) {
     
    11891222                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    11901223                                        // assertPrimitiveType(tokens[2], 2);
    1191                                         Integer size = ((Item) context.getPointers().getVariable(
    1192                                                         tokens[1]).getValue()).getSize();
     1224                                        Integer size = (int) ((Item) context.getPointers()
     1225                                                        .getVariable(tokens[1]).getValue()).getSize();
    11931226                                        context.getPrimitives().setValue(tokens[2],
    11941227                                                        new SInteger(size));
     
    14021435                        String codeText = getMessage(tokens, context, code.toString(), " ",
    14031436                                        1);
    1404                         Text dynamicCode = new Text(1, codeText);
     1437                        Text dynamicCode = new Text(codeText);
    14051438                        RunItem(dynamicCode, context, Status.OK);
    14061439                } else if (tokens[0].equals("runoscommand")) {
     
    16821715                        try {
    16831716                                success = FrameIO.DeleteFrame(frame);
    1684                                 if (!success)
     1717                                if (!success && _verbose)
    16851718                                        FrameGraphics.WarningMessage(errorMessage);
    16861719                        } catch (Exception e) {
    16871720                                // If an exception is thrown then success is false
    1688                                 FrameGraphics
    1689                                                 .WarningMessage(errorMessage
    1690                                                                 + (e.getMessage() != null ? ". "
    1691                                                                                 + e.getMessage() : ""));
     1721                                if (_verbose) {
     1722                                        FrameGraphics.WarningMessage(errorMessage
     1723                                                        + (e.getMessage() != null ? ". " + e.getMessage()
     1724                                                                        : ""));
     1725                                }
    16921726                        }
    16931727                        if (tokens.length > 2) {
     
    17001734                                        tokens[1]);
    17011735                        boolean success = FrameIO.DeleteFrameset(framesetName);
    1702                         if (!success)
     1736                        if (!success && _verbose) {
    17031737                                FrameGraphics.WarningMessage("Error deleting " + framesetName);
     1738                        }
    17041739                        if (tokens.length > 2) {
    17051740                                context.getPrimitives().setValue(tokens[2],
     
    17221757                        boolean success = FrameIO.CopyFrameset(framesetToCopy,
    17231758                                        copiedFrameset);
    1724                         if (!success)
     1759                        if (!success && _verbose)
    17251760                                FrameGraphics.WarningMessage("Error copying " + framesetToCopy);
    17261761                        if (tokens.length > 3) {
     
    17461781                        context.getPointers().setObject(tokens[2], freshCopy);
    17471782                        String fileContents = FrameIO.ForceSaveFrame(freshCopy);
     1783                        FrameIO.ResumeCache();
     1784                        // Need to add the new copy to the cache in case it is edited by
     1785                        // other simple statements
     1786                        FrameIO.addToCache(freshCopy);
    17481787                        boolean success = fileContents != null;
    1749                         if (!success)
     1788                        if (!success && _verbose)
    17501789                                FrameGraphics.WarningMessage("Error copying "
    17511790                                                + frameToCopy.getName());
    1752                         FrameIO.ResumeCache();
    17531791                        if (tokens.length > 4) {
    17541792                                context.getPrimitives().setValue(tokens[4],
     
    20142052                                count = countCharsInString(((Text) item).getText(), pattern);
    20152053                        context.getPrimitives().setValue(tokens[3], new SInteger(count));
     2054                } else if (tokens[0].equals("clearframe")) {
     2055                        String frameVar = DEFAULT_FRAME;
     2056                        if (tokens.length > 1) {
     2057                                assertMinParametreCount(tokens, 1);
     2058                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     2059                                frameVar = tokens[1];
     2060                        }
     2061                        boolean success = true;
     2062                        try {
     2063                                Frame frameToClear = (Frame) context.getPointers().getVariable(
     2064                                                frameVar).getValue();
     2065                                frameToClear.clear(false);
     2066                                assert (frameToClear.getItems().size() <= 1);
     2067                        } catch (Exception e) {
     2068                                success = false;
     2069                        }
     2070                        if (tokens.length > 2) {
     2071                                assertExactParametreCount(tokens, 2);
     2072                                context.getPrimitives().setValue(tokens[2],
     2073                                                new SBoolean(success));
     2074                        }
    20162075                } else if (tokens[0].equals("parseframename")) {
    20172076                        assertExactParametreCount(tokens, 4);
     
    20262085                        } catch (Exception e) {
    20272086                                success = false;
    2028                                 FrameGraphics.WarningMessage("Error parsing " + frameName);
     2087                                if (_verbose)
     2088                                        FrameGraphics.WarningMessage("Error parsing " + frameName);
    20292089                        }
    20302090                        // assertPrimitiveType(tokens[2], 2);
     
    24912551                FrameGraphics.DisplayMessage("Running SimpleProgram...", Color.BLUE);
    24922552        }
     2553
     2554        public static boolean isVerbose() {
     2555                return _verbose;
     2556        }
    24932557}
Note: See TracChangeset for help on using the changeset viewer.