Changeset 95 for trunk


Ignore:
Timestamp:
06/06/08 16:42:37 (16 years ago)
Author:
ra33
Message:

Added a couple of tests for AttributeUtils class

Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/.classpath

    r86 r95  
    11<?xml version="1.0" encoding="UTF-8"?>
    22<classpath>
    3         <classpathentry kind="src" output="bin/tests" path="tests"/>
    4         <classpathentry kind="src" output="bin/src" path="src"/>
     3        <classpathentry kind="src" path="tests"/>
     4        <classpathentry kind="src" path="src"/>
    55        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    66        <classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/>
  • trunk/src/org/expeditee/agents/ComputeTree.java

    r80 r95  
    9696
    9797                        if (value == null) {
    98                                 value = AttributeUtils.getDoubleValue(((Text) i)
    99                                                 .getText());
     98                                value = AttributeUtils.getDoubleValue(((Text) i).getFirstLine());
    10099                        }
    101100
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r88 r95  
    625625                        return "";
    626626
     627                int lineSeparator = toStrip.indexOf(Character.LINE_SEPARATOR);
     628                if(lineSeparator > 0){
     629                        toStrip = toStrip.substring(0,lineSeparator);
     630                }
     631               
    627632                int ind = toStrip.lastIndexOf(SEPARATOR_CHAR);
    628633
     
    634639                        }
    635640                        // It is a value with no attribute.
    636                         return toStrip;
     641                        return toStrip.trim();
    637642                }
    638643
     
    663668        }
    664669
     670        /**
     671         *
     672         * @param text
     673         * @param value
     674         */
    665675        public static void setSingleValue(Text text, String value) {
    666676                assert (value != null);
  • trunk/src/org/expeditee/gui/Frame.java

    r90 r95  
    3939public class Frame implements ImageObserver {
    4040
    41         public static Color[] COLOR_WHEEL = { Color.BLACK, Color.WHITE, Color.GRAY,
     41        public static Color[] COLOR_WHEEL = {
    4242                        new Color(235, 235, 235), new Color(225, 225, 255),
    4343                        new Color(195, 255, 255), new Color(225, 255, 225),
    4444                        new Color(255, 255, 195), new Color(255, 225, 225),
    45                         new Color(255, 195, 255), null };
     45                        new Color(255, 195, 255), Color.WHITE,
     46                        Color.GRAY, Color.DARK_GRAY,Color.BLACK, null };
    4647
    4748        // The various attributes of this Frame
  • trunk/src/org/expeditee/gui/FrameIO.java

    r90 r95  
    764764                        // check if this was the profile frame (and thus needs
    765765                        // re-parsing)
    766                         if (toSave.getFramesetName().toLowerCase().equals(
    767                                         UserSettings.Username.toLowerCase())) {
    768                                 FrameUtils.ParseProfile(FrameIO.LoadFrame(toSave
    769                                                 .getFramesetName()
    770                                                 + "1"));
     766                        if (isProfileFrame(toSave)) {
     767                                Frame profile = FrameIO.LoadFrame(toSave.getFramesetName()+ "1");
     768                                assert(profile != null);
     769                                FrameUtils.ParseProfile(profile);
    771770                        }
    772771                } catch (IOException ioe) {
    773                         // ioe.printStackTrace();
     772                        ioe.getStackTrace();
    774773                        Logger.Log(ioe);
    775774                        return null;
     
    777776
    778777                return writer.getFileContents();
     778        }
     779
     780        /**
     781         * Checks if a frame is in the current user profile frameset.
     782         * @param toCheck the frame to check
     783         * @return true if the frame is in the current user profile frameset
     784         */
     785        public static boolean isProfileFrame(Frame toCheck) {
     786                if(toCheck.getNumber() == 0)
     787                        return false;
     788                return toCheck.getFramesetName()
     789                .equalsIgnoreCase(UserSettings.Username);
    779790        }
    780791
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r88 r95  
    489489                Item current = FrameUtils.getCurrentItem();
    490490                Frame currentFrame = DisplayIO.getCurrentFrame();
    491                 //Link or delink an item
    492                 if (ch.charAt(0) ==  KeyEvent.VK_L) {
     491                // Link or delink an item
     492                if (ch.charAt(0) == KeyEvent.VK_L) {
    493493                        // If its not linked then link it to its self
    494494                        if (current instanceof Text && current.getLink() == null) {
     
    503503                                current.setLink(null);
    504504                        }
    505                 } else if (ch.charAt(0) ==  KeyEvent.VK_G) {
     505                } else if (ch.charAt(0) == KeyEvent.VK_G) {
    506506                        // If its not linked then link it to its self
    507507                        if (current instanceof Text) {
     
    513513                                }
    514514                        }
    515                         if (current.getLink() != null){
     515                        if (current.getLink() != null) {
    516516                                NavigationActions.Goto(current.getAbsoluteLink());
    517517                                return;
    518518                        }
    519                 } else if (ch.charAt(0) ==  KeyEvent.VK_A) {
     519                } else if (ch.charAt(0) == KeyEvent.VK_A) {
    520520                        // If its not linked then link it to its self
    521521                        if (current instanceof Text && current.getAction() == null) {
    522522                                String text = ((Text) current).getText().trim();
    523                                 //first trim the annotation
     523                                // first trim the annotation
    524524                                if (text.startsWith("@")) {
    525525                                        text = text.substring(1).trim();
    526526                                }
    527                                 //then trim the action
     527                                // then trim the action
    528528                                String lowerCaseText = text.toLowerCase();
    529529                                if (lowerCaseText.startsWith("a:")) {
     
    531531                                } else if (lowerCaseText.startsWith("action:")) {
    532532                                        text = text.substring("action:".length()).trim();
    533                                        
     533
    534534                                }
    535535                                current.setAction(text);
     
    624624                        processChar((char) KeyEvent.VK_DELETE, e.isShiftDown());
    625625                        FrameMouseActions.delete(current);
    626                 }else if (ch.charAt(0) == KeyEvent.VK_F) {
     626                } else if (ch.charAt(0) == KeyEvent.VK_F) {
    627627                        // perform a delete operation
    628628                        Actions.PerformAction(currentFrame, null, "Format");
     
    662662                        }
    663663                }
    664                         FrameGraphics.Repaint();
     664                FrameGraphics.Repaint();
    665665        }
    666666
     
    814814                        break;
    815815                case Refresh:
    816                         Repaint(on);
     816                        Refresh(on);
    817817                        break;
    818818                }
     
    15821582         *            This Item is currently ignored
    15831583         */
    1584         private static void Repaint(Item ignored) {
    1585                 FrameUtils.Parse(DisplayIO.getCurrentFrame());
     1584        private static void Refresh(Item ignored) {
     1585                Frame currentFrame = DisplayIO.getCurrentFrame();
     1586                if (FrameIO.isProfileFrame(currentFrame)) {
     1587                        //TODO ensure that users can not delete the first frame in a frameset...
     1588                        //TODO handle the case when users manually delete the first frame in a frameset from the filesystem
     1589                        Frame profile = FrameIO.LoadFrame(currentFrame.getFramesetName()
     1590                                        + "1");
     1591                        assert (profile != null);
     1592                        FrameUtils.ParseProfile(profile);
     1593                } else {
     1594                        FrameUtils.Parse(currentFrame);
     1595                }
    15861596                // Need to update the cursor for when text items change to @b pictures
    15871597                // etc and the text cursor is showing
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r90 r95  
    577577                // check for all tags setting user values
    578578                for (Item item : items) {
     579                        if (!item.isAnnotation())
     580                                continue;
     581                       
    579582                        if (ItemUtils.startsWithTag(item, "@HomeFrame")) {
    580583                                String first = getLink(item, UserSettings.FirstFrame);
     
    585588                                // warn the user
    586589                                else {
    587                                         FrameGraphics.WarningMessage("Home frame: " + first
    588                                                         + " is not a valid frame.");
     590                                        //FrameGraphics.WarningMessage("Home frame: " + first
     591                                        //              + " is not a valid frame.");
    589592                                        UserSettings.FirstFrame = profile.getName();
    590593                                }
     
    638641                        } else if (ItemUtils.startsWithTag(item, "@FramesetDir")) {
    639642                                String dir = getDir(item, null);
    640                                 if (dir != null)
     643                                if (dir != null){
    641644                                        UserSettings.FrameDirs.add(dir);
     645                                }
    642646                        } else if (ItemUtils.startsWithTag(item, "@LogDir")) {
    643647                                org.expeditee.gui.FrameIO.LOGS_DIR = getDir(item,
     
    658662                        } else if (ItemUtils.startsWithTag(item, "@FramesetDirs")) {
    659663                                UserSettings.FrameDirs.addAll(getDirs(item));
     664                        } else {
     665                               
    660666                        }
    661667                }
     
    750756                                else
    751757                                        return name + File.separator;
    752                         }
    753                 }
    754 
     758                        }else{
     759                                FrameGraphics.ErrorMessage("Directory not found: " + name);
     760                        }
     761                }else{
     762                        FrameGraphics.WarningMessage("Missing value for profile attribute" + name);
     763                }
    755764                return alt;
    756765        }
     
    14041413                                for (File helpFrameset : helpFramesets) {
    14051414                                        String framesetName = helpFrameset.getName();
     1415                                        if(!FrameIO.isValidFramesetName(framesetName))
     1416                                                continue;
    14061417                                        Frame indexFrame = FrameIO.LoadFrame(framesetName + '1');
    14071418                                        // Look through the folder for help index pages
  • trunk/src/org/expeditee/items/Item.java

    r88 r95  
    9898         * this Item.
    9999         */
    100         public static Color[] COLOR_WHEEL = { Color.BLACK, Color.RED, Color.BLUE,
    101                         Item.GREEN, Color.MAGENTA, Color.YELLOW.darker(), Color.WHITE, null };
    102 
    103         public static Color[] FILL_COLOR_WHEEL = { Color.BLACK,
    104                         new Color(255, 150, 150), new Color(150, 150, 255),
    105                         new Color(150, 255, 150), new Color(255, 150, 255),
    106                         new Color(255, 255, 100), Color.WHITE, null };
     100        public static Color[] COLOR_WHEEL = { Color.RED, Color.BLUE, Item.GREEN,
     101                        Color.MAGENTA, Color.YELLOW.darker(), Color.BLACK, Color.DARK_GRAY,
     102                        Color.GRAY, Color.WHITE, null };
     103
     104        public static Color[] FILL_COLOR_WHEEL = { new Color(255, 150, 150),
     105                        new Color(150, 150, 255), new Color(150, 255, 150),
     106                        new Color(255, 150, 255), new Color(255, 255, 100), Color.WHITE,
     107                        Color.GRAY, Color.DARK_GRAY, Color.BLACK, null };
    107108
    108109        public static final int UNCHANGED_CURSOR = -100;
     
    116117        public static final int CROP_CURSOR = Cursor.CROSSHAIR_CURSOR;
    117118
    118         //The default value for integer attributes
     119        // The default value for integer attributes
    119120        public static final int DEFAULT_INTEGER = -1;
    120121
     
    173174                dest._mode = SelectedMode.None;
    174175                dest._lastMode = source._mode;
    175                
     176
    176177                Frame parent = source.getParentOrCurrentFrame();
    177178                // TODO MIKE says maybe we could tighten up and only give items ID's if
     
    13251326                        // only set position if the other dot is still fixed to the
    13261327                        // frame
    1327                         if (/*this.isFloating() &&*/ !other.isFloating()) {
     1328                        if (/* this.isFloating() && */!other.isFloating()) {
    13281329                                if (c.getType() == Constraint.HORIZONTAL) {
    13291330                                        if (other.getY() != y)
  • trunk/src/org/expeditee/items/ItemUtils.java

    r90 r95  
    11package org.expeditee.items;
    22
    3 import java.awt.Font;
    4 import java.awt.FontMetrics;
    5 import java.awt.Image;
    63import java.awt.image.ImageObserver;
    74import java.io.File;
     
    1714import java.util.Map;
    1815
    19 import javax.swing.JFrame;
    20 
    2116import org.expeditee.gui.AttributeUtils;
    2217import org.expeditee.gui.DisplayIO;
     
    3025 */
    3126public class ItemUtils {
    32         private static JFrame _jf = new JFrame();
    33 
    3427        // Tag constants
    3528        public static final int TAG_SORT = 0;
     
    321314
    322315        /**
    323          * Returns a FontMetrics object that corresponds to the given Font.
    324          *
    325          * @param font
    326          *            The Font to derive the FontMetrics from
    327          * @return FontMetrics that correspond to the given Font
    328          */
    329         public static FontMetrics getFontMetrics(Font font) {
    330                 return _jf.getFontMetrics(font);
    331         }
    332 
    333         public static Image CreateImage(int x, int y) {
    334                 return _jf.createImage(x, y);
    335         }
    336 
    337         /**
    338316         * Creates a picture object from the information stored in the given Text
    339317         * object. <br>
Note: See TracChangeset for help on using the changeset viewer.