Changeset 1102 for trunk/src/org/expeditee/io/Conversion.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/io/Conversion.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Color;22 import java.awt.Font;23 import java.awt.Point;24 21 import java.lang.reflect.Field; 25 22 import java.lang.reflect.Method; … … 29 26 30 27 import org.expeditee.actions.Actions; 28 import org.expeditee.core.Colour; 29 import org.expeditee.core.Font; 30 import org.expeditee.core.Point; 31 31 import org.expeditee.items.Item; 32 32 import org.expeditee.items.Text; … … 43 43 public class Conversion { 44 44 45 public static final int RGB_MAX = 255;46 47 private static final float RGB_CONVERSION_FACTOR = 2.55F;45 public static final short RGB_MAX = Colour.COMPONENT_MAX_VALUE; 46 47 private static final float RGB_CONVERSION_FACTOR = RGB_MAX / 100.0f; 48 48 49 49 /** … … 56 56 * @return The Color object corresponding to the given code 57 57 */ 58 public static Colo r getColor(String colorCode, Color current) {58 public static Colour getColor(String colorCode, Colour current) { 59 59 if (colorCode == null) { 60 60 return null; … … 66 66 67 67 // check if its a normal rgb code ie. 100 0 40 68 Colo r rgb = getRGBColor(colorCode, current);68 Colour rgb = getRGBColor(colorCode, current); 69 69 if (rgb != null) 70 70 return rgb; … … 104 104 return null; 105 105 106 return new Colo r(color[0], color[1], color[2]);107 } 108 109 private static Colo r getRGBColor(String colorCode, Color current) {106 return new Colour(color[0], color[1], color[2]); 107 } 108 109 private static Colour getRGBColor(String colorCode, Colour current) { 110 110 int color[] = new int[4]; 111 111 // Assert.assertTrue(color.length == 3); … … 135 135 color[i] = toRGB(color[i]); 136 136 } 137 return new Colo r(color[0], color[1], color[2], color[3]);137 return new Colour(color[0], color[1], color[2], color[3]); 138 138 } catch (Exception e) { 139 139 return null; … … 175 175 * is black. 176 176 */ 177 public static String getExpediteeColorCode(Colo r color) {177 public static String getExpediteeColorCode(Colour color) { 178 178 if (color == null) 179 179 return null; … … 195 195 */ 196 196 public static String getExpediteeFontCode(Font font) { 197 String fontName = font.getFamily ();198 String code = font.getFamily () + '_';197 String fontName = font.getFamilyName(); 198 String code = font.getFamilyName() + '_'; 199 199 200 200 for (int i = 0; i < Text.FONT_WHEEL.length; i++) { … … 206 206 207 207 switch (font.getStyle()) { 208 case Font.BOLD:208 case BOLD: 209 209 code += "b"; 210 210 break; 211 case Font.PLAIN:211 case PLAIN: 212 212 code += "r"; 213 213 break; 214 case Font.ITALIC:214 case ITALIC: 215 215 code += "i"; 216 216 break; … … 237 237 238 238 int separator = fontCode.indexOf('_'); 239 String code = Text.FONT_WHEEL[0];239 String familyName = Text.FONT_WHEEL[0]; 240 240 if (separator > 0) { 241 code = Actions.getCapitalizedFontName(fontCode.substring(0, 242 separator)) + '-'; 241 familyName = Actions.getCapitalizedFontName(fontCode.substring(0, separator)); 243 242 fontCode = fontCode.substring(separator); 244 243 } else { … … 246 245 for (int i = 0; i < Text.FONT_CHARS.length; i++) { 247 246 if (c == Text.FONT_CHARS[i]) { 248 code = Text.FONT_WHEEL[i] + '-';247 familyName = Text.FONT_WHEEL[i]; 249 248 break; 250 249 } 251 250 } 252 251 } 252 253 Font font = new Font(familyName); 253 254 254 255 switch (fontCode.charAt(1)) { 255 256 case 'r': 256 code += "Plain";257 font.setStyle(Font.Style.PLAIN); 257 258 break; 258 259 case 'b': 259 code += "Bold";260 font.setStyle(Font.Style.BOLD); 260 261 break; 261 262 case 'i': 262 code += "Italic";263 font.setStyle(Font.Style.ITALIC); 263 264 break; 264 265 case 'p': 265 code += "BoldItalic";266 font.setStyle(Font.Style.BOLD_ITALIC); 266 267 break; 267 268 } 268 269 code += "-";270 271 Font font = null;272 269 273 270 try { 274 271 int size = Integer.parseInt(fontCode.substring(2)); 275 // double dsize = size * FONT_SCALE; 276 // if (dsize - ((int) dsize) > FONT_ROUNDING) 277 // dsize = Math.ceil(dsize); 278 279 // code += (int) dsize; 280 code += size; 281 282 font = Font.decode(code); 272 273 font.setSize(size); 283 274 } catch (NumberFormatException nfe) { 284 font = Font.decode(fontCode);275 // Just keep going 285 276 } 286 277 … … 362 353 } 363 354 364 if (type.equals(Colo r.class)) {355 if (type.equals(Colour.class)) { 365 356 if (value.length() == 0) 366 357 return null; … … 368 359 try { 369 360 // Try to decode the string as a hex or octal color code 370 return Colo r.decode(value);361 return Colour.decode(value); 371 362 } catch (NumberFormatException nfe) { 372 363 try { 373 // Try to find the field in the Colo r class with the same name as the given string374 Field[] fields = java.awt.Color.class.getFields();364 // Try to find the field in the Colour class with the same name as the given string 365 Field[] fields = Colour.class.getFields(); 375 366 Field field = null; 376 367 for (int i = 0; i < fields.length; i++) { … … 380 371 } 381 372 } 382 return (Colo r) field.get(null);373 return (Colour) field.get(null); 383 374 } catch (Exception e) { 384 return getColor(value, (Colo r) orig);375 return getColor(value, (Colour) orig); 385 376 } 386 377 } … … 388 379 389 380 if (type.equals(int.class)) { 390 if (orig instanceof Integer 391 && (value.startsWith("+") || value.startsWith("-"))) { 381 if (orig instanceof Integer && (value.startsWith("+") || value.startsWith("-"))) { 392 382 value = value.replace("+", ""); 393 383 … … 395 385 } 396 386 397 if (value.length() == 0 || value.equals("null")) 398 return Item.DEFAULT_INTEGER; 387 if (value.length() == 0 || value.equals("null")) return Item.DEFAULT_INTEGER; 399 388 400 389 return Integer.decode(value); … … 427 416 428 417 if (type.equals(Integer.class)) { 429 if (orig instanceof Integer 430 && (value.startsWith("+") || value.startsWith("-"))) { 418 if (orig instanceof Integer && (value.startsWith("+") || value.startsWith("-"))) { 431 419 value = value.replace("+", ""); 432 420 433 Integer newValue = ((Integer) orig) + Integer. parseInt(value);421 Integer newValue = ((Integer) orig) + Integer.valueOf((int) Double.parseDouble(value)); 434 422 if (newValue <= 0) 435 423 return null; … … 440 428 return null; 441 429 442 return Integer. parseInt(value);430 return Integer.valueOf((int) Double.parseDouble(value)); 443 431 } 444 432 … … 700 688 701 689 // convert colors 702 if (output instanceof Colo r)703 return getExpediteeColorCode((Colo r) output);690 if (output instanceof Colour) 691 return getExpediteeColorCode((Colour) output); 704 692 705 693 // covert points … … 737 725 } 738 726 739 public static String getCssColor(Colo r c) {727 public static String getCssColor(Colour c) { 740 728 assert (c != null); 741 return "rgb(" + c.getRed () + "," + c.getGreen() + "," + c.getBlue()729 return "rgb(" + c.getRed255() + "," + c.getGreen255() + "," + c.getBlue255() 742 730 + ")"; 743 731 }
Note:
See TracChangeset
for help on using the changeset viewer.