Changeset 67 for trunk/src/org/expeditee/io/Conversion.java
- Timestamp:
- 05/19/08 12:03:18 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/io/Conversion.java
r4 r67 10 10 import java.util.StringTokenizer; 11 11 12 import org.expeditee.gui.DisplayIO;13 12 import org.expeditee.items.Item; 14 13 import org.expeditee.items.Text; … … 48 47 } 49 48 49 // check if its a normal rgb code ie. 100 0 40 50 50 Color rgb = getRGBColor(colorCode, current); 51 51 if (rgb != null) … … 58 58 char c = colorCode.charAt(last); 59 59 60 while ( c >= '0' && c <= '9') {60 while (Character.isDigit(c)) { 61 61 num = c + num; 62 62 if (last <= 0) … … 69 69 if (num.length() > 0) 70 70 amount = Float.parseFloat(num); 71 72 if(amount > 10) 73 amount = 10; 71 74 72 75 float color[] = { 0, 0, 0 }; … … 74 77 if (colorCode.toLowerCase().startsWith("red")) 75 78 color[0] = amount / 10; 76 77 if (colorCode.toLowerCase().startsWith("green")) 79 else if (colorCode.toLowerCase().startsWith("green")) 78 80 color[1] = amount / 10; 79 80 if (colorCode.toLowerCase().startsWith("blue")) 81 else if (colorCode.toLowerCase().startsWith("blue")) 81 82 color[2] = amount / 10; 83 else 84 return current; 82 85 83 86 return new Color(color[0], color[1], color[2]); … … 88 91 89 92 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"; 97 98 98 99 if (current != null && (r.startsWith("+") || r.startsWith("-"))) { … … 125 126 return new Color(color[0], color[1], color[2]); 126 127 } catch (Exception e) { 127 return current;128 return null; 128 129 } 129 130 } … … 200 201 String code = "t"; 201 202 String fontName = font.getFamily().toLowerCase(); 202 203 203 204 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)) { 205 206 code = "" + Text.FONT_CHARS[i]; 206 207 break; 207 208 } 208 209 } 209 210 210 211 switch (font.getStyle()) { 211 212 case Font.BOLD: … … 297 298 */ 298 299 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 } 301 312 302 313 try { … … 309 320 /** 310 321 * Returns the frameset poriton of the given Frame name (frame number 311 * removed) 322 * removed) converted to lower case. 312 323 * 313 324 * @param frame … … 319 330 } 320 331 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 } 327 343 } 328 344 … … 343 359 */ 344 360 public static int getJustification(String justCode) { 361 assert (justCode != null); 362 justCode = justCode.trim().toLowerCase(); 345 363 // as read from file 346 364 if (justCode.length() == 1) { 347 365 switch (justCode.charAt(0)) { 348 case ' F':366 case 'f': 349 367 return Item.JUSTIFICATION_FULL; 350 case ' L':368 case 'l': 351 369 return Item.JUSTIFICATION_LEFT; 352 case ' R':370 case 'r': 353 371 return Item.JUSTIFICATION_RIGHT; 354 case ' C':372 case 'c': 355 373 return Item.JUSTIFICATION_CENTER; 356 374 } … … 358 376 359 377 // from the user 360 justCode = justCode.trim().toLowerCase();361 378 if (justCode.equals("center")) 362 379 return Item.JUSTIFICATION_CENTER; … … 395 412 public static Object Convert(Class type, String value, Object orig) { 396 413 // System.out.println("Orig: " + orig); 414 assert (value != null); 415 value = value.trim(); 397 416 398 417 if (type == String.class … … 401 420 else if (type == String.class) 402 421 return value; 403 404 /*405 * if(type == int.class || type == Integer.class){ return406 * Integer.parseInt(value); }407 *408 * if(type == float.class || type == Float.class){ return409 * Float.parseFloat(value); }410 */411 422 412 423 if (type == Font.class) { … … 510 521 511 522 public static Object[] Convert(Method method, String value, Object current) { 523 value = value.trim(); 512 524 513 525 String name = method.getName();
Note:
See TracChangeset
for help on using the changeset viewer.