001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.properties.editors;
020:
021: import java.awt.Color;
022: import java.awt.Component;
023: import java.awt.Graphics;
024: import java.awt.Rectangle;
025:
026: import com.jeta.open.i18n.I18N;
027: import com.jeta.swingbuilder.gui.colorchooser.JETAColorChooser;
028: import com.jeta.swingbuilder.gui.properties.JETAPropertyEditor;
029:
030: public class ColorEditor extends JETAPropertyEditor {
031: private Color m_last_color;
032: private String m_rgb;
033: private ValuePainter m_value_painter = new ValuePainter();
034:
035: public ColorEditor() {
036:
037: }
038:
039: public String getJavaInitializationString() {
040: return "new RGB()";
041: }
042:
043: public boolean isPaintable() {
044: return true;
045: }
046:
047: /**
048: * Invokes a dialog used to update the property
049: */
050: public void invokePropertyDialog(Component comp) {
051: Color new_color = JETAColorChooser.invokeColorChooser(comp,
052: (Color) getValue());
053: if (new_color != null) {
054: setValue(new_color);
055: }
056: }
057:
058: /**
059: *
060: */
061: public boolean supportsCustomEditor() {
062: return true;
063: }
064:
065: public void paintValue(Graphics g, Rectangle rect) {
066: Color c = (Color) getValue();
067: if (c != null) {
068: int box_height = 12;
069: int box_width = 12;
070: int y = (rect.height - box_height) / 2;
071: int x = 5;
072:
073: assert (rect != null);
074: g.setColor((Color) c);
075: g.fillRect(x, y, box_width, box_height);
076:
077: g.setColor(Color.white);
078: g.drawRect(x + 1, y + 1, box_width - 2, box_height - 2);
079:
080: g.setColor(Color.black);
081: g.drawRect(x, y, box_width, box_height);
082:
083: if (!c.equals(m_last_color)) {
084: m_last_color = c;
085: m_rgb = I18N.format("RGB_3", new Integer(c.getRed()),
086: new Integer(c.getGreen()), new Integer(c
087: .getBlue()));
088: }
089: m_value_painter.drawString(g, rect, box_width + 10, m_rgb);
090:
091: }
092: }
093:
094: private String getHexString(int ival) {
095: String result = Integer.toHexString(ival).toUpperCase();
096: if (result.length() == 1)
097: return "0" + result;
098: else
099: return result;
100: }
101:
102: }
|