1 52 53 package org.jfree.chart.ui; 54 55 import java.awt.BorderLayout ; 56 import java.awt.Color ; 57 import java.awt.Paint ; 58 import java.awt.event.ActionEvent ; 59 import java.awt.event.ActionListener ; 60 import java.util.ResourceBundle ; 61 62 import javax.swing.BorderFactory ; 63 import javax.swing.JButton ; 64 import javax.swing.JCheckBox ; 65 import javax.swing.JColorChooser ; 66 import javax.swing.JLabel ; 67 import javax.swing.JPanel ; 68 import javax.swing.JTabbedPane ; 69 import javax.swing.JTextField ; 70 71 import org.jfree.chart.JFreeChart; 72 import org.jfree.chart.OldLegend; 73 import org.jfree.chart.plot.Plot; 74 import org.jfree.chart.title.Title; 75 import org.jfree.layout.LCBLayout; 76 import org.jfree.ui.PaintSample; 77 78 82 public class ChartPropertyEditPanel extends JPanel implements ActionListener { 83 84 85 private TitlePropertyEditPanel titlePropertiesPanel; 86 87 88 private LegendPropertyEditPanel legendPropertiesPanel; 89 90 91 private PlotPropertyEditPanel plotPropertiesPanel; 92 93 96 private JCheckBox antialias; 97 98 99 private PaintSample background; 100 101 102 protected static ResourceBundle localizationResources 103 = ResourceBundle.getBundle("org.jfree.chart.ui.LocalizationBundle"); 104 105 111 public ChartPropertyEditPanel(JFreeChart chart) { 112 setLayout(new BorderLayout ()); 113 114 JPanel other = new JPanel (new BorderLayout ()); 115 other.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); 116 117 JPanel general = new JPanel (new BorderLayout ()); 118 general.setBorder( 119 BorderFactory.createTitledBorder( 120 BorderFactory.createEtchedBorder(), 121 localizationResources.getString("General") 122 ) 123 ); 124 125 JPanel interior = new JPanel (new LCBLayout(6)); 126 interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); 127 128 this.antialias = new JCheckBox ( 129 localizationResources.getString("Draw_anti-aliased") 130 ); 131 this.antialias.setSelected(chart.getAntiAlias()); 132 interior.add(this.antialias); 133 interior.add(new JLabel ("")); 134 interior.add(new JLabel ("")); 135 interior.add( 136 new JLabel (localizationResources.getString("Background_paint")) 137 ); 138 this.background = new PaintSample(chart.getBackgroundPaint()); 139 interior.add(this.background); 140 JButton button = new JButton ( 141 localizationResources.getString("Select...") 142 ); 143 button.setActionCommand("BackgroundPaint"); 144 button.addActionListener(this); 145 interior.add(button); 146 147 interior.add( 148 new JLabel (localizationResources.getString("Series_Paint")) 149 ); 150 JTextField info = new JTextField ( 151 localizationResources.getString("No_editor_implemented") 152 ); 153 info.setEnabled(false); 154 interior.add(info); 155 button = new JButton (localizationResources.getString("Edit...")); 156 button.setEnabled(false); 157 interior.add(button); 158 159 interior.add( 160 new JLabel (localizationResources.getString("Series_Stroke")) 161 ); 162 info = new JTextField ( 163 localizationResources.getString("No_editor_implemented") 164 ); 165 info.setEnabled(false); 166 interior.add(info); 167 button = new JButton (localizationResources.getString("Edit...")); 168 button.setEnabled(false); 169 interior.add(button); 170 171 interior.add( 172 new JLabel (localizationResources.getString("Series_Outline_Paint")) 173 ); 174 info = new JTextField ( 175 localizationResources.getString("No_editor_implemented") 176 ); 177 info.setEnabled(false); 178 interior.add(info); 179 button = new JButton (localizationResources.getString("Edit...")); 180 button.setEnabled(false); 181 interior.add(button); 182 183 interior.add( 184 new JLabel (localizationResources.getString("Series_Outline_Stroke")) 185 ); 186 info = new JTextField ( 187 localizationResources.getString("No_editor_implemented") 188 ); 189 info.setEnabled(false); 190 interior.add(info); 191 button = new JButton (localizationResources.getString("Edit...")); 192 button.setEnabled(false); 193 interior.add(button); 194 195 general.add(interior, BorderLayout.NORTH); 196 other.add(general, BorderLayout.NORTH); 197 198 JPanel parts = new JPanel (new BorderLayout ()); 199 200 Title title = chart.getTitle(); 201 OldLegend legend = chart.getOldLegend(); 202 Plot plot = chart.getPlot(); 203 204 JTabbedPane tabs = new JTabbedPane (); 205 206 this.titlePropertiesPanel = new TitlePropertyEditPanel(title); 207 this.titlePropertiesPanel.setBorder( 208 BorderFactory.createEmptyBorder(2, 2, 2, 2) 209 ); 210 tabs.addTab( 211 localizationResources.getString("Title"), this.titlePropertiesPanel 212 ); 213 214 this.legendPropertiesPanel = new LegendPropertyEditPanel(legend); 215 this.legendPropertiesPanel.setBorder( 216 BorderFactory.createEmptyBorder(2, 2, 2, 2) 217 ); 218 tabs.addTab( 219 localizationResources.getString("Legend"), 220 this.legendPropertiesPanel 221 ); 222 223 this.plotPropertiesPanel = new PlotPropertyEditPanel(plot); 224 this.plotPropertiesPanel.setBorder( 225 BorderFactory.createEmptyBorder(2, 2, 2, 2) 226 ); 227 tabs.addTab( 228 localizationResources.getString("Plot"), this.plotPropertiesPanel 229 ); 230 231 tabs.add(localizationResources.getString("Other"), other); 232 parts.add(tabs, BorderLayout.NORTH); 233 add(parts); 234 } 235 236 241 public TitlePropertyEditPanel getTitlePropertyEditPanel() { 242 return this.titlePropertiesPanel; 243 } 244 245 250 public LegendPropertyEditPanel getLegendPropertyEditPanel() { 251 return this.legendPropertiesPanel; 252 } 253 254 259 public PlotPropertyEditPanel getPlotPropertyEditPanel() { 260 return this.plotPropertiesPanel; 261 } 262 263 268 public boolean getAntiAlias() { 269 return this.antialias.isSelected(); 270 } 271 272 277 public Paint getBackgroundPaint() { 278 return this.background.getPaint(); 279 } 280 281 286 public void actionPerformed(ActionEvent event) { 287 String command = event.getActionCommand(); 288 if (command.equals("BackgroundPaint")) { 289 attemptModifyBackgroundPaint(); 290 } 291 } 292 293 298 private void attemptModifyBackgroundPaint() { 299 Color c; 300 c = JColorChooser.showDialog( 301 this, localizationResources.getString("Background_Color"), 302 Color.blue 303 ); 304 if (c != null) { 305 this.background.setPaint(c); 306 } 307 } 308 309 315 public void updateChartProperties(JFreeChart chart) { 316 317 this.titlePropertiesPanel.setTitleProperties(chart); 318 this.legendPropertiesPanel.setLegendProperties(chart); 319 this.plotPropertiesPanel.updatePlotProperties(chart.getPlot()); 320 321 chart.setAntiAlias(getAntiAlias()); 322 chart.setBackgroundPaint(getBackgroundPaint()); 323 } 324 325 } 326 | Popular Tags |