001: /*
002: * ColorChooser.java Copyright (c) 2006,07 Swaroop Belur
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008:
009: * This program 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
012: * GNU General Public License for more details.
013:
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
017: *
018: */
019:
020: package net.sf.jdec.ui.util.highlight;
021:
022: import java.awt.BorderLayout;
023: import java.awt.Color;
024: import java.awt.event.ActionEvent;
025: import java.awt.event.ActionListener;
026:
027: import javax.swing.JButton;
028: import javax.swing.JColorChooser;
029: import javax.swing.JFrame;
030: import javax.swing.JLabel;
031: import javax.swing.JPanel;
032: import javax.swing.event.ChangeEvent;
033: import javax.swing.event.ChangeListener;
034:
035: import net.sf.jdec.ui.main.UILauncher;
036:
037: public class ColorChooser extends JFrame implements ChangeListener,
038: ActionListener {
039:
040: private JLabel banner = null;
041: private JColorChooser colorChooser = null;
042: private JButton apply = new JButton("Select");
043: private JButton close = new JButton("Close");
044:
045: public ColorChooser() {
046:
047: JPanel colorPanel = new JPanel();
048: banner = new JLabel("Please Select A Color", JLabel.CENTER);
049: banner.setForeground(Color.yellow);
050: colorPanel.add(banner, BorderLayout.NORTH);
051: colorChooser = new JColorChooser(banner.getForeground());
052: colorPanel.add(colorChooser, BorderLayout.CENTER);
053: colorChooser.getSelectionModel().addChangeListener(this );
054: JPanel actions = new JPanel();
055: actions.add(apply);
056: actions.add(close);
057: colorPanel.add(actions, BorderLayout.CENTER);
058: getContentPane().add(colorPanel);
059: apply.addActionListener(this );
060: close.addActionListener(this );
061: setSize(500, 500);
062: setVisible(true);
063: }
064:
065: public static void main(String a[]) {
066: new ColorChooser();
067: }
068:
069: public void stateChanged(ChangeEvent e) {
070:
071: Color newColor = colorChooser.getColor();
072: //JOptionPane.showMessageDialog(this,"["+newColor.getRed()+" "+newColor.getGreen()+" "+newColor.getBlue()+"]");
073: banner.setForeground(newColor);
074: }
075:
076: public void actionPerformed(ActionEvent e) {
077:
078: if (e.getSource() == apply) {
079: Color newColor = colorChooser.getColor();
080: int r = newColor.getRed();
081: int g = newColor.getGreen();
082: int b = newColor.getBlue();
083: String color = "[" + r + "," + g + "," + b + "]";
084: CategoryChooser ch = UILauncher.getUIConfigRef().cc;
085: if (ch != null) {
086: if (!isForeG) {
087:
088: Object at1 = ch.getBackg().getItemAt(1);
089: if (at1 != null
090: && at1.toString().indexOf("Choose") == -1) {
091: ch.getBackg().removeItemAt(1);
092: }
093: ch.getBackg().insertItemAt(color, 1);
094: ch.getBackg().setSelectedIndex(1);
095: ch.getTypes2().revalidate();
096: ch.getValues().revalidate();
097: } else {
098:
099: Object at1 = ch.getForeg().getItemAt(1);
100: if (at1 != null
101: && at1.toString().indexOf("Choose") == -1) {
102: ch.getForeg().removeItemAt(1);
103: }
104: ch.getForeg().insertItemAt(color, 1);
105: ch.getForeg().setSelectedIndex(1);
106: ch.getTypes2().revalidate();
107: ch.getValues().revalidate();
108: }
109:
110: }
111:
112: }
113:
114: else if (e.getSource() == close) {
115: this .setVisible(false);
116: this .dispose();
117: }
118:
119: }
120:
121: public void setForeGround(boolean b) {
122: isForeG = b;
123: }
124:
125: private boolean isForeG = false;
126: }
|