2
package org.crosswire.common.config.swing.fields;
4
import java.awt.BorderLayout;
6
import java.awt.Component;
7
import java.awt.Graphics;
8
import java.awt.Insets;
9
import java.awt.event.ActionEvent;
10
import java.awt.event.ActionListener;
12
import javax.swing.Icon;
13
import javax.swing.JButton;
14
import javax.swing.JColorChooser;
15
import javax.swing.JComponent;
16
import javax.swing.JPanel;
18
import org.crosswire.common.config.swing.Field;
19
import org.crosswire.common.swing.GuiConvert;
22
* A Filename selection.
24
* <table border='1' cellPadding='3' cellSpacing='0' width="100%">
25
* <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
26
* Distribution Licence:<br />
27
* Project B is free software; you can redistribute it
28
* and/or modify it under the terms of the GNU General Public License,
29
* version 2 as published by the Free Software Foundation.<br />
30
* This program is distributed in the hope that it will be useful,
31
* but WITHOUT ANY WARRANTY; without even the implied warranty of
32
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33
* General Public License for more details.<br />
34
* The License is available on the internet
35
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
36
* <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
37
* MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
38
* The copyright to this program is held by it's authors.
39
* </font></td></tr></table>
40
* @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
41
* @see <{docs.Licence}>
44
public class ColorField extends JPanel implements Field
47
* Create a new FileField
51
edit.setIcon(new CustomIcon());
52
edit.setMargin(new Insets(1, 2, 1, 1));
53
edit.addActionListener(new ActionListener()
55
public void actionPerformed(ActionEvent ex)
57
color = JColorChooser.showDialog(ColorField.this, name, color);
58
//text.setText(Convert.color2String(color));
63
setLayout(new BorderLayout());
64
add(edit, BorderLayout.WEST);
65
//add(text, BorderLayout.EAST);
69
* Some fields will need some extra info to display properly
70
* like the options in an options field. FieldMap calls this
71
* method with options provided by the choice.
72
* @param param The options provided by the Choice
74
public void setOptions(Object param)
76
name = (String) param;
81
* Return a string version of the current value
82
* @return The current value
84
public String getValue()
86
return GuiConvert.color2String(color);
90
* Set the current value
91
* @param value The new text
93
public void setValue(String value)
95
color = GuiConvert.string2Color(value);
96
//text.setText(value);
101
* Get the actual component that we can add to a Panel.
102
* (This can well be this in an implementation).
104
public JComponent getComponent()
109
/** The name of the Color selection */
110
protected String name = "Edit";
112
/** What to do when we are clicked */
113
private Runnable runner;
115
/** The browse button */
116
protected JButton edit = new JButton(name);
118
/** Some feedback on the color */
119
//private JLabel text = new JLabel();
121
/** The current Color */
122
protected Color color = Color.white;
124
/** The icon square size */
125
private static final int SIZE = 16;
128
* The CustomIcon that shows the selected color
130
class CustomIcon implements Icon
133
* Returns the icon's height.
135
public int getIconHeight()
141
* Returns the icon's width.
143
public int getIconWidth()
149
* Draw the icon at the specified location.
151
public void paintIcon(Component c, Graphics g, int x, int y)
155
g.setColor(Color.black);
156
g.drawRect(x, y, SIZE, SIZE);
157
g.drawLine(x, y, x+SIZE, y+SIZE);
158
g.drawLine(x+SIZE, y, x, y+SIZE);
163
g.fillRect(x, y, SIZE, SIZE);
164
g.setColor(Color.black);
165
g.drawRect(x, y, SIZE, SIZE);