Show
Ignore:
Timestamp:
08/21/08 11:00:07 (5 months ago)
Author:
joonas.lehtinen@…
Message:

Fixes #2000 : AbstractComponent? parses size "100" incorrectly

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/com/itmill/toolkit/ui/AbstractComponent.java

    r5033 r5235  
    3434public abstract class AbstractComponent implements Component, MethodEventSource { 
    3535 
    36     /* Private members ************************************************* */ 
     36    /* Private members */ 
    3737 
    3838    /** 
     
    122122    private int heightUnit = UNITS_PIXELS; 
    123123 
    124     /* Constructor ***************************************************** */ 
     124    /* Constructor */ 
    125125 
    126126    /** 
     
    130130    } 
    131131 
    132     /* Get/Set component properties ************************************ */ 
     132    /* Get/Set component properties */ 
    133133 
    134134    /** 
     
    162162     * Sets and replaces all previous style names of the component. This method 
    163163     * will trigger a 
    164      * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}. 
     164     * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent 
     165     * RepaintRequestEvent}. 
    165166     *  
    166167     * @param style 
    167      *                the new style of the component. 
     168     *            the new style of the component. 
    168169     * @deprecated Use setStyleName() instead; renamed for consistency and to 
    169170     *             indicate that "style" should not be used to switch client 
     
    236237 
    237238    /** 
    238      * Sets the component's caption <code>String</code>. Caption is the 
    239      * visible name of the component. This method will trigger a 
    240      * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}. 
     239     * Sets the component's caption <code>String</code>. Caption is the visible 
     240     * name of the component. This method will trigger a 
     241     * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent 
     242     * RepaintRequestEvent}. 
    241243     *  
    242244     * @param caption 
    243      *                the new caption <code>String</code> for the component. 
     245     *            the new caption <code>String</code> for the component. 
    244246     */ 
    245247    public void setCaption(String caption) { 
     
    270272     *  
    271273     * @param locale 
    272      *                the locale to become this component's locale. 
     274     *            the locale to become this component's locale. 
    273275     */ 
    274276    public void setLocale(Locale locale) { 
     
    286288    /** 
    287289     * Sets the component's icon. This method will trigger a 
    288      * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}. 
     290     * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent 
     291     * RepaintRequestEvent}. 
    289292     *  
    290293     * @param icon 
    291      *                the icon to be shown with the component's caption. 
     294     *            the icon to be shown with the component's caption. 
    292295     */ 
    293296    public void setIcon(Resource icon) { 
     
    327330     * Sets the component's immediate mode to the specified status. This method 
    328331     * will trigger a 
    329      * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}. 
     332     * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent 
     333     * RepaintRequestEvent}. 
    330334     *  
    331335     * @param immediate 
    332      *                the boolean value specifying if the component should be in 
    333      *                the immediate mode after the call. 
     336     *            the boolean value specifying if the component should be in the 
     337     *            immediate mode after the call. 
    334338     * @see Component#isImmediate() 
    335339     */ 
     
    426430     * Sets the component's description. See {@link #getDescription()} for more 
    427431     * information on what the description is. This method will trigger a 
    428      * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}. 
     432     * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent 
     433     * RepaintRequestEvent}. 
    429434     *  
    430435     * @param description 
    431      *                the new description string for the component. 
     436     *            the new description string for the component. 
    432437     */ 
    433438    public void setDescription(String description) { 
     
    504509     *  
    505510     * @param componentError 
    506      *                the new <code>ErrorMessage</code> of the component. 
     511     *            the new <code>ErrorMessage</code> of the component. 
    507512     */ 
    508513    public void setComponentError(ErrorMessage componentError) { 
     
    569574    } 
    570575 
    571     /* Component painting ********************************************** */ 
     576    /* Component painting */ 
    572577 
    573578    /* Documented in super interface */ 
     
    647652     *  
    648653     * @param target 
    649      *                the target UIDL stream where the component should paint 
    650      *                itself to 
     654     *            the target UIDL stream where the component should paint itself 
     655     *            to 
    651656     * @throws PaintException 
    652      *                 if the paint operation failed. 
     657     *             if the paint operation failed. 
    653658     */ 
    654659    public void paintContent(PaintTarget target) throws PaintException { 
     
    728733    } 
    729734 
    730     /* Component variable changes ************************************** */ 
     735    /* Component variable changes */ 
    731736 
    732737    /* 
     
    738743    } 
    739744 
    740     /* General event framework *************************************** */ 
     745    /* General event framework */ 
    741746 
    742747    private static final Method COMPONENT_EVENT_METHOD; 
     
    764769     * <p> 
    765770     * For more information on the inheritable event mechanism see the 
    766      * {@link com.itmill.toolkit.event com.itmill.toolkit.event package documentation}. 
     771     * {@link com.itmill.toolkit.event com.itmill.toolkit.event package 
     772     * documentation}. 
    767773     * </p> 
    768774     *  
    769775     * @param eventType 
    770      *                the type of the listened event. Events of this type or its 
    771      *                subclasses activate the listener. 
     776     *            the type of the listened event. Events of this type or its 
     777     *            subclasses activate the listener. 
    772778     * @param object 
    773      *                the object instance who owns the activation method. 
     779     *            the object instance who owns the activation method. 
    774780     * @param method 
    775      *                the activation method. 
     781     *            the activation method. 
    776782     */ 
    777783    public void addListener(Class eventType, Object object, Method method) { 
     
    791797     *  
    792798     * <p> 
    793      * This version of <code>addListener</code> gets the name of the 
    794      * activation method as a parameter. The actual method is reflected from 
     799     * This version of <code>addListener</code> gets the name of the activation 
     800     * method as a parameter. The actual method is reflected from 
    795801     * <code>object</code>, and unless exactly one match is found, 
    796802     * <code>java.lang.IllegalArgumentException</code> is thrown. 
     
    799805     * <p> 
    800806     * For more information on the inheritable event mechanism see the 
    801      * {@link com.itmill.toolkit.event com.itmill.toolkit.event package documentation}. 
     807     * {@link com.itmill.toolkit.event com.itmill.toolkit.event package 
     808     * documentation}. 
    802809     * </p> 
    803810     *  
     
    809816     *  
    810817     * @param eventType 
    811      *                the type of the listened event. Events of this type or its 
    812      *                subclasses activate the listener. 
     818     *            the type of the listened event. Events of this type or its 
     819     *            subclasses activate the listener. 
    813820     * @param object 
    814      *                the object instance who owns the activation method. 
     821     *            the object instance who owns the activation method. 
    815822     * @param methodName 
    816      *                the name of the activation method. 
     823     *            the name of the activation method. 
    817824     */ 
    818825    public void addListener(Class eventType, Object object, String methodName) { 
     
    826833     * Removes all registered listeners matching the given parameters. Since 
    827834     * this method receives the event type and the listener object as 
    828      * parameters, it will unregister all <code>object</code>'s methods that 
    829      * are registered to listen to events of type <code>eventType</code> 
    830      * generated by this component. 
     835     * parameters, it will unregister all <code>object</code>'s methods that are 
     836     * registered to listen to events of type <code>eventType</code> generated 
     837     * by this component. 
    831838     *  
    832839     * <p> 
    833840     * For more information on the inheritable event mechanism see the 
    834      * {@link com.itmill.toolkit.event com.itmill.toolkit.event package documentation}. 
     841     * {@link com.itmill.toolkit.event com.itmill.toolkit.event package 
     842     * documentation}. 
    835843     * </p> 
    836844     *  
    837845     * @param eventType 
    838      *                the exact event type the <code>object</code> listens to. 
     846     *            the exact event type the <code>object</code> listens to. 
    839847     * @param target 
    840      *                the target object that has registered to listen to events 
    841      *                of type <code>eventType</code> with one or more methods. 
     848     *            the target object that has registered to listen to events of 
     849     *            type <code>eventType</code> with one or more methods. 
    842850     */ 
    843851    public void removeListener(Class eventType, Object target) { 
     
    854862     * <p> 
    855863     * For more information on the inheritable event mechanism see the 
    856      * {@link com.itmill.toolkit.event com.itmill.toolkit.event package documentation}. 
     864     * {@link com.itmill.toolkit.event com.itmill.toolkit.event package 
     865     * documentation}. 
    857866     * </p> 
    858867     *  
    859868     * @param eventType 
    860      *                the exact event type the <code>object</code> listens to. 
     869     *            the exact event type the <code>object</code> listens to. 
    861870     * @param target 
    862      *                target object that has registered to listen to events of 
    863      *                type <code>eventType</code> with one or more methods. 
     871     *            target object that has registered to listen to events of type 
     872     *            <code>eventType</code> with one or more methods. 
    864873     * @param method 
    865      *                the method owned by <code>target</code> that's 
    866      *                registered to listen to events of type 
    867      *                <code>eventType</code>. 
     874     *            the method owned by <code>target</code> that's registered to 
     875     *            listen to events of type <code>eventType</code>. 
    868876     */ 
    869877    public void removeListener(Class eventType, Object target, Method method) { 
     
    889897     * <p> 
    890898     * For more information on the inheritable event mechanism see the 
    891      * {@link com.itmill.toolkit.event com.itmill.toolkit.event package documentation}. 
     899     * {@link com.itmill.toolkit.event com.itmill.toolkit.event package 
     900     * documentation}. 
    892901     * </p> 
    893902     *  
    894903     * @param eventType 
    895      *                the exact event type the <code>object</code> listens to. 
     904     *            the exact event type the <code>object</code> listens to. 
    896905     * @param target 
    897      *                the target object that has registered to listen to events 
    898      *                of type <code>eventType</code> with one or more methods. 
     906     *            the target object that has registered to listen to events of 
     907     *            type <code>eventType</code> with one or more methods. 
    899908     * @param methodName 
    900      *                the name of the method owned by <code>target</code> 
    901      *                that's registered to listen to events of type 
    902      *                <code>eventType</code>. 
     909     *            the name of the method owned by <code>target</code> that's 
     910     *            registered to listen to events of type <code>eventType</code>. 
    903911     */ 
    904912    public void removeListener(Class eventType, Object target, String methodName) { 
     
    912920     *  
    913921     * @param event 
    914      *                the Event to be sent to all listeners. 
     922     *            the Event to be sent to all listeners. 
    915923     */ 
    916924    protected void fireEvent(Component.Event event) { 
     
    921929    } 
    922930 
    923     /* Component event framework *************************************** */ 
     931    /* Component event framework */ 
    924932 
    925933    /* 
     
    970978     *  
    971979     * @param data 
    972      *                the Application specific data. 
     980     *            the Application specific data. 
    973981     * @since 3.1 
    974982     */ 
     
    11191127        int[] values = new int[2]; 
    11201128        s = s.trim(); 
     1129 
     1130        // Percentages 
    11211131        if (s.indexOf("%") != -1) { 
    11221132            values[1] = UNITS_PERCENTAGE; 
    11231133            values[0] = (int) Float.parseFloat(s.substring(0, s.indexOf("%"))); 
    11241134        } else { 
    1125             values[0] = (int) Float.parseFloat(s.substring(0, s.length() - 2)); 
    1126             if (s.endsWith("px")) { 
    1127                 values[1] = UNITS_PIXELS; 
    1128             } else if (s.endsWith("em")) { 
    1129                 values[1] = UNITS_EM; 
    1130             } else if (s.endsWith("ex")) { 
    1131                 values[1] = UNITS_EX; 
    1132             } else if (s.endsWith("in")) { 
    1133                 values[1] = UNITS_INCH; 
    1134             } else if (s.endsWith("cm")) { 
    1135                 values[1] = UNITS_CM; 
    1136             } else if (s.endsWith("mm")) { 
    1137                 values[1] = UNITS_MM; 
    1138             } else if (s.endsWith("pt")) { 
    1139                 values[1] = UNITS_POINTS; 
    1140             } else if (s.endsWith("pc")) { 
    1141                 values[1] = UNITS_PICAS; 
     1135 
     1136            // We default to pixels 
     1137            values[1] = UNITS_PIXELS; 
     1138            try { 
     1139 
     1140                // If no units are specified 
     1141                values[0] = (int) Float.parseFloat(s); 
     1142                return values; 
     1143            } catch (NumberFormatException e) { 
     1144 
     1145                // Unit is specified and we assume 2 characters unit length 
     1146                values[0] = (int) Float.parseFloat(s.substring(0, 
     1147                        s.length() - 2)); 
     1148 
     1149                // Resolve unit 
     1150                String unit = s.substring(s.length() - 2).toLowerCase(); 
     1151                if (unit.equals("px")) { 
     1152                    // Already set 
     1153                } else if (unit.equals("em")) { 
     1154                    values[1] = UNITS_EM; 
     1155                } else if (unit.equals("ex")) { 
     1156                    values[1] = UNITS_EX; 
     1157                } else if (unit.equals("in")) { 
     1158                    values[1] = UNITS_INCH; 
     1159                } else if (unit.equals("cm")) { 
     1160                    values[1] = UNITS_CM; 
     1161                } else if (unit.equals("mm")) { 
     1162                    values[1] = UNITS_MM; 
     1163                } else if (unit.equals("pt")) { 
     1164                    values[1] = UNITS_POINTS; 
     1165                } else if (unit.equals("pc")) { 
     1166                    values[1] = UNITS_PICAS; 
     1167                } 
    11421168            } 
    11431169        }