1 package rero.dck.items; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 6 import javax.swing.*; 7 import javax.swing.event.*; 8 9 import java.util.*; 10 11 import rero.config.*; 12 import rero.dck.*; 13 14 public class CheckboxInput extends SuperInput implements ChangeListener 15 { 16 protected LinkedList enabledTrue = new LinkedList(); 17 protected LinkedList enabledFalse = new LinkedList(); 18 protected JCheckBox box; 19 20 protected boolean defaultVal; 21 22 public CheckboxInput(String var, boolean defaultVar, String _label, char mnemonic) 23 { 24 this(var, defaultVar, _label, mnemonic, FlowLayout.LEFT); 25 } 26 27 public CheckboxInput(String var, boolean defaultVar, String _label, char mnemonic, int alignment) 28 { 29 setLayout(new FlowLayout(alignment, 0, 0)); 30 31 box = new JCheckBox(_label); 32 box.addChangeListener(this); 33 34 add(box); 35 box.setMnemonic(mnemonic); 36 37 setPreferredSize(box.getPreferredSize()); 38 39 variable = var; 40 defaultVal = defaultVar; 41 } 42 43 public void stateChanged(ChangeEvent ev) 44 { 45 handleDependents(); 46 notifyParent(); 47 } 48 49 public void addDependent(DItem item) 50 { 51 enabledTrue.add(item); 52 } 53 54 public void addAntiDependent(DItem item) 55 { 56 enabledFalse.add(item); 57 } 58 59 public void save() 60 { 61 63 ClientState.getClientState().setOption(getVariable(), box.isSelected()); 64 } 65 66 public int getEstimatedWidth() 67 { 68 return 0; 69 } 70 71 public void setAlignWidth(int width) 72 { 73 } 74 75 public JComponent getComponent() 76 { 77 return this; 78 } 79 80 public void refresh() 81 { 82 84 box.setSelected(ClientState.getClientState().isOption(getVariable(), defaultVal)); 85 handleDependents(); 86 } 87 88 public void handleDependents() 89 { 90 Iterator i = enabledTrue.iterator(); 91 while (i.hasNext()) 92 { 93 DItem temp = (DItem)i.next(); 94 temp.setEnabled(box.isSelected()); 95 } 96 97 i = enabledFalse.iterator(); 98 while (i.hasNext()) 99 { 100 DItem temp = (DItem)i.next(); 101 temp.setEnabled(!box.isSelected()); 102 } 103 } 104 105 public JCheckBox getCheckBox() 106 { 107 return box; 108 } 109 } 110 111 112 | Popular Tags |