public ColorSwatch getColorSwatch(Color color) { if (color == null) { return new ColorSwatch("CLEAR", null); } ColorSwatch swatch = null; for (ColorSwatch cs : userColors.values()) { if (cs.getColor().equals(color)) { swatch = cs; break; } } if (swatch == null) { for (int j = 0; j < standardColors.length && swatch == null; j++) { if (standardColors[j] != null && standardColors[j].equals(color)) { swatch = new ColorSwatch(standardColorNames[j], standardColors[j]); } } } if (swatch == null) { swatch = new ColorSwatch(SELECT_COLOR, color); } return swatch; }
public Color getColorByName(String colorName) { ColorSwatch gcolor = getColorSwatch(colorName); if (gcolor != null) { Color color = gcolor.getColor(); // if (color != null) { return color; // } } return DEFAULT_COLOR; }
public String[] getColorNames() { ArrayList<ColorSwatch> a = new ArrayList<ColorSwatch>(userColors.values()); Collections.sort(a); ArrayList<String> names = new ArrayList<String>(a.size() + standardColors.length); for (ColorSwatch cs : a) { names.add(cs.getConfigureName()); } names.addAll(Arrays.asList(standardColorNames)); return names.toArray(new String[names.size()]); }
public void add(Buildable b) { super.add(b); if (b instanceof ColorSwatch) { ColorSwatch def = (ColorSwatch) b; userColors.put(def.getConfigureName(), def); def.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (Configurable.NAME_PROPERTY.equals(evt.getPropertyName())) { userColors.remove((String) evt.getOldValue()); userColors.put((String) evt.getNewValue(), (ColorSwatch) evt.getSource()); } } }); } }