1 | /* |
---|
2 | * $Id: ColorEntryPanel.java,v 1.2 2003/08/22 23:02:39 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt.swing.prop; |
---|
14 | |
---|
15 | import javax.swing.*; |
---|
16 | import java.awt.event.*; |
---|
17 | import java.awt.*; |
---|
18 | |
---|
19 | import gov.noaa.pmel.swing.ThreeDotsButton; |
---|
20 | |
---|
21 | |
---|
22 | /** |
---|
23 | * @author Donald Denbo |
---|
24 | * @version $Revision: 1.2 $, $Date: 2003/08/22 23:02:39 $ |
---|
25 | * @since 3.0 |
---|
26 | **/ |
---|
27 | public class ColorEntryPanel extends JComponent { |
---|
28 | // private ThreeDotsIcon dotsIcon_ = new ThreeDotsIcon(Color.black); |
---|
29 | private JLabel redLabel = new JLabel(); |
---|
30 | private JLabel greenLabel = new JLabel(); |
---|
31 | private JLabel blueLabel = new JLabel(); |
---|
32 | private JLabel alphaLabel = new JLabel(); |
---|
33 | private JTextField redTF = new JTextField(); |
---|
34 | private JTextField greenTF = new JTextField(); |
---|
35 | private JTextField blueTF = new JTextField(); |
---|
36 | private JTextField alphaTF = new JTextField(); |
---|
37 | private ThreeDotsButton button = new ThreeDotsButton(); |
---|
38 | private FlowLayout fLayout = new FlowLayout(); |
---|
39 | |
---|
40 | private Color color_ = Color.black; |
---|
41 | private String title_ = "Set Color"; |
---|
42 | |
---|
43 | public ColorEntryPanel(String title, Color color) { |
---|
44 | super(); |
---|
45 | setColor(color); |
---|
46 | setTitle(title); |
---|
47 | } |
---|
48 | |
---|
49 | public ColorEntryPanel() { |
---|
50 | try { |
---|
51 | jbInit(); |
---|
52 | } |
---|
53 | catch(Exception e) { |
---|
54 | e.printStackTrace(); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | private void jbInit() throws Exception { |
---|
59 | setLayout(fLayout); |
---|
60 | redLabel.setText("red"); |
---|
61 | greenLabel.setText("green"); |
---|
62 | blueLabel.setText("blue"); |
---|
63 | alphaLabel.setText("alpha"); |
---|
64 | redTF.setText("0"); |
---|
65 | redTF.setColumns(3); |
---|
66 | greenTF.setText("0"); |
---|
67 | greenTF.setColumns(3); |
---|
68 | blueTF.setText("0"); |
---|
69 | blueTF.setColumns(3); |
---|
70 | alphaTF.setText("0"); |
---|
71 | alphaTF.setColumns(3); |
---|
72 | button.addActionListener(new java.awt.event.ActionListener() { |
---|
73 | public void actionPerformed(ActionEvent e) { |
---|
74 | button_actionPerformed(e); |
---|
75 | } |
---|
76 | }); |
---|
77 | button.setToolTipText("Edit color."); |
---|
78 | button.setActionCommand("..."); |
---|
79 | add(redLabel); |
---|
80 | add(redTF); |
---|
81 | add(greenLabel); |
---|
82 | add(greenTF); |
---|
83 | add(blueLabel); |
---|
84 | add(blueTF); |
---|
85 | add(alphaLabel); |
---|
86 | add(alphaTF); |
---|
87 | add(button); |
---|
88 | boolean enabled = isEnabled(); |
---|
89 | redTF.setEnabled(enabled); |
---|
90 | greenTF.setEnabled(enabled); |
---|
91 | blueTF.setEnabled(enabled); |
---|
92 | alphaTF.setEnabled(enabled); |
---|
93 | button.setEnabled(enabled); |
---|
94 | } |
---|
95 | |
---|
96 | public void setEnabled(boolean enabled) { |
---|
97 | super.setEnabled(enabled); |
---|
98 | redTF.setEnabled(enabled); |
---|
99 | greenTF.setEnabled(enabled); |
---|
100 | blueTF.setEnabled(enabled); |
---|
101 | alphaTF.setEnabled(enabled); |
---|
102 | button.setEnabled(enabled); |
---|
103 | } |
---|
104 | |
---|
105 | void button_actionPerformed(ActionEvent e) { |
---|
106 | Window win = javax.swing.SwingUtilities.getWindowAncestor(this); |
---|
107 | ColorDialog cd = null; |
---|
108 | if(win instanceof Frame) { |
---|
109 | cd = new ColorDialog((Frame)win, title_, true); |
---|
110 | } else if(win instanceof Dialog) { |
---|
111 | cd = new ColorDialog((Dialog)win, title_, true); |
---|
112 | } else { |
---|
113 | cd = new ColorDialog((Frame)null, title_, true); |
---|
114 | } |
---|
115 | cd.setColor(getColorFromTF()); |
---|
116 | cd.setVisible(true); |
---|
117 | setColor(cd.getColor()); |
---|
118 | } |
---|
119 | |
---|
120 | public void setColor(Color color) { |
---|
121 | color_ = color; |
---|
122 | redTF.setText(Integer.toString(color_.getRed())); |
---|
123 | greenTF.setText(Integer.toString(color_.getGreen())); |
---|
124 | blueTF.setText(Integer.toString(color_.getBlue())); |
---|
125 | alphaTF.setText(Integer.toString(color_.getAlpha())); |
---|
126 | } |
---|
127 | |
---|
128 | public Color getColor() { |
---|
129 | return getColorFromTF(); |
---|
130 | } |
---|
131 | |
---|
132 | private Color getColorFromTF() { |
---|
133 | int red = Integer.parseInt(redTF.getText()); |
---|
134 | int green = Integer.parseInt(greenTF.getText()); |
---|
135 | int blue = Integer.parseInt(blueTF.getText()); |
---|
136 | int alpha = Integer.parseInt(alphaTF.getText()); |
---|
137 | return new Color(red, green, blue, alpha); |
---|
138 | } |
---|
139 | |
---|
140 | public void setTitle(String title) { |
---|
141 | title_ = title; |
---|
142 | } |
---|
143 | public String getTitle() { |
---|
144 | return title_; |
---|
145 | } |
---|
146 | } |
---|