Changeset 790


Ignore:
Timestamp:
01/30/14 12:01:46 (10 years ago)
Author:
ngw8
Message:

Added support for setting (via the UI) color attributes from a hex or octal string (e.g. #FF00A3)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/io/Conversion.java

    r659 r790  
    349349
    350350                        try {
    351                                 // Find the field and value of colorName
    352                                 Field[] fields = java.awt.Color.class.getFields();
    353                                 Field field = null;
    354                                 for (int i = 0; i < fields.length; i++) {
    355                                         if (fields[i].getName().equalsIgnoreCase(value)) {
    356                                                 field = fields[i];
    357                                                 break;
     351                                // Try to decode the string as a hex or octal color code
     352                                return Color.decode(value);
     353                        } catch (NumberFormatException nfe) {
     354                                try {
     355                                        // Try to find the field in the Color class with the same name as the given string
     356                                        Field[] fields = java.awt.Color.class.getFields();
     357                                        Field field = null;
     358                                        for (int i = 0; i < fields.length; i++) {
     359                                                if (fields[i].getName().equalsIgnoreCase(value)) {
     360                                                        field = fields[i];
     361                                                        break;
     362                                                }
    358363                                        }
     364                                        return (Color) field.get(null);
     365                                } catch (Exception e) {
     366                                        return getColor(value, (Color) orig);
    359367                                }
    360                                 return (Color) field.get(null);
    361                         } catch (Exception e) {
    362                                 return getColor(value, (Color) orig);
    363368                        }
    364369                }
Note: See TracChangeset for help on using the changeset viewer.