1 44 45 package org.jfree.chart.ui; 46 47 import java.awt.event.ActionEvent ; 48 import java.util.ResourceBundle ; 49 50 import javax.swing.BorderFactory ; 51 import javax.swing.JButton ; 52 import javax.swing.JCheckBox ; 53 import javax.swing.JLabel ; 54 import javax.swing.JOptionPane ; 55 import javax.swing.JPanel ; 56 import javax.swing.JTabbedPane ; 57 58 import org.jfree.chart.axis.ColorBar; 59 import org.jfree.chart.axis.NumberAxis; 60 import org.jfree.layout.LCBLayout; 61 62 63 69 public class ColorBarPropertyEditPanel extends NumberAxisPropertyEditPanel { 70 71 75 private JCheckBox invertPaletteCheckBox; 76 77 78 private boolean invertPalette = false; 79 80 81 private JCheckBox stepPaletteCheckBox; 82 83 84 private boolean stepPalette = false; 85 86 87 private PaletteSample currentPalette; 88 89 90 private PaletteSample[] availablePaletteSamples; 91 92 93 protected static ResourceBundle localizationResources = 94 ResourceBundle.getBundle("org.jfree.chart.ui.LocalizationBundle"); 95 96 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 other = getOtherTabs(); 113 114 JPanel palettePanel = new JPanel (new LCBLayout(4)); 115 palettePanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); 116 117 palettePanel.add(new JPanel ()); 118 this.invertPaletteCheckBox = new JCheckBox ( 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 ()); 126 127 palettePanel.add(new JPanel ()); 128 this.stepPaletteCheckBox = new JCheckBox ( 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 ()); 136 137 palettePanel.add( 138 new JLabel (localizationResources.getString("Palette")) 139 ); 140 JButton button 141 = new JButton (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 156 public void actionPerformed(ActionEvent event) { 157 String 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); } 170 } 171 172 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 198 public void setAxisProperties(ColorBar colorBar) { 199 super.setAxisProperties(colorBar.getAxis()); 200 colorBar.setColorPalette(this.currentPalette.getPalette()); 201 colorBar.getColorPalette().setInverse(this.invertPalette); colorBar.getColorPalette().setStepped(this.stepPalette); } 204 205 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 |