KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > ui > ColorBarPropertyEditPanel


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ------------------------------
27  * ColorBarPropertyEditPanel.java
28  * ------------------------------
29  * (C) Copyright 2002-2004, by David M. O'Donnell and Contributors.
30  *
31  * Original Author: David M. O'Donnell;
32  * Contributor(s): David Gilbert (for Object Refinery Limited);
33  * Arnaud Lelievre;
34  *
35  * $Id: ColorBarPropertyEditPanel.java,v 1.2 2005/03/28 19:46:27 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 26-Nov-2002 : Version 1 contributed by David M. O'Donnell (DG);
40  * 08-Sep-2003 : Added internationalization via use of properties
41  * resourceBundle (RFE 690236) (AL);
42  *
43  */

44
45 package org.jfree.chart.ui;
46
47 import java.awt.event.ActionEvent JavaDoc;
48 import java.util.ResourceBundle JavaDoc;
49
50 import javax.swing.BorderFactory JavaDoc;
51 import javax.swing.JButton JavaDoc;
52 import javax.swing.JCheckBox JavaDoc;
53 import javax.swing.JLabel JavaDoc;
54 import javax.swing.JOptionPane JavaDoc;
55 import javax.swing.JPanel JavaDoc;
56 import javax.swing.JTabbedPane JavaDoc;
57
58 import org.jfree.chart.axis.ColorBar;
59 import org.jfree.chart.axis.NumberAxis;
60 import org.jfree.layout.LCBLayout;
61
62
63 /**
64  * A ColorBarPropertyEditPanel. Extends NumberAxisPropertyEditPanel to allow
65  * change general axis type parameters.
66  *
67  * @author David M. O'Donnell
68  */

69 public class ColorBarPropertyEditPanel extends NumberAxisPropertyEditPanel {
70
71     /**
72      * A checkbox that indicates whether or not the color indices should run
73      * high to low.
74      */

75     private JCheckBox JavaDoc invertPaletteCheckBox;
76
77     /** Flag set by invertPaletteCheckBox. */
78     private boolean invertPalette = false;
79
80     /** A checkbox that indicates whether the palette is stepped. */
81     private JCheckBox JavaDoc stepPaletteCheckBox;
82
83     /** Flag set by stepPaletteCheckBox. */
84     private boolean stepPalette = false;
85
86     /** The Palette Sample displaying the current Palette. */
87     private PaletteSample currentPalette;
88
89     /** An array of availiable sample palettes. */
90     private PaletteSample[] availablePaletteSamples;
91
92     /** The resourceBundle for the localization. */
93    protected static ResourceBundle JavaDoc localizationResources =
94        ResourceBundle.getBundle("org.jfree.chart.ui.LocalizationBundle");
95
96     /**
97      * Creates a new edit panel for a color bar.
98      *
99      * @param colorBar the color bar.
100      */

101     public ColorBarPropertyEditPanel(ColorBar colorBar) {
102         super((NumberAxis) colorBar.getAxis());
103         this.invertPalette = colorBar.getColorPalette().isInverse();
104         this.stepPalette = colorBar.getColorPalette().isStepped();
105         this.currentPalette = new PaletteSample(colorBar.getColorPalette());
106         this.availablePaletteSamples = new PaletteSample[2];
107         this.availablePaletteSamples[0]
108             = new PaletteSample(new RainbowPalette());
109         this.availablePaletteSamples[1]
110             = new PaletteSample(new GreyPalette());
111
112         JTabbedPane JavaDoc other = getOtherTabs();
113
114         JPanel JavaDoc palettePanel = new JPanel JavaDoc(new LCBLayout(4));
115         palettePanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
116
117         palettePanel.add(new JPanel JavaDoc());
118         this.invertPaletteCheckBox = new JCheckBox JavaDoc(
119             localizationResources.getString("Invert_Palette"),
120             this.invertPalette
121         );
122         this.invertPaletteCheckBox.setActionCommand("invertPalette");
123         this.invertPaletteCheckBox.addActionListener(this);
124         palettePanel.add(this.invertPaletteCheckBox);
125         palettePanel.add(new JPanel JavaDoc());
126
127         palettePanel.add(new JPanel JavaDoc());
128         this.stepPaletteCheckBox = new JCheckBox JavaDoc(
129             localizationResources.getString("Step_Palette"),
130             this.stepPalette
131         );
132         this.stepPaletteCheckBox.setActionCommand("stepPalette");
133         this.stepPaletteCheckBox.addActionListener(this);
134         palettePanel.add(this.stepPaletteCheckBox);
135         palettePanel.add(new JPanel JavaDoc());
136
137         palettePanel.add(
138             new JLabel JavaDoc(localizationResources.getString("Palette"))
139         );
140         JButton JavaDoc button
141             = new JButton JavaDoc(localizationResources.getString("Set_palette..."));
142         button.setActionCommand("PaletteChoice");
143         button.addActionListener(this);
144         palettePanel.add(this.currentPalette);
145         palettePanel.add(button);
146
147         other.add(localizationResources.getString("Palette"), palettePanel);
148
149     }
150
151     /**
152      * Handles actions from within the property panel.
153      *
154      * @param event the event.
155      */

156     public void actionPerformed(ActionEvent JavaDoc event) {
157         String JavaDoc command = event.getActionCommand();
158         if (command.equals("PaletteChoice")) {
159             attemptPaletteSelection();
160         }
161         else if (command.equals("invertPalette")) {
162             this.invertPalette = this.invertPaletteCheckBox.isSelected();
163         }
164         else if (command.equals("stepPalette")) {
165             this.stepPalette = this.stepPaletteCheckBox.isSelected();
166         }
167         else {
168             super.actionPerformed(event); // pass to super-class for handling
169
}
170     }
171
172     /**
173      * Handle a palette selection.
174      */

175     private void attemptPaletteSelection() {
176         PaletteChooserPanel panel
177             = new PaletteChooserPanel(null, this.availablePaletteSamples);
178         int result = JOptionPane.showConfirmDialog(
179             this, panel, localizationResources.getString("Palette_Selection"),
180             JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE
181         );
182
183         if (result == JOptionPane.OK_OPTION) {
184             double zmin = this.currentPalette.getPalette().getMinZ();
185             double zmax = this.currentPalette.getPalette().getMaxZ();
186             this.currentPalette.setPalette(panel.getSelectedPalette());
187             this.currentPalette.getPalette().setMinZ(zmin);
188             this.currentPalette.getPalette().setMaxZ(zmax);
189         }
190     }
191
192     /**
193      * Sets the properties of the specified axis to match the properties
194      * defined on this panel.
195      *
196      * @param colorBar the color bar.
197      */

198     public void setAxisProperties(ColorBar colorBar) {
199         super.setAxisProperties(colorBar.getAxis());
200         colorBar.setColorPalette(this.currentPalette.getPalette());
201         colorBar.getColorPalette().setInverse(this.invertPalette); //dmo added
202
colorBar.getColorPalette().setStepped(this.stepPalette); //dmo added
203
}
204
205     /**
206      * A static method that returns a panel that is appropriate for the axis
207      * type.
208      *
209      * @param colorBar the color bar.
210      *
211      * @return A panel or <code>null</code< if axis is <code>null</code>.
212      */

213     public static ColorBarPropertyEditPanel getInstance(ColorBar colorBar) {
214
215         if (colorBar != null) {
216             return new ColorBarPropertyEditPanel(colorBar);
217         }
218         else {
219             return null;
220         }
221
222     }
223
224 }
225
Popular Tags