Changeset 80 for trunk/src/org


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
Files:
3 added
58 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])
  • trunk/src/org/expeditee/agents/ClipboardTree.java

    r4 r80  
    88 *
    99 */
    10 public class ClipboardTree extends WriteTree {
    11 
     10public class ClipboardTree extends WriteTree { 
    1211        public ClipboardTree() {
    13                 super("clipboard");
     12                super(CLIPBOARD);
    1413        }
    1514
    1615        public ClipboardTree(String format) {
    17                 super(format + " clipboard");
     16                super(format + " " + CLIPBOARD);
    1817        }
    1918
  • trunk/src/org/expeditee/agents/ComputeTree.java

    r66 r80  
    9797                        if (value == null) {
    9898                                value = AttributeUtils.getDoubleValue(((Text) i)
    99                                                 .getTextNoList());
     99                                                .getText());
    100100                        }
    101101
     
    126126
    127127                if (result != null) {
    128                         AttributeUtils.setSingleValue(frame.getTitle(), _format
     128                        AttributeUtils.setSingleValue(frame.getTitleItem(), _format
    129129                                        .format(result));
    130130                }
  • trunk/src/org/expeditee/agents/CopyTree.java

    r45 r80  
    6464                FrameIO.SuspendCache();
    6565
    66                 Frame fresh = FrameIO.LoadFrame(toProcess.getFrameName());
    67                 if (_nameMap.containsKey(fresh.getFrameName().toLowerCase())) {
     66                Frame fresh = FrameIO.LoadFrame(toProcess.getName());
     67                if (_nameMap.containsKey(fresh.getName().toLowerCase())) {
    6868                        fresh
    69                                         .setFrameName(_nameMap.get(fresh.getFrameName()
     69                                        .setName(_nameMap.get(fresh.getName()
    7070                                                        .toLowerCase()));
    7171                } else {
     
    7373                        fresh.setFrameNumber(++_lastNumber);
    7474
    75                         _nameMap.put(toProcess.getFrameName().toLowerCase(), fresh
    76                                         .getFrameName().toLowerCase());
     75                        _nameMap.put(toProcess.getName().toLowerCase(), fresh
     76                                        .getName().toLowerCase());
    7777                }
    7878
     
    9898                                // annotation links need to be parsed at the end
    9999                                if (i.getAbsoluteLink().toLowerCase().startsWith(_nameFrom)) {
    100                                         _toReparse.add(fresh.getFrameName());
     100                                        _toReparse.add(fresh.getName());
    101101                                        added = true;
    102102                                }
  • trunk/src/org/expeditee/agents/DefaultAgent.java

    r72 r80  
    1616 */
    1717public abstract class DefaultAgent implements Agent {
    18 
     18        public static final String CLIPBOARD = "Clipboard";
     19       
    1920        protected long _timeRemaining = 0;
    2021
  • trunk/src/org/expeditee/agents/Format.java

    r78 r80  
    162162        protected void finalise(Frame start) {
    163163                if (_success)
    164                         overwriteMessage("Formating complete.");
     164                        overwriteMessage("Formatting complete.");
     165        }
     166       
     167        @Override
     168        protected void message(String message) {
     169        }
     170
     171        @Override
     172        protected void overwriteMessage(String message) {
    165173        }
    166174
  • trunk/src/org/expeditee/agents/Sort.java

    r4 r80  
    2323                        if (i instanceof Text)
    2424                                // do not sort title and framename
    25                                 if (i.getID() > -1 && i != start.getTitle()
     25                                if (i.getID() > -1 && i != start.getTitleItem()
    2626                                                && !i.isAnnotation()) {
    2727                                        textItems.add((Text) i);
  • trunk/src/org/expeditee/agents/SwitchyardTree.java

    r50 r80  
    1616                for (Text textItem : frame.getBodyTextItems(false)) {
    1717                        // Delete all non-annotations with more that one letter
    18                         if (textItem.getTextNoList().length() > 1)
     18                        if (textItem.getText().length() > 1)
    1919                                frame.removeItem(textItem);
    2020                        else {
  • trunk/src/org/expeditee/agents/TreeProcessor.java

    r70 r80  
    3939                        return null;
    4040
    41                 _frames.push(new FrameCounter(toProcess.getFrameName(), -1));
     41                _frames.push(new FrameCounter(toProcess.getName(), -1));
    4242
    4343                // process the entire tree of frames in depth-first order
     
    5656                        if (cur.index < 0) {
    5757                                if (next != null)
    58                                         overwriteMessage("Processing: " + next.getFrameName());
     58                                        overwriteMessage("Processing: " + next.getName());
    5959                                processFrame(next);
    6060                        }
     
    7878                                                if (linked != null) {
    7979                                                        FrameCounter fc = new FrameCounter(linked
    80                                                                         .getFrameName(), -1);
     80                                                                        .getName(), -1);
    8181                                                        if (!_frames.contains(fc)) {
    8282                                                                // remember what frame we are on before
  • trunk/src/org/expeditee/agents/WriteTree.java

    r50 r80  
    33import java.io.IOException;
    44import java.lang.reflect.Constructor;
    5 import java.lang.reflect.InvocationTargetException;
    65
    76import org.expeditee.actions.Actions;
     
    3433
    3534        public WriteTree(String params) {
    36                 String format = params.trim().toLowerCase();
     35                String format = params.trim();
    3736
    38                 if (format.equals("clipboard")) {
     37                if (format.equalsIgnoreCase(CLIPBOARD)) {
    3938                        _clipboard = true;
    4039                        return;
     
    4847                        _format = params.substring(0, ind).toLowerCase();
    4948
    50                         if (lastParam.equals("clipboard"))
     49                        if (lastParam.equalsIgnoreCase(CLIPBOARD))
    5150                                _clipboard = true;
    5251                        else
     
    9796
    9897                                if (_clipboard)
    99                                         _treeWriter.setOutputLocation("clipboard");
     98                                        _treeWriter.setOutputLocation(CLIPBOARD);
    10099                                else if (_outFile != null)
    101100                                        _treeWriter.setOutputLocation(_outFile);
     
    110109
    111110                                if (_clipboard)
    112                                         _frameWriter.setOutputLocation("clipboard");
     111                                        _frameWriter.setOutputLocation(CLIPBOARD);
    113112                                else if (_outFile != null)
    114113                                        _frameWriter.setOutputLocation(_outFile);
     
    116115
    117116                } catch (ClassNotFoundException e) {
    118                         // TODO Auto-generated catch block
    119                         // e.printStackTrace();
    120117                        FrameGraphics
    121118                                        .WarningMessage("The agent does not exist or has incorrect parametres.");
    122119                        return false;
    123                 } catch (InstantiationException e) {
    124                         // TODO Auto-generated catch block
    125                         e.printStackTrace();
    126                         return false;
    127                 } catch (IllegalAccessException e) {
    128                         // TODO Auto-generated catch block
    129                         e.printStackTrace();
    130                         return false;
    131                 } catch (SecurityException e) {
    132                         // TODO Auto-generated catch block
    133                         e.printStackTrace();
    134                         return false;
    135                 } catch (NoSuchMethodException e) {
    136                         // TODO Auto-generated catch block
    137                         e.printStackTrace();
    138                         return false;
    139                 } catch (IllegalArgumentException e) {
    140                         // TODO Auto-generated catch block
    141                         e.printStackTrace();
    142                         return false;
    143                 } catch (InvocationTargetException e) {
    144                         // TODO Auto-generated catch block
     120                } catch (Exception e) {
    145121                        e.printStackTrace();
    146122                        return false;
     
    163139                        }
    164140                } catch (IOException e) {
    165                         System.out.println("Caught");
     141                        //System.out.println("Caught");
    166142                        Logger.Log(e);
    167                         FrameGraphics.ErrorMessage("Exception in WriteTree: "
     143                        FrameGraphics.ErrorMessage("IOException in WriteTree: "
    168144                                        + e.getMessage());
    169145                        e.printStackTrace();
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r78 r80  
    7777                        _AllowNull = new LinkedList<Method>();
    7878                        _AllowNull.add(Item.class.getMethod("getColor", param));
    79                         _AllowNull.add(Item.class.getMethod("getBackgroundColor", param));
    8079
    8180                        _AllowNull.add(Frame.class.getMethod("getBackgroundColor", param));
     
    160159                                        pColor));
    161160
    162                         _SetMethods.put("action", Item.class.getMethod("setActions", pList));
     161                        _SetMethods
     162                                        .put("action", Item.class.getMethod("setActions", pList));
    163163                        _SetMethods.put("a", Item.class.getMethod("setActions", pList));
    164164                        _SetMethods.put("d", Item.class.getMethod("setData", pList));
     
    180180                        _SetMethods.put("linkmark", Item.class.getMethod("setLinkMark",
    181181                                        pBool));
    182                         _SetMethods.put("lm", Item.class.getMethod("setLinkMark",
    183                                         pBool));
     182                        _SetMethods.put("lm", Item.class.getMethod("setLinkMark", pBool));
    184183                        _SetMethods.put("actionmark", Item.class.getMethod("setActionMark",
    185184                                        pBool));
    186                         _SetMethods.put("am", Item.class.getMethod("setActionMark",
    187                                         pBool));
     185                        _SetMethods.put("am", Item.class.getMethod("setActionMark", pBool));
    188186
    189187                        _SetMethods.put("actioncursorenter", Item.class.getMethod(
     
    206204                        _SetMethods.put("lp", Item.class.getMethod("setLinePattern",
    207205                                        pIntArray));
    208                        
     206
    209207                        _SetMethods.put("linkframeset", Item.class.getMethod(
    210208                                        "setLinkFrameset", pString));
    211                         _SetMethods.put("lf", Item.class.getMethod(
    212                                         "setLinkFrameset", pString));
     209                        _SetMethods.put("lf", Item.class.getMethod("setLinkFrameset",
     210                                        pString));
    213211                        _SetMethods.put("linktemplate", Item.class.getMethod(
    214212                                        "setLinkTemplate", pString));
    215                         _SetMethods.put("lt", Item.class.getMethod(
    216                                         "setLinkTemplate", pString));
     213                        _SetMethods.put("lt", Item.class.getMethod("setLinkTemplate",
     214                                        pString));
    217215
    218216                        _SetMethods.put("family", Text.class
     
    236234                        _SetMethods.put("bgc0", Frame.class.getMethod("setBackgroundColor",
    237235                                        pColor));
    238                         _SetMethods.put("protection", Frame.class.getMethod("setProtection",
    239                                         pString));
     236                        _SetMethods.put("protection", Frame.class.getMethod(
     237                                        "setProtection", pString));
    240238
    241239                } catch (SecurityException e) {
     
    280278                                try {
    281279                                        Object o = m.invoke(toExtract, (Object[]) null);
    282                                         if (o != null) {
    283                                                 // skip methods that are in the ignore lists
    284                                                 if (_ExtractIgnore.contains(m.getName().substring(
    285                                                                 GET_LENGTH).toLowerCase()))
     280
     281                                        if (o == null) {
     282                                                // methods that return null are only included if they
     283                                                // are in the AllowNull list
     284                                                if (_AllowNull.contains(m)) {
     285                                                        String name = m.getName().substring(
     286                                                                        GET_LENGTH).toLowerCase();
     287                                                        if (name.equals("color"))
     288                                                                o = "default";
     289                                                        else if (name.equals("backgroundcolor"))
     290                                                                o = "transparent";
     291                                                        else if (name.equals("foregroundcolor"))
     292                                                                o = "auto";
     293                                                        else
     294                                                                o = "";
     295                                                } else {
    286296                                                        continue;
    287 
    288                                                 if (o instanceof Integer) {
    289                                                         if (m.getName().endsWith("Justification")
    290                                                                         && convertJustificationToString((Integer) o) != null)
    291                                                                 attributes
    292                                                                                 .append(
    293                                                                                                 m.getName().substring(
    294                                                                                                                 GET_LENGTH))
    295                                                                                 .append(SEPARATOR_STRING)
    296                                                                                 .append(
    297                                                                                                 convertJustificationToString((Integer) o))
    298                                                                                 .append("\n");
    299                                                         // -1 indicates default value
    300                                                         else if (((Integer) o) > -1)
    301                                                                 attributes.append(
    302                                                                                 m.getName().substring(GET_LENGTH))
    303                                                                                 .append(SEPARATOR_STRING).append(o)
    304                                                                                 .append("\n");
    305                                                 } else if (o instanceof Float) {
    306                                                         // -1 indicates default value
    307                                                         if (((Float) o) > 0.0001)
    308                                                                 attributes.append(
    309                                                                                 m.getName().substring(GET_LENGTH))
    310                                                                                 .append(SEPARATOR_STRING).append(o)
    311                                                                                 .append("\n");
    312                                                 } else if (o instanceof Double) {
    313                                                         // -1 indicates default value
    314                                                         if (((Double) o) > 0.0001)
    315                                                                 attributes.append(
    316                                                                                 m.getName().substring(GET_LENGTH))
    317                                                                                 .append(SEPARATOR_STRING).append(o)
    318                                                                                 .append("\n");
    319                                                 } else if (o instanceof Color) {
    320                                                         // converts the color to the KMS code
    321                                                         String s = Conversion.getKMSColorCode((Color) o);
    322                                                         if (s != null)
    323                                                                 attributes.append(
    324                                                                                 m.getName().substring(GET_LENGTH))
    325                                                                                 .append(SEPARATOR_STRING).append(s)
    326                                                                                 .append("\n");
    327                                                 } else if (o instanceof Point) {
    328                                                         Point p = (Point) o;
    329                                                         String s = (int) p.getX() + " " + (int) p.getY();
     297                                                }
     298                                        }
     299                                        // skip methods that are in the ignore lists
     300                                        if (_ExtractIgnore.contains(m.getName().substring(
     301                                                        GET_LENGTH).toLowerCase())) {
     302                                                continue;
     303                                        }
     304
     305                                        if (o instanceof Integer) {
     306                                                Integer i =  (Integer)o;
     307                                                if (i == Item.DEFAULT_INTEGER)
     308                                                        continue;
     309                                                if (m.getName().endsWith("Justification")
     310                                                                && convertJustificationToString((Integer) o) != null)
     311                                                        o = convertJustificationToString((Integer) o);
     312                                                // -1 indicates default value
     313                                                else
     314                                                        o = i;
     315                                        } else if (o instanceof Float) {
     316                                                // -1 indicates default value
     317                                                if (((Float) o) < 0.0001)
     318                                                        continue;
     319                                        } else if (o instanceof Double) {
     320                                                // -1 indicates default value
     321                                                if (((Double) o) < 0.0001)
     322                                                        continue;
     323                                        } else if (o instanceof Color) {
     324                                                // converts the color to the Expeditee code
     325                                                o = Conversion.getExpediteeColorCode((Color) o);
     326                                                if (o == null)
     327                                                        continue;
     328                                        } else if (o instanceof Point) {
     329                                                Point p = (Point) o;
     330                                                o = (int) p.getX() + " " + (int) p.getY();
     331                                        } else if (o instanceof Font) {
     332                                                Font f = (Font) o;
     333
     334                                                String s = f.getName() + "-";
     335                                                if (f.isPlain())
     336                                                        s += "Plain";
     337
     338                                                if (f.isBold())
     339                                                        s += "Bold";
     340
     341                                                if (f.isItalic())
     342                                                        s += "Italic";
     343
     344                                                s += "-" + f.getSize();
     345                                                o = s;
     346                                        } else if (o instanceof Text) {
     347                                                o = ((Text) o).getFirstLine();
     348                                        } else if (o instanceof List) {
     349                                                List list = (List) o;
     350                                                for (Object ob : list)
    330351                                                        attributes
    331352                                                                        .append(m.getName().substring(GET_LENGTH))
    332                                                                         .append(SEPARATOR_STRING).append(s).append(
    333                                                                                         "\n");
    334                                                 } else if (o instanceof Font) {
    335                                                         Font f = (Font) o;
    336 
    337                                                         String s = f.getName() + "-";
    338                                                         if (f.isPlain())
    339                                                                 s += "Plain";
    340 
    341                                                         if (f.isBold())
    342                                                                 s += "Bold";
    343 
    344                                                         if (f.isItalic())
    345                                                                 s += "Italic";
    346 
    347                                                         s += "-" + f.getSize();
    348 
    349                                                         attributes
    350                                                                         .append(m.getName().substring(GET_LENGTH))
    351                                                                         .append(SEPARATOR_STRING).append(s).append(
    352                                                                                         "\n");
    353                                                 } else if (o instanceof Text) {
    354                                                         attributes
    355                                                                         .append(m.getName().substring(GET_LENGTH))
    356                                                                         .append(SEPARATOR_STRING).append(
    357                                                                                         ((Text) o).getFirstLine()).append(
    358                                                                                         "\n");
    359                                                 } else if (o instanceof List) {
    360                                                         List list = (List) o;
    361                                                         for (Object ob : list)
    362                                                                 attributes.append(
    363                                                                                 m.getName().substring(GET_LENGTH))
    364                                                                                 .append(SEPARATOR_STRING).append(ob)
    365                                                                                 .append("\n");
    366                                                 } else if (o instanceof int[]) {
    367                                                         attributes
    368                                                                         .append(m.getName().substring(GET_LENGTH))
    369                                                                         .append(SEPARATOR_STRING);
    370                                                         int[] values = (int[]) o;
    371                                                         for (int i = 0; i < values.length; i++) {
    372                                                                 attributes.append(values[i]).append(' ');
    373                                                         }
    374                                                         attributes.deleteCharAt(attributes.length() - 1);
    375                                                         attributes.append("\n");
    376                                                 } else if (o instanceof Boolean) {
    377                                                         // true is the default for boolean values
    378                                                         if (!((Boolean) o).booleanValue())
    379                                                                 attributes.append(
    380                                                                                 m.getName().substring(GET_LENGTH))
    381                                                                                 .append(SEPARATOR_STRING).append(o)
    382                                                                                 .append("\n");
    383                                                 } else
    384                                                         attributes
    385                                                                         .append(m.getName().substring(GET_LENGTH))
    386                                                                         .append(SEPARATOR_STRING).append(o).append(
    387                                                                                         "\n");
    388 
    389                                                 /*
    390                                                  * } catch (SecurityException e) { e.printStackTrace(); }
    391                                                  * /*catch (NoSuchMethodException e) {
    392                                                  * e.printStackTrace(); }
    393                                                  */
    394 
    395                                                 // methods that return null are only included if they
    396                                                 // are in the AllowNull list
    397                                         } else if (_AllowNull.contains(m))
    398                                                 attributes.append(m.getName().substring(GET_LENGTH))
    399                                                                 .append(SEPARATOR_CHAR + "\n");
    400                                 } catch (IllegalArgumentException e) {
    401                                         // TODO Auto-generated catch block
    402                                         e.printStackTrace();
    403                                 } catch (IllegalAccessException e) {
    404                                         // TODO Auto-generated catch block
    405                                         e.printStackTrace();
    406                                 } catch (InvocationTargetException e) {
     353                                                                        .append(SEPARATOR_STRING).append(ob)
     354                                                                        .append("\n");
     355                                                continue;
     356                                        } else if (o instanceof int[]) {
     357                                                StringBuffer sb = new StringBuffer();
     358                                                int[] values = (int[]) o;
     359                                                for (int i = 0; i < values.length; i++) {
     360                                                        sb.append(values[i]).append(' ');
     361                                                }
     362                                                sb.deleteCharAt(attributes.length() - 1);
     363                                                o = sb.toString();
     364                                        } else if (o instanceof Boolean) {
     365                                                // true is the default for boolean values
     366                                                if (((Boolean) o).booleanValue())
     367                                                        continue;
     368                                        }
     369                                        //Append the attributes
     370                                        attributes.append(m.getName().substring(GET_LENGTH))
     371                                                        .append(SEPARATOR_STRING).append(o).append("\n");
     372                                } catch (Exception e) {
    407373                                        // TODO Auto-generated catch block
    408374                                        e.printStackTrace();
     
    471437
    472438                // get the list of attribute: value pairs
    473                 List<String> values = attribs.getText();
     439                List<String> values = attribs.getTextList();
    474440                // if no paris exist, we are done
    475441                if (values.size() == 0
     
    495461                                        // if the attribute is the same as v, then it is a
    496462                                        // continuation
    497                                         if (v.indexOf(stripAttribute(next.toString())) == 0) {
     463                                        if (v.indexOf(getAttribute(next.toString())) == 0) {
    498464                                                // strip the attribute from next
    499                                                 next = new StringBuffer(stripValue(next.toString()));
     465                                                next = new StringBuffer(getValue(next.toString()));
    500466                                                // if the attribute is not the same, then it may be a
    501467                                                // new method
     
    519485                                // otherwise, this is a list of attributes, so continue
    520486                                else {
    521                                         String stripped = stripAttribute(v.toString());
     487                                        String stripped = getAttribute(v.toString());
    522488                                        if (stripped == null) {
    523489                                                // This happens when there is an attribute at the start
     
    530496                                                // attributes to ignore when copying
    531497                                                FrameGraphics.WarningMessage("Attribute: '"
    532                                                                 + stripAttribute(v.toString())
     498                                                                + getAttribute(v.toString())
    533499                                                                + "' does not exist.");
    534500                                        } else {
     
    538504                                                        types += c.getSimpleName() + " ";
    539505                                                FrameGraphics.WarningMessage("Wrong arguments for: '"
    540                                                                 + stripAttribute(v.toString()) + "' expecting "
     506                                                                + getAttribute(v.toString()) + "' expecting "
    541507                                                                + types.trim() + " found '"
    542                                                                 + stripValue(v.toString()) + "'");
     508                                                                + getValue(v.toString()) + "'");
    543509                                        }
    544510                                }
     
    553519                        boolean isAttributeList) {
    554520                // separate attribute and value from string
    555                 String attribute = stripAttribute(value);
    556                 value = stripValue(value);
     521                String attribute = getAttribute(value);
     522                value = getValue(value);
    557523
    558524                // if there was no colon
     
    601567                        Class toSetSuperClass = toSetClass.getSuperclass();
    602568                        // find the corresponding get method for this set method
     569                        // and get the current value of the attribute
    603570                        for (Method m : _GetMethods) {
    604571                                if ((m.getDeclaringClass() == toSetClass || m
     
    651618
    652619        /**
    653          * Returns the part of the given string that is after a colon, or null if
    654          * the given String has no colon
     620         * Returns the part of the given string that is after the attribute value
     621         * pair separator. If that character is not there it returns the empty
     622         * string if it is an annotation item or the entire string if it is not.
    655623         *
    656          * @param toStrip
     624         * @param attributeValuePair
     625         *            the string to get the value from.
     626         * @return the value from the attribute value pair.
     627         */
     628        public static String getValue(String toStrip) {
     629                assert (toStrip != null);
     630                if (toStrip.length() == 0)
     631                        return "";
     632
     633                int ind = toStrip.lastIndexOf(SEPARATOR_CHAR);
     634
     635                if (ind < 0) {
     636                        // If it is an annotation item return the empty string
     637                        // Annotation items can not be values only
     638                        if (toStrip.charAt(0) == '@') {
     639                                return "";
     640                        }
     641                        // It is a value with no attribute.
     642                        return toStrip;
     643                }
     644
     645                return toStrip.substring(ind + 1).trim();
     646        }
     647
     648        /**
     649         * Returns the part of the given string that is before the attribute value
     650         * pair separator, or null if the given String does not include the
     651         * separator.
     652         *
     653         * @param attributeValuePair
    657654         *            The String to strip
    658          * @return The part of the String that is after a colon if there is one, or
    659          *         the entire string if there is no colon
     655         * @return the attribute if there is one or null if there is not
    660656         */
    661         public static String stripValue(String toStrip) {
    662                 int ind = toStrip.lastIndexOf(SEPARATOR_CHAR);
    663                 if (ind < 0)
    664                         return toStrip;
    665 
    666                 toStrip = toStrip.substring(ind + 1);
    667                 // This line must be separate from above
    668                 // It removes spaces from the string returned by the above statement
    669                 toStrip = toStrip.trim();
    670 
    671                 return toStrip;
    672         }
    673 
    674         /**
    675          * Returns the part of the given string that is before a colon, or null if
    676          * the given String has no colon
    677          *
    678          * @param toStrip
    679          *            The String to strip
    680          * @return The part of the String that is before a colon if there is one, or
    681          *         null if there is no colon
    682          */
    683         public static String stripAttribute(String toStrip) {
    684                 int ind = toStrip.indexOf(SEPARATOR_CHAR);
     657        public static String getAttribute(String attributeValuePair) {
     658                int ind = attributeValuePair.indexOf(SEPARATOR_CHAR);
    685659                if (ind < 0)
    686660                        return null;
    687661
    688                 toStrip = toStrip.substring(0, ind);
    689                 toStrip = toStrip.trim();
    690 
    691                 if (toStrip.length() == 0)
     662                attributeValuePair = attributeValuePair.substring(0, ind);
     663                attributeValuePair = attributeValuePair.trim();
     664
     665                if (attributeValuePair.length() == 0)
    692666                        return null;
    693667
    694                 return toStrip;
     668                return attributeValuePair;
    695669        }
    696670
     
    698672                assert (value != null);
    699673
    700                 String oldText = text.getTextNoList();
    701                 String attribute = stripAttribute(oldText);
     674                String oldText = text.getText();
     675                String attribute = getAttribute(oldText);
    702676
    703677                if (attribute == null)
    704                         attribute = text.getTextNoList().trim();
     678                        attribute = text.getText().trim();
    705679
    706680                text.setText(attribute + SEPARATOR_STRING + value);
     
    708682
    709683        public static Double getDoubleValue(String attributeValuePair) {
    710                 String value = stripValue(attributeValuePair);
     684                String value = getValue(attributeValuePair);
    711685
    712686                if (value == null)
  • trunk/src/org/expeditee/gui/Browser.java

    r72 r80  
    1212import java.awt.event.WindowListener;
    1313import java.awt.event.WindowStateListener;
     14import java.util.Collection;
    1415
    1516import javax.swing.JFrame;
     
    5960                setSize(size);
    6061                setPreferredSize(size);
    61 
    62                 FrameGraphics.setMaxSize(this.getContentPane().getSize());
     62                Dimension paneSize = getContentPane().getSize();
     63                FrameGraphics.setMaxSize(paneSize);
    6364        }
    6465
     
    128129         */
    129130        public void go() {
    130 
    131                 Actions.Init();
     131                Collection<String> warningMessages = Actions.Init();
    132132                DisplayIO.Init(this);
    133133                // Set visible must be just after DisplayIO.Init for the message box to
     
    145145                DisplayIO.setCurrentFrame(firstFrame);
    146146                DisplayIO.UpdateTitle();
     147               
     148
     149               
     150                for(String message: warningMessages)
     151                        FrameGraphics.WarningMessage(message);
    147152
    148153                FrameKeyboardActions keyboardListner = new FrameKeyboardActions();
  • trunk/src/org/expeditee/gui/ColorUtils.java

    r4 r80  
    88                // search through the colour wheel to find the next colour
    99                int pos = -1;
    10                 for (int i = 0; i < wheel.length; i++)
    11                         if (color == null || color.equals(wheel[i])) {
     10                for (int i = 0; i < wheel.length; i++){
     11                        if (color == null) {
     12                                break;
     13                        } else if (color.equals(wheel[i])) {
    1214                                pos = i;
    1315                                break;
    1416                        }
    15                 // if we didnt find the color on the wheel
    16                 if (pos < 0) {
    17                         return null;
    18                 } else {
    19                         pos++;
    20                         pos = pos % wheel.length;
    21                         color = wheel[pos];
    2217                }
     18                pos++;
     19                pos = pos % wheel.length;
     20                color = wheel[pos];
    2321
    2422                return color;
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r78 r80  
    5858         * The title to display in the Title bar.
    5959         */
    60         public static final String TITLE = "Exp26May2008A";
     60        public static final String TITLE = "Exp30May2008A";
    6161
    6262        private DisplayIO() {
     
    259259                // do not allow duplicate frames
    260260                if (_VisitedFrames[side].size() > 0)
    261                         if (_VisitedFrames[side].peek().equals(toAdd.getFrameName())) {
     261                        if (_VisitedFrames[side].peek().equals(toAdd.getName())) {
    262262                                return;
    263263                        }
     
    265265                Item ip = FrameUtils.getCurrentItem();
    266266                if (ip == null)
    267                         _VisitedFrames[side].push(toAdd.getFrameName());
     267                        _VisitedFrames[side].push(toAdd.getName());
    268268                else
    269                         _VisitedFrames[side].push(toAdd.getFrameName());
     269                        _VisitedFrames[side].push(toAdd.getName());
    270270        }
    271271
     
    312312                if (frame == getCurrentFrame()) {
    313313                        FrameGraphics.Repaint();
    314                         FrameGraphics.DisplayMessage(frame.getFrameName()
     314                        FrameGraphics.DisplayMessage(frame.getName()
    315315                                        + " is already the current frame.");
    316316                        return;
     
    327327                                                        .contains(new Overlay(frame, 1))) {
    328328                                FrameIO.SuspendCache();
    329                                 frame = FrameIO.LoadFrame(frame.getFrameName());
     329                                frame = FrameIO.LoadFrame(frame.getName());
    330330                                FrameIO.ResumeCache();
    331331                        }
     
    455455                if (FrameGraphics.isAudienceMode())
    456456                        title.append(" - Audience Mode");
     457                else if (FrameGraphics.isXRayMode())
     458                        title.append(" - X-Ray Mode");
    457459                else
    458460                        title.append(" [").append(SessionStats.getShortStats()).append(']');
     
    564566                }
    565567
    566                 String oldFrame = getCurrentFrame().getFrameName().toLowerCase();
     568                String oldFrame = getCurrentFrame().getName().toLowerCase();
    567569
    568570                // do not get a cached version (in case it is in the other window)
     
    625627                        Frame hiding = _CurrentFrames[opposite];
    626628                        FrameUtils.LeavingFrame(hiding);
    627                         _VisitedFrames[opposite].add(hiding.getFrameName());
     629                        _VisitedFrames[opposite].add(hiding.getName());
    628630                        _CurrentFrames[opposite] = null;
    629631                        _CurrentFrames[current].setMaxSize(FrameGraphics.getMaxFrameSize());
     
    649651                FrameIO.SuspendCache();
    650652                _CurrentFrames[side] = FrameIO.LoadFrame(_CurrentFrames[side]
    651                                 .getFrameName());
     653                                .getName());
    652654                FrameIO.ResumeCache();
    653655        }
  • trunk/src/org/expeditee/gui/Frame.java

    r78 r80  
    3535public class Frame implements ImageObserver {
    3636
    37         public static final Color[] COLOR_WHEEL = { Color.BLACK, Color.GRAY,
     37        public static Color[] COLOR_WHEEL = { Color.BLACK, Color.WHITE, Color.GRAY,
    3838                        new Color(235, 235, 235), new Color(225, 225, 255),
    3939                        new Color(195, 255, 255), new Color(225, 255, 225),
     
    6060        private String _frozenDate = null;
    6161
    62         private Color _background;
    63 
    64         private Color _foreground = Item.DEFAULT_FOREGROUND;
     62        // Background color is clear
     63        private Color _background = null;
     64
     65        // Foreground color is automatic by default
     66        private Color _foreground = null;
    6567
    6668        public String path;
     
    236238                        }
    237239                }
    238                 bodyTextItems.remove(getTitle());
     240                bodyTextItems.remove(getTitleItem());
    239241
    240242                return bodyTextItems;
     
    285287         */
    286288        public void setTitle(String title) {
    287                 if (title == null || title == "")
     289                if (title == null || title.equals(""))
    288290                        return;
    289291
     
    292294                // remove any numbering this title has
    293295                title = title.replaceAll("^\\d*[.] *", "");
    294                 Text frameTitle = getTitle();
     296                Text frameTitle = getTitleItem();
    295297
    296298                if (frameTitle == null) {
     
    305307                        addItem(frameTitle);
    306308                } else {
     309                        // If it begins with a tag remove it
     310
     311                        // Remove the @ symbol if it is there
     312                        title = ItemUtils.StripTagSymbol(title);
    307313                        frameTitle.setText(title);
    308                         title = ItemUtils.StripTagSymbol(title);
     314                        // If the @ symbol is followed by numbering or a bullet remove that
     315                        // too
    309316                        String autoBulletText = FrameKeyboardActions.getAutoBullet(title);
    310317                        if (autoBulletText.length() > 0)
     
    314321                // Brook: Cannot figure what is going on above... widget annot titles
    315322                // should be stripped always
    316                 if (ItemUtils
    317                                 .isTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) {
     323                if (ItemUtils.startsWithTag(frameTitle, ItemUtils
     324                                .GetTag(ItemUtils.TAG_IWIDGET))) {
    318325                        frameTitle.stripFirstWord();
    319326                }
     
    325332        }
    326333
    327         public Text getTitle() {
     334        public Text getTitleItem() {
    328335                List<Item> items = getItems();
    329336                for (Item i : items) {
    330337                        if (i instanceof Text && i.getX() < UserSettings.TitlePosition
    331                                         && i.getY() < UserSettings.TitlePosition)
     338                                        && i.getY() < UserSettings.TitlePosition && i.getY() > 0)
    332339                                return (Text) i;
    333340                }
     
    336343        }
    337344
    338         public Item getFrameNameItem() {
     345        public String getTitle() {
     346                Text title = getTitleItem();
     347                if (title == null)
     348                        return getName();
     349
     350                return title.getFirstLine();
     351        }
     352
     353        public Item getNameItem() {
    339354                return _frameName;
    340355        }
     
    424439        }
    425440
    426         public void setFrameName(String framename) {
     441        public void setName(String framename) {
    427442                int num = Conversion.getFrameNumber(framename);
    428443                String frameset = Conversion.getFrameset(framename, false);
    429444
    430                 setFrameName(frameset, num);
     445                setName(frameset, num);
    431446        }
    432447
     
    465480         * @return The Frame number of this Frame or -1 if it is not set.
    466481         */
    467         public int getFrameNumber() {
     482        public int getNumber() {
    468483                return _number;
    469484        }
     
    575590                        _body.add(item);
    576591                        item.setParent(this);
     592
     593                        // If the item is a line end and has constraints with items already
     594                        // on the frame then make sure the constraints hold
     595                        if (item.isLineEnd()) {
     596                                item.setPosition(item.getPosition());
     597                        }
    577598
    578599                        _sorted = false;
     
    636657         *            The List of Items to add to the undo stack.
    637658         */
    638         public void addAllToUndo(List<Item> items) {
     659        public void addAllToUndo(Collection<Item> items) {
    639660                if (items.size() < 1)
    640661                        return;
     
    718739        }
    719740
    720         public String getFrameName() {
     741        public String getName() {
    721742                return getFramesetName() + _number;
    722743        }
     
    765786                _background = back;
    766787                change();
    767                 FrameGraphics.Repaint();
     788                // FrameGraphics.Repaint();
    768789        }
    769790
     
    784805                _foreground = front;
    785806                change();
    786                 FrameGraphics.Repaint();
     807                // FrameGraphics.Repaint();
    787808        }
    788809
     
    792813
    793814        public Color getPaintForegroundColor() {
    794                 final int GRAY = 127;
     815                final int GRAY = Color.gray.getBlue();
    795816                final int THRESHOLD = 10;
    796817
     
    802823                                return Color.WHITE;
    803824
    804                         Color fore = new Color(Math.abs(255 - back.getRed()), Math
    805                                         .abs(255 - back.getGreen()), Math.abs(255 - back.getBlue()));
     825                        Color fore = new Color(
     826                                        Math.abs(Conversion.RGB_MAX - back.getRed()), Math
     827                                                        .abs(Conversion.RGB_MAX - back.getGreen()), Math
     828                                                        .abs(Conversion.RGB_MAX - back.getBlue()));
    806829                        return fore;
    807                         // return Item.DEFAULT_FOREGROUND;
    808830                }
    809831
     
    11671189        public boolean equals(Object o) {
    11681190                if (o instanceof String) {
    1169                         return (String.CASE_INSENSITIVE_ORDER.compare((String) o,
    1170                                         getFrameName()) == 0);
     1191                        return (String.CASE_INSENSITIVE_ORDER
     1192                                        .compare((String) o, getName()) == 0);
    11711193                }
    11721194
    11731195                if (o instanceof Frame) {
    1174                         return getFrameName().equals(((Frame) o).getFrameName());
     1196                        return getName().equals(((Frame) o).getName());
    11751197                }
    11761198
     
    11881210
    11891211                List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems());
    1190                 copies.remove(toMergeWith.getFrameNameItem());
     1212                copies.remove(toMergeWith.getNameItem());
    11911213
    11921214                for (Item i : copies) {
     
    12341256                List<Item> newBody = new ArrayList<Item>(0);
    12351257                for (Item i : _body)
    1236                         if (i.isAnnotation() || i == getFrameNameItem() || i == getTitle())
     1258                        if (i.isAnnotation() || i == getNameItem() || i == getTitleItem())
    12371259                                newBody.add(i);
    12381260
     
    13001322                // check for an updated template...
    13011323                for (Item i : this.getItems()) {
    1302                         if (ItemUtils.isTag(i, templateTag)) {
     1324                        if (ItemUtils.startsWithTag(i, templateTag)) {
    13031325                                t = (Text) i;
    13041326                                break;
     
    14011423         */
    14021424        public boolean isNormalTextItem(Item it) {
    1403                 if (it instanceof Text && it != getTitle() && it != _frameName
     1425                if (it instanceof Text && it != getTitleItem() && it != _frameName
    14041426                                && !((Text) it).isSpecialAnnotation()) {
    14051427                        return true;
     
    14551477                        if (it instanceof Text) {
    14561478                                Text t = (Text) it;
    1457                                 if (t.getTextNoList().toLowerCase().startsWith("@start")
    1458                                                 || t.getTextNoList().toLowerCase().equals("@start:")) {
     1479                                if (t.getText().toLowerCase().startsWith("@start")
     1480                                                || t.getText().toLowerCase().equals("@start:")) {
    14591481                                        t.stripFirstWord();
    14601482
    1461                                         if (t.getTextNoList().equals(""))
     1483                                        if (t.getText().equals(""))
    14621484                                                DisplayIO.getCurrentFrame().removeItem(t);
    14631485                                        if (!Frame.itemAttachedToCursor()) {
     
    14911513                }
    14921514
    1493                 return _frameName.getTextNoList();
     1515                return _frameName.getText();
    14941516        }
    14951517
     
    14991521        }
    15001522
    1501         public void setFrameName(String frameset, int i) {
     1523        public void setName(String frameset, int i) {
    15021524                setFrameset(frameset);
    15031525                setFrameNumber(i);
  • trunk/src/org/expeditee/gui/FrameCreator.java

    r78 r80  
    6161                        _prev = _Mprev.copy();
    6262                        _prev.setID(newFrame.getNextItemID());
    63                         _prev.setLink(_current.getFrameName());
     63                        _prev.setLink(_current.getName());
    6464                        newFrame.addItem(_prev);
    6565
     
    6767                        _next = _Mnext.copy();
    6868                        _next.setID(_current.getNextItemID());
    69                         _next.setLink(newFrame.getFrameName());
     69                        _next.setLink(newFrame.getName());
    7070                        _current.addItem(_next);
    7171                        FrameIO.SaveFrame(_current, false);
     
    8080
    8181        private void resetGlobals(Frame toUse) {
    82                 _lastY = START_Y + toUse.getTitle().getPosition().y;
     82                _lastY = START_Y + toUse.getTitleItem().getPosition().y;
    8383                _lastX = START_X;
    8484                //Check for @Start
     
    8686                        if (it instanceof Text) {
    8787                                Text t = (Text) it;
    88                                 if (t.getTextNoList().toLowerCase().equals("@start") ||
    89                                                 t.getTextNoList().toLowerCase().startsWith("@start:")) {
     88                                if (t.getText().toLowerCase().equals("@start") ||
     89                                                t.getText().toLowerCase().startsWith("@start:")) {
    9090                                        t.stripFirstWord();
    9191
    92                                         if (t.getTextNoList().equals("")){
     92                                        if (t.getText().equals("")){
    9393                                                _lastY = t.getY();
    9494                                                _lastX = t.getX();
     
    157157                        return null;
    158158
    159                 return _current.getFrameName();
     159                return _current.getName();
    160160        }
    161161}
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r78 r80  
    1616import java.util.Collection;
    1717import java.util.HashSet;
     18import java.util.Iterator;
    1819import java.util.LinkedList;
    1920import java.util.List;
     
    7374
    7475        // The link to the message frameset
    75         public static Item MessageLink = new Text(-2, MESSAGES_FRAMESET_NAME);
     76        public static Item MessageLink = new Text(-2, "@" + MESSAGES_FRAMESET_NAME);
    7677
    7778        // creator for creating the message frames
     
    9899                FrameUtils.Parse(current);
    99100                DisplayIO.UpdateTitle();
     101                setMaxSize(new Dimension(_MaxSize.width, _MessageBuffer.getHeight()
     102                                + _MaxSize.height));
    100103                Repaint();
    101104        }
     
    112115
    113116                FrameUtils.Parse(DisplayIO.getCurrentFrame());
     117                DisplayIO.UpdateTitle();
    114118                Repaint();
    115119        }
     
    133137                        _MaxSize = max;
    134138
    135                 // Mike assumes this is the height of the Message window?
    136                 _MaxSize.setSize(max.width, max.height - MESSAGE_BUFFER_HEIGHT);
     139                // Hide the message buffer if in audience mode
     140                int newMaxHeight = max.height
     141                                - (isAudienceMode() ? 0 : MESSAGE_BUFFER_HEIGHT);
     142                if (newMaxHeight > 0)
     143                        _MaxSize.setSize(max.width, newMaxHeight);
     144
    137145                if (DisplayIO.getCurrentFrame() != null) {
    138146                        DisplayIO.getCurrentFrame().setBuffer(null);
     
    140148                }
    141149
    142                 _MessageBuffer = null;
    143 
    144                 for (int i = 0; i < Messages.length; i++) {
    145                         if (Messages[i] != null) {
    146                                 Messages[i].setOffset(0, -_MaxSize.height);
    147                                 Messages[i].setMaxSize(_MaxSize);
    148                         }
    149                 }
    150 
    151                 MessageLink.setOffset(0, -_MaxSize.height);
    152                 MessageLink.setMaxSize(_MaxSize);
    153                 MessageLink.setPosition(_MaxSize.width - MESSAGE_LINK_Y_OFFSET,
    154                                 MESSAGE_LINK_X);
    155 
     150                if (newMaxHeight > 0) {
     151                        _MessageBuffer = null;
     152
     153                        for (int i = 0; i < Messages.length; i++) {
     154                                if (Messages[i] != null) {
     155                                        Messages[i].setOffset(0, -_MaxSize.height);
     156                                        Messages[i].setMaxSize(_MaxSize);
     157                                }
     158                        }
     159
     160                        MessageLink.setOffset(0, -_MaxSize.height);
     161                        MessageLink.setMaxSize(_MaxSize);
     162                        MessageLink.setPosition(_MaxSize.width - MESSAGE_LINK_Y_OFFSET,
     163                                        MESSAGE_LINK_X);
     164                }
    156165                // Repaint();
    157166        }
     
    254263                List<Item> copies = ItemUtils.CopyItems(vector.getItems());
    255264                // FrameMouseActions
    256                 for (Item i : copies) {
     265                Iterator<Item> iterator = copies.iterator();
     266                while(iterator.hasNext()){
     267                        Item i = iterator.next();
     268                        //Dont paint annotation items for @v
     269                        if (i.isAnnotation()){
     270                                iterator.remove();
     271                                continue;
     272                        }
     273                        i.setLinkMark(false);
     274                        i.setActionMark(false);
    257275                        if (!(i instanceof Line)) {
    258276                                i.setPosition((int) (i.getX() * scale + dx + 0.5), (int) (i
     
    260278                                                * scale + dy + 0.5));
    261279                                i.setThickness((int) (i.getThickness() * scale + 0.5));
     280                                i.setArrowheadLength((int) (i.getArrowheadLength() * scale + 0.5));
    262281                        }
    263282                        if (i instanceof Text)
     
    419438
    420439                        if (isActualFrame) {
    421                                 PaintItem(bg, toPaint.getFrameNameItem());
     440                                PaintItem(bg, toPaint.getNameItem());
    422441                        }
    423442
     
    476495                        _MessageBuffer = ge.getDefaultScreenDevice()
    477496                                        .getDefaultConfiguration().createCompatibleVolatileImage(
    478                                                         _MaxSize.width, MESSAGE_BUFFER_HEIGHT);
     497                                                        _MaxSize.width,
     498                                                        (isAudienceMode() ? 0 : MESSAGE_BUFFER_HEIGHT));
    479499                }
    480500
     
    507527                                g.drawImage(right, 0, 0, Item.DEFAULT_BACKGROUND, null);
    508528                }
    509                 // draw the message area
    510                 g.drawImage(_MessageBuffer, 0, _MaxSize.height, null);
     529                // Dont display the message area in audience mode
     530                if (!isAudienceMode()) {
     531                        // draw the message area
     532                        g.drawImage(_MessageBuffer, 0, _MaxSize.height, null);
     533                }
    511534                g.dispose();
    512535
     
    749772                MessageLink.setLink(_creator.getCurrent());
    750773                Repaint();
     774               
     775                System.out.println(message);
    751776        }
    752777
  • trunk/src/org/expeditee/gui/FrameIO.java

    r78 r80  
    4141                FRAME_PATH = PARENT_FOLDER + "framesets" + File.separator;
    4242                TRASH_PATH = PARENT_FOLDER + "trash" + File.separator;
    43                 IMAGES_PATH = PARENT_FOLDER + "images" + File.separator;
     43                IMAGES_PATH = PARENT_FOLDER + IMAGES_FOLDER;
    4444                HELP_PATH = PARENT_FOLDER + "help" + File.separator;
    4545                PROFILE_PATH = PARENT_FOLDER + "profiles" + File.separator;
     
    5353         * subdirectory in this directory.
    5454         */
    55 
     55        public static String IMAGES_FOLDER = "images" + File.separator;
     56       
    5657        public static String TRASH_PATH;
    5758
     
    263264                                _Cache.clear();
    264265
    265                         if (frame.getFrameNumber() > 0 && isCacheOn())
     266                        if (frame.getNumber() > 0 && isCacheOn())
    266267                                _Cache.put(frameName.toLowerCase(), frame);
    267268
     
    286287                _UseCache = false;
    287288                Frame fresh = FrameIO.LoadFrame(DisplayIO.getCurrentFrame()
    288                                 .getFrameName());
     289                                .getName());
    289290                _UseCache = cache;
    290                 if (_Cache.containsKey(fresh.getFrameName().toLowerCase()))
    291                         _Cache.put(fresh.getFrameName().toLowerCase(), fresh);
     291                if (_Cache.containsKey(fresh.getName().toLowerCase()))
     292                        _Cache.put(fresh.getName().toLowerCase(), fresh);
    292293                DisplayIO.setCurrentFrame(fresh);
    293294        }
     
    298299                // the current name and number
    299300                String name = current.getFramesetName();
    300                 int num = current.getFrameNumber() - 1;
     301                int num = current.getNumber() - 1;
    301302
    302303                // loop until a frame that exists is found
     
    324325
    325326                // the current name and number
    326                 int num = current.getFrameNumber() + 1;
     327                int num = current.getNumber() + 1;
    327328                int max = num + 1;
    328329                String name = current.getFramesetName();
     
    424425
    425426                // Dont delete the zero frame
    426                 if (toDelete.getFrameNumber() == 0) {
     427                if (toDelete.getNumber() == 0) {
    427428                        FrameGraphics.ErrorMessage("Zero frame's can not be deleted");
    428429                        return false;
     
    447448                // get the fill path to determine which file version it is
    448449                String source = getFrameFullPathName(toDelete.path, toDelete
    449                                 .getFrameName());
    450 
    451                 String oldFrameName = toDelete.getFrameName().toLowerCase();
     450                                .getName());
     451
     452                String oldFrameName = toDelete.getName().toLowerCase();
    452453                // Now save the frame in the new location
    453454                toDelete.setFrameset(DELETED_FRAMES);
     
    519520
    520521                // set the number and title of the new frame
    521                 template.setFrameName(frameset, ++ next);
     522                template.setName(frameset, ++ next);
    522523                template.setTitle(frameTitle);
    523524
    524525                Logger.Log(Logger.SYSTEM, Logger.TDFC, "Creating new frame: "
    525                                 + template.getFrameName() + " from TDFC");
     526                                + template.getName() + " from TDFC");
    526527
    527528                // update INF file
     
    536537                template.resetDateCreated();
    537538                for (Item i : template.getItems()) {
    538                         if (ItemUtils.isTag(i, ItemUtils.TAG_PARENT))
     539                        if (ItemUtils.startsWithTag(i, ItemUtils.TAG_PARENT))
    539540                                i.setLink(null);
    540541                }
     
    656657               
    657658                //Dont save if the frame is protected
    658                 if (toSave.getFrameNameItem().Permission < Item.PERMISSION_TDFC)
     659                if (toSave.getNameItem().Permission < Item.PERMISSION_TDFC)
    659660                        return "";
    660661
     
    665666                // Exp format.
    666667                String fullPath = getFrameFullPathName(toSave.path, toSave
    667                                 .getFrameName());
     668                                .getName());
    668669
    669670                // Check if the frame exists
     
    691692                                // remove this frame from the cache if it is there
    692693                                // This will make sure links to the original are set correctly
    693                                 _Cache.remove(toSave.getFrameName().toLowerCase());
     694                                _Cache.remove(toSave.getName().toLowerCase());
    694695                                int nextnum = ReadINF(toSave.path, toSave.getFramesetName()) + 1;
    695696                                SuspendCache();
    696                                 Frame original = LoadFrame(toSave.getFrameName());
     697                                Frame original = LoadFrame(toSave.getName());
    697698                                toSave.setFrameNumber(nextnum);
    698699                                ResumeCache();
    699700                                // Put the modified version in the cache
    700                                 _Cache.put(toSave.getFrameName().toLowerCase(), toSave);
     701                                _Cache.put(toSave.getName().toLowerCase(), toSave);
    701702                                // Show the messages alerting the user
    702703                                Text originalMessage = new Text(-1);
    703704                                originalMessage.setColor(FrameGraphics.ERROR_COLOR);
    704                                 originalMessage.setText(original.getFrameName()
     705                                originalMessage.setText(original.getName()
    705706                                                + " was updated by another user.");
    706                                 originalMessage.setLink(original.getFrameName());
     707                                originalMessage.setLink(original.getName());
    707708                                Text yourMessage = new Text(-1);
    708709                                yourMessage.setColor(FrameGraphics.ERROR_COLOR);
    709710                                yourMessage.setText("Your version was renamed "
    710                                                 + toSave.getFrameName());
    711                                 yourMessage.setLink(toSave.getFrameName());
     711                                                + toSave.getName());
     712                                yourMessage.setLink(toSave.getName());
    712713                                FrameGraphics.DisplayMessage(originalMessage);
    713714                                FrameGraphics.DisplayMessage(yourMessage);
     
    716717                                                        ItemUtils.TAG_BACKUP)) {
    717718                                SuspendCache();
    718                                 Frame original = LoadFrame(toSave.getFrameName());
     719                                Frame original = LoadFrame(toSave.getName());
    719720                                if (original == null)
    720721                                        original = toSave;
    721                                 int orignum = original.getFrameNumber();
     722                                int orignum = original.getNumber();
    722723                                int nextnum = ReadINF(toSave.path, toSave.getFramesetName()) + 1;
    723724
     
    731732                                Item i = ItemUtils.FindExactTag(toSave.getItems(),
    732733                                                ItemUtils.TAG_BACKUP);
    733                                 i.setLink(original.getFrameName());
     734                                i.setLink(original.getName());
    734735                                toSave.setFrameNumber(orignum);
    735736                                ResumeCache();
     
    741742                        toSave.setSaved();
    742743                        if (inc)
    743                                 SessionStats.SavedFrame(toSave.getFrameName());
     744                                SessionStats.SavedFrame(toSave.getName());
    744745
    745746                        // avoid out-of-sync frames (when in TwinFrames mode)
    746                         if (_Cache.containsKey(toSave.getFrameName().toLowerCase()))
    747                                 _Cache.put(toSave.getFrameName().toLowerCase(), toSave);
     747                        if (_Cache.containsKey(toSave.getName().toLowerCase()))
     748                                _Cache.put(toSave.getName().toLowerCase(), toSave);
    748749
    749750                        Logger.Log(Logger.SYSTEM, Logger.SAVE, "Saving "
    750                                         + toSave.getFrameName() + " to disk.");
     751                                        + toSave.getName() + " to disk.");
    751752
    752753                        // check that the INF file is not out of date
    753754                        int last = ReadINF(toSave.path, toSave.getFramesetName());
    754                         if (last <= toSave.getFrameNumber())
     755                        if (last <= toSave.getNumber())
    755756                                WriteINF(toSave.path, toSave.getFramesetName(), toSave
    756                                                 .getFrameName());
     757                                                .getName());
    757758
    758759                        // check if this was the profile frame (and thus needs
     
    874875
    875876        public static Frame CreateNewFrame(Item linker) throws RuntimeException {
    876                 String title = null;
    877                 if (linker instanceof Text)
    878                         title = ((Text) linker).getFirstLine();
    879 
    880                 String templateLink = linker.getLinkTemplate();
    881                 String framesetLink = linker.getLinkFrameset();
     877                String title = linker.getName();
     878
     879                String templateLink = linker.getAbsoluteLinkTemplate();
     880                String framesetLink = linker.getAbsoluteLinkFrameset();
    882881                String frameset = (framesetLink != null ? framesetLink : DisplayIO
    883882                                .getCurrentFrame().getFramesetName());
     
    886885
    887886                // do auto shrinking of the title IF not in twin frames mode
    888                 Item titleItem = newFrame.getTitle();
     887                Item titleItem = newFrame.getTitleItem();
    889888
    890889                if (!DisplayIO.isTwinFramesOn()) {
    891890                        // BROOK: This had recursion!! Changed to avoid...
    892                         if ((titleItem.getX() + 1) < newFrame.getFrameNameItem().getX()) {
     891                        if ((titleItem.getX() + 1) < newFrame.getNameItem().getX()) {
    893892                                while (titleItem.getBoundsWidth() + titleItem.getX() > newFrame
    894                                                 .getFrameNameItem().getX()) {
     893                                                .getNameItem().getX()) {
    895894                                        titleItem.setSize(titleItem.getSize() - 1);
    896895                                }
     
    11221121        }
    11231122
     1123        /**
     1124         * Copies a file from one location to another.
     1125         * @param existingFile
     1126         * @param newFileName
     1127         * @throws Exception
     1128         */
    11241129        public static void copyFile(String existingFile, String newFileName)
    11251130                        throws Exception {
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r78 r80  
    2929        private static Text _toRemove = null;
    3030
    31         // these numbers correspond to the Function Key numbers (0 = Escape key)
    32         public static final int DROP_DOWN = 0;
    33 
    34         public static final int SIZE_UP = 1;
    35 
    36         public static final int SIZE_DOWN = 2;
    37 
    38         public static final int COLOR_CHANGE = 3;
    39 
    40         public static final int ANNOTATION_CHANGE = 4;
    41 
    42         public static final int DATE_ITEM = 5;
    43 
    44         public static final int NEW_FRAMESET = 6;
    45 
    46         public static final int FONT_STYLE_CHANGE = 7;
    47 
    48         public static final int FONT_FAMILY_CHANGE = 8;
    49 
    50         public static final int AUDIENCE_MODE = 9;
    51 
    52         public static final int XRAY_MODE = 10;
    53 
    54         // public static final int RUN_MENU = 11;
    55 
    56         public static final int FORCE_REPAINT = 12;
    57 
    5831        public synchronized void keyTyped(KeyEvent e) {
    5932                if (Simple.acceptKeyboardInput()) {
     
    9366                                // remove the link for alt+l
    9467                                if (ch == 'l') {
    95                                         FrameUtils.getCurrentItem().setLink(null);
     68                                        Item current = FrameUtils.getCurrentItem();
     69                                        // If its not linked then link it to its self
     70                                        if (current instanceof Text && current.getLink() == null) {
     71                                                String text = ((Text) current).getText();
     72                                                if (FrameIO.isValidFrameName(text)) {
     73                                                        current.setLink(text);
     74                                                } else if (FrameIO.isValidFramesetName(text)) {
     75                                                        current.setLink(text + '1');
     76                                                }
     77                                        } else {
     78                                                // If its linked remove the link
     79                                                current.setLink(null);
     80                                        }
     81                                        FrameGraphics.Repaint();
     82                                } else if (ch == 'a') {
     83                                        Item current = FrameUtils.getCurrentItem();
     84                                        // If its not linked then link it to its self
     85                                        if (current instanceof Text && current.getAction() == null) {
     86                                                String text = ((Text) current).getText().trim();
     87                                                if (text.startsWith("a:")) {
     88                                                        text = text.substring(2).trim();
     89                                                } else if (text.startsWith("@")) {
     90                                                        text = text.substring(1).trim();
     91                                                }
     92                                                current.setAction(text);
     93                                        } else {
     94                                                // If its linked remove the link
     95                                                current.setActions(null);
     96                                        }
    9697                                        FrameGraphics.Repaint();
    9798                                }
    9899                        }
    99100                } else {
    100                         processChar(ch);
     101                        processChar(ch, e.isShiftDown());
    101102                }
    102103                // FrameGraphics.Repaint();
    103104        }
    104105
    105         public static void processChar(char ch) {
     106        public static void processChar(char ch, boolean isShiftDown) {
    106107                NavigationActions.ResetLastAddToBack();
    107108                Item on = FrameUtils.getCurrentItem();
     
    169170
    170171                DisplayIO.setTextCursor(text.getSize());
    171                 Point newMouse = text.insertChar(ch, DisplayIO.getMouseX(), DisplayIO
    172                                 .getMouseY());
     172                Point newMouse = null;
     173                if (ch == '\t') {
     174                        if (isShiftDown) {
     175                                newMouse = text.removeTab(ch, DisplayIO.getMouseX(), DisplayIO
     176                                                .getMouseY());
     177                        } else {
     178                                newMouse = text.insertTab(ch, DisplayIO.getMouseX(), DisplayIO
     179                                                .getMouseY());
     180                        }
     181                } else {
     182                        newMouse = text.insertChar(ch, DisplayIO.getMouseX(), DisplayIO
     183                                        .getMouseY());
     184                }
    173185                DisplayIO.setCursorPosition(newMouse.x, newMouse.y, false);
    174186
     
    332344
    333345                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
    334                         functionKey(DROP_DOWN);
     346                        functionKey(FunctionKey.DropDown);
    335347                        SessionStats.Escape();
    336348                        return;
    337349                } else if (e.getKeyCode() >= KeyEvent.VK_F1
    338350                                && e.getKeyCode() <= KeyEvent.VK_F12) {
    339                         functionKey(e.getKeyCode() - KeyEvent.VK_F1 + 1);
     351                        functionKey(FunctionKey.values()[e.getKeyCode() - KeyEvent.VK_F1
     352                                        + 1]);
    340353                        return;
    341354                } else if (e.isControlDown() && e.getKeyCode() != KeyEvent.VK_CONTROL)
     
    378391                        if (e.isControlDown()) {
    379392                                FrameMouseActions.leftButton(FrameUtils.getCurrentItem());
     393                                FrameMouseActions.updateCursor();
    380394                        }
    381395                        break;
     
    394408                // Move the cursor to the next text item
    395409                Frame current = DisplayIO.getCurrentFrame();
    396                 Item title = current.getTitle();
     410                Item title = current.getTitleItem();
    397411                List<Text> textItems = current.getBodyTextItems(false);
    398412                if (textItems.size() == 0) {
     
    402416                }
    403417
     418                // If the user is mouse wheeling in free space...
    404419                if (currentItem == null) {
    405420                        // find the nearest item in the correct direction
     
    411426                                                DisplayIO.setCursorPosition(t.getPosition());
    412427                                        } else {
    413                                                 if (i == 0)
    414                                                         break;
    415                                                 DisplayIO.setCursorPosition(textItems.get(i - 1)
    416                                                                 .getPosition());
     428                                                if (i == 0) {
     429                                                        DisplayIO.setCursorPosition(current.getTitleItem()
     430                                                                        .getPosition());
     431                                                } else {
     432                                                        DisplayIO.setCursorPosition(textItems.get(i - 1)
     433                                                                        .getPosition());
     434                                                }
    417435                                        }
    418436                                        FrameGraphics.Repaint();
     
    420438                                }
    421439                        }
    422                         DisplayIO.setCursorPosition(title.getPosition());
    423                         return;
    424                 }
    425 
    426                 if (current.getTitle().equals(currentItem)) {
     440                        // If we are at the botton of the screen and the user scrolls down
     441                        // then scroll backup to the title
     442                        if (textItems.size() > 0) {
     443                                DisplayIO.setCursorPosition(textItems.get(textItems.size() - 1)
     444                                                .getPosition());
     445                        }
     446                        return;
     447                }
     448                // If the user is on the title item
     449                if (current.getTitleItem().equals(currentItem)) {
    427450                        if (down) {
    428451                                // Show the first item
    429452                                DisplayIO.setCursorPosition(textItems.get(0).getPosition());
    430                         } else {
    431                                 // Show the last item
    432                                 DisplayIO.setCursorPosition(textItems.get(textItems.size() - 1)
    433                                                 .getPosition());
    434                         }
    435                         FrameGraphics.Repaint();
     453                                FrameGraphics.Repaint();
     454                        }
    436455                        return;
    437456                }
     
    440459                        if (textItems.get(i).equals(currentItem)) {
    441460                                int nextIndex = i + (down ? 1 : -1);
    442                                 if (nextIndex >= 0 && nextIndex < textItems.size()) {
    443                                         DisplayIO.setCursorPosition(textItems.get(nextIndex)
    444                                                         .getPosition());
     461                                if (nextIndex >= 0) {
     462                                        if (nextIndex < textItems.size()) {
     463                                                DisplayIO.setCursorPosition(textItems.get(nextIndex)
     464                                                                .getPosition());
     465                                        }
    445466                                } else {
    446467                                        DisplayIO.setCursorPosition(title.getPosition());
     
    502523                                        if (clicked.Permission < Item.PERMISSION_FULL
    503524                                                        && clicked.getParent() != null
    504                                                         && clicked.getParent().getFrameNameItem() != clicked) {
     525                                                        && clicked.getParent().getNameItem() != clicked) {
    505526                                                FrameGraphics.DisplayMessage("Insufficient Permission");
    506527                                                return;
     
    563584                        String text = "";
    564585
    565                         List<String> lines = ((Text) on).getText();
     586                        List<String> lines = ((Text) on).getTextList();
    566587                        for (String s : lines)
    567588                                text += s + "\n";
     
    578599                } else if (ch.charAt(0) == KeyEvent.VK_D) {
    579600                        // perform a delete operation
    580                         processChar((char) KeyEvent.VK_DELETE);
     601                        processChar((char) KeyEvent.VK_DELETE, e.isShiftDown());
    581602                        FrameGraphics.Repaint();
    582603                } else if (ch.charAt(0) == KeyEvent.VK_J) {
     
    599620                        if (text == null)
    600621                                return;
    601                         List<String> textLines = text.getText();
     622                        List<String> textLines = text.getTextList();
    602623                        if (textLines.size() <= 1)
    603624                                return;
     
    653674        }
    654675
    655         public static void functionKey(int key) {
     676        public static void functionKey(FunctionKey key) {
    656677                functionKey(key, 1);
    657678        }
     
    661682         * action based on the key.
    662683         */
    663         public static void functionKey(int key, int repeat) {
     684        public static void functionKey(FunctionKey key, int repeat) {
    664685                // get whatever the user is pointing at
    665686                Item on = FrameUtils.getCurrentItem();
    666687
    667688                // check for enclosed mode
    668                 if (on == null && key < AUDIENCE_MODE) {
     689                if (on == null && key.ordinal() < FunctionKey.AudienceMode.ordinal()) {
    669690                        Collection<Item> enclosed = FrameUtils.getCurrentItems();
    670691
     
    688709
    689710                                switch (key) {
    690                                 case SIZE_UP:
     711                                case SizeUp:
    691712                                        if (resizeLines
    692713                                                        || (!(firstConnected instanceof Line) && !(firstConnected instanceof Dot)))
    693714                                                SetSize(firstConnected, repeat, false);
    694715                                        break;
    695                                 case SIZE_DOWN:
     716                                case SizeDown:
    696717                                        if (resizeLines
    697718                                                        || (!(firstConnected instanceof Line) && !(firstConnected instanceof Dot)))
    698719                                                SetSize(firstConnected, -repeat, false);
    699720                                        break;
    700                                 // case COLOR_CHANGE: SetFillColor(firstConnected); break;
    701                                 case ANNOTATION_CHANGE:
     721                                case ChangeColor:
     722                                        if (connected.size() > 0) {
     723                                                for (Item d : dots) {
     724                                                        SetFillColor(d);
     725                                                        break;
     726                                                }
     727                                        }
     728                                        break;
     729                                case ToggleAnnotation:
    702730                                        ToggleAnnotation(firstConnected);
    703731                                        break;
    704                                 case FONT_STYLE_CHANGE:
     732                                case ChangeFontStyle:
    705733                                        ToggleFontStyle(firstConnected);
    706734                                        break;
    707                                 case FONT_FAMILY_CHANGE:
     735                                case ChangeFontFamily:
    708736                                        ToggleFontFamily(firstConnected);
    709737                                        break;
    710                                 case DATE_ITEM:
     738                                case InsertDate:
    711739                                        AddDate(firstConnected);
    712740                                        break;
    713741                                }
    714 
    715                                 if (key == COLOR_CHANGE && connected.size() > 0) {
    716                                         for (Item d : dots) {
    717                                                 SetFillColor(d);
    718                                                 break;
    719                                         }
    720                                 }
     742                                return;
     743                        }
     744                }
     745                String displayMessage = "F" + key.ordinal() + ": " + key.toString();
     746                // Show a description of the function key pressed if the user is in free
     747                // space and return for the F keys that dont do anything in free space.
     748                if (on == null) {
     749                        switch (key) {
     750                        case DropDown:
     751                        case InsertDate:
     752                        case XRayMode:
     753                        case AudienceMode:
     754                        case Refresh:
     755                                break;
     756                        default:
     757                                FrameGraphics.DisplayMessage(displayMessage);
    721758                                return;
    722759                        }
     
    724761
    725762                switch (key) {
    726                 case DROP_DOWN:
     763                case DropDown:
    727764                        Drop(on);
    728                         break;
    729                 case SIZE_UP:
     765                        return;
     766                case SizeUp:
    730767                        SetSize(on, repeat, true);
    731768                        break;
    732                 case SIZE_DOWN:
     769                case SizeDown:
    733770                        SetSize(on, -repeat, true);
    734771                        break;
    735                 case COLOR_CHANGE:
     772                case ChangeColor:
    736773                        SetColor(on);
    737774                        break;
    738                 case ANNOTATION_CHANGE:
     775                case ToggleAnnotation:
    739776                        ToggleAnnotation(on);
    740777                        break;
    741                 case FONT_STYLE_CHANGE:
     778                case ChangeFontStyle:
    742779                        ToggleFontStyle(on);
    743780                        break;
    744                 case FONT_FAMILY_CHANGE:
     781                case ChangeFontFamily:
    745782                        ToggleFontFamily(on);
    746783                        break;
    747                 case DATE_ITEM:
     784                case InsertDate:
    748785                        AddDate(on);
    749                         break;
    750                 case NEW_FRAMESET:
     786                        return;
     787                case NewFrameset:
    751788                        CreateFrameset(on);
    752789                        break;
    753                 case XRAY_MODE:
     790                case XRayMode:
    754791                        ToggleXRayMode(on);
    755792                        break;
    756                 case AUDIENCE_MODE:
     793                case AudienceMode:
    757794                        ToggleAudience(on);
    758795                        break;
    759                 case FORCE_REPAINT:
     796                case Refresh:
    760797                        Repaint(on);
    761798                        break;
    762799                }
     800                if (on == null)
     801                        FrameGraphics.DisplayMessage(displayMessage);
    763802        }
    764803
     
    818857                        }
    819858
    820                         Item title = DisplayIO.getCurrentFrame().getTitle();
     859                        Item title = DisplayIO.getCurrentFrame().getTitleItem();
    821860
    822861                        // We wont do auto bulleting when dropping from titles
     
    829868                        if (Frame.textItemAttachedToCursor()) {
    830869                                dummyItem = (Text) Frame.getItemAttachedToCursor();
    831                                 String autoBullet = getAutoBullet(dummyItem.getTextNoList());
     870                                String autoBullet = getAutoBullet(dummyItem.getText());
    832871
    833872                                if (autoBullet.length() > 0)
    834873                                        newItemText = "";
    835                                 dummyItem.setText(newItemText + dummyItem.getTextNoList());
     874                                dummyItem.setText(newItemText + dummyItem.getText());
    836875                        }
    837876                        dummyItem = createText();
     
    839878                                Text t = (Text) Frame.getItemAttachedToCursor();
    840879                                dummyItem.setSize(t.getSize());
    841                                 for (int i = 0; i < t.getText().size(); i++) {
     880                                for (int i = 0; i < t.getTextList().size(); i++) {
    842881                                        newItemText += '\n';
    843882                                }
     
    879918                                                boolean mouseMoved = FrameMouseActions.tdfc(i);
    880919                                                Frame moreFrame = DisplayIO.getCurrentFrame();
    881                                                 moreFrame.setTitle(firstFrame.getTitle()
    882                                                                 .getTextNoList());
     920                                                moreFrame.setTitle(firstFrame.getTitleItem().getText());
    883921                                                // need to move the mouse to the top of the frame if
    884922                                                // there
    885923                                                // wasnt an @start on it
    886924                                                if (!mouseMoved) {
    887                                                         Item moreTitle = moreFrame.getTitle();
     925                                                        Item moreTitle = moreFrame.getTitleItem();
    888926                                                        moreTitle.Permission = Item.PERMISSION_FULL;
    889927                                                        Drop(moreTitle);
     
    926964                } catch (RuntimeException e) {
    927965                        FrameGraphics.ErrorMessage(e.getMessage());
     966                        e.printStackTrace();
    928967                }
    929968        }
     
    9621001                 * "@NoAutoBullets"); if (i != null) return newItemText;
    9631002                 */
     1003                // Separate the space at the start of the text item
     1004                String preceedingSpace = "";
     1005                for (int i = 0; i < s.length(); i++) {
     1006                        if (!Character.isSpaceChar(s.charAt(i))) {
     1007                                preceedingSpace = s.substring(0, i);
     1008                                s = s.substring(i);
     1009                                break;
     1010                        }
     1011                }
    9641012
    9651013                // figure out the type of the text item
     
    9751023                                                || s.charAt(0) == '~' || s.charAt(0) == '#') {
    9761024                                        int nonSpaceIndex = 1;
     1025                                        // Find the end of the bullet and space after the bullet
    9771026                                        while (nonSpaceIndex < s.length()
    9781027                                                        && s.charAt(nonSpaceIndex) == ' ') {
     
    9931042                        }
    9941043                }
    995                 return newItemText;
     1044                return preceedingSpace + newItemText;
    9961045        }
    9971046
     
    11011150                        }
    11021151                } else {
     1152                        if (item.isFrameName()) {
     1153                                FrameGraphics.DisplayMessage("Can not resize the frame name");
     1154                                return;
     1155                        }
    11031156                        // check permissions
    11041157                        if (item.Permission < Item.PERMISSION_FULL) {
     
    11941247                color = ColorUtils.getNextColor(color, Item.FILL_COLOR_WHEEL);
    11951248
    1196                 // TODO what happens if the above statement returns null??
     1249                if (color == null) {
     1250                        FrameGraphics.DisplayMessage("FillColor is now transparent");
     1251                }
    11971252
    11981253                toSet.setFillColor(color);
     
    12121267                // first determine the next color
    12131268                Color color = null;
    1214 
     1269                Frame currentFrame = DisplayIO.getCurrentFrame();
    12151270                if (ip == null) {
    12161271                        if (Frame.itemAttachedToCursor()) {
     
    12211276                        // change the background color if the user is pointing on the
    12221277                        // frame name
    1223                 } else if (ip == DisplayIO.getCurrentFrame().getFrameNameItem()) {
    1224                         DisplayIO.getCurrentFrame().toggleBackgroundColor();
     1278                } else if (ip == currentFrame.getNameItem()) {
     1279                        currentFrame.toggleBackgroundColor();
     1280                        // Display a message if the color has changed to transparent
     1281                        if (currentFrame.getBackgroundColor() == null)
     1282                                FrameGraphics
     1283                                                .DisplayMessage("Background color is now transparent");
     1284                        FrameGraphics.Repaint();
    12251285                        return;
    12261286                } else {
     
    12381298                // if we didnt find the color on the wheel
    12391299                if (color == null) {
    1240                         color = DisplayIO.getCurrentFrame().getItemTemplate().getColor();
     1300                        FrameGraphics.DisplayMessage("Color is set to default");
    12411301                }
    12421302
     
    12481308                        toSet.setColor(color);
    12491309                        toSet.getParent().setChanged(true);
    1250 
    1251                 }
    1252 
     1310                }
    12531311                FrameGraphics.Repaint();
    12541312        }
     
    12721330                        return;
    12731331                }
    1274 
    12751332                toToggle.setAnnotation(!toToggle.isAnnotation());
     1333
    12761334                toToggle.getParent().setChanged(true);
    12771335                FrameGraphics.Repaint();
     
    13641422                                Text textItem = (Text) toAdd;
    13651423
    1366                                 String text = textItem.getTextNoList();
     1424                                String text = textItem.getText();
    13671425
    13681426                                // check if the default date has already been put on this item
     
    14021460                                } else {
    14031461                                        for (int i = 0; i < date1.length(); i++) {
    1404                                                 processChar(date1.charAt(i));
     1462                                                processChar(date1.charAt(i), false);
    14051463                                        }
    14061464                                }
     
    14621520                        Frame linkTo = FrameIO.CreateNewFrameset(text.getFirstLine());
    14631521                        DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    1464                         text.setLink(linkTo.getFrameName());
     1522                        text.setLink(linkTo.getName());
    14651523                        text.getParent().setChanged(true);
    14661524                        FrameUtils.DisplayFrame(linkTo, true);
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r78 r80  
    439439                                Item i = Frame.getItemAttachedToCursor();
    440440                                if (i != null && i instanceof Text) {
    441                                         lastRanged.replaceSelectedText(((Text) i).getTextNoList());
     441                                        lastRanged.replaceSelectedText(((Text) i).getText());
    442442                                        Frame.FreeItems.clear();
    443443                                } else
     
    507507
    508508                // if the user is cropping an image
    509                 if (clickedOn != null && clickedOn == _lastCropped
    510                                 && _lastCropped.getCroppedSize() > 0) {
    511                         Picture cropped = _lastCropped.copy();
    512                         cropped.setParent(null);
    513                         pickup(cropped);
    514 
    515                 }
    516 
    517                 // if the user has cropped an imate, either the above happend or this is
     509                if (clickedOn != null && clickedOn == _lastCropped) {
     510                        if (_lastCropped.isCropTooSmall()) {
     511                                _lastCropped = null;
     512                                // FrameGraphics
     513                                // .WarningMessage("Crop cancelled because it was below the
     514                                // minimum size");
     515                        } else {
     516                                Picture cropped = _lastCropped.copy();
     517                                cropped.setParent(null);
     518                                pickup(cropped);
     519                        }
     520                }
     521
     522                // if the user has cropped an image, either the above happend or this is
    518523                // a no-op
    519                 if (_lastCropped != null && _lastCropped.getCroppedSize() > 0) {
     524                if (_lastCropped != null) {
    520525                        _lastCropped.clearCropping();
    521526                        _lastCropped = null;
     
    570575
    571576                if (clicked instanceof Text) {
    572                         if (((Text) clicked).getTextNoList().length() == 0)
     577                        if (((Text) clicked).getText().length() == 0)
    573578                                clicked = null;
    574579                }
     
    681686                                if (clicked.Permission < Item.PERMISSION_FULL
    682687                                                && clicked.getParent() != null
    683                                                 && clicked.getParent().getFrameNameItem() != clicked) {
     688                                                && clicked.getParent().getNameItem() != clicked) {
    684689                                        FrameGraphics.DisplayMessage("Insufficient permission");
    685690                                        return;
     
    862867                                // check permissions
    863868                                if (clicked.Permission < Item.PERMISSION_FULL
    864                                                 && clicked.getParent().getFrameNameItem() != clicked) {
     869                                                && clicked.getParent().getNameItem() != clicked) {
    865870                                        FrameGraphics
    866871                                                        .DisplayMessage("Insufficient permission to merge items");
     
    12551260                        LastRobotX = null;
    12561261                        LastRobotY = null;
    1257                         //System.out.println("RobotTimer");
     1262                        // System.out.println("RobotTimer");
    12581263                }
    12591264        });
     
    15081513        }
    15091514
    1510         private static void move(List<Item> toMove) {
     1515        private static void move(Collection<Item> toMove) {
    15111516
    15121517                // Gets the origin of the first item to move
    15131518                int xPos = (DisplayIO.getMouseX() - _offX);
    15141519
    1515                 Item firstDot = toMove.get(0);
     1520                Item firstDot = toMove.iterator().next();
    15161521
    15171522                int deltax = firstDot.getX() - xPos;
     
    15651570                Frame next = FrameIO.CreateNewFrame(linker);
    15661571
    1567                 linker.setLink("" + next.getFrameNumber());
     1572                linker.setLink("" + next.getNumber());
    15681573
    15691574                for (Item i : next.getBodyTextItems(true)) {
    15701575                        // Set the link for @Parent annotation item if one
    1571                         if (ItemUtils.isTag(i, ItemUtils.TAG_PARENT) && i.getLink() == null) {
     1576                        if (ItemUtils.startsWithTag(i, ItemUtils.TAG_PARENT)
     1577                                        && i.getLink() == null) {
    15721578                                Frame parent = linker.getParentOrCurrentFrame();
    1573                                 i.setLink(parent.getFrameName());
    1574                         } else if (ItemUtils.isTag(i, ItemUtils.TAG_BACKUP, false)) {
     1579                                i.setLink(parent.getName());
     1580                        } else if (ItemUtils.startsWithTag(i, ItemUtils.TAG_BACKUP, false)) {
    15751581                                // Delink backup tag if it is on the frame
    15761582                                i.setLink(null);
     
    16311637                // check if the user is pointing at the frame's framename
    16321638                if (toDelete != null
    1633                                 && toDelete == DisplayIO.getCurrentFrame().getFrameNameItem()) {
     1639                                && toDelete == DisplayIO.getCurrentFrame().getNameItem()) {
    16341640                        DisplayIO.getCurrentFrame().clear();
    16351641                        FrameGraphics.Repaint();
     
    16541660                                SessionStats.DeletedItem(free);
    16551661                                // List<String> temp = anchored.getText();
    1656                                 anchored.setTextList(free.getText());
     1662                                anchored.setTextList(free.getTextList());
    16571663
    16581664                                // free.setTextList(temp);
     
    16801686
    16811687                        if (items != null) {
    1682                                 List<Item> toRemove = new ArrayList<Item>(items.size());
     1688                                Collection<Item> toRemove = new LinkedHashSet<Item>(items
     1689                                                .size());
    16831690                                for (Item ip : items) {
    16841691                                        if (ip.Permission >= Item.PERMISSION_FULL) {
     
    17191726                        current.setChanged(true);
    17201727
    1721                         List<Item> toUndo = null;
     1728                        Collection<Item> toUndo = null;
    17221729                        if (toDelete.isLineEnd()) {
    17231730                                toUndo = deleteLineEnd(toDelete);
     
    17371744        }
    17381745
    1739         private static void deleteItems(List<Item> itemList) {
     1746        private static void deleteItems(Collection<Item> itemList) {
    17401747                SessionStats.DeletedItems(itemList);
    17411748                List<Frame> modifiedFrames = new LinkedList<Frame>();
     
    17461753                                modifiedFrames.add(parent);
    17471754                }
    1748 
    1749                 List<Item> toUndo = new LinkedList<Item>();
    1750                 List<Item> seen = new LinkedList<Item>();
    1751 
     1755                // If they are all free items then add the current frame
     1756                if (modifiedFrames.size() == 0) {
     1757                        modifiedFrames.add(DisplayIO.getCurrentFrame());
     1758                }
     1759
     1760                Collection<Item> toUndo = new LinkedHashSet<Item>();
    17521761                // disconnect any connected items
    17531762                for (Item i : itemList) {
    17541763                        if (i.getLines().size() > 0) {
    1755                                 List<Item> copy = deleteLineEnd(i);
     1764                                Collection<Item> toDelete = deleteLineEnd(i);
    17561765                                // add the copied items to the undo stack
    1757                                 for (Item cop : copy)
    1758                                         if (!toUndo.contains(cop))
    1759                                                 toUndo.add(cop);
    1760                         } else {
    1761                                 if (!seen.contains(i))
    1762                                         toUndo.addAll(copy(i));
    1763                         }
    1764                         seen.add(i);
     1766                                for (Item itemToUndo : toDelete)
     1767                                        if (!toUndo.contains(itemToUndo))
     1768                                                toUndo.add(itemToUndo);
     1769                        } else if (!toUndo.contains(i)) {
     1770                                toUndo.add(i); // Why was is this a copy
     1771                        }
    17651772                }
    17661773                for (Frame f : modifiedFrames) {
     
    17741781        }
    17751782
    1776         private static List<Item> deleteLineEnd(Item lineEnd) {
     1783        private static Collection<Item> deleteLineEnd(Item lineEnd) {
    17771784
    17781785                if (lineEnd instanceof WidgetCorner) { // Brook
     
    17951802                } else {
    17961803
    1797                         // create a backup copy of the dot
    1798                         List<Item> copy = copy(lineEnd.getConnected());
    1799                         // Remove lines from their anchored dots
    1800                         // note: the line is kept so that it can be properly restored
    1801                         for (Item ic : copy) {
    1802                                 if (ic instanceof Line) {
    1803                                         Line line = (Line) ic;
    1804                                         // Remove the line from the item that is not the copy of the
    1805                                         // line end being deletedF
    1806                                         if (!copy.contains(line.getStartItem()))
    1807                                                 line.getStartItem().removeLine(line);
    1808                                         if (!copy.contains(line.getEndItem()))
    1809                                                 line.getEndItem().removeLine(line);
    1810                                 }
    1811                         }
     1804                        // // create a backup copy of the dot and its lines
     1805                        // List<Item> copy = copy(lineEnd.getConnected());
     1806                        //                     
     1807                        // // Remove lines from their anchored dots
     1808                        // // note: the line is kept so that it can be properly restored
     1809                        // for (Item ic : copy) {
     1810                        // if (ic instanceof Line) {
     1811                        // Line line = (Line) ic;
     1812                        // // Remove the line from the item that is not the copy of the
     1813                        // // line end being deletedF
     1814                        // if (!copy.contains(line.getStartItem()))
     1815                        // line.getStartItem().removeLine(line);
     1816                        // if (!copy.contains(line.getEndItem()))
     1817                        // line.getEndItem().removeLine(line);
     1818                        // }
     1819                        // }
     1820
     1821                        Collection<Item> copy = lineEnd.getConnected();
    18121822
    18131823                        // remove all lines being deleted
     
    18521862
    18531863        public static Collection<Item> merge(List<Item> merger, Item mergee) {
    1854                 if (mergee.getParent().getFrameNameItem() == mergee) {
     1864                if (mergee.getParent().getNameItem() == mergee) {
    18551865                        return mergee.getParent().merge(merger);
    18561866                }
     
    19251935                                                // set mouse position for text merges
    19261936                                                if (mergee instanceof Text)
    1927                                                         ((Text) mergee).insertText(txt.getTextNoList(),
    1928                                                                         DisplayIO.getMouseX(), DisplayIO
    1929                                                                                         .getMouseY());
     1937                                                        ((Text) mergee).insertText(txt.getText(), DisplayIO
     1938                                                                        .getMouseX(), DisplayIO.getMouseY());
    19301939
    19311940                                                else if (mergee instanceof Dot) {
     
    19541963                                        }
    19551964                                } else {
    1956                                         if (mergee instanceof Dot || mergee instanceof Text){
     1965                                        if (mergee instanceof Dot || mergee instanceof Text) {
    19571966                                                DisplayIO.setCursorPosition(mergee.getPosition());
    19581967                                        }
     
    19841993                if (toGrab.isFrameName())
    19851994                        return;
    1986                
     1995
    19871996                if (toGrab.Permission < Item.PERMISSION_FULL) {
    19881997                        FrameGraphics
     
    20082017        public static void pickup(Collection<Item> toGrab) {
    20092018
    2010                 String currentFrame = DisplayIO.getCurrentFrame().getFrameName();
     2019                String currentFrame = DisplayIO.getCurrentFrame().getName();
    20112020                Iterator<Item> iter = toGrab.iterator();
    20122021                while (iter.hasNext()) {
     
    20222031                        if (i.getParent() != null) {
    20232032                                i.getParent().removeItem(i);
    2024                                 if (currentFrame.equals(i.getParent().getFrameName()))
     2033                                if (currentFrame.equals(i.getParent().getName()))
    20252034                                        i.setParent(null);
    20262035                        }
     
    20572066                                        + soleItem.getOffset().x;
    20582067                        _offY = MouseY - soleItem.getY() + soleItem.getOffset().y;
     2068                        // Now call move so that if we are on a message in the message box
     2069                        // It doesnt appear up the top of the scree!!
     2070                        move(toGrab);
    20592071                } else {
    20602072                        FrameGraphics
     
    20792091
    20802092                return line;
    2081         }
    2082 
    2083         private static List<Item> copy(Item toCopy) {
    2084                 return copy(toCopy.getConnected());
    20852093        }
    20862094
     
    21612169                } else if (arg0.getWheelRotation() != 0 && arg0.isShiftDown()) {
    21622170
    2163                         int rotationType = FrameKeyboardActions.SIZE_UP;
     2171                        FunctionKey rotationType = FunctionKey.SizeUp;
    21642172                        if (arg0.getWheelRotation() > 0) {
    2165                                 rotationType = FrameKeyboardActions.SIZE_DOWN;
     2173                                rotationType = FunctionKey.SizeDown;
    21662174                        }
    21672175
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r78 r80  
    9090                        return false;
    9191
    92                 if (bullet1 == "" || bullet2 == "")
     92                if (bullet1.equals("") || bullet2.equals(""))
    9393                        return false;
    9494
     
    107107
    108108        private static boolean needsRenumbering(String s) {
    109                 if (s == null || s == "")
     109                if (s == null || s.equals(""))
    110110                        return false;
    111111                if (!Character.isLetterOrDigit(s.charAt(0)))
     
    152152                if (above != null && curr.isNormalTextItem(above))
    153153                        lastBullet = FrameKeyboardActions.getAutoBullet(((Text) above)
    154                                         .getTextNoList());
     154                                        .getText());
    155155                else {
    156156                        lastBullet = FrameKeyboardActions.getBullet(((Text) toAlign.get(0))
    157                                         .getTextNoList());
     157                                        .getText());
    158158                }
    159159                if (needsRenumbering(lastBullet)) {
     
    164164                                Text currentText = ((Text) toAlign.get(i));
    165165                                String currentBullet = FrameKeyboardActions
    166                                                 .getAutoBullet(currentText.getTextNoList());
     166                                                .getAutoBullet(currentText.getText());
    167167
    168168                                if (sameBulletType(lastBullet, currentBullet)) {
    169169                                        currentText.stripFirstWord();
    170170
    171                                         currentText.setText(lastBullet
    172                                                         + currentText.getTextNoList());
     171                                        currentText.setText(lastBullet + currentText.getText());
    173172                                        lastBullet = FrameKeyboardActions.getAutoBullet(currentText
    174                                                         .getTextNoList());
     173                                                        .getText());
    175174                                }
    176175                        }
     
    183182                // if we are dropping from the title make the space a little bigger
    184183                // than normal
    185                 if (above != curr.getTitle() && above != null) {
     184                if (above != curr.getTitleItem() && above != null) {
    186185                        // Make the gap between all items the same as the gap between
    187186                        // the first two
     
    192191                                space = MINIMUM_INTERITEM_SPACING;
    193192
    194                         if (above != curr.getFrameNameItem() && above != curr.getTitle())
     193                        if (above != curr.getNameItem() && above != curr.getTitleItem())
    195194                                x = above.getX();
    196195
     
    481480                return true;
    482481        }
    483        
     482
    484483        private static boolean createFrameBitmap(Frame frame, Text txt) {
    485484                if (txt.getLink() == null)
     
    558557                        return;
    559558
    560                 UserSettings.TitleTemplate = profile.getTitle();
     559                UserSettings.TitleTemplate = profile.getTitleItem();
    561560
    562561                List<Item> items = profile.getItems();
     
    564563                // check for all tags setting user values
    565564                for (Item item : items) {
    566                         if (ItemUtils.isTag(item, "@HomeFrame:")) {
     565                        if (ItemUtils.startsWithTag(item, "@HomeFrame")) {
    567566                                String first = getLink(item, UserSettings.FirstFrame);
    568567                                // do not use non-existant frames as the first frame
     
    574573                                        FrameGraphics.WarningMessage("Home frame: " + first
    575574                                                        + " is not a valid frame.");
    576                                         UserSettings.FirstFrame = profile.getFrameName();
    577                                 }
    578                         } else if (ItemUtils.isTag(item, "@MenuFrame:"))
     575                                        UserSettings.FirstFrame = profile.getName();
     576                                }
     577                        } else if (ItemUtils.startsWithTag(item, "@MenuFrame"))
    579578                                UserSettings.MenuFrame = getLink(item, UserSettings.MenuFrame);
    580                         else if (ItemUtils.isTag(item, "@DefaultFrame:"))
     579                        else if (ItemUtils.startsWithTag(item, "@DefaultFrame"))
    581580                                UserSettings.DefaultFrame = getLink(item,
    582581                                                UserSettings.DefaultFrame);
    583                         else if (ItemUtils.isTag(item, "@AntiAlias:"))
     582                        else if (ItemUtils.startsWithTag(item, "@AntiAlias"))
    584583                                UserSettings.AntiAlias = getBoolean(item,
    585584                                                UserSettings.AntiAlias);
    586                         else if (ItemUtils.isTag(item, "@Gravity:"))
     585                        else if (ItemUtils.startsWithTag(item, "@Gravity"))
    587586                                UserSettings.Gravity = getInt(item, UserSettings.Gravity);
    588                         else if (ItemUtils.isTag(item, "@ShowLineHighlight:"))
     587                        else if (ItemUtils.startsWithTag(item, "@ShowLineHighlight"))
    589588                                UserSettings.LineHighlight = getBoolean(item,
    590589                                                UserSettings.LineHighlight);
    591                         else if (ItemUtils.isTag(item, "@LineStraightenThreshold:"))
     590                        else if (ItemUtils.startsWithTag(item, "@LineStraightenThreshold"))
    592591                                UserSettings.LineStraightenThreshold = getInt(item,
    593592                                                UserSettings.LineStraightenThreshold);
    594                         else if (ItemUtils.isTag(item, "@NoOpThreshold:"))
     593                        else if (ItemUtils.startsWithTag(item, "@NoOpThreshold"))
    595594                                UserSettings.NoOpThreshold = getInt(item,
    596595                                                UserSettings.NoOpThreshold);
    597                         else if (ItemUtils.isTag(item, "@InitialWidth:")) {
     596                        else if (ItemUtils.startsWithTag(item, "@InitialWidth")) {
    598597                                UserSettings.InitialWidth = getInt(item,
    599598                                                UserSettings.InitialWidth);
    600                         } else if (ItemUtils.isTag(item, "@InitialHeight:")) {
     599                        } else if (ItemUtils.startsWithTag(item, "@InitialHeight")) {
    601600                                UserSettings.InitialHeight = getInt(item,
    602601                                                UserSettings.InitialHeight);
    603                         } else if (ItemUtils.isTag(item, "@TitlePosition:")) {
     602                        } else if (ItemUtils.startsWithTag(item, "@TitlePosition")) {
    604603                                UserSettings.TitlePosition = getInt(item,
    605604                                                UserSettings.TitlePosition);
    606                         } else if (ItemUtils.isTag(item, "@Logging:")) {
     605                        } else if (ItemUtils.startsWithTag(item, "@Logging")) {
    607606                                UserSettings.Logging = getBoolean(item, UserSettings.Logging);
    608                         } else if (ItemUtils.isTag(item, ItemUtils.TAG_ITEM_TEMPLATE)) {
     607                        } else if (ItemUtils.startsWithTag(item,
     608                                        ItemUtils.TAG_ITEM_TEMPLATE)) {
    609609                                UserSettings.ItemTemplate = ((Text) item).getTemplateForm();
    610                         } else if (ItemUtils.isTag(item, ItemUtils.TAG_ANNOTATION_TEMPLATE)) {
     610                        } else if (ItemUtils.startsWithTag(item,
     611                                        ItemUtils.TAG_ANNOTATION_TEMPLATE)) {
    611612                                UserSettings.AnnotationTemplate = ((Text) item)
    612613                                                .getTemplateForm();
    613                         } else if (ItemUtils.isTag(item, ItemUtils.TAG_STAT_TEMPLATE)) {
     614                        } else if (ItemUtils.startsWithTag(item,
     615                                        ItemUtils.TAG_STAT_TEMPLATE)) {
    614616                                UserSettings.StatTemplate = ((Text) item).getTemplateForm();
    615                         } else if (ItemUtils.isTag(item,
     617                        } else if (ItemUtils.startsWithTag(item,
    616618                                        ItemUtils.TAG_CODE_COMMENT_TEMPLATE)) {
    617619                                UserSettings.CodeCommentTemplate = ((Text) item)
    618620                                                .getTemplateForm();
    619                         } else if (ItemUtils.isTag(item, ItemUtils.TAG_LINE_TEMPLATE)) {
     621                        } else if (ItemUtils.startsWithTag(item,
     622                                        ItemUtils.TAG_LINE_TEMPLATE)) {
    620623                                UserSettings.LineTemplate = ((Text) item).getTemplateForm();
    621                         } else if (ItemUtils.isTag(item, "@FramesetDir:")) {
     624                        } else if (ItemUtils.startsWithTag(item, "@FramesetDir")) {
    622625                                String dir = getDir(item, null);
    623626                                if (dir != null)
    624627                                        UserSettings.FrameDirs.add(dir);
    625                         } else if (ItemUtils.isTag(item, "@LogDir:")) {
     628                        } else if (ItemUtils.startsWithTag(item, "@LogDir")) {
    626629                                org.expeditee.gui.FrameIO.LOGS_DIR = getDir(item,
    627630                                                org.expeditee.gui.FrameIO.LOGS_DIR);
    628                         } else if (ItemUtils.isTag(item, "@ImageDir:")) {
     631                        } else if (ItemUtils.startsWithTag(item, "@ImageDir")) {
    629632                                String dir = getDir(item, null);
    630633                                if (dir != null)
    631634                                        UserSettings.ImageDirs.add(0, dir);
    632                         } else if (ItemUtils.isTag(item, "@Threading:")) {
     635                        } else if (ItemUtils.startsWithTag(item, "@Threading")) {
    633636                                UserSettings.Threading = getBoolean(item,
    634637                                                UserSettings.Threading);
    635                         } else if (ItemUtils.isTag(item, "@ColorWheel")) {
     638                        } else if (ItemUtils.startsWithTag(item, "@ColorWheel")) {
    636639                                Item.COLOR_WHEEL = getColorWheel(item);
    637                         } else if (ItemUtils.isTag(item, "@BackgroundColorWheel")) {
     640                        } else if (ItemUtils.startsWithTag(item, "@FillColorWheel")) {
    638641                                Item.FILL_COLOR_WHEEL = getColorWheel(item);
    639                         } else if (ItemUtils.isTag(item, "@FramesetDirs")) {
     642                        } else if (ItemUtils.startsWithTag(item, "@BackgroundColorWheel")) {
     643                                Frame.COLOR_WHEEL = getColorWheel(item);
     644                        } else if (ItemUtils.startsWithTag(item, "@FramesetDirs")) {
    640645                                UserSettings.FrameDirs.addAll(getDirs(item));
    641646                        }
     
    643648
    644649                if (UserSettings.FirstFrame == null)
    645                         UserSettings.FirstFrame = profile.getFrameName();
     650                        UserSettings.FirstFrame = profile.getName();
    646651                else {
    647652                        if (FrameIO.LoadFrame(UserSettings.FirstFrame) == null) {
    648653                                FrameGraphics.WarningMessage("Home frame: "
    649654                                                + UserSettings.FirstFrame + " could not be found.");
    650                                 UserSettings.FirstFrame = profile.getFrameName();
     655                                UserSettings.FirstFrame = profile.getName();
    651656                        }
    652657                }
     
    660665                        if (child != null) {
    661666                                List<Text> textItems = child.getBodyTextItems(true);
    662                                 Color[] colorList = new Color[textItems.size()];
     667                                Color[] colorList = new Color[textItems.size() + 1];
    663668                                for (int i = 0; i < textItems.size(); i++) {
    664669                                        colorList[i] = textItems.get(i).getColor();
    665670                                }
     671                                // Make the last item transparency or default for forecolor
     672                                colorList[colorList.length - 1] = null;
     673
    666674                                return colorList;
    667675                        }
    668676                }
    669                 return new Color[] { Color.black, Color.white };
     677                return new Color[] { Color.black, Color.white, null};
    670678        }
    671679
     
    674682                        return alt;
    675683
    676                 String value = AttributeUtils.stripValue(((Text) item).getFirstLine())
     684                String value = AttributeUtils.getValue(((Text) item).getFirstLine())
    677685                                .trim();
    678686                if (value.length() > 0) {
     
    689697                        return alt;
    690698
    691                 String value = AttributeUtils.stripValue(((Text) item).getFirstLine())
     699                String value = AttributeUtils.getValue(((Text) item).getFirstLine())
    692700                                .trim().toLowerCase();
    693701                if (value != null && value.length() > 0) {
     
    709717                        return alt;
    710718
    711                 String value = AttributeUtils.stripValue(((Text) item).getFirstLine())
     719                String value = AttributeUtils.getValue(((Text) item).getFirstLine())
    712720                                .trim().toLowerCase();
    713721                try {
     
    741749                        if (dirListFrame != null) {
    742750                                for (Text t : dirListFrame.getBodyTextItems(false)) {
    743                                         String dirName = t.getTextNoList().trim();
     751                                        String dirName = t.getText().trim();
    744752                                        File tester = new File(dirName);
    745753                                        if (tester.exists() && tester.isDirectory()) {
     
    767775                        return alt;
    768776
    769                 String value = AttributeUtils.stripValue(((Text) item).getFirstLine())
     777                String value = AttributeUtils.getValue(((Text) item).getFirstLine())
    770778                                .trim();
    771779                if (value != null && value.length() > 0)
     
    835843                        try {
    836844                                i.Permission = permissionLevel;
    837                                 if (ItemUtils.isTag(i, ItemUtils.TAG_POINTTYPE)) {
     845                                if (ItemUtils.startsWithTag(i, ItemUtils.TAG_POINTTYPE)) {
    838846                                        Text txt = (Text) i;
    839847                                        String line = txt.getFirstLine();
     
    860868                                // check for Images and widgets
    861869                                if (!FrameGraphics.isXRayMode()) {
    862                                         if (ItemUtils.isTag(i, ItemUtils.TAG_IMAGE))
     870                                        if (ItemUtils.startsWithTag(i, ItemUtils.TAG_IMAGE))
    863871                                                createPicture(toParse, (Text) i);
    864872                                        // check for frame images
    865                                         else if (i.getLink() != null && !i.getAbsoluteLink().equalsIgnoreCase(toParse.getFrameName())){
    866                                                 if(ItemUtils.isTag(i, ItemUtils.TAG_FRAME_IMAGE)){
     873                                        else if (i.getLink() != null
     874                                                        && !i.getAbsoluteLink().equalsIgnoreCase(
     875                                                                        toParse.getName())) {
     876                                                if (ItemUtils.startsWithTag(i,
     877                                                                ItemUtils.TAG_FRAME_IMAGE)) {
    867878                                                        createFramePicture(toParse, (Text) i);
    868                                                 }else if (ItemUtils.isTag(i, ItemUtils.TAG_BITMAP_IMAGE)){
     879                                                } else if (ItemUtils.startsWithTag(i,
     880                                                                ItemUtils.TAG_BITMAP_IMAGE)) {
    869881                                                        createFrameBitmap(toParse, (Text) i);
    870882                                                }
    871883                                        }
    872884                                        // Check for interactive widgets
    873                                         else if (ItemUtils.isTag(i, ItemUtils.TAG_IWIDGET)) {
     885                                        else if (ItemUtils.startsWithTag(i, ItemUtils.TAG_IWIDGET)) {
    874886                                                createWidget(toParse, (Text) i);
    875887                                        }
     
    877889
    878890                                // check for new VECTOR items
    879                                 if (ItemUtils.isTag(i, ItemUtils.TAG_VECTOR)
     891                                if (ItemUtils.startsWithTag(i, ItemUtils.TAG_VECTOR)
    880892                                                && i.getLink() != null) {
    881893                                        Frame vector = FrameIO.LoadFrame(i.getAbsoluteLink());
    882894                                        if (vector != null) {
    883                                                 String scaleString = ItemUtils.StripTag(((Text) i)
    884                                                                 .getFirstLine());
     895                                                String scaleString = AttributeUtils.getValue(((Text) i)
     896                                                                .getText());
    885897                                                Float scale = 1F;
    886898                                                try {
     
    893905
    894906                                // check for new OVERLAY items
    895                                 if (ItemUtils.isTag(i, ItemUtils.TAG_OVERLAY)
     907                                if (ItemUtils.startsWithTag(i, ItemUtils.TAG_OVERLAY)
    896908                                                && i.getLink() != null) {
    897909                                        Frame overlay = FrameIO.LoadFrame(i.getAbsoluteLink());
     
    903915
    904916                                // check for ACTIVE_OVERLAY items
    905                                 if (ItemUtils.isTag(i, ItemUtils.TAG_ACTIVE_OVERLAY)
     917                                if (ItemUtils.startsWithTag(i, ItemUtils.TAG_ACTIVE_OVERLAY)
    906918                                                && i.getLink() != null) {
    907919                                        String link = i.getAbsoluteLink();
     
    909921                                        // Parse(overlay);
    910922                                        // get level if specified
    911                                         String level = ItemUtils
    912                                                         .StripTag(((Text) i).getFirstLine());
     923                                        String level = AttributeUtils.getValue(((Text) i)
     924                                                        .getFirstLine());
    913925                                        // default permission (if none is specified)
    914926                                        int permission = getPermissionLevel(level,
     
    955967                                        // remove Text that is all whitespace
    956968                                        if (i instanceof Text) {
    957                                                 List<String> text = ((Text) i).getText();
     969                                                List<String> text = ((Text) i).getTextList();
    958970                                                // remove empty text items
    959971                                                if (text == null || text.size() == 0)
     
    10831095                        ArrayList<Item> checkList = new ArrayList<Item>();
    10841096                        checkList.addAll(toCheck.getItems());
    1085                         checkList.add(toCheck.getFrameNameItem());
     1097                        checkList.add(toCheck.getNameItem());
    10861098                        for (Item i : checkList) {
    10871099                                // do not check annotation items in audience mode
     
    10891101                                        if (i.contains(x, y) && !Frame.FreeItems.contains(i)) {
    10901102                                                // names have copy permissions only
    1091                                                 if (i == toCheck.getFrameNameItem()) {
     1103                                                if (i == toCheck.getNameItem()) {
    10921104                                                        // i.Permission = Item.PERMISSION_TDFC;
    10931105                                                        possibles.add(i);
     
    11361148                                        + Math.pow(Math.abs(i.getY() - y), 2)));
    11371149
    1138                         //System.out.println(d);
     1150                        // System.out.println(d);
    11391151                        if (d <= distance) {
    11401152                                distance = d;
     
    12921304         */
    12931305        public static void CreateDefaultProfile(Frame profile) {
    1294                 Text title = profile.getTitle();
     1306                Text title = profile.getTitleItem();
    12951307                title.setText("Profile Frame");
    12961308                title.setSize(50);
     
    13061318
    13071319                yPos += spacing;
    1308                 profile.addText(xPos, yPos, "@HomeFrame: " + profile.getFrameName(),
    1309                                 null, profile.getFrameName());
     1320                profile.addText(xPos, yPos, "@HomeFrame: " + profile.getName(), null,
     1321                                profile.getName());
    13101322                yPos += spacing;
    13111323                String defaultFrameName = profile.getFramesetName() + "0";
     
    13681380                                                t = profile.addText(xPos, yPos, indexFrame
    13691381                                                                .getFramesetName(), null);
    1370                                                 t.setLink(indexFrame.getFrameName());
     1382                                                t.setLink(indexFrame.getName());
    13711383                                        }
    13721384                                }
  • trunk/src/org/expeditee/gui/UserSettings.java

    r78 r80  
    66import java.util.List;
    77
    8 import org.expeditee.items.Item;
    98import org.expeditee.items.Text;
    109
  • trunk/src/org/expeditee/io/Conversion.java

    r72 r80  
    1212import org.expeditee.items.Item;
    1313import org.expeditee.items.Text;
     14import org.junit.Assert;
    1415
    1516/**
    1617 * This class provides various methods for converting values to\from Java
    17  * objects and KMS file values.
     18 * objects and Expeditee file values.
    1819 *
    1920 * @author jdm18
     
    2223public class Conversion {
    2324
    24 private static final int PERCENT_MAX = 100;
    25 private static final int RGB_MAX = 255;
    26 private static final double RGB_CONVERSION_FACTOR = 2.55;
    27 
    28         /**
    29          * Returns the Color corresponding to the given KMS color code. For example:
    30          * <br>
     25        public static final int RGB_MAX = 255;
     26
     27        private static final float RGB_CONVERSION_FACTOR = 2.55F;
     28
     29        /**
     30         * Returns the Color corresponding to the given Expeditee color code. For
     31         * example: <br>
    3132         * green4 = 0% red, 40% green, 0% blue.
    3233         *
    3334         * @param colorCode
    34          *            The KMS color code to convert
     35         *            The Expeditee color code to convert
    3536         * @return The Color object corresponding to the given code
    3637         */
    3738        public static Color getColor(String colorCode, Color current) {
    38                 if (colorCode == null || colorCode.equals("null")
    39                                 || colorCode.equals("none")) {
    40                         return current;
    41                 }
     39                if (colorCode == null) {
     40                        return null;
     41                }
     42                // The if we dont do this then we end up getting black
     43                colorCode = colorCode.toLowerCase();
     44                if (colorCode.equals("null"))
     45                        return null;
    4246
    4347                // check if its a normal rgb code ie. 100 0 40
     
    6973
    7074                float color[] = { 0, 0, 0 };
    71 
    72                 if (colorCode.toLowerCase().startsWith("red"))
     75                Assert.assertTrue(color.length == 3);
     76
     77                if (colorCode.startsWith("red"))
    7378                        color[0] = amount / MAX_AMOUNT;
    74                 else if (colorCode.toLowerCase().startsWith("green"))
     79                else if (colorCode.startsWith("green"))
    7580                        color[1] = amount / MAX_AMOUNT;
    76                 else if (colorCode.toLowerCase().startsWith("blue"))
     81                else if (colorCode.startsWith("blue"))
    7782                        color[2] = amount / MAX_AMOUNT;
    7883                else
    79                         //TODO: Should we not throw an error here!
    80                         return current;
     84                        return null;
    8185
    8286                return new Color(color[0], color[1], color[2]);
     
    8488
    8589        private static Color getRGBColor(String colorCode, Color current) {
    86                 int color[] = { 0, 0, 0 };
     90                int color[] = new int[3];
     91                Assert.assertTrue(color.length == 3);
    8792
    8893                try {
    8994                        String[] values = colorCode.trim().split("\\s+");
     95                        // For now no transparency only RGB
     96                        if (values.length > color.length)
     97                                return null;
    9098
    9199                        String r = values.length > 0 ? values[0] : "0";
     
    111119
    112120        private static Integer toColorPercent(int rgb) {
     121                assert (rgb >= 0);
     122                assert (rgb <= RGB_MAX);
     123
    113124                int percent = (int) Math.round(rgb / RGB_CONVERSION_FACTOR);
    114                 if (percent > PERCENT_MAX)
    115                         percent = PERCENT_MAX;
    116                 else if (percent < 0)
    117                         percent = 0;
     125
     126                // Dont need to do the checking below because this method will always be
     127                // called with good values
     128                // if (percent > PERCENT_MAX)
     129                // percent = PERCENT_MAX;
     130                // else if (percent < 0)
     131                // percent = 0;
    118132
    119133                return percent;
     
    121135
    122136        private static Integer toRGB(int percent) {
    123                 int rgb = (int) Math.round(percent * RGB_CONVERSION_FACTOR);
     137                int rgb = Math.round(percent * RGB_CONVERSION_FACTOR);
    124138                if (rgb > RGB_MAX)
    125139                        rgb = RGB_MAX;
     
    130144        }
    131145
    132        
    133        
    134         /**
    135          * Converts the given Color object to the corresponding KMS color code
     146        /**
     147         * Converts the given Color object to the corresponding Expeditee color code
    136148         *
    137149         * @param color
    138          *            The Color to be turned into KMS color code.
    139          * @return A String containing the KMS color code, NULL if the color is
    140          *         black.
    141          */
    142         public static String getKMSColorCode(Color color) {
     150         *            The Color to be turned into Expeditee color code.
     151         * @return A String containing the Expeditee color code, NULL if the color
     152         *         is black.
     153         */
     154        public static String getExpediteeColorCode(Color color) {
    143155                if (color == null)
    144156                        return null;
     
    152164
    153165        /**
    154          * Converts the given Font to a corresponding KMS font code.
     166         * Converts the given Font to a corresponding Expeditee font code.
    155167         *
    156168         * @param font
    157169         *            The Font to convert to a code.
    158          * @return The KMS font code that corresponds to the given Font.
    159          */
    160         public static String getKMSFontCode(Font font) {
     170         * @return The Expeditee font code that corresponds to the given Font.
     171         */
     172        public static String getExpediteeFontCode(Font font) {
    161173                String code = "t";
    162174                String fontName = font.getFamily().toLowerCase();
     
    183195                        break;
    184196                }
    185                
     197
    186198                code += font.getSize();
    187199                return code;
     
    189201
    190202        /**
    191          * Converts the given KMS font code to a Font object.<br>
     203         * Converts the given Expeditee font code to a Font object.<br>
    192204         * For example: <br>
    193205         * tr16 = times, roman, 16pt
     
    198210         */
    199211        public static Font getFont(String fontCode) {
     212                assert (fontCode != null);
     213
    200214                String code = Text.FONT_WHEEL[0];
    201215
     
    229243                try {
    230244                        int size = Integer.parseInt(fontCode.substring(2));
    231                         //double dsize = size * FONT_SCALE;
    232                         //if (dsize - ((int) dsize) > FONT_ROUNDING)
    233                         //      dsize = Math.ceil(dsize);
    234 
    235                         //code += (int) dsize;
     245                        // double dsize = size * FONT_SCALE;
     246                        // if (dsize - ((int) dsize) > FONT_ROUNDING)
     247                        // dsize = Math.ceil(dsize);
     248
     249                        // code += (int) dsize;
    236250                        code += size;
    237                        
     251
    238252                        font = Font.decode(code);
    239253                } catch (NumberFormatException nfe) {
     
    264278                        }
    265279                }
    266 
    267                 try {
    268                         return Integer.parseInt(num);
    269                 } catch (NumberFormatException nfe) {
    270                         return -1;
    271                 }
     280                return Integer.parseInt(num);
    272281        }
    273282
     
    304313
    305314        /**
    306          * Converts the given KMS justification code into a int corresponding to the
    307          * constants defined in Item.
     315         * Converts the given Expeditee justification code into a int corresponding
     316         * to the constants defined in Item.
    308317         *
    309318         * @param justCode
    310          *            The KMS justification code to convert
     319         *            The Expeditee justification code to convert
    311320         * @return The resulting int corresponding to one of the constants defined
    312321         *         in Item
     
    343352        }
    344353
    345         public static String getKMSJustificationCode(int justification) {
     354        public static String getExpediteeJustificationCode(int justification) {
    346355                switch (justification) {
    347356                case Item.JUSTIFICATION_CENTER:
     
    356365                        return null;
    357366                }
    358 
    359367        }
    360368
     
    363371        }
    364372
    365         // Will convert from KMS color values to RGB...
     373        // Will convert from Expeditee color values to RGB...
    366374        public static Object Convert(Class type, String value, Object orig) {
    367375                // System.out.println("Orig: " + orig);
     376                assert (type != null);
     377
    368378                if (value == null)
    369379                        return null;
    370                 value = value.trim();
    371 
    372                 if (type == String.class
    373                                 && String.CASE_INSENSITIVE_ORDER.compare(value, "") == 0)
    374                         return null;
    375                 else if (type == String.class)
    376                         return value;
     380
     381                String fullCaseValue = value.trim();
     382                value = fullCaseValue.toLowerCase();
    377383
    378384                if (type == Font.class) {
     
    409415
    410416                        if (value.equals("null"))
    411                                 return -1;
     417                                return Item.DEFAULT_INTEGER;
    412418
    413419                        return Integer.parseInt(value);
     
    455461
    456462                if (type.equals(boolean.class)) {
    457                         value = value.toLowerCase().trim();
    458 
    459463                        if (value.equals("t") || value.equals("true")
    460464                                        || value.equals("yes") || value.equals("y")
    461465                                        || value.equals(""))
    462466                                return true;
    463 
    464                         if (value.equals("f") || value.equals("false")
    465                                         || value.equals("no") || value.equals("n"))
    466                                 return false;
    467 
    468                         return null;
    469                 }
    470 
    471                 // return name + ": " + value;
    472                 /*
    473                  * String[] val = new String[1]; val[0] = value;
    474                  */
    475                 return null;
    476 
     467                        return false;
     468
     469                }
     470
     471                if (type.equals(Point.class)) {
     472                        Point p = new Point();
     473                        String xPos = value.substring(0, value.indexOf(" "));
     474                        String yPos = value.substring(value.indexOf(" ") + 1);
     475
     476                        if (orig == null) {
     477                                p.x = Integer.parseInt(xPos.trim());
     478                                p.y = Integer.parseInt(yPos.trim());
     479                        } else {
     480                                assert (orig instanceof Point);
     481                                Point originalPoint = (Point) orig;
     482                                p.x = (Integer) Convert(int.class, xPos, originalPoint.x);
     483                                p.y = (Integer) Convert(int.class, yPos, originalPoint.y);
     484                        }
     485                        return p;
     486                }
     487
     488                assert (type == String.class);
     489                if (value.equals(""))
     490                        return null;
     491                return fullCaseValue;
    477492        }
    478493
     
    481496        }
    482497
     498        /**
     499         * Converts parameters for setting an attribute from a string form into an
     500         * object array form. The object array can then be passed when invoke the
     501         * set method via reflection.
     502         *
     503         * @param method
     504         *            a method which sets an attribute
     505         * @param value
     506         *            new value for the attribute
     507         * @param current
     508         *            current value of the attribute
     509         * @return
     510         */
    483511        public static Object[] Convert(Method method, String value, Object current) {
    484512                value = value.trim();
     
    486514                String name = method.getName();
    487515                Class[] types = method.getParameterTypes();
    488                 if (name.equals("setPosition")) {
    489                         Point[] p = new Point[1];
    490                         p[0] = new Point();
    491                         String xPos = value.substring(0, value.indexOf(" "));
    492                         String yPos = value.substring(value.indexOf(" ") + 1);
    493 
    494                         if (current == null) {
    495                                 p[0].x = Integer.parseInt(xPos);
    496                                 p[0].y = Integer.parseInt(yPos);
    497                         } else {
    498                                 assert (current instanceof Point);
    499                                 assert (p.length == 1);
    500                                 Point originalPoint = (Point) current;
    501                                 p[0].x = (Integer) Convert(int.class, xPos, originalPoint.x);
    502                                 p[0].y = (Integer) Convert(int.class, yPos, originalPoint.y);
    503                         }
    504                         return p;
    505                 }
    506 
    507                 if (name.equals("setJustification")) {
     516
     517                if (name.endsWith("Justification")) {
    508518                        Integer[] just = new Integer[1];
    509519                        just[0] = getJustification(value);
     
    515525                                return null;
    516526
    517                         Integer a = Integer
    518                                         .parseInt(value.substring(0, value.indexOf(" ")));
    519                         Double b = Double.parseDouble(value
    520                                         .substring(value.indexOf(" ") + 1));
     527                        Integer length = null;
     528                        Double ratio = null;
     529
     530                        if (current == null) {
     531                                length = getArrowLength(value);
     532                                ratio = getArrowRatio(value);
     533                        } else {
     534                                assert (current instanceof String);
     535                                int oldLength = getArrowLength(current.toString());
     536                                double oldRatio = getArrowRatio(current.toString());
     537                                length = (Integer) Convert(int.class, value.substring(0, value
     538                                                .indexOf(" ")), oldLength);
     539                                ratio = (Double) Convert(double.class, value.substring(
     540                                                value.indexOf(" ")).trim(), oldRatio);
     541                        }
    521542
    522543                        Object[] vals = new Object[2];
    523                         vals[0] = a;
    524                         vals[1] = b;
     544                        vals[0] = length;
     545                        vals[1] = ratio;
    525546                        return vals;
    526547                }
     
    537558                }
    538559
    539                 if (types.length == 1) {
    540                         Object o[] = new Object[1];
    541                         o[0] = Convert(types[0], value, current);
    542                         return o;
    543                 }
    544 
    545                 String[] val = new String[1];
    546                 val[0] = value;
    547                 return val;
    548         }
    549 
    550         public static Object ConvertToKMS(Method method, Object output) {
     560                assert (types.length == 1);
     561
     562                Object o[] = new Object[1];
     563                o[0] = Convert(types[0], value, current);
     564                return o;
     565        }
     566
     567        private static int getArrowLength(String s) {
     568                return Integer.parseInt(s.substring(0, s.indexOf(" ")));
     569        }
     570
     571        private static double getArrowRatio(String s) {
     572                return Double.parseDouble(s.substring(s.indexOf(" ")).trim());
     573        }
     574
     575        public static Object ConvertToExpeditee(Method method, Object output) {
    551576                if (output == null)
    552577                        return null;
    553578
    554                 assert(method != null);
     579                assert (method != null);
    555580
    556581                String name = method.getName();
     
    560585
    561586                if (name.endsWith("Justification"))
    562                         return getKMSJustificationCode((Integer) output);
     587                        return getExpediteeJustificationCode((Integer) output);
    563588
    564589                // strings can be returned immediately
     
    576601                // convert fonts
    577602                if (output instanceof Font)
    578                         return getKMSFontCode((Font) output);
     603                        return getExpediteeFontCode((Font) output);
    579604
    580605                // convert colors
    581606                if (output instanceof Color)
    582                         return getKMSColorCode((Color) output);
     607                        return getExpediteeColorCode((Color) output);
    583608
    584609                // covert points
  • trunk/src/org/expeditee/io/DefaultFrameWriter.java

    r67 r80  
    77import java.util.LinkedHashMap;
    88
     9import org.expeditee.agents.WriteTree;
    910import org.expeditee.gui.Frame;
    1011import org.expeditee.gui.FrameIO;
     
    4243
    4344                try {
    44                         _FrameTags.put("A", Frame.class.getMethod("getFrameName", param));
     45                        _FrameTags.put("A", Frame.class.getMethod("getName", param));
    4546                        _FrameTags.put("V", Frame.class.getMethod("getVersion", param));
    4647                        _FrameTags.put("p", Frame.class.getMethod("getProtection", param));
     
    8889                        _ItemTags.put("f", Text.class.getMethod("getFont", param));
    8990                        _ItemTags.put("t", Text.class.getMethod("getSpacing", param));
    90                         _ItemTags.put("T", Text.class.getMethod("getText", param));
     91                        _ItemTags.put("T", Text.class.getMethod("getTextList", param));
    9192
    9293                        _ItemTags.put("a", Text.class.getMethod("getWordSpacing", param));
     
    125126        }
    126127
     128        /**
     129         * Called before writing out the body items of each frame.
     130         * @param starting the name of the frame currently being written out.
     131         * @throws IOException
     132         */
    127133        protected void writeStartFrame(Frame starting) throws IOException {
    128                 if (starting.getTitle() != null) {
    129                         if (starting.getTitle().isAnnotation())
    130                                 this.writeAnnotationTitle(starting.getTitle());
     134                if (starting.getTitleItem() != null) {
     135                        if (starting.getTitleItem().isAnnotation())
     136                                this.writeAnnotationTitle(starting.getTitleItem());
    131137                        else
    132                                 this.writeTitle(starting.getTitle(), starting.getItems());
    133                 }
    134         }
    135 
     138                                this.writeTitle(starting.getTitleItem(), starting.getItems());
     139                }
     140        }
     141
     142        /**
     143         * Called after writing out the body items of each frame.
     144         * @param ending the name of the frame currently being written out.
     145         * @throws IOException
     146         */
    136147        protected void writeEndFrame(Frame ending) throws IOException {
    137148        }
     
    139150        protected void initialise(Frame start) throws IOException {
    140151                if (_filename == null)
    141                         _filename = FrameIO.EXPORTS_DIR + start.getFrameName() + _format;
    142 
    143                 if (_filename.toLowerCase().equals("clipboard")) {
     152                        _filename = FrameIO.EXPORTS_DIR + getValidFilename(start.getTitle()) + _format;
     153
     154                if (_filename.equalsIgnoreCase(WriteTree.CLIPBOARD)) {
    144155                        _writer = new ProxyWriter(true);
    145                         _output = "Clipboard";
     156                        _output = WriteTree.CLIPBOARD;
    146157                } else {
    147158                        if (_filename.contains(File.separator)) {
     
    168179        }
    169180
     181        protected static String getValidFilename(String filename) {
     182                return filename.replaceAll("[ \\.]", "_");
     183        }
     184
    170185        protected String finalise() throws IOException {
    171186                try {
  • trunk/src/org/expeditee/io/DefaultTreeWriter.java

    r46 r80  
    99import org.expeditee.gui.FrameIO;
    1010import org.expeditee.items.Item;
     11import org.expeditee.items.Text;
    1112
    1213public abstract class DefaultTreeWriter extends DefaultFrameWriter implements
     
    1516        // the list of frames currently being processed
    1617        private Stack<FrameCounter> _frames = new Stack<FrameCounter>();
     18
    1719        private int _frameCount = 0;
    18        
     20
    1921        public int getFrameCount() {
    2022                return _frameCount;
     
    2426                try {
    2527                        initialise(toWrite);
    26 
    2728                        outputTree(toWrite);
    2829
    29                         _running = false;
    30                         return finaliseTree();
    3130                } catch (IOException ioe) {
    3231                        _running = false;
    3332                        throw ioe;
     33                } catch (Exception e) {
     34                        e.printStackTrace();
    3435                }
     36                _running = false;
     37                return finaliseTree();
    3538        }
    3639
     
    6669                        return;
    6770
    68                 _frames.push(new FrameCounter(toWrite.getFrameName(), -1));
     71                _frames.push(new FrameCounter(toWrite.getName(), -1));
    6972
    7073                // process the entire tree of frames in depth-first order
    7174                while (_frames.size() > 0) {
    7275                        FrameCounter cur = _frames.pop();
     76
     77                        if (_stop)
     78                                return;
    7379
    7480                        Frame next = FrameIO.LoadFrame(cur.frame);
     
    8591                                this.resumeFrame(next);
    8692                        } else {
    87                                 FrameGraphics.OverwriteMessage("Writing: "
    88                                                 + next.getFrameName());
    89                                 _frameCount ++;
     93                                FrameGraphics.OverwriteMessage("Writing: " + next.getName());
     94                                _frameCount++;
    9095                                writeStartFrame(next);
    9196                        }
     
    102107                                // ignore annotation and framenames
    103108                                if (item.getID() >= 0) {
    104                                         if (item.getLink() != null && !item.isAnnotation()) {
     109                                        //Only follow the links of text items
     110                                        if (item instanceof Text && item.getLink() != null
     111                                                        && !item.isAnnotation()) {
    105112                                                cur.index = i;
    106113                                                _frames.push(cur);
     
    110117                                                this.writeStartLink(item);
    111118
    112                                                 Frame linked = FrameIO.LoadFrame(item.getAbsoluteLink());
     119                                                Frame linked = FrameIO
     120                                                                .LoadFrame(item.getAbsoluteLink());
    113121
    114122                                                // if the linked frame was found, then display it next
    115123                                                if (linked != null) {
    116                                                         FrameCounter fc = new FrameCounter(linked
    117                                                                         .getFrameName(), -1);
     124                                                        FrameCounter fc = new FrameCounter(
     125                                                                        linked.getName(), -1);
    118126                                                        if (!_frames.contains(fc)) {
    119127                                                                // remember what frame we are on before
     
    127135                                                        }
    128136                                                }
    129                                         } else if (item != next.getTitle())
     137                                                // Dont write out the title here because it is written
     138                                                // out earlier
     139                                        } else if (item != next.getTitleItem())
    130140                                                this.writeItem(item);
    131141                                }
     
    160170                        if (o instanceof FrameCounter)
    161171                                return (((FrameCounter) o).frame.equals(frame));// && fc.index
    162                                                                                                                                 // == index);
     172                        // == index);
    163173
    164174                        return false;
  • trunk/src/org/expeditee/io/ExpReader.java

    r72 r80  
    6666                try {
    6767                        // Framename must be set before setting the frame number
    68                         newFrame.setFrameName(_frameName);
     68                        newFrame.setName(_frameName);
    6969
    7070                        // First read all the header lines
     
    167167                Character tag = getTag(line);
    168168                String value = getValue(line);
    169 
     169               
    170170                Method toRun = _ItemTags.get(tag);
    171171                if (toRun == null)
  • trunk/src/org/expeditee/io/ExpWriter.java

    r67 r80  
    99import java.util.List;
    1010
     11import org.expeditee.agents.DefaultAgent;
    1112import org.expeditee.gui.Frame;
    1213import org.expeditee.items.Constraint;
     
    2021
    2122/**
    22  * Writes a Frame out to a KMS format file.
     23 * Writes a Frame out to a Expeditee format file.
    2324 *
    2425 * @author jdm18
     
    4243                if (_filename == null)
    4344                        _filename = start.path + name + File.separator
    44                                         + start.getFrameNumber() + ExpReader.EXTENTION;
     45                                        + start.getNumber() + ExpReader.EXTENTION;
    4546
    4647                _stringWriter = new StringBuilder();
    47                 if (_filename.toLowerCase().equals("clipboard")) {
     48                if (_filename.equalsIgnoreCase(DefaultAgent.CLIPBOARD)) {
    4849                        _writer = new ProxyWriter(true);
    49                         _filename = "Clipboard";
     50                        _filename = DefaultAgent.CLIPBOARD;
    5051                } else
    5152                        _writer = new ProxyWriter(new FileWriter(_filename));
     
    5960
    6061        /**
    61          * Writes the given Frame (and all items it contains) to a KMS file. Note:
     62         * Writes the given Frame (and all items it contains) to a Expeditee file. Note:
    6263         * File path and location must be set before calling this or it will do
    6364         * nothing.
     
    113114                        try {
    114115                                Object o = _FrameTags.get(tag).invoke(toWrite, param);
    115                                 o = Conversion.ConvertToKMS(_FrameTags.get(tag), o);
     116                                o = Conversion.ConvertToExpeditee(_FrameTags.get(tag), o);
    116117                                if (o != null) {
    117118                                        writeLine(tag, (String) o);
     
    272273                                try {
    273274                                        Object o = toRun.invoke(toWrite, param);
    274                                         o = Conversion.ConvertToKMS(toRun, o);
     275                                        o = Conversion.ConvertToExpeditee(toRun, o);
    275276                                        if (o != null) {
    276277                                                if (o instanceof List) {
  • trunk/src/org/expeditee/io/FrameReader.java

    r74 r80  
    4040
    4141                try {
    42                         _FrameTags.put('A', Frame.class.getMethod("setFrameName", pString));
     42                        _FrameTags.put('A', Frame.class.getMethod("setName", pString));
    4343                        _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt));
    4444                        _FrameTags
     
    9494                        _ItemTags.put('t', Text.class.getMethod("setSpacing", pInt));
    9595                        _ItemTags.put('T', Text.class.getMethod("appendLine", pString));
    96 
    9796                        _ItemTags.put('a', Text.class.getMethod("setWordSpacing", pInt));
    9897                        _ItemTags.put('b', Text.class.getMethod("setLetterSpacing", pInt));
  • trunk/src/org/expeditee/io/HTMLBWriter.java

    r20 r80  
    11package org.expeditee.io;
    22
     3import java.awt.Image;
     4import java.awt.image.BufferedImage;
    35import java.io.IOException;
    46import java.util.List;
    57
    6 import org.expeditee.gui.Frame;
     8import org.expeditee.actions.Misc;
     9import org.expeditee.gui.FrameIO;
    710import org.expeditee.items.Item;
    811import org.expeditee.items.Picture;
    912import org.expeditee.items.Text;
    1013
    11 public class HTMLBWriter extends DefaultTreeWriter {
    12 
    13         private int _indent = 0;
    14 
    15         private static final String INDENT = "   ";
    16 
    17         @Override
    18         protected void initialise(Frame start) throws IOException {
    19                 _format = ".html";
    20                 super.initialise(start);
    21 
    22                 _writer.write("<HTML>" + ItemWriter.NEW_LINE);
    23                 _writer.write("<HEAD>" + ItemWriter.NEW_LINE);
    24                 _writer.write("</HEAD>" + ItemWriter.NEW_LINE);
    25                 _writer.write("<BODY>" + ItemWriter.NEW_LINE);
    26         }
    27 
    28         @Override
    29         protected String finaliseTree() throws IOException {
    30                 _writer.write("</BODY>" + ItemWriter.NEW_LINE);
    31                 return super.finaliseTree();
    32         }
    33 
    34         @Override
    35         protected void writeStartLink(Item linker) throws IOException {
    36                 _indent++;
    37         }
    38 
    39         @Override
    40         protected void writeEndLink(Item linker) throws IOException {
    41                 _indent--;
    42         }
     14public class HTMLBWriter extends AbstractHTMLWriter {
    4315
    4416        @Override
    4517        protected void writeTitle(Text toWrite, List<Item> items)
    4618                        throws IOException {
    47                 String heading = toWrite.getTextNoList();
    48                 String tag = "H" + (_indent + 1);
     19                String heading = toWrite.getText();
     20                String tag = "h" + (getIndent() + 1);
    4921                // indenting for tag
    5022                indent();
     
    5729                indent();
    5830                _writer.write("<p>");
    59                 _writer.write(text.getTextNoList().replace('\n', ' '));
     31                _writer.write(text.getText().replace('\n', ' '));
    6032                _writer.write("</p>" + ItemWriter.NEW_LINE);
    61         }
    62 
    63         private void indent() throws IOException {
    64                 for (int i = 0; i < _indent; i++)
    65                         _writer.write(INDENT);
    6633        }
    6734
    6835        @Override
    6936        protected void writePicture(Picture pic) throws IOException {
    70                 Text source = pic.getText();
     37                Image image = pic.getImage();
     38                String filesFolder = getFilesFolder();
     39                String fileName;
     40                // If its a bufferedImage then just write it out to the files directory
     41                //This means it is probably a FrameImage
     42                if (image instanceof BufferedImage) {
     43                        String link = pic.getAbsoluteLink();
     44                        // Account for the possiblitly of an unlinked buffered image
     45                        fileName = link == null ? ("Image" + pic.getID()) : link;
     46                        fileName = Misc.SaveImage((BufferedImage) image, "PNG", FrameIO.EXPORTS_DIR
     47                                        + filesFolder, fileName);
     48                } else {//It is a normal Image stored somewhere
     49                        Text source = pic.getText();
    7150
    72                 String line = source.getFirstLine();
    73                 line = line.substring(line.indexOf(":") + 1).trim();
     51                        fileName = source.getFirstLine();
     52                        fileName = fileName.substring(fileName.indexOf(":") + 1).trim();
    7453
     54                        String oldImageName = FrameIO.IMAGES_PATH + fileName;
     55                        String newImageName = FrameIO.EXPORTS_DIR + filesFolder + fileName;
     56                        try {
     57                                FrameIO.copyFile(oldImageName, newImageName);
     58                        } catch (Exception e) {
     59                                filesFolder = "";
     60                        }
     61                        if (filesFolder.equals("")) {
     62                                filesFolder = "../" + FrameIO.IMAGES_FOLDER;
     63                        }
     64                }
    7565                indent();
    76 
    77                 _writer.write("<img src = '../images/" + line + "'>");
     66                StringBuffer imageTag = new StringBuffer("<img src=\"");
     67                imageTag.append(filesFolder).append(fileName);
     68                imageTag.append("\" height=").append(pic.getHeight());
     69                imageTag.append(" width=").append(pic.getWidth());
     70                imageTag.append(" border=1>");
     71                _writer.write(imageTag.toString());
    7872                _writer.write(ItemWriter.NEW_LINE);
    7973        }
  • trunk/src/org/expeditee/io/HTMLWriter.java

    r4 r80  
    3030
    3131                Text text = (Text) linker;
    32                 List<String> toWrite = text.getText();
     32                List<String> toWrite = text.getTextList();
    3333
    3434                String first = toWrite.get(0);
     
    6767
    6868                Text text = (Text) linker;
    69                 List<String> toWrite = text.getText();
     69                List<String> toWrite = text.getTextList();
    7070
    7171                String first = toWrite.get(0);
     
    8484        @Override
    8585        protected void writeText(Text text) throws IOException {
    86                 for (String s : text.getText()) {
     86                for (String s : text.getTextList()) {
    8787
    8888                        indent();
  • trunk/src/org/expeditee/io/ItemWriter.java

    r78 r80  
    2121        }
    2222
     23        /**
     24         * Called for each item on each frame to write out the contents of the items.
     25         * @param toWrite the item to be written out.
     26         * @throws IOException
     27         */
    2328        protected void writeItem(Item toWrite) throws IOException {
    2429                if (toWrite.isAnnotation()) {
     
    7782        protected void writeDot(Item toWrite) throws IOException {
    7883        }
    79 
    80         /*
    81          * public static final String NEW_LINE =
    82          * System.getProperty("line.separator");
    83          *
    84          * protected BufferedWriter _writer = null;
    85          *
    86          * public FrameWriter(String format){}
    87          *
    88          * public String initialise(String path, String filename) throws
    89          * IOException{ if(path.charAt(path.length() - 1) != File.separatorChar)
    90          * path += File.separator;
    91          *
    92          * _writer = new BufferedWriter(new FileWriter(path.toLowerCase() +
    93          * filename.toLowerCase()));
    94          *
    95          * return filename; }
    96          *
    97          * public void initialise(Frame toWrite) throws IOException{ String name =
    98          * toWrite.getFrameset().toLowerCase(); if(name.endsWith(".")) name =
    99          * name.substring(0, name.length() - 1);
    100          *
    101          * String filepath = toWrite.path + name;
    102          *
    103          * String filename = name + "." + toWrite.getFrameNumber();
    104          *
    105          * initialise(filepath, filename); }
    106          *
    107          * public void write(Frame toWrite) throws IOException{ initialise(toWrite);
    108          *
    109          * writeFrame(toWrite);
    110          *
    111          * finalise(); }
    112          *
    113          * public void writeFrame(Frame toWrite) throws IOException{ for(Item i :
    114          * toWrite.getItems()) writeItem(i, 0); }
    115          *
    116          * public void writeItem(Item item, int indent) throws IOException{ if(item
    117          * instanceof Text) writeText((Text) item, indent);
    118          *
    119          * if(item instanceof Dot) writeDot((Dot) item);
    120          *
    121          * if(item instanceof Line) writeLine((Line) item);
    122          *
    123          * if(item instanceof Picture) writePicture((Picture) item); }
    124          *
    125          * public void writeStartLinkItem(Item item, int indent) throws IOException{ }
    126          *
    127          * public void writeEndLinkItem(Item item, int indent) throws IOException{ }
    128          *
    129          * protected void writeText(Text text, int indent) throws IOException{}
    130          *
    131          * protected void writeDot(Dot dot) throws IOException{}
    132          *
    133          * protected void writeLine(Line line) throws IOException{}
    134          *
    135          * protected void writePicture(Picture pic) throws IOException{}
    136          *
    137          * public abstract void insertLine() throws IOException;
    138          *
    139          * public abstract void indent() throws IOException;
    140          *
    141          * public void finalise() throws IOException{ _writer.flush();
    142          * _writer.close(); _writer = null; }
    143          */
    14484}
  • trunk/src/org/expeditee/io/JAVAWriter.java

    r22 r80  
    4646        protected void writeTitle(Text toWrite, List<Item> items)
    4747                        throws IOException {
    48                 String heading = toWrite.getTextNoList();
     48                String heading = toWrite.getText();
    4949
    5050                _writer.write("public class " + heading + "{" + ItemWriter.NEW_LINE);
     
    5454        protected void writeText(Text text) throws IOException {
    5555                indent();
    56                 _writer.write(text.getTextNoList().replace('\n', ' '));
     56                _writer.write(text.getText().replace('\n', ' '));
    5757                _writer.write(";" + ItemWriter.NEW_LINE);
    5858        }
  • trunk/src/org/expeditee/io/KMSReader.java

    r74 r80  
    4545
    4646                try {
    47                         _FrameTags.put("A", Frame.class.getMethod("setFrameName", pString));
     47                        _FrameTags.put("A", Frame.class.getMethod("setName", pString));
    4848                        _FrameTags.put("V", Frame.class.getMethod("setVersion", pInt));
    4949                        _FrameTags
     
    9898                        _ItemTags.put("f", Text.class.getMethod("setFont", pFont));
    9999                        _ItemTags.put("t", Text.class.getMethod("setSpacing", pInt));
    100                         _ItemTags.put("T", Text.class.getMethod("setText", pString));
     100                        _ItemTags.put("T", Text.class.getMethod("appendText", pString));
    101101
    102102                        _ItemTags.put("a", Text.class.getMethod("setWordSpacing", pInt));
  • trunk/src/org/expeditee/io/KMSWriter.java

    r72 r80  
    1010import java.util.List;
    1111
     12import org.expeditee.agents.DefaultAgent;
    1213import org.expeditee.gui.Frame;
    1314import org.expeditee.items.Constraint;
     
    4344                if (_filename == null)
    4445                        _filename = start.path + name + File.separator + name + "."
    45                                         + start.getFrameNumber();
     46                                        + start.getNumber();
    4647
    4748                _stringWriter = new StringBuilder();
    48                 if (_filename.toLowerCase().equals("clipboard")) {
     49                if (_filename.toLowerCase().equals(DefaultAgent.CLIPBOARD)) {
    4950                        _writer = new ProxyWriter(true);
    50                         _filename = "Clipboard";
     51                        _filename = DefaultAgent.CLIPBOARD;
    5152                } else
    5253                        _writer = new ProxyWriter(new FileWriter(_filename));
     
    104105                        try {
    105106                                Object o = _FrameTags.get(tag).invoke(toWrite, param);
    106                                 o = Conversion.ConvertToKMS(_FrameTags.get(tag), o);
     107                                o = Conversion.ConvertToExpeditee(_FrameTags.get(tag), o);
    107108                                if (o != null) {
    108109                                        writeLine(tag, (String) o);
     
    145146                if (_writer == null)
    146147                        return;
     148               
     149                if (item.offScreen()) {
     150                        //System.out.println("item offscreen!");
     151                        return;
     152                }
    147153
    148154                writeLine("");
     
    253259                                try {
    254260                                        Object o = toRun.invoke(toWrite, param);
    255                                         o = Conversion.ConvertToKMS(toRun, o);
     261                                        o = Conversion.ConvertToExpeditee(toRun, o);
    256262                                        if (o != null) {
    257263                                                if (o instanceof List) {
  • trunk/src/org/expeditee/io/TEXWriter.java

    r17 r80  
    3434                                _writer.write("\\" + command + "{");
    3535
    36                                 List<String> titleLines = _title.getText();
     36                                List<String> titleLines = _title.getTextList();
    3737                                for (int i = 0; i < titleLines.size() - 1; i++) {
    3838                                        _writer.write(titleLines.get(i));
     
    5454
    5555                Text text = (Text) linker;
    56                 List<String> toWrite = text.getText();
     56                List<String> toWrite = text.getTextList();
    5757
    5858                String first = toWrite.get(0);
     
    7373
    7474                Text text = (Text) linker;
    75                 List<String> toWrite = text.getText();
     75                List<String> toWrite = text.getTextList();
    7676
    7777                String first = toWrite.get(0);
     
    8686        @Override
    8787        protected void writeText(Text text) throws IOException {
    88                 for (String s : text.getText()) {
     88                for (String s : text.getTextList()) {
    8989                        _writer.write(s);
    9090                        _writer.write(ItemWriter.NEW_LINE);
  • trunk/src/org/expeditee/io/TXTWriter.java

    r4 r80  
    99import org.expeditee.items.Text;
    1010
    11 public class TXTWriter extends DefaultTreeWriter implements FrameWriter {
     11public class TXTWriter extends DefaultTreeWriter{
    1212
    1313        private boolean _join = false;
     
    3939                        indent = _indent - 1;
    4040
    41                 for (String s : title.getText()) {
     41                for (String s : title.getTextList()) {
    4242
    4343                        for (int i = 0; i < indent; i++)
     
    7171        @Override
    7272        protected void writeText(Text text) throws IOException {
    73                 for (String s : text.getText()) {
     73                for (String s : text.getTextList()) {
    7474
    7575                        for (int i = 0; i < _indent; i++)
  • trunk/src/org/expeditee/items/FrameBitmap.java

    r79 r80  
    1010
    1111public class FrameBitmap extends FramePicture {
    12         public FrameBitmap(Text source,  String size,ImageObserver observer)
     12        public FrameBitmap(Text source, String size, ImageObserver observer)
    1313                        throws IllegalArgumentException {
    1414                super();
     
    1717
    1818                refresh();
    19                
     19
    2020                if (_image == null)
    2121                        throw new IllegalArgumentException();
     
    2626        @Override
    2727        public boolean refresh() {
    28                 // Check if the picture is being created with @f
    2928                assert (_source.getLink() != null);
    3029                Frame frame = FrameIO.LoadFrame(_source.getAbsoluteLink());
    31                 //if the frame cant be found just use the current image
    32                 if (frame == null){
     30                // if the frame cant be found just use the current image
     31                if (frame == null) {
    3332                        return false;
    3433                }
    35                
     34
    3635                List<Text> textList = frame.getBodyTextItems(false);
    3736                if (textList.size() == 0)
    3837                        return false;
    39                 List<String> imageLines = textList.get(0).getText();
     38                List<String> imageLines = textList.get(0).getTextList();
    4039                int width = 0;
    4140                int height = imageLines.size();
     
    4847                                BufferedImage.TYPE_INT_ARGB);
    4948                // now set the bits on the image
    50                 final int transparent = (new Color(0F,0F,0F,0F)).getRGB();
    51                 final int black = _source.getColor().getRGB();
    52                 int currentColor = transparent;
     49                final int transparent = (new Color(0F, 0F, 0F, 0F)).getRGB();
     50                final int main = _source.getColor().getRGB();
     51                final Color c = _source.getColor();
     52                int currentColor = main;
    5353                int row = 0;
    5454                for (String s : imageLines) {
    5555                        for (int i = 0; i < width; i++) {
    56                                 if (i < s.length() && s.charAt(i) != '0') {
    57                                         currentColor = black;
    58                                 } else {
    59                                         currentColor = transparent;
     56                                currentColor = transparent;
     57                                if (i < s.length()) {
     58                                        char currentPixel = s.charAt(i);
     59                                        // Space is transparent as is 0
     60                                        if (Character.isDigit(currentPixel)) {
     61                                                int alpha = (int)((currentPixel - '0') * 25.5F + 0.5F);
     62                                                currentColor = new Color(c.getRed(), c.getGreen(), c
     63                                                                .getBlue(), alpha).getRGB();
     64                                        }else if (currentPixel != ' ') {
     65                                                currentColor = main;
     66                                        }
    6067                                }
    6168                                bi.setRGB(i, row, currentColor);
     
    6471                }
    6572                _image = bi;
    66                
     73
    6774                return true;
    6875        }
    69        
     76
    7077        @Override
    71         protected Picture createPicture(){
     78        protected Picture createPicture() {
    7279                return ItemUtils.CreateFrameBitmap((Text) _source.copy(),
    7380                                _imageObserver);
    7481        }
     82
     83        @Override
     84        protected String getTagText() {
     85                return "@b: ";
     86        }
    7587}
  • trunk/src/org/expeditee/items/FrameImage.java

    r79 r80  
    2828                _imageObserver = observer;
    2929
    30                 // Check if the picture is being created with @f
    3130                refresh();
    3231
     
    5756                return true;
    5857        }
     58       
     59        @Override
     60        protected String getTagText() {
     61                return "@f: ";
     62        }
    5963}
  • trunk/src/org/expeditee/items/FramePicture.java

    r79 r80  
    2727                updatePolygon();
    2828        }
     29       
     30        @Override
     31        public String getName() {
     32                return _source.getAbsoluteLink();
     33        }
    2934}
  • trunk/src/org/expeditee/items/InteractiveWidget.java

    r78 r80  
    101101                String TAG = ItemUtils.GetTag(ItemUtils.TAG_IWIDGET);
    102102
    103                 String text = source.getTextNoList();
     103                String text = source.getText();
    104104                if (text == null)
    105105                        throw new IllegalArgumentException("source does not have any text");
  • trunk/src/org/expeditee/items/Item.java

    r78 r80  
    4141        // if this dot is part of an enclosing shape
    4242        private Collection<Item> _enclosure = null;
    43        
     43
    4444        public static final int LEFT_MARGIN = 13;
    4545
     
    7878
    7979        public static final Color DEFAULT_BACKGROUND = Color.white;
    80        
    81         public static final Color TRANSPARENT = new Color(0,0,0,0);
     80
     81        public static final Color TRANSPARENT = new Color(0, 0, 0, 0);
    8282
    8383        /**
     
    9999         */
    100100        public static Color[] COLOR_WHEEL = { Color.BLACK, Color.RED, Color.BLUE,
    101                         Item.GREEN, Color.MAGENTA, Color.YELLOW.darker(),
    102                         DEFAULT_BACKGROUND };
     101                        Item.GREEN, Color.MAGENTA, Color.YELLOW.darker(), Color.WHITE, null };
    103102
    104103        public static Color[] FILL_COLOR_WHEEL = { Color.BLACK,
    105104                        new Color(255, 150, 150), new Color(150, 150, 255),
    106105                        new Color(150, 255, 150), new Color(255, 150, 255),
    107                         new Color(255, 255, 100), DEFAULT_BACKGROUND };
     106                        new Color(255, 255, 100), Color.WHITE, null };
    108107
    109108        public static final int UNCHANGED_CURSOR = -100;
     
    117116        public static final int CROP_CURSOR = Cursor.CROSSHAIR_CURSOR;
    118117
    119         public static final int JUSTIFICATION_NONE = -1;
     118        //The default value for integer attributes
     119        public static final int DEFAULT_INTEGER = -1;
     120
     121        public static final int JUSTIFICATION_NONE = DEFAULT_INTEGER;
    120122
    121123        public static final int JUSTIFICATION_FULL = 0;
     
    230232        public int Permission = PERMISSION_FULL;
    231233
     234        // A fill color of null represents transparent
    232235        private Color _colorFill = null;
    233236
    234         private Color _color = DEFAULT_FOREGROUND;
     237        // A fore color of null represents the default color
     238        private Color _color = null;
    235239
    236240        private Color _highlightColor = DEFAULT_HIGHLIGHT;
     
    392396                } else
    393397                        return false;
    394         }
    395 
    396         final public String getAbsoluteLink() {
    397                 String link = getLink();
    398 
    399                 if (link == null)
    400                         return null;
    401                 // assert (_parent!= null);
    402                 if (_parent == null) {
    403                         // if parent is null it is an item on the message box
    404                         // so it must already be absolute
    405                         assert (!FrameIO.isPositiveInteger(link));
    406                         return link;
    407                 }
    408 
    409                 // if its a relative link then return absolute
    410                 if (FrameIO.isPositiveInteger(link)) {
    411                         return _parent.getFramesetName() + link;
    412                 }
    413                 return link;
    414398        }
    415399
     
    731715         */
    732716        public Color getPaintColor() {
     717                // If color is null then get the paint foregroundColor for the frame the
     718                // item is on which is a color adjusted to suit the background
    733719                if (_color == null) {
    734720                        if (getParent() != null)
    735721                                return getParent().getPaintForegroundColor();
    736722
    737                         if (DisplayIO.getCurrentFrame() == null)
     723                        Frame current = DisplayIO.getCurrentFrame();
     724                        if (current == null)
    738725                                return DEFAULT_FOREGROUND;
    739726
    740                         return DisplayIO.getCurrentFrame().getPaintForegroundColor();
     727                        return current.getPaintForegroundColor();
    741728                }
    742729
     
    854841
    855842        public boolean isFrameName() {
    856                 if (this.getParent() == null
    857                                 || this.getParent().getFrameNameItem() != this)
     843                if (this.getParent() == null || this.getParent().getNameItem() != this)
    858844                        return false;
    859845                return true;
     
    861847
    862848        public boolean isFrameTitle() {
    863                 if (this.getParent() == null || this.getParent().getTitle() != this)
     849                if (this.getParent() == null || this.getParent().getTitleItem() != this)
    864850                        return false;
    865851                return true;
     
    916902        public boolean isOldTag() {
    917903                if (this instanceof Text)
    918                         if (((Text) this).getText().get(0).toLowerCase().equals("@old"))
     904                        if (((Text) this).getTextList().get(0).toLowerCase().equals("@old"))
    919905                                return true;
    920906                return false;
     
    944930                if (getFillColor() != null && getEnclosingDots() != null) {
    945931                        g.setColor(getFillColor());
    946                         //Shape s = getEnclosedShape();
    947                         //Rectangle b = s.getBounds();
    948                         //GradientPaint gp = new GradientPaint((int) (b.x + b.width * 0.3),
    949                         //              b.y, getFillColor(), (int) (b.x + b.width * 1.3), b.y,
    950                         //              Color.white);
    951                         //g.setPaint(gp);
    952                         //g.fill(s);
     932                        // Shape s = getEnclosedShape();
     933                        // Rectangle b = s.getBounds();
     934                        // GradientPaint gp = new GradientPaint((int) (b.x + b.width * 0.3),
     935                        // b.y, getFillColor(), (int) (b.x + b.width * 1.3), b.y,
     936                        // Color.white);
     937                        // g.setPaint(gp);
     938                        // g.fill(s);
    953939                        g.fillPolygon(getEnclosedShape());
    954940                }
     
    16531639                _actions.add(string);
    16541640        }
    1655        
     1641
    16561642        protected int getLinkYOffset() {
    16571643                return 0;
     
    16591645
    16601646        /**
     1647         * Paint the link symbol for the item if it is a
     1648         *
    16611649         * @param g
    16621650         */
    16631651        protected void paintLink(Graphics2D g) {
     1652                if (FrameGraphics.isAudienceMode())
     1653                        return;
     1654
    16641655                if (getLink() != null || getAction() != null) {
    16651656                        if (getLink() != null && getAction() != null) {
     
    16701661                                g.setColor(ACTION_COLOR);
    16711662                        }
    1672        
     1663
    16731664                        AffineTransform at = new AffineTransform();
    16741665                        AffineTransform orig = g.getTransform();
    1675                         at.translate(getX() - LEFT_MARGIN, getY()+ getLinkYOffset());
     1666                        at.translate(getX() - LEFT_MARGIN, getY() + getLinkYOffset());
    16761667                        g.setTransform(at);
    1677        
     1668
    16781669                        if (getLinkMark() && getLink() != null) {
    16791670                                g.drawPolygon(getCircle());
    1680        
     1671
    16811672                                // if the link is not valid, cross out the circle
    16821673                                if (!isLinkValid())
    16831674                                        g.drawPolygon(getCircleCross());
    16841675                        }
    1685        
     1676
    16861677                        if (getActionMark() && getAction() != null) {
    16871678                                g.drawPolygon(getCircle());
    16881679                                g.fillPolygon(getCircle());
    1689        
     1680
    16901681                                // if the link is not valid, cross out the circle
    16911682                                if (!isLinkValid() && getLink() != null) {
     
    16941685                                }
    16951686                        }
    1696        
     1687
    16971688                        // reset the graphics tranformation
    16981689                        g.setTransform(orig);
    16991690                }
    17001691        }
    1701        
     1692
    17021693        /**
    17031694         * Gets the distance between the start of the text and the left border of
     
    17121703                                - MARGIN_RIGHT : MARGIN_RIGHT);
    17131704        }
     1705
     1706        public String getName() {
     1707                return null;
     1708        }
     1709
     1710        final public String getAbsoluteLinkTemplate() {
     1711                return getAbsoluteLink(getLinkTemplate());
     1712        }
     1713
     1714        final public String getAbsoluteLinkFrameset() {
     1715                return getAbsoluteLink(getLinkFrameset());
     1716        }
     1717
     1718        final public String getAbsoluteLink() {
     1719                return getAbsoluteLink(getLink());
     1720        }
     1721
     1722        /**
     1723         * @param link
     1724         * @return
     1725         */
     1726        private String getAbsoluteLink(String link) {
     1727                if (link == null)
     1728                        return null;
     1729                // assert (_parent!= null);
     1730                if (_parent == null) {
     1731                        // if parent is null it is an item on the message box
     1732                        // so it must already be absolute
     1733                        assert (!FrameIO.isPositiveInteger(link));
     1734                        return link;
     1735                }
     1736
     1737                // if its a relative link then return absolute
     1738                if (FrameIO.isPositiveInteger(link)) {
     1739                        return _parent.getFramesetName() + link;
     1740                }
     1741                return link;
     1742        }
    17141743}
  • trunk/src/org/expeditee/items/ItemUtils.java

    r78 r80  
    1919import javax.swing.JFrame;
    2020
     21import org.expeditee.gui.AttributeUtils;
    2122import org.expeditee.gui.DisplayIO;
    2223import org.expeditee.gui.Frame;
     
    7071
    7172        public static final int TAG_STAT_TEMPLATE = 18;
    72        
     73
    7374        public static final int TAG_VECTOR = 19;
    74        
     75
    7576        public static final int TAG_BITMAP_IMAGE = 20;
    7677
     
    145146                for (Item i : items) {
    146147                        if (i instanceof Text && i.isAnnotation())
    147                                 if (((Text) i).getTextNoList().trim().equalsIgnoreCase(toFind))
     148                                if (((Text) i).getText().trim().equalsIgnoreCase(toFind))
    148149                                        return (Item) i;
    149150                }
     
    166167         * @return True if the Item matches the given tag, false otherwise
    167168         */
    168         public static boolean isTag(Item toCheck, int tag) {
    169                 return isTag(toCheck, GetTag(tag));
    170         }
    171 
    172         public static boolean isTag(Item toCheck, int tag, boolean hasValue) {
    173                 return isTag(toCheck, GetTag(tag), hasValue);
    174         }
    175 
    176         /**
    177          * Checks if the given Item contains the desired tag (case insensitive)
     169        public static boolean startsWithTag(Item toCheck, int tag) {
     170                return startsWithTag(toCheck, GetTag(tag));
     171        }
     172
     173        public static boolean startsWithTag(Item toCheck, int tag, boolean hasValue) {
     174                return startsWithTag(toCheck, GetTag(tag), hasValue);
     175        }
     176
     177        /**
     178         * Checks if the given Item begins with the desired tag (case insensitive).
    178179         *
    179180         * @param toCheck
     
    185186         * @return True if the tag is found in the given Item, False otherwise.
    186187         */
    187         public static boolean isTag(Item toCheck, String tag, boolean hasValue) {
    188                 if (!(toCheck instanceof Text) || !toCheck.isAnnotation())
     188        public static boolean startsWithTag(Item toCheck, String tag, boolean valueAllowed) {
     189                if (!(toCheck instanceof Text))
    189190                        return false;
    190191
    191192                Text txt = (Text) toCheck;
    192                 // tags are ase-insensitive
    193                 return String.CASE_INSENSITIVE_ORDER.compare(txt.getFirstLine().trim(),
    194                                 tag) == 0
    195                                 || (hasValue && txt.startsWith(tag + " ", true));
    196         }
    197 
    198         public static boolean isTag(Item toCheck, String tag) {
    199                 return isTag(toCheck, tag, true);
     193                String value = ItemUtils.StripTag(txt.getText(), tag);
     194
     195                if (value == null)
     196                        return false;
     197                return valueAllowed || value.equals("");
     198        }
     199
     200        /**
     201         * Checks if the item begins with the desired tag.
     202         * @param toCheck
     203         * @param tag
     204         * @return
     205         */
     206        public static boolean startsWithTag(Item toCheck, String tag) {
     207                return startsWithTag(toCheck, tag, true);
    200208        }
    201209
    202210        /**
    203211         * Strips off the given tag from the given String, and returns wathever is
    204          * left
     212         * left.
    205213         *
    206214         * @param toStrip
     
    212220         */
    213221        public static String StripTag(String toStrip, String tag) {
    214                 if (toStrip.toLowerCase().startsWith(tag.toLowerCase())) {
    215                         toStrip = toStrip.substring(tag.length()).trim();
    216                         return toStrip;
    217                 }
    218 
    219                 /**
    220                  * TODO: Change this to use REGEX
    221                  */
    222 
    223                 return null;
    224         }
    225 
    226         /**
    227          * The same as StripTag(String, String), but this method iterates through
    228          * the list of pre-defined tags until one is found.
    229          *
    230          * @param toStrip
    231          *            The String to strip the tag from
    232          * @return The String that results from stripping off the Tag, or null if
    233          *         the given String was not a tag
    234          */
    235         public static String StripTag(String toStrip) {
    236                 // there must be something left after stripping
    237                 if (toStrip == null)// || toStrip.trim().indexOf(" ") < 0)
    238                         return toStrip;
    239 
    240                 for (int i = TAG_MIN; i <= TAG_MAX; i++) {
    241                         String res = StripTag(toStrip, GetTag(i));
    242                         if (res != null)
    243                                 return res;
    244                 }
    245 
    246                 return null;
    247         }
    248 
    249         /**
    250          * Strips the first character from a string if it is the @ symbol
     222                if (toStrip == null)
     223                        return null;
     224                toStrip = toStrip.trim();
     225                if (!toStrip.toLowerCase().startsWith(tag.toLowerCase()))
     226                        return null;
     227
     228                if (toStrip.length() == tag.length())
     229                        return "";
     230                // remove tag and ensure the char is the tag separator
     231                char separator = toStrip.charAt(tag.length());
     232                if (separator != ':')
     233                        return null;
     234
     235                if (toStrip.length() == tag.length() + 1)
     236                        return "";
     237
     238                return toStrip.substring(tag.length() + 1).trim();
     239        }
     240
     241        /**
     242         * Strips the first character from a string if it is the tag symbol and
     243         * returns the remainder.
    251244         * @param toStrip
    252245         *            the string to be stripped
    253          * @return the stripped version of the string
     246         * @return the stripped version of the string.
    254247         */
    255248        public static String StripTagSymbol(String toStrip) {
    256249                // there must be something left after stripping
    257250                if (toStrip != null) {
     251                        toStrip = toStrip.trim();
    258252                        if (toStrip.length() > 0) {
    259253                                if (toStrip.charAt(0) == '@') {
     
    262256                        }
    263257                }
    264 
    265258                return toStrip;
    266259        }
     
    293286                        return "@ao";
    294287                case TAG_IMAGE:
    295                         return "@i:";
     288                        return "@i";
    296289                case TAG_ITEM_TEMPLATE:
    297290                        return "@itemtemplate";
     
    317310                        return "@old";
    318311                case TAG_POINTTYPE:
    319                         return "@pointtype:";
     312                        return "@pointtype";
    320313                case TAG_IWIDGET:
    321314                        return "@iw";
     
    358351         */
    359352        public static Picture CreatePicture(Text source, ImageObserver observer) {
    360                 String text = source.getTextNoList();
     353                String text = source.getText();
    361354                String path = "";
     355                String fileName = "";
    362356                String size = "";
    363357
     
    368362                        text = text.trim();
    369363
    370                         if (text.indexOf(".") >= text.lastIndexOf(" "))
     364                        int fileSuffixChar = text.indexOf('.');
     365                        if (fileSuffixChar < 0)
     366                                return null;
     367                        int endOfFileName = text.indexOf(' ', fileSuffixChar);
     368                        if (endOfFileName < 0) {
    371369                                path = text;
    372                         else
    373                                 path = text.substring(0, text.lastIndexOf(" "));
    374 
    375                         size = text.substring(path.length()).trim();
     370                                size = "";
     371                        } else {
     372                                path = text.substring(0, endOfFileName);
     373                                size = text.substring(endOfFileName).trim();
     374                        }
     375                        fileName = path;
    376376
    377377                        // try images subdirectory
     
    415415
    416416                try {
    417                         Picture pic = new Picture(source, path, size, observer);
     417                        Picture pic = new Picture(source, fileName, path, size, observer);
    418418
    419419                        return pic;
     
    429429
    430430                // remove @f tag
    431                 size = size.replaceFirst("@f", "");
    432                 size = size.trim();
     431                size = AttributeUtils.getValue(size);
    433432
    434433                try {
     
    440439                }
    441440        }
    442        
     441
    443442        public static Picture CreateFrameBitmap(Text source, ImageObserver observer) {
    444443                String size = source.getFirstLine();
    445444
    446445                // remove @b tag
    447                 size = size.replaceFirst("@b", "");
    448                 size = size.trim();
     446                size = AttributeUtils.getValue(size);
    449447
    450448                try {
     
    515513                                // if this is the frame name, make sure the frame is saved (in
    516514                                // case it is a TDFC frame)
    517                                 if (i == i.getParent().getFrameNameItem())
     515                                if (i == i.getParent().getNameItem())
    518516                                        i.getParent().setChanged(true);
    519517
    520518                                // if this is the title of the frame, link it to the frame
    521                                 if (i.getLink() == null && i == i.getParent().getTitle()
     519                                if (i.getLink() == null && i == i.getParent().getTitleItem()
    522520                                                && toCopy.size() == 1) {
    523521                                        // save the frame after copying
    524522                                        i.getParent().setChanged(true);
    525                                         copy.setLink(i.getParent().getFrameName());
     523                                        copy.setLink(i.getParent().getName());
    526524                                }
    527525                        }
     
    552550                for (Line line : lines) {
    553551                        Line lineCopy = line.copy();
    554                         //get the lineEnd we copied above if it is in the MAPPING
     552                        // get the lineEnd we copied above if it is in the MAPPING
    555553                        Item originalLineEnd = line.getEndItem();
    556554                        Item actualLineEnd = lineEndMap.get(originalLineEnd);
     
    559557                        else
    560558                                lineCopy.setEndItem(actualLineEnd);
    561                        
     559
    562560                        Item originalLineStart = line.getStartItem();
    563561                        Item actualLineStart = lineEndMap.get(originalLineStart);
     
    566564                        else
    567565                                lineCopy.setStartItem(actualLineStart);
    568                        
     566
    569567                        copies.add(lineCopy);
    570568                }
     
    593591
    594592                return copies;
    595         }
    596 
    597         private static void ReplaceAll(List<Item> list, Item replace, Item with) {
    598                 // replace all other instances with the copy
    599                 for (int pos = 0; pos < list.size(); pos++)
    600                         if (list.get(pos) == replace) {
    601                                 list.set(pos, with);
    602                         }
    603593        }
    604594
  • trunk/src/org/expeditee/items/Line.java

    r78 r80  
    839839        public Item forceMerge(Item spot, int mouseX, int mouseY) {
    840840
    841                 spot.removeAllConstraints();
    842 
    843                 _end.removeAllConstraints();
    844 
    845                 _start.removeAllConstraints();
     841                // spot.removeAllConstraints();
     842                // _end.removeAllConstraints();
     843                // _start.removeAllConstraints();
     844
     845                // Keep constraints
     846                for (Constraint c : _end.getConstraints()) {
     847                        if (c.getOppositeEnd(_end).equals(_start)) {
     848                                c.replaceEnd(_start, spot);
     849                                new Constraint(spot, _start, getParentOrCurrentFrame()
     850                                                .getNextItemID(), c.getType());
     851                                break;
     852                        }
     853                }
    846854
    847855                // calculate nearest point on line from spot
  • trunk/src/org/expeditee/items/Picture.java

    r78 r80  
    1919import javax.swing.ImageIcon;
    2020
    21 import org.expeditee.gui.FrameGraphics;
    2221import org.expeditee.io.Logger;
    2322
     
    4140public class Picture extends Item {
    4241
     42        private static final int MINIMUM_WIDTH = 10;
     43
    4344        public static final int WIDTH = 0;
    4445
    4546        public static final int RATIO = 1;
    46 
    47         public static final int FRACTION = 2;
    4847
    4948        protected Image _image = null;
     
    5453        protected Text _source = null;
    5554
    56         private int _numerator = -1;
    57 
    58         private int _denominator = -1;
    59 
    60         private float _ratio = 1.0f;
    61 
    62         private int _width = -1;
    63 
    6455        private int _scaleType = RATIO;
    6556
    6657        private float _scale = 1.0f;
    6758
     59        // Start of the crop relative to START
    6860        private Point _cropStart = null;
    6961
     62        // Start of the crop relative to END
    7063        private Point _cropEnd = null;
    7164
    72         private Point _cropOrigin = null;
     65        private Point _start = new Point(0, 0);;
     66
     67        private Point _end = new Point(0, 0);;
    7368
    7469        private boolean _showCropping = false;
    7570
    7671        private String _path = null;
     72
     73        private String _fileName = null;
    7774
    7875        // used to repaint animated GIF images, among other things.
     
    9188         * @param source
    9289         *            The Text Item that was used to create this Picture
     90         * @param fileName
     91         *            the name of the file as it should be displayed in the source
     92         *            text
    9393         * @param path
    9494         *            The Path of the Image to load from disk.
     
    9797         *            screen.
    9898         */
    99         public Picture(Text source, String path, String size, ImageObserver observer)
    100                         throws IllegalArgumentException {
     99        public Picture(Text source, String fileName, String path, String size,
     100                        ImageObserver observer) throws IllegalArgumentException {
    101101                super();
     102                _fileName = fileName;
    102103                _path = path;
    103104                _source = source;
     
    113114
    114115        protected void parseSize(String size) {
     116                // set the default values for start and end
     117                _start = new Point(0, 0);
     118                _end = new Point(_image.getWidth(null), _image.getHeight(null));
     119                size = size.trim();
     120                String[] values = size.split("\\s+");
     121                // Now get the cropping values if there are any
     122                try {
     123                        if (values.length > 2) {
     124                                int startX = Integer.parseInt(values[1]);
     125                                int startY = Integer.parseInt(values[2]);
     126                                _start = new Point(startX, startY);
     127                                if (values.length > 4) {
     128                                        int endX = Integer.parseInt(values[3]);
     129                                        int endY = Integer.parseInt(values[4]);
     130                                        _end = new Point(endX, endY);
     131                                }
     132                        }
     133                } catch (Exception e) {
     134                }
     135
    115136                try {
    116137                        if (size.length() == 0) {
    117138                                size = "" + _image.getWidth(null);
    118                                 _source.setText(_source.getFirstLine() + " " + size);
    119                         }
    120 
    121                         // parse size from text
    122                         if (size.contains("/")) {
    123                                 // this is a fraction
    124                                 _numerator = Integer.parseInt(size.substring(0, size
    125                                                 .indexOf("/")));
    126                                 _denominator = Integer.parseInt(size.substring(size
    127                                                 .indexOf("/") + 1));
    128                                 _scale = (_numerator * 1.0f) / _denominator;
    129                                 _scaleType = FRACTION;
    130                         } else if (size.contains(".")) {
     139                                _source.setText(getTagText() + size);
     140                                return;
     141                        }
     142                        size = values[0];
     143                        // parse width or ratio from text
     144                        if (size.contains(".")) {
    131145                                // this is a ratio
    132                                 _ratio = Float.parseFloat(size);
     146                                _scale = Float.parseFloat(size);
    133147                                _scaleType = RATIO;
    134                                 _scale = _ratio;
    135148                        } else if (size.length() > 0) {
    136149                                // this is an absolute width
    137                                 _width = Integer.parseInt(size);
     150                                int width = Integer.parseInt(size);
    138151                                _scaleType = WIDTH;
    139                                 _scale = _width / (_image.getWidth(null) * 1.0f);
     152                                setWidth(width);
    140153                        }
    141154                } catch (Exception e) {
    142                         size = "" + _image.getWidth(null);
    143                         _source.setText("@f " + size);
    144                         FrameGraphics.ErrorMessage("Invalid argument for image tag");
     155                        _scale = 1F;
    145156                }
    146157        }
     
    148159        public void setStartCrop(int x, int y) {
    149160                _cropStart = new Point(x - getX(), y - getY());
    150                 _cropOrigin = new Point(getX(), getY());
    151161        }
    152162
     
    155165        }
    156166
     167        public Point getTopLeftCrop() {
     168                return new Point(Math.min(_cropStart.x, _cropEnd.x), Math.min(
     169                                _cropStart.y, _cropEnd.y));
     170        }
     171
     172        public Point getBottomRightCrop() {
     173                return new Point(Math.max(_cropStart.x, _cropEnd.x), Math.max(
     174                                _cropStart.y, _cropEnd.y));
     175        }
     176
    157177        public void setShowCrop(boolean value) {
    158178                _showCropping = value;
    159179        }
    160180
    161         public int getCroppedSize() {
     181        public boolean isCropTooSmall() {
    162182                if (_cropStart == null || _cropEnd == null)
    163                         return 0;
    164 
    165                 int diff = (_cropEnd.x - _cropStart.x);
    166                 diff *= (_cropEnd.y - _cropStart.y);
    167                 return diff;
     183                        return true;
     184
     185                int cropWidth = Math.abs(_cropEnd.x - _cropStart.x);
     186                int cropHeight = Math.abs(_cropEnd.y - _cropStart.y);
     187
     188                return cropWidth < MINIMUM_WIDTH || cropHeight < MINIMUM_WIDTH;
    168189        }
    169190
     
    181202
    182203                if (_cropStart == null || _cropEnd == null) {
    183                         int width = _image.getWidth(null);
    184                         int height = _image.getHeight(null);
    185 
    186                         width *= _scale;
    187                         height *= _scale;
     204                        int width = getWidth();
     205                        int height = getHeight();
    188206
    189207                        int xdiff = -getLeftMargin();
    190208
    191209                        // extra pixel around the image so the highlighting is visible
    192                         _poly.addPoint(_source.getX()+ 1 + xdiff, _source.getY() - 1);
     210                        _poly.addPoint(_source.getX() + 1 + xdiff, _source.getY() - 1);
    193211                        _poly.addPoint(_source.getX() + width, _source.getY() - 1);
    194212                        _poly.addPoint(_source.getX() + width, _source.getY() + height);
    195                         _poly.addPoint(_source.getX() + 1 +xdiff, _source.getY() + height);
     213                        _poly.addPoint(_source.getX() + 1 + xdiff, _source.getY() + height);
    196214                } else {
    197                         Rectangle clip = new Rectangle(_source.getX() + _cropStart.x
    198                                         + _cropOrigin.x, _source.getY() + _cropStart.y
    199                                         + _cropOrigin.y, _cropEnd.x - _cropStart.x, _cropEnd.y
    200                                         - _cropStart.y).getBounds();
     215                        Point topLeft = getTopLeftCrop();
     216                        Point bottomRight = getBottomRightCrop();
     217                        Rectangle clip = new Rectangle(topLeft.x + _source.getX(),
     218                                        topLeft.y + _source.getY(), bottomRight.x - topLeft.x,
     219                                        bottomRight.y - topLeft.y).getBounds();
    201220                        _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMinY() - 1);
    202                         _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMaxY() + 1);
    203                         _poly.addPoint((int) clip.getMaxX() + 1, (int) clip.getMaxY() + 1);
    204                         _poly.addPoint((int) clip.getMaxX() + 1, (int) clip.getMinY() - 1);
     221                        _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMaxY());
     222                        _poly.addPoint((int) clip.getMaxX(), (int) clip.getMaxY());
     223                        _poly.addPoint((int) clip.getMaxX(), (int) clip.getMinY() - 1);
    205224
    206225                }
     
    282301
    283302        @Override
     303        public void setWidth(int width) {
     304                _scale = width * 1F / (_end.x - _start.x);
     305        }
     306
     307        /**
     308         * Gets the width with which the picture is displayed on the screen.
     309         */
     310        @Override
     311        public int getWidth() {
     312                return Math.round((_end.x - _start.x) * _scale);
     313        }
     314
     315        /**
     316         * Gets the height with which the picture is displayed on the screen.
     317         */
     318        public int getHeight() {
     319                return Math.round((_end.y - _start.y) * _scale);
     320        }
     321
     322        @Override
    284323        public void paint(Graphics2D g) {
    285324                if (_image == null)
    286325                        return;
    287326
    288                 int width = _image.getWidth(null);
    289                 int height = _image.getHeight(null);
    290 
    291                 width *= _scale;
    292                 height *= _scale;
     327                int width = getWidth();
     328                int height = getHeight();
    293329
    294330                paintLink(g);
    295331
    296                 if (isHighlighted()) {
    297                         g.setColor(getHighlightColor());
    298                         g.drawPolygon(getPolygon());
    299                 }
     332                int dX1 = _source.getX();
     333                int dY1 = _source.getY();
     334                int dX2 = _source.getX() + width;
     335                int dY2 = _source.getY() + height;
    300336
    301337                // if we are showing the cropping, then show the original as transparent
    302                 if (_showCropping && _cropStart != null && _cropEnd != null) {
     338                if (_showCropping && !isCropTooSmall()) {
    303339                        // show the full image as transparent
    304340                        float alpha = .5f;
    305341                        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
    306342                                        alpha));
    307                         g.drawImage(_image, _source.getX(), _source.getY(), width, height,
    308                                         _imageObserver);
     343                        g.drawImage(_image, dX1, dY1, dX2, dY2, _start.x, _start.y, _end.x,
     344                                        _end.y, _imageObserver);
    309345
    310346                        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
    311347                                        1.0f));
    312348                        // show the cropped area normally
    313                         Shape clip = new Rectangle(_source.getX() + _cropStart.x, _source
    314                                         .getY()
    315                                         + _cropStart.y, _cropEnd.x - _cropStart.x, _cropEnd.y
    316                                         - _cropStart.y);
     349                        Point topLeft = getTopLeftCrop();
     350                        Point bottomRight = getBottomRightCrop();
     351                        Shape clip = new Rectangle(dX1 + topLeft.x, dY1 + topLeft.y,
     352                                        bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
    317353                        g.setColor(getPaintHighlightColor());
    318354                        g.draw(clip);
    319355                        g.setClip(clip);
    320356
    321                         g.drawImage(_image, _source.getX(), _source.getY(), width, height,
    322                                         _imageObserver);
     357                        g.drawImage(_image, dX1, dY1, dX2, dY2, _start.x, _start.y, _end.x,
     358                                        _end.y, _imageObserver);
    323359                        g.draw(clip);
    324360                        // if the image is cropped, but we are not showing the cropping
    325                 } else if (_cropStart != null && _cropEnd != null) {
    326                         Shape clip = new Rectangle(_source.getX() + _cropStart.x
    327                                         + _cropOrigin.x, _source.getY() + _cropStart.y
    328                                         + _cropOrigin.y, _cropEnd.x - _cropStart.x, _cropEnd.y
    329                                         - _cropStart.y);
    330                         g.setClip(clip);
    331 
    332                         g.drawImage(_image, _source.getX(), _source.getY(), width, height,
    333                                         _imageObserver);
    334 
    335361                        // otherwise, paint normally
    336362                } else {
    337                        
    338                         g.drawImage(_image, _source.getX(), _source.getY(), width, height,
    339                                         _imageObserver);
     363                        g.drawImage(_image, dX1, dY1, dX2, dY2, _start.x, _start.y, _end.x,
     364                                        _end.y, _imageObserver);
     365                }
     366
     367                if (isHighlighted()) {
     368                        g.setColor(getHighlightColor());
     369                        g.drawPolygon(getPolygon());
    340370                }
    341371        }
     
    365395        public Picture copy() {
    366396                Picture p = createPicture();
     397                p._image = _image;
     398                p._imageObserver = _imageObserver;
     399                p._source = _source.copy();
    367400                Item.DuplicateItem(this, p);
    368401
    369                 if (_cropStart != null)
    370                         p.setStartCrop(_cropStart.x, _cropStart.y);
    371 
    372                 if (_cropEnd != null)
    373                         p.setEndCrop(_cropEnd.x, _cropEnd.y);
     402                if (_cropStart != null && _cropEnd != null) {
     403                        assert (_cropEnd != null);
     404                        // make the start be the top left
     405                        // make the end be the bottom right
     406                        Point topLeft = getTopLeftCrop();
     407                        Point bottomRight = getBottomRightCrop();
     408                        int startX = Math.round(topLeft.x / _scale) + _start.x;
     409                        int startY = Math.round(topLeft.y / _scale) + _start.y;
     410                        int endX = Math.round(bottomRight.x / _scale + _start.x);
     411                        int endY = Math.round(bottomRight.y / _scale + _start.y);
     412                        int width = _image.getWidth(null);
     413                        int height = _image.getHeight(null);
     414                        // adjust our start and end if the user has dragged outside of the
     415                        // shape
     416                        if (endX > width) {
     417                                endX = width;
     418                        }
     419                        if (endY > height) {
     420                                endY = height;
     421                        }
     422                        if (startX < 0) {
     423                                startX = 0;
     424                        }
     425                        if (startY < 0) {
     426                                startY = 0;
     427                        }
     428                        p._start = new Point(startX, startY);
     429                        p._end = new Point(endX, endY);
     430                        p.setPosition(topLeft.x + _source.getX(), topLeft.y + _source.getY());
     431                } else {
     432                        p._start = _start;
     433                        p._end = _end;
     434                }
     435                p._scale = _scale;
     436                p._scaleType = _scaleType;
     437                p._path = _path;
     438                p._fileName = _fileName;
     439
     440                p.updateSource();
     441                p.updatePolygon();
    374442
    375443                return p;
     
    401469                float oldScale = _scale;
    402470
    403                 int oldDenom = _denominator;
    404                 int oldNumer = _numerator;
    405                 float oldRatio = _ratio;
    406                 int oldWidth = _width;
    407 
    408471                switch (_scaleType) {
    409                 case (FRACTION):
    410                         _numerator += diff;
    411                         _scale = (_numerator * 1.0f) / _denominator;
    412                         break;
    413472                case (RATIO):
    414                         _ratio += (diff) * 0.05;
    415                         _scale = _ratio;
     473                        _scale += (diff) * 0.05;
    416474                        break;
    417475                case (WIDTH):
    418                         _width += 10 * diff;
    419                         _scale = _width / (_image.getWidth(null) * 1.0f);
     476                        int width = getWidth();
     477                        width += 10 * diff;
     478                        setWidth(width);
    420479                        break;
    421480                }
    422481
    423                 // picture must still be at least 10 pixels wide
    424                 if ((_scale * _image.getWidth(null)) <= 10) {
     482                // picture must still be at least XX pixels wide
     483                if (getWidth() <= MINIMUM_WIDTH) {
    425484                        _scale = oldScale;
    426 
    427                         _denominator = oldDenom;
    428                         _numerator = oldNumer;
    429                         _ratio = oldRatio;
    430                         _width = oldWidth;
    431                 }
    432 
    433                 // update source text item
    434                 String line = _source.getFirstLine();
    435                 String oldString = "";
    436                 String newString = "";
    437                 switch (_scaleType) {
    438                 case (FRACTION):
    439                         oldString = oldNumer + "/" + oldDenom;
    440                         newString = _numerator + "/" + _denominator;
    441                         break;
    442                 case (RATIO):
    443                         DecimalFormat format = new DecimalFormat("0.00");
    444                         oldString = format.format(oldRatio);
    445                         newString = format.format(_ratio);
    446                         break;
    447                 case (WIDTH):
    448                         oldString = "" + oldWidth;
    449                         newString = "" + _width;
    450                         break;
    451                 }
    452                 if (line.contains(oldString)) {
    453                         line = line.replace(oldString, newString);
    454                 } else {
    455                         line += " " + newString;
    456                 }
    457 
    458                 _source.setText(line);
     485                }
     486
     487                updateSource();
    459488                updatePolygon();
    460489        }
     
    495524                                Logger.Log(e);
    496525                                _image = null;
     526                                return false;
    497527                        }
    498528                }
     
    524554                return _source.getActionMark();
    525555        }
     556
     557        @Override
     558        public String getName() {
     559                return _fileName;
     560        }
     561
     562        protected String getTagText() {
     563                return "@i: " + _fileName + " ";
     564        }
     565
     566        /**
     567         * Updates the source text for this item to match the current size of the
     568         * image.
     569         *
     570         */
     571        private void updateSource() {
     572                StringBuffer newText = new StringBuffer(getTagText());
     573
     574                switch (_scaleType) {
     575                case (RATIO):
     576                        DecimalFormat format = new DecimalFormat("0.00");
     577                        newText.append(format.format(_scale));
     578                        break;
     579                case (WIDTH):
     580                        newText.append(getWidth());
     581                        break;
     582                }
     583
     584                // If the image is cropped add the position for the start and finish of
     585                // the crop to the soure text
     586                if (_start.x > 0 || _start.y > 0 || _end.x < _image.getWidth(null)
     587                                || _end.y < _image.getHeight(null)) {
     588                        newText.append(" ").append(_start.x).append(" ").append(_start.y);
     589                        newText.append(" ").append(_end.x).append(" ").append(_end.y);
     590                }
     591
     592                _source.setText(newText.toString());
     593        }
    526594}
  • trunk/src/org/expeditee/items/Text.java

    r78 r80  
    33import java.awt.BasicStroke;
    44import java.awt.Color;
     5import java.awt.Dimension;
    56import java.awt.Font;
    67import java.awt.Graphics2D;
     
    316317                if (ch != '\t')
    317318                        return insertText("" + ch, mouseX, mouseY);
    318                 return insertText("   " + ch, mouseX, mouseY);
    319                 // return new Point(mouseX, mouseY);
     319
     320                return insertText(" " + ch, mouseX, mouseY);
     321        }
     322
     323        /**
     324         * @param index
     325         * @return
     326         */
     327        private char getNextBullet(char bullet) {
     328                switch (bullet) {
     329                case '*':
     330                        return '>';
     331                case '>':
     332                        return '+';
     333                case '+':
     334                        return 'o';
     335                case 'o':
     336                        return '*';
     337                }
     338                return bullet;
     339        }
     340
     341        private char getPreviousBullet(char bullet) {
     342                switch (bullet) {
     343                case '*':
     344                        return 'o';
     345                case '>':
     346                        return '*';
     347                case '+':
     348                        return '>';
     349                case 'o':
     350                        return '+';
     351                }
     352                return bullet;
    320353        }
    321354
     
    449482                // if there is no text yet
    450483                if (_text == null || _text.length() == 0) {
    451                         if (text.equals("@")) {
    452 
    453                         }
    454 
    455484                        _text = new StringBuffer().append(text);
    456485                        // create the linebreaker and layouts
    457486                        rebuild(true);
    458 
    459                         current = _textLayouts.get(_textLayouts.size() - 1);
     487                        assert (_textLayouts.size() == 1);
     488                        current = _textLayouts.get(0);
    460489                        hit = current.getNextRightHit(0);
    461490                        line = 0;
     
    475504                                pos++;
    476505
    477                         // compensate for newline character
    478                         // if(line > 0 && hit.getInsertionIndex() == 0)
    479                         // if(pos < (_text.length() - 1) && _text.charAt(pos) == '\n')
    480                         // pos++;
    481 
    482506                        // if this is a backspace key
    483507                        if (text.charAt(0) == KeyEvent.VK_BACK_SPACE) {
    484508                                if (pos > 0) {
    485                                         _text.delete(pos - 1, pos);
    486 
    487                                         if (_text.length() > 0) {
    488                                                 AttributedString inserting = new AttributedString(_text
    489                                                                 .toString());
    490                                                 inserting.addAttribute(TextAttribute.FONT,
    491                                                                 getPaintFont());
    492                                                 _lineBreaker.deleteChar(inserting.getIterator(),
    493                                                                 pos - 1);
    494                                         }
     509                                        deleteChar(pos - 1, false);
    495510
    496511                                        pos--;
     
    499514                        } else if (text.charAt(0) == KeyEvent.VK_DELETE) {
    500515                                if (pos < _text.length()) {
    501                                         _text.delete(pos, pos + 1);
    502 
    503                                         if (_text.length() > 0) {
    504                                                 AttributedString inserting = new AttributedString(_text
    505                                                                 .toString());
    506                                                 inserting.addAttribute(TextAttribute.FONT,
    507                                                                 getPaintFont());
    508                                                 _lineBreaker.deleteChar(inserting.getIterator(), pos);
     516                                        deleteChar(pos, false);
     517                                }
     518                                // this is a tab
     519                        } else if (text.charAt(0) == KeyEvent.VK_TAB) {
     520                                // Text length greater than 1 signals a backwards tab
     521                                if (text.length() > 1) {
     522//                                       Find the first non space char to see if its a bullet
     523                                        int index = 0;
     524                                        for (index = 0; index < _text.length(); index++) {
     525                                                if (!Character.isSpaceChar(_text.charAt(index)))
     526                                                        break;
    509527                                        }
     528                                        // Check if there is a space after the bullet
     529                                        if (index < _text.length() - 1 && _text.charAt(index + 1) == ' ') {
     530                                                // Change the bullet
     531                                                _text.setCharAt(index, getPreviousBullet(_text.charAt(index)));
     532                                        }
     533                                        // Remove the spacing at the start
     534                                        for (int i = 0; i < TAB_STRING.length(); i++) {
     535                                                if (_text.length() > 0 && Character.isSpaceChar(_text.charAt(0))){
     536                                                        deleteChar(0, false);
     537                                                        pos--;
     538                                                } else
     539                                                        break;
     540                                        }
     541                                        _lineBreaker = null;
     542                                } else {
     543                                        // / Find the first non space char to see if its a bullet
     544                                        int index = 0;
     545                                        for (index = 0; index < _text.length(); index++) {
     546                                                if (!Character.isSpaceChar(_text.charAt(index)))
     547                                                        break;
     548                                        }
     549                                        // Check if there is a space after the bullet
     550                                        if (index < _text.length() - 1
     551                                                        && _text.charAt(index + 1) == ' ') {
     552                                                char nextBullet = getNextBullet(_text.charAt(index));
     553                                                // Change the bullet
     554                                                _text.setCharAt(index, nextBullet);
     555                                        }
     556                                        // Insert the spacing at the start
     557                                        insertString(TAB_STRING, 0);
     558                                        pos += TAB_STRING.length();
    510559                                }
    511560                                // this is a normal insert
    512561                        } else {
    513                                 _text.insert(pos, text);
    514                                 if (text.length() < 2) {
    515                                         AttributedString inserting = new AttributedString(_text
    516                                                         .toString());
    517                                         inserting.addAttribute(TextAttribute.FONT, getPaintFont());
    518                                         _lineBreaker.insertChar(inserting.getIterator(), pos);
    519                                 } else
    520                                         _lineBreaker = null;
    521 
     562                                insertString(text, pos);
    522563                                pos += text.length();
    523564                        }
     
    540581
    541582                        current = _textLayouts.get(newLine);
    542                         pos = pos - _lineOffsets.get(newLine);
     583                        pos -= _lineOffsets.get(newLine);
    543584
    544585                        if (newLine == line) {
     
    807848         * @return The String array with one element per line of text in this Item.
    808849         */
    809         public List<String> getText() {
     850        public List<String> getTextList() {
    810851                if (_text == null)
    811852                        return null;
     
    830871        }
    831872
    832         public String getTextNoList() {
     873        public String getText() {
    833874                return _text.toString();
    834875        }
     
    13461387        @Override
    13471388        public void setSize(int size) {
    1348                 if (size >= MINIMUM_FONT_SIZE)
    1349                         setFont(getPaintFont().deriveFont((float) size));
     1389                // Dont want to have size set when duplicating a point which has size 0
     1390                if (size < 0)
     1391                        return;
     1392
     1393                if (size < MINIMUM_FONT_SIZE)
     1394                        size = MINIMUM_FONT_SIZE;
     1395                setFont(getPaintFont().deriveFont((float) size));
    13501396        }
    13511397
     
    13561402                        if (isAnnotation())
    13571403                                return;
    1358 
    1359                         _text.insert(0, "@");
    1360 
    1361                         if (_lineBreaker != null) {
    1362                                 AttributedString inserting = new AttributedString(_text
    1363                                                 .toString());
    1364                                 inserting.addAttribute(TextAttribute.FONT, getPaintFont());
    1365                                 _lineBreaker.insertChar(inserting.getIterator(), 0);
     1404                        if (_text.charAt(0) == '*') {
     1405                                deleteChar(0, true);
     1406                                if (_text.length() > 0 && _text.charAt(0) == ' ')
     1407                                        deleteChar(0, true);
     1408                        } else {
     1409                                insertString("@", 0);
    13661410                        }
    13671411                } else {
     
    13701414                                return;
    13711415
    1372                         if (_text.length() == 1) {
     1416                        if (_text.charAt(0) == '@') {
     1417                                _text.setCharAt(0, ' ');
     1418                                insertString("*", 0);
     1419                        } else {
     1420                                deleteChar(0, true);
     1421                        }
     1422                }
     1423                rebuild(false);
     1424        }
     1425
     1426        /**
     1427         *
     1428         */
     1429        private void insertString(String toInsert, int pos) {
     1430                assert (toInsert.length() > 0);
     1431
     1432                _text.insert(pos, toInsert);
     1433
     1434                if (toInsert.length() > 1) {
     1435                        _lineBreaker = null;
     1436                }
     1437
     1438                if (_lineBreaker != null) {
     1439                        AttributedString inserting = new AttributedString(_text.toString());
     1440                        inserting.addAttribute(TextAttribute.FONT, getPaintFont());
     1441                        _lineBreaker.insertChar(inserting.getIterator(), pos);
     1442                }
     1443        }
     1444
     1445        private void deleteChar(int pos, boolean replaceWithDot) {
     1446                _text.deleteCharAt(pos);
     1447
     1448                if (_text.length() == 0) {
     1449                        if (replaceWithDot) {
    13731450                                // Remove and replace with a dot
    13741451                                FrameKeyboardActions.replaceText(this);
    1375 
    13761452                                DisplayIO.setCursorPosition(this.getPosition());
    1377                                 return;
    13781453                        }
    1379 
    1380                         _text.deleteCharAt(0);
    1381 
    1382                         if (_lineBreaker != null) {
    1383                                 AttributedString inserting = new AttributedString(_text
    1384                                                 .toString());
    1385                                 inserting.addAttribute(TextAttribute.FONT, getPaintFont());
    1386                                 _lineBreaker.deleteChar(inserting.getIterator(), 0);
    1387                         }
    1388                 }
    1389                 rebuild(false);
     1454                        return;
     1455                }
     1456
     1457                if (_lineBreaker != null) {
     1458                        AttributedString inserting = new AttributedString(_text.toString());
     1459                        inserting.addAttribute(TextAttribute.FONT, getPaintFont());
     1460                        _lineBreaker.deleteChar(inserting.getIterator(), pos);
     1461                }
    13901462        }
    13911463
     
    14181490                if (merger.isLineEnd()) {
    14191491                        if (merger instanceof Text)
    1420                                 insertText(((Text) merger).getTextNoList(), mouseX, mouseY);
     1492                                insertText(((Text) merger).getText(), mouseX, mouseY);
    14211493
    14221494                        // Set the position by moving the cursor before calling this
     
    14641536        }
    14651537
     1538        /**
     1539         * Removes the set of characters up to the first space in this text item.
     1540         *
     1541         * @return the string that was removed.
     1542         */
    14661543        public String stripFirstWord() {
    14671544                int firstSpace = _text.toString().indexOf(' ');
     
    14751552
    14761553                String firstWord = _text.toString().substring(0, firstSpace);
    1477 
    1478                 String text = _text.toString();
    1479                 int secondWord;
    1480                 for (secondWord = firstSpace; secondWord < _text.length(); secondWord++) {
    1481                         if (!Character.isSpaceChar(text.charAt(secondWord))) {
    1482                                 break;
    1483                         }
    1484                 }
    1485                 setText(_text.toString().substring(secondWord));
     1554                setText(_text.toString().substring(firstSpace).trim());
    14861555
    14871556                return firstWord;
     
    14921561
    14931562                if (getParent() != null)
    1494                         return message + getParent().getFrameName();
     1563                        return message + getParent().getName();
    14951564                return message + getDateCreated();
    14961565        }
     
    15501619
    15511620        public void resetFrameNamePosition() {
    1552                 setMaxSize(FrameGraphics.getMaxFrameSize());
    1553                 setPosition(FrameGraphics.getMaxFrameSize().width - getBoundsWidth(),
    1554                                 getBoundsHeight());
    1555         }
    1556        
     1621                Dimension maxSize = FrameGraphics.getMaxFrameSize();
     1622                setMaxSize(maxSize);
     1623                if (maxSize != null) {
     1624                        setPosition(maxSize.width - getBoundsWidth(), getBoundsHeight());
     1625                }
     1626        }
     1627
    15571628        @Override
    1558         protected int getLinkYOffset(){
     1629        protected int getLinkYOffset() {
    15591630                return Math.round(-(_textLayouts.get(0).getAscent() / 2));
    15601631        }
     1632
     1633        @Override
     1634        public String getName() {
     1635                return getFirstLine();
     1636        }
     1637
     1638        public static final String TAB_STRING = "      ";
     1639
     1640        public Point insertTab(char ch, int mouseX, int mouseY) {
     1641                return insertText("" + ch, mouseX, mouseY);
     1642        }
     1643
     1644        public Point removeTab(char ch, int mouseX, int mouseY) {
     1645                // Insert a space as a flag that it is a backwards tab
     1646                return insertText(ch + " ", mouseX, mouseY);
     1647        }
    15611648}
  • trunk/src/org/expeditee/simple/Pointers.java

    r4 r80  
    44
    55        private static final String[] prefixes = new String[] {
    6                         SPointer.itemPrefix, SPointer.framePrefix, SPointer.filePrefix };
     6                        SPointer.itemPrefix, SPointer.framePrefix, SPointer.filePrefix,
     7                        SPointer.associationPrefix };
    78
    89        public static boolean isPointer(String varName) {
     
    4950                        // if it is an existing variable change the value
    5051                        v = getVariable(name);
    51                 } catch (Exception e) {
     52                } catch (VariableNotFoundException e) {
    5253                        // If the first variable doesnt exist then add it
    5354                        list_.add(new SPointer<T>(name, value));
     
    5758                v.setValue(value);
    5859        }
     60
     61        /**
     62         * Deletes a variable if it exists.
     63         * @param variableName name of the variable to delete
     64         */
     65        public void delete(String variableName) {
     66                try {
     67                        list_.remove(getVariable(variableName));
     68                } catch (VariableNotFoundException e) {
     69
     70                }
     71        }
    5972}
  • trunk/src/org/expeditee/simple/Primitives.java

    r21 r80  
    157157        }
    158158
     159        /**
     160         * Increments a variable.
     161         * @param var the name of the variable to increment
     162         * @throws Exception
     163         */
    159164        public void add(String var) throws Exception {
    160165                setValue(var, new SReal(getVariable(var).doubleValue() + 1));
    161166        }
    162167
     168        /**
     169         * Decrements a variable.
     170         * @param var the name of the variable to decrement
     171         * @throws Exception
     172         */
    163173        public void subtract(String var) throws Exception {
    164174                setValue(var, new SReal(getVariable(var).doubleValue() - 1));
  • trunk/src/org/expeditee/simple/SCharacter.java

    r21 r80  
    1818        @Override
    1919        public void parse(String s) {
    20                 if (s == "")
     20                if (s.equals(""))
    2121                        value_ = '\0';
    2222                else
  • trunk/src/org/expeditee/simple/SInteger.java

    r21 r80  
    2626        @Override
    2727        public void parse(String s) throws Exception {
    28                 if (s == "")
     28                if (s.equals(""))
    2929                        value_ = 0L;
    3030                else
  • trunk/src/org/expeditee/simple/SPointer.java

    r4 r80  
    1010
    1111        public static final String filePrefix = SVariable.prefix + "f"
     12                        + SVariable.separator;
     13
     14        public static final String associationPrefix = SVariable.prefix + "ap"
    1215                        + SVariable.separator;
    1316
  • trunk/src/org/expeditee/simple/SReal.java

    r21 r80  
    2222        @Override
    2323        public void parse(String s) throws Exception {
    24                 if (s == "")
     24                if (s.equals(""))
    2525                        value_ = 0.0;
    2626                else
  • trunk/src/org/expeditee/simple/SString.java

    r4 r80  
    2828        @Override
    2929        public Long integerValue() {
    30                 if (value_ == "")
     30                if (value_.equals(""))
    3131                        return 0L;
    3232                return (long) Double.parseDouble(value_);
     
    3535        @Override
    3636        public Double doubleValue() {
    37                 if (value_ == "")
     37                if (value_.equals(""))
    3838                        return 0.0;
    3939                return Double.parseDouble(value_);
  • trunk/src/org/expeditee/simple/Variables.java

    r4 r80  
    2727        }
    2828
    29         public T getVariable(String name) throws Exception {
     29        public T getVariable(String name) throws VariableNotFoundException {
    3030                for (T v : list_) {
    3131                        if (v.getName().equalsIgnoreCase(name)) {
  • trunk/src/org/expeditee/stats/SessionStats.java

    r72 r80  
    8282        private static int _BackspaceCount;
    8383
     84        private static Date _FrameAccessDarkTime = new Date();
     85
    8486        public static String getCurrentStats() {
    8587                StringBuffer stats = getSessionDateTime();
     
    134136        private static String getFrameStats(boolean newline) {
    135137                StringBuffer stats = new StringBuffer();
    136                 appendStat(stats, "FramesAccessed", _AccessedFrames, newline, false, DEFAULT_VALUE_WIDTH,
    137                                 DEFAULT_RATE_WIDTH);
    138                 appendStat(stats, "FramesEdited", _SavedFrames, newline, false, DEFAULT_VALUE_WIDTH, DEFAULT_RATE_WIDTH);
     138                appendStat(stats, "FramesAccessed", _AccessedFrames, newline, false,
     139                                DEFAULT_VALUE_WIDTH, DEFAULT_RATE_WIDTH);
     140                appendStat(stats, "FramesEdited", _SavedFrames, newline, false,
     141                                DEFAULT_VALUE_WIDTH, DEFAULT_RATE_WIDTH);
    139142                return stats.toString();
    140143        }
     
    218221
    219222        }
    220        
    221         private static String getRate(int value){
     223
     224        private static String getRate(int value) {
    222225                return "" + Math.round(value * 60 / getMinutesUsed());
    223226        }
    224227
    225228        private static void appendStat(StringBuffer stats, String name, int value) {
    226                 appendStat(stats, name, value, true, false, DEFAULT_VALUE_WIDTH, DEFAULT_RATE_WIDTH);
     229                appendStat(stats, name, value, true, false, DEFAULT_VALUE_WIDTH,
     230                                DEFAULT_RATE_WIDTH);
    227231        }
    228232
     
    254258                        _FrameEvents.clear();
    255259                        _FrameAccessTime = new Date();
     260                        _FrameAccessDarkTime = (Time) _DarkTime.clone();
    256261                }
    257262        }
     
    303308        public static String getFrameEventList() {
    304309                StringBuilder eventList = new StringBuilder();
     310                // First put on the session and darkTime
     311                Time darkTime = new Time(_DarkTime.getTime()
     312                                - _FrameAccessDarkTime.getTime());
     313                Time activeTime = new Time((new Date()).getTime()
     314                                - _FrameAccessTime.getTime() - darkTime.getTime());
     315                eventList.append("ActiveTime:").append(
     316                                Logger.EasyDateFormat("KK:mm:ss", activeTime)).append('\n');
     317                eventList.append("DarkTime:").append(
     318                                Logger.EasyDateFormat("KK:mm:ss", darkTime)).append('\n');
    305319                for (String s : _FrameEvents)
    306                         eventList.append(s + '\n');
     320                        eventList.append(s).append('\n');
    307321                if (eventList.length() > 0)
    308322                        eventList.deleteCharAt(eventList.length() - 1);
     
    382396                int maxWidthValue = ("" + max).length();
    383397                int maxWidthRate = (getRate(max)).length();
    384                
     398
    385399                for (int i = 0; i < STAT_TYPES; i++) {
    386400                        int total = 0;
     
    398412                        // statType > 1
    399413                        if (nonZeroItems > 1)
    400                                 appendStat(stats, "Total" + statName, total, true, false, maxWidthValue , maxWidthRate);
     414                                appendStat(stats, "Total" + statName, total, true, false,
     415                                                maxWidthValue, maxWidthRate);
    401416                }
    402417                stats.deleteCharAt(stats.length() - 1);
     
    412427                        String upperBound = getFormattedTime(EVENT_INTERVALS[i]);
    413428                        appendStat(stats, "<" + upperBound, _EventTimes[i], true, false,
    414                                         maxWidthEvents,maxWidthRate);
     429                                        maxWidthEvents, maxWidthRate);
    415430                }
    416431                int lastIndex = EVENT_INTERVALS.length - 1;
    417432                appendStat(stats, "+"
    418433                                + getFormattedTime(EVENT_INTERVALS[lastIndex - 1]),
    419                                 _EventTimes[lastIndex], false, false, maxWidthEvents,maxWidthRate);
     434                                _EventTimes[lastIndex], false, false, maxWidthEvents,
     435                                maxWidthRate);
    420436                return stats.toString();
    421437        }
     
    424440         * Gets the highest number in the list of numbers.
    425441         *
    426          * @param nums list of numbers
     442         * @param nums
     443         *            list of numbers
    427444         * @return highest number in the list
    428445         */
Note: See TracChangeset for help on using the changeset viewer.