1 49 50 package org.jfree.chart.ui; 51 52 import java.awt.BorderLayout ; 53 import java.awt.Color ; 54 import java.awt.Font ; 55 import java.awt.Paint ; 56 import java.awt.event.ActionEvent ; 57 import java.awt.event.ActionListener ; 58 import java.util.ResourceBundle ; 59 60 import javax.swing.BorderFactory ; 61 import javax.swing.JButton ; 62 import javax.swing.JCheckBox ; 63 import javax.swing.JColorChooser ; 64 import javax.swing.JLabel ; 65 import javax.swing.JOptionPane ; 66 import javax.swing.JPanel ; 67 import javax.swing.JTabbedPane ; 68 import javax.swing.JTextField ; 69 70 import org.jfree.chart.axis.Axis; 71 import org.jfree.chart.axis.NumberAxis; 72 import org.jfree.layout.LCBLayout; 73 import org.jfree.ui.FontChooserPanel; 74 import org.jfree.ui.FontDisplayField; 75 import org.jfree.ui.PaintSample; 76 import org.jfree.ui.RectangleInsets; 77 78 82 public class AxisPropertyEditPanel extends JPanel implements ActionListener { 83 84 85 private JTextField label; 86 87 88 private Font labelFont; 89 90 91 private PaintSample labelPaintSample; 92 93 94 private JTextField labelFontField; 95 96 97 private Font tickLabelFont; 98 99 103 private JTextField tickLabelFontField; 104 105 106 private PaintSample tickLabelPaintSample; 107 108 112 private JPanel slot1; 113 114 118 private JPanel slot2; 119 120 121 private JCheckBox showTickLabelsCheckBox; 122 123 124 private JCheckBox showTickMarksCheckBox; 125 126 132 133 private RectangleInsets tickLabelInsets; 134 135 136 private RectangleInsets labelInsets; 137 138 139 private JTabbedPane otherTabs; 140 141 142 protected static ResourceBundle localizationResources = 143 ResourceBundle.getBundle("org.jfree.chart.ui.LocalizationBundle"); 144 145 154 public static AxisPropertyEditPanel getInstance(Axis axis) { 155 156 if (axis != null) { 157 if (axis instanceof NumberAxis) { 160 return new NumberAxisPropertyEditPanel((NumberAxis) axis); 161 } 162 else { 163 return new AxisPropertyEditPanel(axis); 164 } 165 } 166 else { 167 return null; 168 } 169 170 } 171 172 179 public AxisPropertyEditPanel(Axis axis) { 180 181 this.labelFont = axis.getLabelFont(); 182 this.labelPaintSample = new PaintSample(axis.getLabelPaint()); 183 this.tickLabelFont = axis.getTickLabelFont(); 184 this.tickLabelPaintSample = new PaintSample(axis.getTickLabelPaint()); 185 186 this.tickLabelInsets = axis.getTickLabelInsets(); 188 this.labelInsets = axis.getLabelInsets(); 189 190 setLayout(new BorderLayout ()); 191 192 JPanel general = new JPanel (new BorderLayout ()); 193 general.setBorder( 194 BorderFactory.createTitledBorder( 195 BorderFactory.createEtchedBorder(), 196 localizationResources.getString("General") 197 ) 198 ); 199 200 JPanel interior = new JPanel (new LCBLayout(5)); 201 interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); 202 interior.add(new JLabel (localizationResources.getString("Label"))); 203 this.label = new JTextField (axis.getLabel()); 204 interior.add(this.label); 205 interior.add(new JPanel ()); 206 207 interior.add(new JLabel (localizationResources.getString("Font"))); 208 this.labelFontField = new FontDisplayField(this.labelFont); 209 interior.add(this.labelFontField); 210 JButton b = new JButton (localizationResources.getString("Select...")); 211 b.setActionCommand("SelectLabelFont"); 212 b.addActionListener(this); 213 interior.add(b); 214 215 interior.add(new JLabel (localizationResources.getString("Paint"))); 216 interior.add(this.labelPaintSample); 217 b = new JButton (localizationResources.getString("Select...")); 218 b.setActionCommand("SelectLabelPaint"); 219 b.addActionListener(this); 220 interior.add(b); 221 222 243 general.add(interior); 244 245 add(general, BorderLayout.NORTH); 246 247 this.slot1 = new JPanel (new BorderLayout ()); 248 249 JPanel other = new JPanel (new BorderLayout ()); 250 other.setBorder(BorderFactory.createTitledBorder( 251 BorderFactory.createEtchedBorder(), 252 localizationResources.getString("Other"))); 253 254 this.otherTabs = new JTabbedPane (); 255 this.otherTabs.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); 256 257 JPanel ticks = new JPanel (new LCBLayout(3)); 258 ticks.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); 259 260 this.showTickLabelsCheckBox = new JCheckBox ( 261 localizationResources.getString("Show_tick_labels"), 262 axis.isTickLabelsVisible() 263 ); 264 ticks.add(this.showTickLabelsCheckBox); 265 ticks.add(new JPanel ()); 266 ticks.add(new JPanel ()); 267 268 ticks.add( 269 new JLabel (localizationResources.getString("Tick_label_font")) 270 ); 271 this.tickLabelFontField = new FontDisplayField(this.tickLabelFont); 272 ticks.add(this.tickLabelFontField); 273 b = new JButton (localizationResources.getString("Select...")); 274 b.setActionCommand("SelectTickLabelFont"); 275 b.addActionListener(this); 276 ticks.add(b); 277 278 this.showTickMarksCheckBox = new JCheckBox ( 279 localizationResources.getString("Show_tick_marks"), 280 axis.isTickMarksVisible() 281 ); 282 ticks.add(this.showTickMarksCheckBox); 283 ticks.add(new JPanel ()); 284 ticks.add(new JPanel ()); 285 286 this.otherTabs.add(localizationResources.getString("Ticks"), ticks); 287 288 other.add(this.otherTabs); 289 290 this.slot1.add(other); 291 292 this.slot2 = new JPanel (new BorderLayout ()); 293 this.slot2.add(this.slot1, BorderLayout.NORTH); 294 add(this.slot2); 295 296 } 297 298 303 public String getLabel() { 304 return this.label.getText(); 305 } 306 307 312 public Font getLabelFont() { 313 return this.labelFont; 314 } 315 316 321 public Paint getLabelPaint() { 322 return this.labelPaintSample.getPaint(); 323 } 324 325 330 public boolean isTickLabelsVisible() { 331 return this.showTickLabelsCheckBox.isSelected(); 332 } 333 334 339 public Font getTickLabelFont() { 340 return this.tickLabelFont; 341 } 342 343 348 public Paint getTickLabelPaint() { 349 return this.tickLabelPaintSample.getPaint(); 350 } 351 352 358 public boolean isTickMarksVisible() { 359 return this.showTickMarksCheckBox.isSelected(); 360 } 361 362 367 public RectangleInsets getTickLabelInsets() { 368 return (this.tickLabelInsets == null) 369 ? new RectangleInsets(0, 0, 0, 0) 370 : this.tickLabelInsets; 371 } 372 373 378 public RectangleInsets getLabelInsets() { 379 return (this.labelInsets == null) 380 ? new RectangleInsets(0, 0, 0, 0) : this.labelInsets; 381 } 382 383 388 public JTabbedPane getOtherTabs() { 389 return this.otherTabs; 390 } 391 392 398 public void actionPerformed(ActionEvent event) { 399 String command = event.getActionCommand(); 400 if (command.equals("SelectLabelFont")) { 401 attemptLabelFontSelection(); 402 } 403 else if (command.equals("SelectLabelPaint")) { 404 attemptModifyLabelPaint(); 405 } 406 else if (command.equals("SelectTickLabelFont")) { 407 attemptTickLabelFontSelection(); 408 } 409 } 416 417 420 private void attemptLabelFontSelection() { 421 422 FontChooserPanel panel = new FontChooserPanel(this.labelFont); 423 int result = JOptionPane.showConfirmDialog(this, panel, 424 localizationResources.getString("Font_Selection"), 425 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 426 427 if (result == JOptionPane.OK_OPTION) { 428 this.labelFont = panel.getSelectedFont(); 429 this.labelFontField.setText( 430 this.labelFont.getFontName() + " " + this.labelFont.getSize() 431 ); 432 } 433 434 } 435 436 439 private void attemptModifyLabelPaint() { 440 Color c; 441 c = JColorChooser.showDialog( 442 this, localizationResources.getString("Label_Color"), Color.blue 443 ); 444 if (c != null) { 445 this.labelPaintSample.setPaint(c); 446 } 447 } 448 449 452 public void attemptTickLabelFontSelection() { 453 454 FontChooserPanel panel = new FontChooserPanel(this.tickLabelFont); 455 int result = JOptionPane.showConfirmDialog(this, panel, 456 localizationResources.getString("Font_Selection"), 457 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 458 459 if (result == JOptionPane.OK_OPTION) { 460 this.tickLabelFont = panel.getSelectedFont(); 461 this.tickLabelFontField.setText( 462 this.tickLabelFont.getFontName() + " " 463 + this.tickLabelFont.getSize() 464 ); 465 } 466 467 } 468 469 505 511 public void setAxisProperties(Axis axis) { 512 axis.setLabel(getLabel()); 513 axis.setLabelFont(getLabelFont()); 514 axis.setLabelPaint(getLabelPaint()); 515 axis.setTickMarksVisible(isTickMarksVisible()); 516 axis.setTickLabelsVisible(isTickLabelsVisible()); 518 axis.setTickLabelFont(getTickLabelFont()); 519 axis.setTickLabelPaint(getTickLabelPaint()); 520 axis.setTickLabelInsets(getTickLabelInsets()); 521 axis.setLabelInsets(getLabelInsets()); 522 } 523 524 } 525 | Popular Tags |