Ignore:
Timestamp:
05/30/08 10:14:43 (16 years ago)
Author:
ra33
Message:

Added some more unit tests
Did a bunch of refactoring
AND added a few new features... @b @v were the most significant

Location:
trunk/src/org/expeditee/actions
Files:
5 edited

Legend:

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

    r72 r80  
    77import java.net.URL;
    88import java.util.ArrayList;
     9import java.util.Collection;
    910import java.util.Enumeration;
    1011import java.util.HashMap;
     
    2627
    2728/**
    28  * The Action class is used to launch KMS Actions as well as launching JAGs.
     29 * The Action class is used to launch Actions and Agents.
    2930 *
    3031 * This class checks all class files in the same directory, and reads in and
     
    3233 * the lowercase method names can be mapped to the correctly capatilized method
    3334 * names (to provide case-insensitivity)
     35 *
     36 * When adding an action to a class in the actions folder the following must be
     37 * considered:
     38 * <li> If the first parameter is of type Frame or Item they will be called with
     39 * the current frame and the item used to execute the action.</li>
     40 * <li> If the second item is also of type Frame or Item it will be set to the
     41 * current frame or item.</li>
     42 * <li> If there are multiple overloads for the same method they should be
     43 * declared in order of the methods with the most parameteres to least
     44 * parameters.</li>
    3445 */
    3546public class Actions {
     
    5970                // Get a File object for the package
    6071                File directory = null;
    61                 String path = pckgname.replace('.', '/');
     72                String path = pckgname.replace('.', File.separatorChar);
    6273                try {
    6374                        ClassLoader cld = Thread.currentThread().getContextClassLoader();
     
    6576                                throw new ClassNotFoundException("Can't get class loader.");
    6677                        }
    67                         URL resource = cld.getResource(path);
     78                        URL resource = null;
     79                        try {
     80                                Enumeration<URL> resources = cld.getResources(path);
     81                                while (resources.hasMoreElements()) {
     82                                        URL url = resources.nextElement();
     83                                        // Ingore the classes in the test folder when we are running
     84                                        // the program from Eclipse
     85                                        // This doesnt apply when running directly from the jar
     86                                        // because the test classes are not compiled into the jar.
     87                                        if (!url.toString().toLowerCase().contains("test")) {
     88                                                resource = url;
     89                                                break;
     90                                        }
     91                                }
     92                        } catch (Exception e) {
     93
     94                        }
    6895                        if (resource == null) {
    6996                                throw new ClassNotFoundException("No resource for " + path);
     
    137164         * Clears out the Action and JAG Hashtables and refills them. Normally this
    138165         * is only called once when the system starts.
    139          */
    140         public static void Init() {
     166         * @return a warning message if there were any problems loading agents or actions.
     167         */
     168        public static Collection<String> Init() {
     169                Collection<String> warnings = new LinkedList<String>();
    141170                Class[] classes;
     171               
    142172                try {
    143173                        classes = getClasses(AGENTS_PACKAGE);
     
    149179                        }
    150180                } catch (Exception e) {
    151                         System.out
    152                                         .println("You must have Java 1.5 or higher to run Expeditee");
    153                         System.out.println(e.getMessage());
     181                        warnings.add("You must have Java 1.5 or higher to run Expeditee");
     182                        warnings.add(e.getMessage());
    154183                }
    155184                try {
     
    158187                        for (int i = 0; i < classes.length; i++) {
    159188                                String name = classes[i].getSimpleName();
     189                                // Ignore the test classes
     190                                if (name.toLowerCase().contains("test"))
     191                                        continue;
    160192                                // read in all the methods from the class
    161193                                try {
    162                                         // System.out.println(name);
     194                                        // System.out.println(name)
    163195                                        LoadMethods(Class.forName(ACTIONS_PACKAGE + name));
    164196                                } catch (ClassNotFoundException e) {
     
    168200                        }
    169201                } catch (Exception e) {
    170                         System.out.println(e.getMessage());
    171                 }
     202                        warnings.add(e.getMessage());
     203                }
     204                return warnings;
    172205        }
    173206
     
    186219                        // only allow methods with the right modifiers
    187220                        if (MethodCheck(m)) {
    188                                 if (!(_Actions.containsKey(m.getName().toLowerCase())))
    189                                         _Actions.put(m.getName().toLowerCase(), m);
     221                                String lowercaseName = m.getName().toLowerCase();
     222                                if (!(_Actions.containsKey(lowercaseName)))
     223                                        _Actions.put(lowercaseName, m);
    190224                                else {
    191225                                        int i = 0;
    192                                         while (_Actions.containsKey(m.getName().toLowerCase() + i))
     226                                        while (_Actions.containsKey(lowercaseName + i))
    193227                                                i++;
    194228
    195                                         _Actions.put(m.getName().toLowerCase() + i, m);
     229                                        _Actions.put(lowercaseName + i, m);
    196230                                }
    197231
     
    259293                        mname = mname.substring(1);
    260294
    261                 mname = mname.trim().toLowerCase();
    262 
     295                mname = mname.trim();
     296                String lowercaseName = mname.toLowerCase();
    263297                // check for protection on frame
    264298                if (ItemUtils.ContainsTag(source.getItems(), "@No" + mname)) {
     
    269303
    270304                // retrieve methods that match the name
    271                 Method toRun = _Actions.get(mname);
     305                Method toRun = _Actions.get(lowercaseName);
    272306
    273307                // if this is not the name of a method, it may be the name of an agent
     
    287321                possibles.add(toRun);
    288322                int i = 0;
    289                 while (_Actions.containsKey(mname + i)) {
    290                         possibles.add(_Actions.get(mname + i));
     323                while (_Actions.containsKey(lowercaseName + i)) {
     324                        possibles.add(_Actions.get(lowercaseName + i));
    291325                        i++;
    292326                }
     
    301335                                Object[] parameters = CreateObjects(possible, source, launcher,
    302336                                                command);
     337                                // Check that there are the same amount of params
     338                                if (parameters == null) {
     339                                        continue;
     340                                }
    303341
    304342                                possible.invoke(null, parameters);
     
    322360         */
    323361        private static void LaunchAgent(String name, String parameters, Frame source) {
     362                // Use the correct case version for printing error messages
     363                String nameWithCorrectCase = name;
     364                name = name.toLowerCase();
    324365                // save the current frame (if necesssary)
    325366                FrameUtils.LeavingFrame(source);
     
    362403                        // if there is no constructor, return
    363404                        if (con == null) {
    364                                 FrameGraphics.DisplayMessage("Invalid parametres for agent.");
     405                                FrameGraphics.DisplayMessage("Invalid parametres for agent: "
     406                                                + nameWithCorrectCase);
    365407                                // System.out.println("Constructor not found...");
    366408                                return;
     
    375417                        // check for errors during initialisation
    376418                        if (!_Agent.initialise(source)) {
    377                                 FrameGraphics.ErrorMessage("Error initialising agent: " + name);
     419                                FrameGraphics.ErrorMessage("Error initialising agent: "
     420                                                + nameWithCorrectCase);
    378421                                return;
    379422                        }
     
    390433
    391434                } catch (ClassNotFoundException cnf) {
    392                         FrameGraphics.ErrorMessage("Error: '" + name
    393                                         + "' is not an action statement or Agent.");
     435                        FrameGraphics.ErrorMessage("Error: '" + nameWithCorrectCase
     436                                        + "' is not an action or agent.");
    394437                } catch (Exception e) {
    395                         FrameGraphics.ErrorMessage("Error creating Agent: '" + name + "'");
     438                        FrameGraphics.ErrorMessage("Error creating Agent: '"
     439                                        + nameWithCorrectCase + "'");
    396440                        System.out.println("Agent set to Null.");
    397441                        _Agent = null;
     
    421465         */
    422466        public static void stopAgent() {
    423                 if (_Agent != null) {
     467                if (_Agent != null && _Agent.isRunning()) {
    424468                        FrameGraphics.DisplayMessage("Stopping Agent...");
    425469                        _Agent.stop();
    426 
    427                         // while (_Agent.isRunning())
    428                         // ;
    429                         // FrameGraphics.DisplayMessage("Agent Stopped.");
    430470                }
    431471        }
     
    489529                                param = values.trim();
    490530                                // check if its a string
    491                                 if (param.length() > 0 && param.charAt(0) == '"'){
     531                                if (param.length() > 0 && param.charAt(0) == '"') {
    492532                                        int endOfString = param.indexOf('"', 1);
    493                                         if (endOfString > 0){
    494                                                 param = param.substring(0,endOfString);
     533                                        if (endOfString > 0) {
     534                                                param = param.substring(0, endOfString);
    495535                                        }
    496536                                }
     
    501541                        // convert the value to an object
    502542                        Object o = Conversion.Convert(paramTypes[ind], param);
     543                        if (o == null)
     544                                return null;
    503545                        objects[ind] = o;
    504546                }
     
    530572                if (params.charAt(0) == '"') {
    531573                        int endOfString = params.indexOf('"', 1);
    532                         if (endOfString > 0){
     574                        if (endOfString > 0) {
    533575                                if (endOfString > params.length())
    534576                                        return "";
  • trunk/src/org/expeditee/actions/IDE.java

    r22 r80  
    1313        public static void CompileClass() {
    1414                Frame source = DisplayIO.getCurrentFrame();
    15                 String title = source.getTitle().getTextNoList();
     15                String title = source.getTitleItem().getText();
    1616                String[] tokens = title.split(" ");
    1717                String className = tokens[tokens.length - 1];
     
    3333
    3434        public static String getClassName(Frame source) {
    35                 return source.getTitle().getTextNoList().trim();
     35                return source.getTitleItem().getText().trim();
    3636                //String title = source.getTitle().getTextNoList();
    3737                //String[] tokens = title.split(" ");
  • trunk/src/org/expeditee/actions/Misc.java

    r78 r80  
    9898        public static void RunCurrentItem(Item current) {
    9999                if (current instanceof Text) {
    100                         List<String> actions = ((Text) current).getText();
     100                        List<String> actions = ((Text) current).getTextList();
    101101
    102102                        for (String action : actions) {
     
    117117                Frame toDelete = DisplayIO.getCurrentFrame();
    118118                DisplayIO.Back();
    119                 String deletedFrame = toDelete.getFrameName();
     119                String deletedFrame = toDelete.getName();
    120120                String deletedFrameNameLowercase = deletedFrame.toLowerCase();
    121121                try {
     
    123123                        if (!del) {
    124124                                FrameGraphics.ErrorMessage("Error trying to delete "
    125                                                 + toDelete.getFrameName());
     125                                                + toDelete.getName());
    126126                        } else {
    127127                                Frame current = DisplayIO.getCurrentFrame();
     
    316316         */
    317317        public static void JpegFrame(String framename) {
    318                 ImageFrame(framename, "JPG");
     318                ImageFrame(framename, "JPEG");
    319319        }
    320320
    321321        /**
    322322         * Saves the current frame as a JPEG image. This is the same as calling
    323          * JpegFrame(currentFrame.getFrameName())
     323         * JpegFrame(currentFrame.getName())
    324324         */
    325325        public static void JpegFrame() {
    326                 ImageFrame(DisplayIO.getCurrentFrame().getFrameName(), "JPG");
     326                ImageFrame(DisplayIO.getCurrentFrame().getName(), "JPEG");
     327        }
     328
     329        public static void JPGFrame() {
     330                JpegFrame();
    327331        }
    328332
     
    339343        /**
    340344         * Saves the current frame as a PNG image. This is the same as calling
    341          * PNGFrame(currentFrame.getFrameName())
     345         * PNGFrame(currentFrame.getName())
    342346         */
    343347        public static void PNGFrame() {
    344                 ImageFrame(DisplayIO.getCurrentFrame().getFrameName(), "PNG");
     348                ImageFrame(DisplayIO.getCurrentFrame().getName(), "PNG");
     349        }
     350
     351        public static String SaveImage(BufferedImage screen, String format, String directory, String fileName){
     352                // Check if we need to append the suffix
     353                if (fileName.indexOf('.') < 0)
     354                        fileName += "." + format.toLowerCase();         
     355
     356                try {
     357                        // set up the file for output
     358                        String fullFileName = directory + fileName;
     359                        File out = new File(fullFileName);
     360                        if (!out.getParentFile().exists())
     361                                out.mkdirs();
     362
     363                        // If the image is successfully written out return the fileName
     364                        if (ImageIO.write(screen, format, out))
     365                                return fileName;
     366
     367                } catch (Exception e) {
     368                        e.printStackTrace();
     369                }
     370                return null;
     371        }
     372       
     373        public static String ImageFrame(Frame frame, String format, String directory) {
     374                assert (frame != null);
     375               
     376                FrameGraphics.UpdateBuffer(frame, false);
     377
     378                BufferedImage screen = null;
     379                Image frameBuffer = frame.getBuffer();
     380                if (frame.getBuffer() instanceof BufferedImage) {
     381                        screen = (BufferedImage) frameBuffer;
     382                } else if (frameBuffer instanceof VolatileImage) {
     383                        screen = ((VolatileImage) frameBuffer).getSnapshot();
     384                } else {
     385                        assert (false);
     386                }
     387                return SaveImage(screen, format, directory, frame.getExportFileName());
    345388        }
    346389
     
    355398        public static void ImageFrame(String framename, String format) {
    356399                Frame loaded = FrameIO.LoadFrame(framename);
    357                 String fileName = loaded.getExportFileName();
    358400
    359401                // if the frame was loaded successfully
    360402                if (loaded != null) {
    361                         // check if the buffer needs to be redrawn
    362                         // if (loaded.getBuffer() == null)
    363                         FrameGraphics.UpdateBuffer(loaded, false);
    364                        
    365                         BufferedImage screen = null;
    366                         Image frameBuffer = loaded.getBuffer();
    367                         if (loaded.getBuffer() instanceof BufferedImage){
    368                                 screen = (BufferedImage)frameBuffer;
    369                         }else if (frameBuffer instanceof VolatileImage){
    370                                 screen = ((VolatileImage)frameBuffer).getSnapshot();
    371                         }else{
    372                                 assert(false);
    373                         }
    374 
    375                         try {
    376                                 // set up the file for output
    377                                 File out = new File(FrameIO.EXPORTS_DIR + fileName + "."
    378                                                 + format.toLowerCase());
    379                                 if (!out.getParentFile().exists())
    380                                         out.mkdirs();
    381 
    382                                 ImageIO.write(screen, format, out);
     403                        String path = FrameIO.IMAGES_PATH;
     404                        String frameName = ImageFrame(loaded, format, path);
     405                        if (frameName != null)
    383406                                FrameGraphics.DisplayMessage("Frame successfully saved to "
    384                                                 + FrameIO.EXPORTS_DIR + out.getName());
    385                         } catch (IOException e) {
    386                                 FrameGraphics.ErrorMessage(e.getMessage());
    387                         }
     407                                                + path + frameName);
     408                        else
     409                                FrameGraphics.ErrorMessage("Could not find image writer for "
     410                                                + format + " format");
    388411                        // if the frame was not loaded successfully, alert the user
    389412                } else
     
    455478                                timeKeeper.restart();
    456479                                for (int j = 0; j < repsPerTest; j++) {
    457                                         methodA.invoke((Object) null, new Object[]{});
     480                                        methodA.invoke((Object) null, new Object[] {});
    458481                                }
    459482                                timeA += timeKeeper.getElapsedMillis();
     
    461484                                // Test methodB
    462485                                for (int j = 0; j < repsPerTest; j++) {
    463                                         methodB.invoke((Object) null, new Object[]{});
     486                                        methodB.invoke((Object) null, new Object[] {});
    464487                                }
    465488                                timeB += timeKeeper.getElapsedMillis();
     
    530553                // swap the items links
    531554                item.setActions(current.getAction());
    532                 item.setLink(childFrame.getFrameName());
    533                 current.setLink(parentFrame.getFrameName());
     555                item.setLink(childFrame.getName());
     556                current.setLink(parentFrame.getName());
    534557                // current.setLink(null);
    535558                current.setActions(null);
     
    564587
    565588                for (Item i : body)
    566                         if (i != child.getTitle() && !i.isAnnotation()) {
     589                        if (i != child.getTitleItem() && !i.isAnnotation()) {
    567590                                item = i;
    568591                                break;
  • trunk/src/org/expeditee/actions/NavigationActions.java

    r70 r80  
    2121                _LastItemUsed = i;
    2222                if (i.getParent() != null) {
    23                         _Parent = i.getParent().getFrameName();
     23                        _Parent = i.getParent().getName();
    2424                }
    2525        }
     
    196196
    197197                // ByMike: If the 'Next' child is being sought for the 1st time...
    198                 String sourceName = source.getFrameName().toLowerCase();
     198                String sourceName = source.getName().toLowerCase();
    199199
    200200                // ByMike: Find the first occurence of a ParentItem linked to the source
     
    212212                                        && !items.get(i).isAnnotation()
    213213                                        && !items.get(i).getAbsoluteLink().equalsIgnoreCase(
    214                                                         source.getFrameName())) {
     214                                                        source.getName())) {
    215215                                _LastItemUsed = items.get(i);
    216216                                FrameUtils.DisplayFrame(_LastItemUsed.getAbsoluteLink(), false);
  • trunk/src/org/expeditee/actions/Simple.java

    r78 r80  
    88import java.util.ArrayList;
    99import java.util.Collection;
     10import java.util.HashMap;
    1011import java.util.LinkedList;
    1112import java.util.List;
     13import java.util.Map;
    1214import java.util.Random;
    1315
     
    6365        private static final String DEFAULT_FRAME = "$fp.";
    6466
     67        private static final String DEFAULT_ASSOCIATION = "$ap.";
     68
    6569        private static final String EXIT_TEXT = "exitall";
    6670
     
    121125                List<String> actions = new ArrayList<String>();
    122126                actions.add(RUN_FRAME_ACTION);
    123                 newSimpleTest.getTitle().setActions(actions);
     127                newSimpleTest.getTitleItem().setActions(actions);
    124128                FrameUtils.DisplayFrame(newSimpleTest, true);
    125129                FrameGraphics.DisplayMessage("New test created");
     
    131135                        next = FrameIO.LoadNext(next);
    132136                } while (next != null
    133                                 && (next.getTitle() == null || !RUN_FRAME_ACTION
    134                                                 .equalsIgnoreCase(next.getTitle().getFirstAction())));
     137                                && (next.getTitleItem() == null || !RUN_FRAME_ACTION
     138                                                .equalsIgnoreCase(next.getTitleItem().getFirstAction())));
    135139                FrameUtils.DisplayFrame(next, true);
    136140        }
     
    141145                        prev = FrameIO.LoadPrevious(prev);
    142146                } while (prev != null
    143                                 && (prev.getTitle() == null || !RUN_FRAME_ACTION
    144                                                 .equalsIgnoreCase(prev.getTitle().getFirstAction())));
     147                                && (prev.getTitleItem() == null || !RUN_FRAME_ACTION
     148                                                .equalsIgnoreCase(prev.getTitleItem().getFirstAction())));
    145149
    146150                FrameUtils.DisplayFrame(prev, true);
     
    153157                        // check if its a test frame
    154158                        if (next != null
    155                                         && next.getTitle() != null
    156                                         && RUN_FRAME_ACTION.equalsIgnoreCase(next.getTitle()
     159                                        && next.getTitleItem() != null
     160                                        && RUN_FRAME_ACTION.equalsIgnoreCase(next.getTitleItem()
    157161                                                        .getFirstAction())) {
    158162                                lastTest = next;
     
    191195                        if (nextFrame == null)
    192196                                continue;
    193                         Item frameTitle = nextFrame.getTitle();
     197                        Item frameTitle = nextFrame.getTitleItem();
    194198                        if (frameTitle == null)
    195199                                continue;
     
    248252                        if (current.getLink() == null) {
    249253                                current = current.copy();
    250                                 current.setLink(DisplayIO.getCurrentFrame().getFrameName());
     254                                current.setLink(DisplayIO.getCurrentFrame().getName());
    251255                        }
    252256
     
    264268
    265269        private static void FlagError(Item item) {
    266                 FrameUtils.DisplayFrame(item.getParent().getFrameName(), true);
     270                FrameUtils.DisplayFrame(item.getParent().getName(), true);
    267271                item.setSelectedMode(SelectedMode.Normal);
    268272                item.setSelectionColor(Color.CYAN);
     
    342346                Frame frame = i.getParent();
    343347
    344                 if (i == frame.getTitle() || i == frame.getFrameNameItem()
     348                if (i == frame.getTitleItem() || i == frame.getNameItem()
    345349                                || i.isAnnotation()) {
    346350                        return false;
     
    357361         */
    358362        private static String[] parseStatement(Text code) throws Exception {
    359                 String statement = code.getTextNoList();
     363                String statement = code.getText();
    360364                ArrayList<String> tokens = new ArrayList<String>();
    361365
     
    420424                // Add call to the start of the title if it doesnt exist
    421425                // This makes the call and signature tokens counts match
    422                 String procedureTitle = procedure.getTitle().getFirstLine();
     426                String procedureTitle = procedure.getTitleItem().getFirstLine();
    423427                if (!procedureTitle.toLowerCase().startsWith("call "))
    424428                        procedureTitle = "call " + procedureTitle;
     
    588592                                        throw new RuntimeException(e.getMessage());
    589593                                }
     594                        } else if (tokens[0].equals("setassociation")) {
     595                                assertMinParametreCount(tokens, 3);
     596
     597                                Map map = (Map) context.getPointers().getVariable(tokens[1])
     598                                                .getValue();
     599                                String attribute = context.getPrimitives().getStringValue(
     600                                                tokens[2]);
     601                                String value = context.getPrimitives()
     602                                                .getStringValue(tokens[3]);
     603                                map.put(attribute, value);
     604                                return Status.OK;
    590605                        } else if (tokens[0].equals("setframevalue")) {
    591606                                assertMinParametreCount(tokens, 3);
     
    605620                                // Begin the search
    606621                                for (Text text : targetFrame.getBodyTextItems(true)) {
    607                                         String s = text.getTextNoList().toLowerCase();
     622                                        String s = text.getText().toLowerCase();
    608623
    609624                                        if (s.startsWith(targetAttribute)) {
     
    697712                                        Item item = (Item) context.getPointers().getVariable(
    698713                                                        tokens[1]).getValue();
    699                                         item.setAction(context.getPrimitives().getVariable(tokens[2])
    700                                                         .stringValue());
     714                                        item.setAction(context.getPrimitives().getVariable(
     715                                                        tokens[2]).stringValue());
    701716                                } else if (tokens[0].equals("setitemfillcolor")) {
    702717                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     
    757772                                Text item = (Text) context.getPointers().getVariable(tokens[1])
    758773                                                .getValue();
    759                                 List<String> itemText = item.getText();
     774                                List<String> itemText = item.getTextList();
    760775
    761776                                while (row >= itemText.size()) {
     
    858873                                        // Begin the search
    859874                                        for (Text text : targetFrame.getBodyTextItems(true)) {
    860                                                 String s = text.getTextNoList().toLowerCase();
     875                                                String s = text.getText().toLowerCase();
    861876                                                if (s.startsWith(targetAttribute)) {
    862877                                                        attributeItem = text;
    863                                                         value = AttributeUtils.stripValue(s);
     878                                                        value = AttributeUtils.getValue(s);
    864879                                                        if (value.length() > 0) {
    865880                                                                found = true;
     
    880895                                                                found = true;
    881896                                                                valueItem = text;
    882                                                                 value = text.getTextNoList();
     897                                                                value = text.getText();
    883898                                                                break;
    884899                                                        }
     
    915930                                                        frameVar).getValue();
    916931                                        context.getPrimitives().setValue(frameNameVar,
    917                                                         frame.getFrameName());
     932                                                        frame.getName());
    918933                                        return Status.OK;
    919934                                } else if (tokens[0].startsWith("getframefilepath")) {
     
    932947                                        String log = SessionStats.getFrameEventList();
    933948                                        Text t;
    934                                         // try {
     949
    935950                                        t = (Text) context.getPointers().getVariable(tokens[1])
    936951                                                        .getValue();
    937952                                        t.setText(log);
    938                                         // } catch (Exception e) {
    939                                         // t = new Text(-1, log);
    940                                         // context.getPointers().setObject(tokens[1], t);
    941                                         // }
    942953
    943954                                        return Status.OK;
    944955                                }
     956                        } else if (tokens[0].equals("getassociation")) {
     957                                assertMinParametreCount(tokens, 3);
     958                                Map map = (Map) context.getPointers().getVariable(tokens[1])
     959                                                .getValue();
     960                                String attribute = context.getPrimitives().getStringValue(
     961                                                tokens[2]);
     962                                String newValue = map.get(attribute).toString();
     963                                context.getPrimitives().setValue(tokens[3], newValue);
     964                                return Status.OK;
    945965                        } else if (tokens[0].startsWith("getcurrent")) {
    946966                                if (tokens[0].equals("getcurrentframe")) {
     
    954974                                        if (tokens.length > 2) {
    955975                                                context.getPrimitives().setValue(tokens[2],
    956                                                                 new SString(currentFrame.getFrameName()));
     976                                                                new SString(currentFrame.getName()));
    957977                                        }
    958978                                        return Status.OK;
     
    10171037                                        context.getPrimitives().setValue(tokens[2],
    10181038                                                        new SString(action));
    1019                                 }else if (tokens[0].equals("getitemfillcolor")) {
     1039                                } else if (tokens[0].equals("getitemfillcolor")) {
    10201040                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    10211041                                        // assertPrimitiveType(tokens[2], 2);
     
    10431063                                                        tokens[2],
    10441064                                                        new SString((item instanceof Text) ? ((Text) item)
    1045                                                                         .getTextNoList() : ""));
     1065                                                                        .getText() : ""));
    10461066                                } else
    10471067                                        throw new Exception("Unsupported getItem command: "
     
    12091229                        String s = getMessage(tokens, context, code.toString(), " ", 2);
    12101230                        for (int i = 0; i < s.length(); i++) {
    1211                                 FrameKeyboardActions.processChar(s.charAt(i));
     1231                                FrameKeyboardActions.processChar(s.charAt(i), false);
    12121232                                Thread.sleep((int) (delay * 1000));
    12131233                        }
     
    12181238                                        .equals("type") ? " " : "", 1);
    12191239                        for (int i = 0; i < s.length(); i++) {
    1220                                 FrameKeyboardActions.processChar(s.charAt(i));
     1240                                FrameKeyboardActions.processChar(s.charAt(i), false);
    12211241                                Thread.sleep(25);
    12221242                        }
     
    15661586                                        tokens[1]).getValue();
    15671587                        FrameIO.SuspendCache();
    1568                         Frame freshCopy = FrameIO.LoadFrame(frameToCopy.getFrameName());
     1588                        Frame freshCopy = FrameIO.LoadFrame(frameToCopy.getName());
    15691589                        // Change the frameset if one was provided
    15701590                        if (tokens.length > 3) {
     
    16581678                                                new SCharacter(nextChar));
    16591679
     1680                        return Status.OK;
     1681                } else if (tokens[0].equals("createassociation")) {
     1682
     1683                        String associationVar = DEFAULT_ASSOCIATION;
     1684
     1685                        if (tokens.length > 0) {
     1686                                assertVariableType(tokens[1], 2, SPointer.associationPrefix);
     1687                                associationVar = tokens[1];
     1688                        }
     1689                        Map<String, String> newMap = new HashMap<String, String>();
     1690                        context.getPointers().setObject(associationVar, newMap);
     1691                        return Status.OK;
     1692                } else if (tokens[0].equals("deleteassociation")) {
     1693
     1694                        String associationVar = DEFAULT_ASSOCIATION;
     1695
     1696                        if (tokens.length > 0) {
     1697                                assertVariableType(tokens[1], 2, SPointer.associationPrefix);
     1698                                associationVar = tokens[1];
     1699                        }
     1700                        context.getPointers().delete(associationVar);
    16601701                        return Status.OK;
    16611702                } else if (tokens[0].equals("openreadfile")) {
     
    18471888                        int count = 0;
    18481889                        if (item instanceof Text)
    1849                                 count = countCharsInString(((Text) item).getTextNoList(),
    1850                                                 pattern);
     1890                                count = countCharsInString(((Text) item).getText(), pattern);
    18511891                        context.getPrimitives().setValue(tokens[3], new SInteger(count));
    18521892                        return Status.OK;
     
    21412181                                }
    21422182
    2143                                 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    2144                                 assertVariableType(tokens[2], 2, SPointer.framePrefix);
     2183                                assertVariableType(tokens[2], 2, SPointer.itemPrefix);
     2184                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
    21452185                                Frame currFrame = (Frame) context.getPointers().getVariable(
    2146                                                 tokens[2]).getValue();
     2186                                                tokens[1]).getValue();
    21472187                                // Create the ip variable
    2148                                 Item frameName = currFrame.getFrameNameItem();
    2149                                 Item frameTitle = currFrame.getTitle();
     2188                                Item frameTitle = currFrame.getTitleItem();
    21502189
    21512190                                for (Item i : currFrame.getItems()) {
    2152                                         if (i == frameName || i == frameTitle)
     2191                                        if (i == frameTitle)
    21532192                                                continue;
    21542193                                        if (!(itemType.isInstance(i)))
    21552194                                                continue;
    21562195
    2157                                         context.getPointers().setObject(tokens[1], i);
     2196                                        context.getPointers().setObject(tokens[2], i);
    21582197                                        Status status = RunFrameAndReportError(code, context);
    21592198                                        // check if we need to exit this loop because of
     
    21822221                                        context.getPrimitives().exp(tokens[1], tokens[2]);
    21832222                                } else if (tokens[0].equals("log")) {
    2184                                         context.getPrimitives().log(tokens[1], tokens[2]);
     2223                                        context.getPrimitives().log(tokens[2], tokens[2]);
    21852224                                } else if (tokens[0].equals("log10")) {
    21862225                                        context.getPrimitives().log10(tokens[1], tokens[2]);
     
    21882227                                        context.getPrimitives().sqrt(tokens[1], tokens[2]);
    21892228                                } else if (tokens[0].equals("add")) {
    2190                                         context.getPrimitives().add(tokens[1], tokens[2]);
     2229                                        context.getPrimitives().add(tokens[2], tokens[1]);
    21912230                                } else if (tokens[0].equals("subtract")) {
    2192                                         context.getPrimitives().subtract(tokens[1], tokens[2]);
     2231                                        context.getPrimitives().subtract(tokens[2], tokens[1]);
    21932232                                } else if (tokens[0].equals("multiply")) {
    2194                                         context.getPrimitives().multiply(tokens[1], tokens[2]);
     2233                                        context.getPrimitives().multiply(tokens[2], tokens[1]);
    21952234                                } else if (tokens[0].equals("divide")) {
    2196                                         context.getPrimitives().divide(tokens[1], tokens[2]);
     2235                                        context.getPrimitives().divide(tokens[2], tokens[1]);
    21972236                                } else
    21982237                                        throw new RuntimeException("Invalid statement:");
     
    22002239                        }
    22012240                } else if (tokens.length == 4) {
     2241                        if (tokens[0].equals("foreachassociation")) {
     2242                                assertExactParametreCount(tokens, 3);
     2243                                assertVariableType(tokens[1], 1, SPointer.associationPrefix);
     2244                                Map<String,String> map = (Map<String,String>) context.getPointers().getVariable(
     2245                                                tokens[1]).getValue();
     2246                                for(Map.Entry entry: map.entrySet()){
     2247                                        String value = entry.getValue().toString();
     2248                                        String key = entry.getKey().toString();
     2249                                        context.getPrimitives().setValue(tokens[2], key);
     2250                                        context.getPrimitives().setValue(tokens[3], value);
     2251                                        Status status = RunFrameAndReportError(code, context);
     2252                                        // check if we need to exit this loop because of
     2253                                        // statements in the code that was run
     2254                                        if (status == Status.Exit || status == Status.Return)
     2255                                                return status;
     2256                                        else if (status == Status.Break)
     2257                                                return Status.OK;
     2258                                }
     2259                                return Status.OK;
     2260                        }
     2261                       
    22022262                        if (Primitives.isPrimitive(tokens[1])
    22032263                                        && Primitives.isPrimitive(tokens[2])
Note: See TracChangeset for help on using the changeset viewer.