1 43 44 package org.jfree.chart.editor; 45 46 import java.awt.BorderLayout ; 47 import java.awt.Color ; 48 import java.awt.Paint ; 49 import java.awt.event.ActionEvent ; 50 import java.awt.event.ActionListener ; 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.JColorChooser ; 57 import javax.swing.JLabel ; 58 import javax.swing.JPanel ; 59 import javax.swing.JTabbedPane ; 60 import javax.swing.JTextField ; 61 62 import org.jfree.chart.JFreeChart; 63 import org.jfree.chart.plot.Plot; 64 import org.jfree.chart.title.Title; 65 import org.jfree.layout.LCBLayout; 66 import org.jfree.ui.PaintSample; 67 68 72 class DefaultChartEditor extends JPanel implements ActionListener , ChartEditor { 73 74 75 private DefaultTitleEditor titleEditor; 76 77 78 private DefaultPlotEditor plotEditor; 79 80 84 private JCheckBox antialias; 85 86 87 private PaintSample background; 88 89 90 protected static ResourceBundle localizationResources 91 = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle"); 92 93 99 public DefaultChartEditor(JFreeChart chart) { 100 setLayout(new BorderLayout ()); 101 102 JPanel other = new JPanel (new BorderLayout ()); 103 other.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); 104 105 JPanel general = new JPanel (new BorderLayout ()); 106 general.setBorder(BorderFactory.createTitledBorder( 107 BorderFactory.createEtchedBorder(), 108 localizationResources.getString("General"))); 109 110 JPanel interior = new JPanel (new LCBLayout(6)); 111 interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); 112 113 this.antialias = new JCheckBox (localizationResources.getString( 114 "Draw_anti-aliased")); 115 this.antialias.setSelected(chart.getAntiAlias()); 116 interior.add(this.antialias); 117 interior.add(new JLabel ("")); 118 interior.add(new JLabel ("")); 119 interior.add(new JLabel (localizationResources.getString( 120 "Background_paint"))); 121 this.background = new PaintSample(chart.getBackgroundPaint()); 122 interior.add(this.background); 123 JButton button = new JButton (localizationResources.getString( 124 "Select...")); 125 button.setActionCommand("BackgroundPaint"); 126 button.addActionListener(this); 127 interior.add(button); 128 129 interior.add(new JLabel (localizationResources.getString( 130 "Series_Paint"))); 131 JTextField info = new JTextField (localizationResources.getString( 132 "No_editor_implemented")); 133 info.setEnabled(false); 134 interior.add(info); 135 button = new JButton (localizationResources.getString("Edit...")); 136 button.setEnabled(false); 137 interior.add(button); 138 139 interior.add(new JLabel (localizationResources.getString( 140 "Series_Stroke"))); 141 info = new JTextField (localizationResources.getString( 142 "No_editor_implemented")); 143 info.setEnabled(false); 144 interior.add(info); 145 button = new JButton (localizationResources.getString("Edit...")); 146 button.setEnabled(false); 147 interior.add(button); 148 149 interior.add(new JLabel (localizationResources.getString( 150 "Series_Outline_Paint"))); 151 info = new JTextField (localizationResources.getString( 152 "No_editor_implemented")); 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(new JLabel (localizationResources.getString( 160 "Series_Outline_Stroke"))); 161 info = new JTextField (localizationResources.getString( 162 "No_editor_implemented")); 163 info.setEnabled(false); 164 interior.add(info); 165 button = new JButton (localizationResources.getString("Edit...")); 166 button.setEnabled(false); 167 interior.add(button); 168 169 general.add(interior, BorderLayout.NORTH); 170 other.add(general, BorderLayout.NORTH); 171 172 JPanel parts = new JPanel (new BorderLayout ()); 173 174 Title title = chart.getTitle(); 175 Plot plot = chart.getPlot(); 176 177 JTabbedPane tabs = new JTabbedPane (); 178 179 this.titleEditor = new DefaultTitleEditor(title); 180 this.titleEditor.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); 181 tabs.addTab(localizationResources.getString("Title"), this.titleEditor); 182 183 this.plotEditor = new DefaultPlotEditor(plot); 184 this.plotEditor.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); 185 tabs.addTab(localizationResources.getString("Plot"), this.plotEditor); 186 187 tabs.add(localizationResources.getString("Other"), other); 188 parts.add(tabs, BorderLayout.NORTH); 189 add(parts); 190 } 191 192 197 public DefaultTitleEditor getTitleEditor() { 198 return this.titleEditor; 199 } 200 201 206 public DefaultPlotEditor getPlotEditor() { 207 return this.plotEditor; 208 } 209 210 215 public boolean getAntiAlias() { 216 return this.antialias.isSelected(); 217 } 218 219 224 public Paint getBackgroundPaint() { 225 return this.background.getPaint(); 226 } 227 228 233 public void actionPerformed(ActionEvent event) { 234 String command = event.getActionCommand(); 235 if (command.equals("BackgroundPaint")) { 236 attemptModifyBackgroundPaint(); 237 } 238 } 239 240 245 private void attemptModifyBackgroundPaint() { 246 Color c; 247 c = JColorChooser.showDialog(this, localizationResources.getString( 248 "Background_Color"), Color.blue); 249 if (c != null) { 250 this.background.setPaint(c); 251 } 252 } 253 254 260 public void updateChart(JFreeChart chart) { 261 262 this.titleEditor.setTitleProperties(chart); 263 this.plotEditor.updatePlotProperties(chart.getPlot()); 264 265 chart.setAntiAlias(getAntiAlias()); 266 chart.setBackgroundPaint(getBackgroundPaint()); 267 } 268 269 } 270 | Popular Tags |