Ignore:
Timestamp:
05/19/08 12:03:18 (16 years ago)
Author:
ra33
Message:

Fixed a bunch of problems with rectangles and resizing the window, as well as adding some more unit tests etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/io/Conversion.java

    r4 r67  
    1010import java.util.StringTokenizer;
    1111
    12 import org.expeditee.gui.DisplayIO;
    1312import org.expeditee.items.Item;
    1413import org.expeditee.items.Text;
     
    4847                }
    4948
     49                // check if its a normal rgb code ie. 100 0 40
    5050                Color rgb = getRGBColor(colorCode, current);
    5151                if (rgb != null)
     
    5858                char c = colorCode.charAt(last);
    5959
    60                 while (c >= '0' && c <= '9') {
     60                while (Character.isDigit(c)) {
    6161                        num = c + num;
    6262                        if (last <= 0)
     
    6969                if (num.length() > 0)
    7070                        amount = Float.parseFloat(num);
     71               
     72                if(amount > 10)
     73                        amount = 10;
    7174
    7275                float color[] = { 0, 0, 0 };
     
    7477                if (colorCode.toLowerCase().startsWith("red"))
    7578                        color[0] = amount / 10;
    76 
    77                 if (colorCode.toLowerCase().startsWith("green"))
     79                else if (colorCode.toLowerCase().startsWith("green"))
    7880                        color[1] = amount / 10;
    79 
    80                 if (colorCode.toLowerCase().startsWith("blue"))
     81                else if (colorCode.toLowerCase().startsWith("blue"))
    8182                        color[2] = amount / 10;
     83                else
     84                        return current;
    8285
    8386                return new Color(color[0], color[1], color[2]);
     
    8891
    8992                try {
    90                         String r = colorCode.substring(0, colorCode.indexOf(" "));
    91                         colorCode = colorCode.substring(r.length() + 1);
    92 
    93                         String g = colorCode.substring(0, colorCode.indexOf(" "));
    94                         colorCode = colorCode.substring(g.length() + 1);
    95 
    96                         String b = colorCode.substring(0);
     93                        String[] values = colorCode.trim().split("\\s+");
     94                       
     95                        String r = values.length > 0 ? values[0] : "0";
     96                        String g = values.length > 1 ? values[1] : "0";
     97                        String b = values.length > 2 ? values[2] : "0";
    9798
    9899                        if (current != null && (r.startsWith("+") || r.startsWith("-"))) {
     
    125126                        return new Color(color[0], color[1], color[2]);
    126127                } catch (Exception e) {
    127                         return current;
     128                        return null;
    128129                }
    129130        }
     
    200201                String code = "t";
    201202                String fontName = font.getFamily().toLowerCase();
    202                
     203
    203204                for (int i = 0; i < Text.FONT_WHEEL.length; i++) {
    204                         if (Text.FONT_WHEEL[i].equals(fontName)){
     205                        if (Text.FONT_WHEEL[i].equals(fontName)) {
    205206                                code = "" + Text.FONT_CHARS[i];
    206207                                break;
    207208                        }
    208209                }
    209                
     210
    210211                switch (font.getStyle()) {
    211212                case Font.BOLD:
     
    297298         */
    298299        public static int getFrameNumber(String framename) {
    299                 String num = framename
    300                                 .replaceFirst("^\\w+([^\\d]+|\\d+[.][^\\d]+)", "");
     300                String num = null;
     301                // The framename must end in a digit
     302                assert (Character.isDigit(framename.charAt(framename.length() - 1)));
     303                // And start with a letter
     304                assert (Character.isLetter(framename.charAt(0)));
     305                // start at the end and find the first non digit char
     306                for (int i = framename.length() - 2; i >= 0; i--) {
     307                        if (!Character.isDigit(framename.charAt(i))) {
     308                                num = framename.substring(i + 1);
     309                                break;
     310                        }
     311                }
    301312
    302313                try {
     
    309320        /**
    310321         * Returns the frameset poriton of the given Frame name (frame number
    311          * removed)
     322         * removed) converted to lower case.
    312323         *
    313324         * @param frame
     
    319330        }
    320331
    321         public static String getFrameset(String frame, boolean convertToLower) {
    322                 String set = frame.replaceFirst("(\\d+|[.]\\d+)$", "");
    323 
    324                 // if there is no frameset given, then add the current frameset
    325                 if (set.length() == 0) {
    326                         set = DisplayIO.getCurrentFrame().getFramesetName();
     332        public static String getFrameset(String framename, boolean convertToLower) {
     333                String set = null;
     334                assert (Character.isDigit(framename.charAt(framename.length() - 1)));
     335                // And start with a letter
     336                assert (Character.isLetter(framename.charAt(0)));
     337                // start at the end and find the first non digit char
     338                for (int i = framename.length() - 2; i >= 0; i--) {
     339                        if (!Character.isDigit(framename.charAt(i))) {
     340                                set = framename.substring(0, i + 1);
     341                                break;
     342                        }
    327343                }
    328344
     
    343359         */
    344360        public static int getJustification(String justCode) {
     361                assert (justCode != null);
     362                justCode = justCode.trim().toLowerCase();
    345363                // as read from file
    346364                if (justCode.length() == 1) {
    347365                        switch (justCode.charAt(0)) {
    348                         case 'F':
     366                        case 'f':
    349367                                return Item.JUSTIFICATION_FULL;
    350                         case 'L':
     368                        case 'l':
    351369                                return Item.JUSTIFICATION_LEFT;
    352                         case 'R':
     370                        case 'r':
    353371                                return Item.JUSTIFICATION_RIGHT;
    354                         case 'C':
     372                        case 'c':
    355373                                return Item.JUSTIFICATION_CENTER;
    356374                        }
     
    358376
    359377                // from the user
    360                 justCode = justCode.trim().toLowerCase();
    361378                if (justCode.equals("center"))
    362379                        return Item.JUSTIFICATION_CENTER;
     
    395412        public static Object Convert(Class type, String value, Object orig) {
    396413                // System.out.println("Orig: " + orig);
     414                assert (value != null);
     415                value = value.trim();
    397416
    398417                if (type == String.class
     
    401420                else if (type == String.class)
    402421                        return value;
    403 
    404                 /*
    405                  * if(type == int.class || type == Integer.class){ return
    406                  * Integer.parseInt(value); }
    407                  *
    408                  * if(type == float.class || type == Float.class){ return
    409                  * Float.parseFloat(value); }
    410                  */
    411422
    412423                if (type == Font.class) {
     
    510521
    511522        public static Object[] Convert(Method method, String value, Object current) {
     523                value = value.trim();
    512524
    513525                String name = method.getName();
Note: See TracChangeset for help on using the changeset viewer.