Debian Codegraph @

freehep-graphicsio/src/main/java/org/freehep/graphicsio/exportchooser/OptionRadioButton.java

raw
1 // Copyright 2003, FreeHEP.
2 package org.freehep.graphicsio.exportchooser;
3
4 import java.awt.Component;
5 import java.awt.event.ItemEvent;
6 import java.awt.event.ItemListener;
7 import java.util.Properties;
8
9 import javax.swing.JRadioButton;
10
11 /**
12 *
13 * @author Mark Donszelmann
14 * @version $Id: freehep-graphicsio/src/main/java/org/freehep/graphicsio/exportchooser/OptionRadioButton.java 5641ca92a537 2005/11/26 00:15:35 duns $
15 */
16 public class OptionRadioButton extends JRadioButton implements Options {
17 protected boolean initialState;
18
19 protected String key;
20
21 public OptionRadioButton(Properties options, String key, String text) {
22 super(text, new Boolean(options.getProperty(key, "false"))
23 .booleanValue());
24 this.key = key;
25 initialState = isSelected();
26 }
27
28 public boolean applyChangedOptions(Properties options) {
29 if (isSelected() != initialState) {
30 options.setProperty(key, Boolean.toString(isSelected()));
31 return true;
32 }
33 return false;
34 }
35
36 /**
37 * Enables (otherwise disables) the supplied component if this radiobutton
38 * is checked. Can be called for multiple components.
39 */
40 public void enables(final Component c) {
41 if (c.isEnabled()) {
42 c.setEnabled(isSelected());
43
44 addItemListener(new ItemListener() {
45 public void itemStateChanged(ItemEvent e) {
46 c.setEnabled(isSelected());
47 }
48 });
49 }
50 }
51
52 /**
53 * Shows (otherwise hides) the supplied component if this radiobutton is
54 * checked. Can be called for multiple components.
55 */
56 public void shows(final Component c) {
57 c.setVisible(isSelected());
58
59 addItemListener(new ItemListener() {
60 public void itemStateChanged(ItemEvent e) {
61 c.setVisible(isSelected());
62 }
63 });
64 }
65 }