1 47 48 package org.jfree.chart.editor; 49 50 import java.awt.event.ActionEvent ; 51 import java.util.ResourceBundle ; 52 53 import javax.swing.BorderFactory ; 54 import javax.swing.JButton ; 55 import javax.swing.JCheckBox ; 56 import javax.swing.JLabel ; 57 import javax.swing.JOptionPane ; 58 import javax.swing.JPanel ; 59 import javax.swing.JTabbedPane ; 60 61 import org.jfree.chart.axis.ColorBar; 62 import org.jfree.chart.axis.NumberAxis; 63 import org.jfree.chart.plot.GreyPalette; 64 import org.jfree.chart.plot.RainbowPalette; 65 import org.jfree.layout.LCBLayout; 66 67 68 74 class DefaultColorBarEditor extends DefaultNumberAxisEditor { 75 76 80 private JCheckBox invertPaletteCheckBox; 81 82 83 private boolean invertPalette = false; 84 85 86 private JCheckBox stepPaletteCheckBox; 87 88 89 private boolean stepPalette = false; 90 91 92 private PaletteSample currentPalette; 93 94 95 private PaletteSample[] availablePaletteSamples; 96 97 98 protected static ResourceBundle localizationResources = 99 ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle"); 100 101 106 public DefaultColorBarEditor(ColorBar colorBar) { 107 super((NumberAxis) colorBar.getAxis()); 108 this.invertPalette = colorBar.getColorPalette().isInverse(); 109 this.stepPalette = colorBar.getColorPalette().isStepped(); 110 this.currentPalette = new PaletteSample(colorBar.getColorPalette()); 111 this.availablePaletteSamples = new PaletteSample[2]; 112 this.availablePaletteSamples[0] 113 = new PaletteSample(new RainbowPalette()); 114 this.availablePaletteSamples[1] 115 = new PaletteSample(new GreyPalette()); 116 117 JTabbedPane other = getOtherTabs(); 118 119 JPanel palettePanel = new JPanel (new LCBLayout(4)); 120 palettePanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); 121 122 palettePanel.add(new JPanel ()); 123 this.invertPaletteCheckBox = new JCheckBox ( 124 localizationResources.getString("Invert_Palette"), 125 this.invertPalette 126 ); 127 this.invertPaletteCheckBox.setActionCommand("invertPalette"); 128 this.invertPaletteCheckBox.addActionListener(this); 129 palettePanel.add(this.invertPaletteCheckBox); 130 palettePanel.add(new JPanel ()); 131 132 palettePanel.add(new JPanel ()); 133 this.stepPaletteCheckBox = new JCheckBox ( 134 localizationResources.getString("Step_Palette"), 135 this.stepPalette 136 ); 137 this.stepPaletteCheckBox.setActionCommand("stepPalette"); 138 this.stepPaletteCheckBox.addActionListener(this); 139 palettePanel.add(this.stepPaletteCheckBox); 140 palettePanel.add(new JPanel ()); 141 142 palettePanel.add( 143 new JLabel (localizationResources.getString("Palette")) 144 ); 145 JButton button 146 = new JButton (localizationResources.getString("Set_palette...")); 147 button.setActionCommand("PaletteChoice"); 148 button.addActionListener(this); 149 palettePanel.add(this.currentPalette); 150 palettePanel.add(button); 151 152 other.add(localizationResources.getString("Palette"), palettePanel); 153 154 } 155 156 161 public void actionPerformed(ActionEvent event) { 162 String command = event.getActionCommand(); 163 if (command.equals("PaletteChoice")) { 164 attemptPaletteSelection(); 165 } 166 else if (command.equals("invertPalette")) { 167 this.invertPalette = this.invertPaletteCheckBox.isSelected(); 168 } 169 else if (command.equals("stepPalette")) { 170 this.stepPalette = this.stepPaletteCheckBox.isSelected(); 171 } 172 else { 173 super.actionPerformed(event); } 175 } 176 177 180 private void attemptPaletteSelection() { 181 PaletteChooserPanel panel 182 = new PaletteChooserPanel(null, this.availablePaletteSamples); 183 int result = JOptionPane.showConfirmDialog( 184 this, panel, localizationResources.getString("Palette_Selection"), 185 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE 186 ); 187 188 if (result == JOptionPane.OK_OPTION) { 189 double zmin = this.currentPalette.getPalette().getMinZ(); 190 double zmax = this.currentPalette.getPalette().getMaxZ(); 191 this.currentPalette.setPalette(panel.getSelectedPalette()); 192 this.currentPalette.getPalette().setMinZ(zmin); 193 this.currentPalette.getPalette().setMaxZ(zmax); 194 } 195 } 196 197 203 public void setAxisProperties(ColorBar colorBar) { 204 super.setAxisProperties(colorBar.getAxis()); 205 colorBar.setColorPalette(this.currentPalette.getPalette()); 206 colorBar.getColorPalette().setInverse(this.invertPalette); colorBar.getColorPalette().setStepped(this.stepPalette); } 209 210 218 public static DefaultColorBarEditor getInstance(ColorBar colorBar) { 219 220 if (colorBar != null) { 221 return new DefaultColorBarEditor(colorBar); 222 } 223 else { 224 return null; 225 } 226 227 } 228 229 } 230 | Popular Tags |