1 3 20 21 25 26 package edu.neu.ccs.jmk.swing; 27 28 import java.awt.*; 29 import java.awt.event.*; 30 import javax.swing.*; 31 import javax.swing.border.*; 32 33 final public 34 class PreferenceDG 35 extends JDialog 36 { 37 static final String metalClassname="javax.swing.plaf.metal.MetalLookAndFeel"; 38 static final String motifClassname="com.sun.java.swing.plaf.motif.MotifLookAndFeel"; 39 static final String windowsClassname="com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; 40 static final String macClassname="com.sun.java.swing.plaf.mac.MacLookAndFeel"; 41 42 44 private String landf_=null; 45 private boolean autoscroll_=true; 46 private boolean autoclear_=true; 47 private boolean automake_=true; 48 private int exitstatus_=0; 50 private JTabbedPane mainTP; 51 private JPanel bottomPL; 52 private JPanel lfPL; 53 private JPanel optionPL; 54 private JPanel line1PL; 55 private JPanel line2PL; 56 private JLabel widthLB; 57 private JTextField widthTF; 58 private JLabel heightLB; 59 private JTextField heightTF; 60 private JRadioButton winRB; 61 private JRadioButton metalRB; 62 private JRadioButton motifRB; 63 private JRadioButton macRB; 64 private JCheckBox autoclearCB; 65 private JCheckBox autoscrollCB; 66 private JCheckBox automakeCB; 67 private JButton saveBT; 68 private JButton okBT; 69 private JButton cancelBT; 70 71 public PreferenceDG(java.awt.Frame parent, boolean modal) 72 { 73 super (parent, modal); 74 initComponents (); 75 pack (); 76 77 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 79 Dimension windowSize = getSize(); 80 setBounds( (screenSize.width-windowSize.width)/2, 81 (screenSize.height-windowSize.height)/2, windowSize.width, windowSize.height); 82 } 83 84 public void setLnF(String _lnf) 86 { 87 metalRB.setSelected(false); 88 motifRB.setSelected(false); 89 winRB.setSelected(false); 90 macRB.setSelected(false); 91 92 if ( _lnf.indexOf("Metal") >= 0 ) metalRB.setSelected(true); 93 else if ( _lnf.indexOf("Motif") >= 0 ) motifRB.setSelected(true); 94 else if ( _lnf.indexOf("Windows") >= 0 ) winRB.setSelected(true); 95 else if ( _lnf.indexOf("Mac") >= 0 ) macRB.setSelected(true); 96 else 97 { 98 System.err.println("Unknown look and Feel:"+_lnf); 99 metalRB.setSelected(true); 100 } 101 } 102 103 private void initComponents () 105 { 106 setTitle ("Jmk Preferences"); 107 addWindowListener (new WindowAdapter () 108 { 109 public void windowClosing (WindowEvent evt) 110 { 111 closeDialog (evt); 112 } 113 } 114 ); 115 getContentPane ().setLayout (new java.awt.BorderLayout ()); 116 117 mainTP = new JTabbedPane (); 118 119 lfPL = new JPanel (); 120 lfPL.setBorder (new EmptyBorder (new java.awt.Insets (5, 40, 5, 1))); 121 lfPL.setLayout (new BoxLayout (lfPL, 1)); 122 123 winRB = new JRadioButton (); 124 winRB.setText ("Windows"); 125 lfPL.add (winRB); 126 127 metalRB = new JRadioButton (); 128 metalRB.setText ("Metal"); 129 lfPL.add (metalRB); 130 131 motifRB = new JRadioButton (); 132 motifRB.setText ("Motif"); 133 lfPL.add (motifRB); 134 135 macRB = new JRadioButton (); 136 macRB.setText ("Mac"); 137 lfPL.add (macRB); 138 139 mainTP.addTab ("Look&Feel", lfPL); 140 141 optionPL = new JPanel (); 142 optionPL.setBorder (new EmptyBorder (new java.awt.Insets (5, 40, 5, 1))); 143 optionPL.setLayout (new BoxLayout (optionPL, 1)); 144 145 autoclearCB = new JCheckBox (); 146 autoclearCB.setText ("Autoclear log"); 147 optionPL.add (autoclearCB); 148 149 autoscrollCB = new JCheckBox (); 150 autoscrollCB.setText ("Autoscroll log"); 151 optionPL.add (autoscrollCB); 152 153 automakeCB = new JCheckBox (); 154 automakeCB.setText ("Automake on target combo selection"); 155 optionPL.add (automakeCB); 156 157 mainTP.addTab ("Options", optionPL); 158 159 getContentPane ().add (mainTP, "Center"); 160 161 bottomPL = new JPanel (); 162 bottomPL.setLayout (new java.awt.FlowLayout ()); 163 164 saveBT = new JButton (); 165 saveBT.setText ("Save"); 166 saveBT.addActionListener (new ActionListener () 167 { 168 public void actionPerformed (ActionEvent evt) 169 { 170 setBooleans(); 171 JmkProperties jp=JmkProperties.getInstance(); 172 jp.put("jmk.lookandfeel", getSelectedLnF()); 173 jp.put("jmk.autoscroll", ""+autoscroll_); 174 jp.put("jmk.autoclear", ""+autoclear_); 175 jp.put("jmk.automake", ""+automake_); 176 jp.save(); 177 exitstatus_=1; 178 setVisible(false); 179 dispose(); 180 181 } 182 }); 183 bottomPL.add (saveBT); 184 185 okBT = new JButton (); 186 okBT.setText ("Apply"); 187 okBT.addActionListener (new ActionListener () 188 { 189 public void actionPerformed (ActionEvent evt) 190 { 191 setBooleans (); 192 exitstatus_=1; 193 setVisible(false); 194 dispose(); 195 196 } 197 }); 198 bottomPL.add (okBT); 199 200 cancelBT = new JButton (); 201 cancelBT.setText ("Cancel"); 202 cancelBT.addActionListener (new ActionListener () 203 { 204 public void actionPerformed (ActionEvent evt) 205 { 206 cancelBTActionPerformed (evt); 207 } 208 }); 209 bottomPL.add (cancelBT); 210 211 getContentPane ().add (bottomPL, "South"); 212 213 ButtonGroup group=new ButtonGroup(); 215 group.add(winRB); 216 group.add(metalRB); 217 group.add(motifRB); 218 group.add(macRB); 219 220 } 221 222 private void cancelBTActionPerformed (ActionEvent evt) 223 { 224 setVisible(false); 225 dispose(); 226 exitstatus_=0; 227 } 228 229 public int getExitStatus() 230 { 231 return(exitstatus_); 232 } 233 234 public void setAutoscroll(boolean _b) 235 { 236 autoscrollCB.setSelected(_b); 237 autoscroll_=_b; 238 } 239 public boolean getAutoscroll() 240 { 241 return(autoscroll_); 242 } 243 244 public void setAutoclear(boolean _b) 245 { 246 autoclearCB.setSelected(_b); 247 autoclear_=_b; 248 } 249 public boolean getAutoclear() 250 { 251 return(autoclear_); 252 } 253 254 public void setAutomake(boolean _b) 255 { 256 automakeCB.setSelected(_b); 257 automake_=_b; 258 } 259 public boolean getAutomake() 260 { 261 return(automake_); 262 } 263 264 public String getSelectedLnF() 265 { 266 267 if ( motifRB.isSelected() ) return(motifClassname); 268 if ( winRB.isSelected() ) return(windowsClassname); 269 if ( macRB.isSelected() ) return(macClassname); 270 return(metalClassname); 271 } 272 273 private void setBooleans() 274 { 275 autoclear_=autoclearCB.isSelected(); 276 autoscroll_=autoscrollCB.isSelected(); 277 automake_=automakeCB.isSelected(); 278 } 279 280 private void closeDialog(WindowEvent evt) 281 { 282 setVisible (false); 283 dispose (); 284 exitstatus_=0; 285 } 286 287 } 288 | Popular Tags |