001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * --------------------------
028: * DefaultColorBarEditor.java
029: * --------------------------
030: * (C) Copyright 2002-2007, by David M. O'Donnell and Contributors.
031: *
032: * Original Author: David M. O'Donnell;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: * Arnaud Lelievre;
035: *
036: * $Id: DefaultColorBarEditor.java,v 1.1.2.2 2007/02/02 14:33:12 mungady Exp $
037: *
038: * Changes
039: * -------
040: * 26-Nov-2002 : Version 1 contributed by David M. O'Donnell (DG);
041: * 08-Sep-2003 : Added internationalization via use of properties
042: * resourceBundle (RFE 690236) (AL);
043: * 24-Nov-2005 : Moved and renamed: org.jfree.chart.ui.ColorBarPropertyEditPanel
044: * --> DefaultColorBarEditor (DG);
045: * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
046: *
047: */
048:
049: package org.jfree.chart.editor;
050:
051: import java.awt.event.ActionEvent;
052: import java.util.ResourceBundle;
053:
054: import javax.swing.BorderFactory;
055: import javax.swing.JButton;
056: import javax.swing.JCheckBox;
057: import javax.swing.JLabel;
058: import javax.swing.JOptionPane;
059: import javax.swing.JPanel;
060: import javax.swing.JTabbedPane;
061:
062: import org.jfree.chart.axis.ColorBar;
063: import org.jfree.chart.axis.NumberAxis;
064: import org.jfree.chart.plot.GreyPalette;
065: import org.jfree.chart.plot.RainbowPalette;
066: import org.jfree.layout.LCBLayout;
067:
068: /**
069: * A DefaultColorBarEditor. Extends DefaultNumberAxisEditor to allow
070: * change general axis type parameters.
071: */
072: class DefaultColorBarEditor extends DefaultNumberAxisEditor {
073:
074: /**
075: * A checkbox that indicates whether or not the color indices should run
076: * high to low.
077: */
078: private JCheckBox invertPaletteCheckBox;
079:
080: /** Flag set by invertPaletteCheckBox. */
081: private boolean invertPalette = false;
082:
083: /** A checkbox that indicates whether the palette is stepped. */
084: private JCheckBox stepPaletteCheckBox;
085:
086: /** Flag set by stepPaletteCheckBox. */
087: private boolean stepPalette = false;
088:
089: /** The Palette Sample displaying the current Palette. */
090: private PaletteSample currentPalette;
091:
092: /** An array of availiable sample palettes. */
093: private PaletteSample[] availablePaletteSamples;
094:
095: /** The resourceBundle for the localization. */
096: protected static ResourceBundle localizationResources = ResourceBundle
097: .getBundle("org.jfree.chart.editor.LocalizationBundle");
098:
099: /**
100: * Creates a new edit panel for a color bar.
101: *
102: * @param colorBar the color bar.
103: */
104: public DefaultColorBarEditor(ColorBar colorBar) {
105: super ((NumberAxis) colorBar.getAxis());
106: this .invertPalette = colorBar.getColorPalette().isInverse();
107: this .stepPalette = colorBar.getColorPalette().isStepped();
108: this .currentPalette = new PaletteSample(colorBar
109: .getColorPalette());
110: this .availablePaletteSamples = new PaletteSample[2];
111: this .availablePaletteSamples[0] = new PaletteSample(
112: new RainbowPalette());
113: this .availablePaletteSamples[1] = new PaletteSample(
114: new GreyPalette());
115:
116: JTabbedPane other = getOtherTabs();
117:
118: JPanel palettePanel = new JPanel(new LCBLayout(4));
119: palettePanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4,
120: 4));
121:
122: palettePanel.add(new JPanel());
123: this .invertPaletteCheckBox = new JCheckBox(
124: localizationResources.getString("Invert_Palette"),
125: this .invertPalette);
126: this .invertPaletteCheckBox.setActionCommand("invertPalette");
127: this .invertPaletteCheckBox.addActionListener(this );
128: palettePanel.add(this .invertPaletteCheckBox);
129: palettePanel.add(new JPanel());
130:
131: palettePanel.add(new JPanel());
132: this .stepPaletteCheckBox = new JCheckBox(localizationResources
133: .getString("Step_Palette"), this .stepPalette);
134: this .stepPaletteCheckBox.setActionCommand("stepPalette");
135: this .stepPaletteCheckBox.addActionListener(this );
136: palettePanel.add(this .stepPaletteCheckBox);
137: palettePanel.add(new JPanel());
138:
139: palettePanel.add(new JLabel(localizationResources
140: .getString("Palette")));
141: JButton button = new JButton(localizationResources
142: .getString("Set_palette..."));
143: button.setActionCommand("PaletteChoice");
144: button.addActionListener(this );
145: palettePanel.add(this .currentPalette);
146: palettePanel.add(button);
147:
148: other.add(localizationResources.getString("Palette"),
149: palettePanel);
150:
151: }
152:
153: /**
154: * Handles actions from within the property panel.
155: *
156: * @param event the event.
157: */
158: public void actionPerformed(ActionEvent event) {
159: String command = event.getActionCommand();
160: if (command.equals("PaletteChoice")) {
161: attemptPaletteSelection();
162: } else if (command.equals("invertPalette")) {
163: this .invertPalette = this .invertPaletteCheckBox
164: .isSelected();
165: } else if (command.equals("stepPalette")) {
166: this .stepPalette = this .stepPaletteCheckBox.isSelected();
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 = new PaletteChooserPanel(null,
177: this .availablePaletteSamples);
178: int result = JOptionPane
179: .showConfirmDialog(this , panel, localizationResources
180: .getString("Palette_Selection"),
181: JOptionPane.OK_CANCEL_OPTION,
182: JOptionPane.PLAIN_MESSAGE);
183:
184: if (result == JOptionPane.OK_OPTION) {
185: double zmin = this .currentPalette.getPalette().getMinZ();
186: double zmax = this .currentPalette.getPalette().getMaxZ();
187: this .currentPalette.setPalette(panel.getSelectedPalette());
188: this .currentPalette.getPalette().setMinZ(zmin);
189: this .currentPalette.getPalette().setMaxZ(zmax);
190: }
191: }
192:
193: /**
194: * Sets the properties of the specified axis to match the properties
195: * defined on this panel.
196: *
197: * @param colorBar the color bar.
198: */
199: public void setAxisProperties(ColorBar colorBar) {
200: super .setAxisProperties(colorBar.getAxis());
201: colorBar.setColorPalette(this .currentPalette.getPalette());
202: colorBar.getColorPalette().setInverse(this .invertPalette); //dmo added
203: colorBar.getColorPalette().setStepped(this .stepPalette); //dmo added
204: }
205:
206: /**
207: * A static method that returns a panel that is appropriate for the axis
208: * type.
209: *
210: * @param colorBar the color bar.
211: *
212: * @return A panel or <code>null</code< if axis is <code>null</code>.
213: */
214: public static DefaultColorBarEditor getInstance(ColorBar colorBar) {
215:
216: if (colorBar != null) {
217: return new DefaultColorBarEditor(colorBar);
218: } else {
219: return null;
220: }
221:
222: }
223:
224: }
|