Changeset 5235
- Timestamp:
- 08/21/08 11:00:07 (3 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/itmill/toolkit/ui/AbstractComponent.java
r5033 r5235 34 34 public abstract class AbstractComponent implements Component, MethodEventSource { 35 35 36 /* Private members * ************************************************ */36 /* Private members */ 37 37 38 38 /** … … 122 122 private int heightUnit = UNITS_PIXELS; 123 123 124 /* Constructor * **************************************************** */124 /* Constructor */ 125 125 126 126 /** … … 130 130 } 131 131 132 /* Get/Set component properties * *********************************** */132 /* Get/Set component properties */ 133 133 134 134 /** … … 162 162 * Sets and replaces all previous style names of the component. This method 163 163 * will trigger a 164 * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}. 164 * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent 165 * RepaintRequestEvent}. 165 166 * 166 167 * @param style 167 * the new style of the component.168 * the new style of the component. 168 169 * @deprecated Use setStyleName() instead; renamed for consistency and to 169 170 * indicate that "style" should not be used to switch client … … 236 237 237 238 /** 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}. 241 243 * 242 244 * @param caption 243 * the new caption <code>String</code> for the component.245 * the new caption <code>String</code> for the component. 244 246 */ 245 247 public void setCaption(String caption) { … … 270 272 * 271 273 * @param locale 272 * the locale to become this component's locale.274 * the locale to become this component's locale. 273 275 */ 274 276 public void setLocale(Locale locale) { … … 286 288 /** 287 289 * 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}. 289 292 * 290 293 * @param icon 291 * the icon to be shown with the component's caption.294 * the icon to be shown with the component's caption. 292 295 */ 293 296 public void setIcon(Resource icon) { … … 327 330 * Sets the component's immediate mode to the specified status. This method 328 331 * will trigger a 329 * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}. 332 * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent 333 * RepaintRequestEvent}. 330 334 * 331 335 * @param immediate 332 * the boolean value specifying if the component should be in333 * theimmediate mode after the call.336 * the boolean value specifying if the component should be in the 337 * immediate mode after the call. 334 338 * @see Component#isImmediate() 335 339 */ … … 426 430 * Sets the component's description. See {@link #getDescription()} for more 427 431 * 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}. 429 434 * 430 435 * @param description 431 * the new description string for the component.436 * the new description string for the component. 432 437 */ 433 438 public void setDescription(String description) { … … 504 509 * 505 510 * @param componentError 506 * the new <code>ErrorMessage</code> of the component.511 * the new <code>ErrorMessage</code> of the component. 507 512 */ 508 513 public void setComponentError(ErrorMessage componentError) { … … 569 574 } 570 575 571 /* Component painting * ********************************************* */576 /* Component painting */ 572 577 573 578 /* Documented in super interface */ … … 647 652 * 648 653 * @param target 649 * the target UIDL stream where the component should paint650 * itselfto654 * the target UIDL stream where the component should paint itself 655 * to 651 656 * @throws PaintException 652 * if the paint operation failed.657 * if the paint operation failed. 653 658 */ 654 659 public void paintContent(PaintTarget target) throws PaintException { … … 728 733 } 729 734 730 /* Component variable changes * ************************************* */735 /* Component variable changes */ 731 736 732 737 /* … … 738 743 } 739 744 740 /* General event framework * ************************************** */745 /* General event framework */ 741 746 742 747 private static final Method COMPONENT_EVENT_METHOD; … … 764 769 * <p> 765 770 * 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}. 767 773 * </p> 768 774 * 769 775 * @param eventType 770 * the type of the listened event. Events of this type or its771 * subclasses activate the listener.776 * the type of the listened event. Events of this type or its 777 * subclasses activate the listener. 772 778 * @param object 773 * the object instance who owns the activation method.779 * the object instance who owns the activation method. 774 780 * @param method 775 * the activation method.781 * the activation method. 776 782 */ 777 783 public void addListener(Class eventType, Object object, Method method) { … … 791 797 * 792 798 * <p> 793 * This version of <code>addListener</code> gets the name of the 794 * activationmethod as a parameter. The actual method is reflected from799 * This version of <code>addListener</code> gets the name of the activation 800 * method as a parameter. The actual method is reflected from 795 801 * <code>object</code>, and unless exactly one match is found, 796 802 * <code>java.lang.IllegalArgumentException</code> is thrown. … … 799 805 * <p> 800 806 * 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}. 802 809 * </p> 803 810 * … … 809 816 * 810 817 * @param eventType 811 * the type of the listened event. Events of this type or its812 * subclasses activate the listener.818 * the type of the listened event. Events of this type or its 819 * subclasses activate the listener. 813 820 * @param object 814 * the object instance who owns the activation method.821 * the object instance who owns the activation method. 815 822 * @param methodName 816 * the name of the activation method.823 * the name of the activation method. 817 824 */ 818 825 public void addListener(Class eventType, Object object, String methodName) { … … 826 833 * Removes all registered listeners matching the given parameters. Since 827 834 * 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 * generatedby 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. 831 838 * 832 839 * <p> 833 840 * 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}. 835 843 * </p> 836 844 * 837 845 * @param eventType 838 * the exact event type the <code>object</code> listens to.846 * the exact event type the <code>object</code> listens to. 839 847 * @param target 840 * the target object that has registered to listen to events841 * oftype <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. 842 850 */ 843 851 public void removeListener(Class eventType, Object target) { … … 854 862 * <p> 855 863 * 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}. 857 866 * </p> 858 867 * 859 868 * @param eventType 860 * the exact event type the <code>object</code> listens to.869 * the exact event type the <code>object</code> listens to. 861 870 * @param target 862 * target object that has registered to listen to events of863 * 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. 864 873 * @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>. 868 876 */ 869 877 public void removeListener(Class eventType, Object target, Method method) { … … 889 897 * <p> 890 898 * 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}. 892 901 * </p> 893 902 * 894 903 * @param eventType 895 * the exact event type the <code>object</code> listens to.904 * the exact event type the <code>object</code> listens to. 896 905 * @param target 897 * the target object that has registered to listen to events898 * oftype <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. 899 908 * @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>. 903 911 */ 904 912 public void removeListener(Class eventType, Object target, String methodName) { … … 912 920 * 913 921 * @param event 914 * the Event to be sent to all listeners.922 * the Event to be sent to all listeners. 915 923 */ 916 924 protected void fireEvent(Component.Event event) { … … 921 929 } 922 930 923 /* Component event framework * ************************************** */931 /* Component event framework */ 924 932 925 933 /* … … 970 978 * 971 979 * @param data 972 * the Application specific data.980 * the Application specific data. 973 981 * @since 3.1 974 982 */ … … 1119 1127 int[] values = new int[2]; 1120 1128 s = s.trim(); 1129 1130 // Percentages 1121 1131 if (s.indexOf("%") != -1) { 1122 1132 values[1] = UNITS_PERCENTAGE; 1123 1133 values[0] = (int) Float.parseFloat(s.substring(0, s.indexOf("%"))); 1124 1134 } 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 } 1142 1168 } 1143 1169 }
