Changeset 70 for trunk/src/org/expeditee/gui/AttributeUtils.java
- Timestamp:
- 05/21/08 09:40:52 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/AttributeUtils.java
r67 r70 3 3 import java.awt.Color; 4 4 import java.awt.Font; 5 import java.awt.Point; 5 6 import java.lang.reflect.InvocationTargetException; 6 7 import java.lang.reflect.Method; … … 27 28 private static final String SEPARATOR_STRING = SEPARATOR_CHAR + " "; 28 29 30 private static final int GET_LENGTH = "get".length(); 31 32 private static int SET_LENGTH = "set".length(); 33 29 34 // List of method names to ignore when searching for a match 30 35 private static List<Method> _GetMethods = null; … … 56 61 _Ignore.add("link"); 57 62 _Ignore.add("l"); 63 _Ignore.add("position"); 64 _Ignore.add("pos"); 65 _Ignore.add("p"); 58 66 59 67 _AllowNull = new LinkedList<Method>(); … … 94 102 _GetMethods.add(Item.class.getMethod("getLinkFrameset", param)); 95 103 _GetMethods.add(Item.class.getMethod("getLinkTemplate", param)); 104 _GetMethods.add(Item.class.getMethod("getPosition", param)); 96 105 97 106 _GetMethods.add(Text.class.getMethod("getFamily", param)); … … 109 118 _GetMethods.add(Frame.class.getMethod("getBackgroundColor", param)); 110 119 120 Class[] pPoint = { Point.class }; 111 121 Class[] pString = { String.class }; 112 122 Class[] pInt = { int.class }; … … 119 129 120 130 _SetMethods = new HashMap<String, Method>(); 121 131 _SetMethods.put("position", Item.class.getMethod("setPosition", 132 pPoint)); 133 _SetMethods.put("p", Item.class.getMethod("setPosition", pPoint)); 134 _SetMethods.put("pos", Item.class.getMethod("setPosition", pPoint)); 122 135 _SetMethods.put("thickness", Item.class.getMethod("setThickness", 123 136 pFloat)); … … 143 156 144 157 _SetMethods.put("fillpattern", Item.class.getMethod( 158 "setFillPattern", pString)); 159 _SetMethods.put("fp", Item.class.getMethod( 145 160 "setFillPattern", pString)); 146 161 … … 167 182 168 183 _SetMethods.put("linepattern", Item.class.getMethod( 184 "setLinePattern", pIntArray)); 185 _SetMethods.put("lp", Item.class.getMethod( 169 186 "setLinePattern", pIntArray)); 170 187 _SetMethods.put("linkframeset", Item.class.getMethod( … … 250 267 && convertJustificationToString((Integer) o) != null) 251 268 attributes 252 .append(m.getName().substring( 3))269 .append(m.getName().substring(GET_LENGTH)) 253 270 .append(SEPARATOR_STRING) 254 271 .append( … … 257 274 // -1 indicates default value 258 275 else if (((Integer) o) > -1) 259 attributes.append(m.getName().substring( 3))276 attributes.append(m.getName().substring(GET_LENGTH)) 260 277 .append(SEPARATOR_STRING).append(o) 261 278 .append("\n"); … … 263 280 // -1 indicates default value 264 281 if (((Float) o) > 0.0001) 265 attributes.append(m.getName().substring( 3))282 attributes.append(m.getName().substring(GET_LENGTH)) 266 283 .append(SEPARATOR_STRING).append(o) 267 284 .append("\n"); … … 269 286 // -1 indicates default value 270 287 if (((Double) o) > 0.0001) 271 attributes.append(m.getName().substring( 3))288 attributes.append(m.getName().substring(GET_LENGTH)) 272 289 .append(SEPARATOR_STRING).append(o) 273 290 .append("\n"); … … 276 293 String s = Conversion.getKMSColorCode((Color) o); 277 294 if (s != null) 278 attributes.append(m.getName().substring( 3))295 attributes.append(m.getName().substring(GET_LENGTH)) 279 296 .append(SEPARATOR_STRING).append(s) 280 297 .append("\n"); 298 } else if (o instanceof Point) { 299 Point p = (Point) o; 300 String s = (int) p.getX() + " " + (int) p.getY(); 301 attributes.append(m.getName().substring(GET_LENGTH)).append( 302 SEPARATOR_STRING).append(s).append("\n"); 281 303 } else if (o instanceof Font) { 282 304 Font f = (Font) o; … … 294 316 s += "-" + f.getSize(); 295 317 296 attributes.append(m.getName().substring( 3)).append(318 attributes.append(m.getName().substring(GET_LENGTH)).append( 297 319 SEPARATOR_STRING).append(s).append("\n"); 298 320 } else if (o instanceof Text) { 299 attributes.append(m.getName().substring( 3)).append(321 attributes.append(m.getName().substring(GET_LENGTH)).append( 300 322 SEPARATOR_STRING).append( 301 323 ((Text) o).getFirstLine()).append("\n"); … … 303 325 List list = (List) o; 304 326 for (Object ob : list) 305 attributes.append(m.getName().substring( 3))327 attributes.append(m.getName().substring(GET_LENGTH)) 306 328 .append(SEPARATOR_STRING).append(ob) 307 329 .append("\n"); … … 309 331 // true is the default for boolean values 310 332 if (!((Boolean) o).booleanValue()) 311 attributes.append(m.getName().substring( 3))333 attributes.append(m.getName().substring(GET_LENGTH)) 312 334 .append(SEPARATOR_STRING).append(o) 313 335 .append("\n"); 314 336 } else 315 attributes.append(m.getName().substring( 3)).append(337 attributes.append(m.getName().substring(GET_LENGTH)).append( 316 338 SEPARATOR_STRING).append(o).append("\n"); 317 339 … … 325 347 // are in the AllowNull list 326 348 } else if (_AllowNull.contains(m)) 327 attributes.append(m.getName().substring( 3)).append(349 attributes.append(m.getName().substring(GET_LENGTH)).append( 328 350 SEPARATOR_CHAR + "\n"); 329 351 } catch (IllegalArgumentException e) { … … 530 552 Object current = null; 531 553 Object[] param = {}; 532 554 Class toSetClass = toSet.getClass(); 555 Class toSetSuperClass = toSetClass.getSuperclass(); 533 556 // find the corresponding get method for this set method 534 557 for (Method m : _GetMethods) { 535 if ( m.getDeclaringClass() == toSet.getClass()536 && m.getName() 537 .endsWith(possible.getName().substring(3))) {558 if ((m.getDeclaringClass() == toSetClass || m.getDeclaringClass() == toSetSuperClass) 559 && m.getName().substring(GET_LENGTH).equals( 560 possible.getName().substring(SET_LENGTH))) { 538 561 try { 539 562 current = m.invoke(toSet, param);
Note:
See TracChangeset
for help on using the changeset viewer.