1 package com.genimen.djeneric.tools.menu; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Dimension ; 5 import java.awt.Frame ; 6 import java.awt.event.ActionEvent ; 7 import java.util.Properties ; 8 9 import javax.swing.DefaultComboBoxModel ; 10 import javax.swing.JButton ; 11 import javax.swing.JCheckBox ; 12 import javax.swing.JComboBox ; 13 import javax.swing.JDialog ; 14 import javax.swing.JLabel ; 15 import javax.swing.JPanel ; 16 import javax.swing.JTextField ; 17 18 import com.genimen.djeneric.language.Messages; 19 import com.genimen.djeneric.ui.DjVerticalFlowLayout; 20 import com.genimen.djeneric.ui.Util; 21 import com.genimen.djeneric.util.DjLogger; 22 23 public class OptionsDialog extends JDialog 24 { 25 private static final long serialVersionUID = 1L; 26 JPanel panel1 = new JPanel (); 27 BorderLayout borderLayout1 = new BorderLayout (); 28 JPanel jPanel1 = new JPanel (); 29 JPanel jPanel2 = new JPanel (); 30 BorderLayout borderLayout2 = new BorderLayout (); 31 JPanel jPanel3 = new JPanel (); 32 JButton _butOk = new JButton (); 33 JButton _butCancel = new JButton (); 34 BorderLayout borderLayout3 = new BorderLayout (); 35 JPanel jPanel4 = new JPanel (); 36 JPanel jPanel5 = new JPanel (); 37 JLabel jLabel1 = new JLabel (); 38 JTextField _edtVmOptions = new JTextField (); 39 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 40 DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout(); 41 JLabel jLabel2 = new JLabel (); 42 JComboBox _cbbLanguage = new JComboBox (); 43 44 Properties _props; 45 JLabel lblProto = new JLabel (); 46 JLabel lblStripspaces = new JLabel (); 47 JCheckBox _chkProtoMode = new JCheckBox (); 48 JCheckBox _chkStripSpaces = new JCheckBox (); 49 50 public OptionsDialog(Frame frame, Properties props) 51 { 52 super(frame, Messages.getString("MenuOptions.Title"), true); _props = props; 54 try 55 { 56 jbInit(); 57 _edtVmOptions.setText(props.getProperty(Menu.TOOL_VM_OPTIONS, "")); 59 _cbbLanguage.setModel(new DefaultComboBoxModel (new String []{ 60 Messages.getString("MenuOptions.defaultLanguage"), "English", "Nederlands"})); 62 String language = props.getProperty(Menu.TOOL_LANGUAGE, ""); 64 if (language.equalsIgnoreCase("en")) _cbbLanguage.setSelectedIndex(1); 67 else if (language.equalsIgnoreCase("nl")) _cbbLanguage.setSelectedIndex(2); 69 else _cbbLanguage.setSelectedIndex(0); 70 71 _chkProtoMode.setSelected("true".equalsIgnoreCase(props.getProperty(Menu.TOOL_PROTOTYPING, "true"))); 72 _chkStripSpaces.setSelected("true".equalsIgnoreCase(props.getProperty(Menu.TOOL_STRIPSPACES, "true"))); 73 74 pack(); 75 setBounds(frame.getX() + 50, frame.getY() + 50, getWidth(), getHeight()); 76 setVisible(true); 77 } 78 catch (Exception ex) 79 { 80 DjLogger.log(ex); 81 } 82 } 83 84 private void jbInit() throws Exception 85 { 86 panel1.setLayout(borderLayout1); 87 jPanel1.setLayout(borderLayout2); 88 _butOk.setText(Messages.getString("global.Ok")); _butOk.addActionListener(new OptionsDialog__butOk_actionAdapter(this)); 90 _butCancel.setText(Messages.getString("global.Cancel")); _butCancel.addActionListener(new OptionsDialog__butCancel_actionAdapter(this)); 92 jPanel2.setLayout(borderLayout3); 93 jLabel1.setText(Messages.getString("MenuOptions.VmOptions")); jPanel5.setLayout(verticalFlowLayout1); 95 jPanel4.setLayout(verticalFlowLayout2); 96 jLabel2.setText(Messages.getString("MenuOptions.Language")); _cbbLanguage.setMinimumSize(new Dimension (31, 21)); 98 _edtVmOptions.setFont(new java.awt.Font ("Monospaced", 0, 12)); _edtVmOptions.setPreferredSize(new Dimension (250, 20)); 100 _edtVmOptions.setToolTipText(Messages.getString("MenuOptions.VmOptionsTooltip")); _edtVmOptions.setText(""); lblProto.setText(Messages.getString("MenuOptions.Prototyping")); 103 lblProto.setToolTipText(Messages.getString("MenuOptions.PrototypingTooltip")); lblStripspaces.setText(Messages.getString("MenuOptions.Stripspaces")); 105 lblStripspaces.setToolTipText(Messages.getString("MenuOptions.StripspacesTooltip")); _chkProtoMode.setText(""); 107 _chkStripSpaces.setText(""); 108 getContentPane().add(panel1); 109 panel1.add(jPanel1, BorderLayout.SOUTH); 110 jPanel1.add(jPanel3, BorderLayout.EAST); 111 jPanel3.add(_butCancel, null); 112 jPanel3.add(_butOk, null); 113 panel1.add(jPanel2, BorderLayout.CENTER); 114 jPanel2.add(jPanel4, BorderLayout.WEST); 115 jPanel4.add(jLabel1, null); 116 jPanel4.add(jLabel2, null); 117 jPanel4.add(lblProto, null); 118 jPanel4.add(lblStripspaces, null); 119 jPanel2.add(jPanel5, BorderLayout.CENTER); 120 jPanel5.add(_edtVmOptions, null); 121 jPanel5.add(_cbbLanguage, null); 122 jPanel5.add(_chkProtoMode, null); 123 jPanel5.add(_chkStripSpaces, null); 124 Util.sizeButtons(panel1); 125 Util.sizeLabels(panel1); 126 } 127 128 void _butOk_actionPerformed(ActionEvent e) 129 { 130 _props.setProperty(Menu.TOOL_VM_OPTIONS, _edtVmOptions.getText().trim()); 131 _props.setProperty(Menu.TOOL_PROTOTYPING, String.valueOf(_chkProtoMode.isSelected())); 132 _props.setProperty(Menu.TOOL_STRIPSPACES, String.valueOf(_chkStripSpaces.isSelected())); 133 134 int idx = _cbbLanguage.getSelectedIndex(); 135 if (idx == 1) _props.setProperty(Menu.TOOL_LANGUAGE, "en"); else if (idx == 2) _props.setProperty(Menu.TOOL_LANGUAGE, "nl"); else _props.setProperty(Menu.TOOL_LANGUAGE, ""); setVisible(false); 139 } 140 141 void _butCancel_actionPerformed(ActionEvent e) 142 { 143 setVisible(false); 144 145 } 146 } 147 148 class OptionsDialog__butOk_actionAdapter implements java.awt.event.ActionListener 149 { 150 OptionsDialog adaptee; 151 152 OptionsDialog__butOk_actionAdapter(OptionsDialog adaptee) 153 { 154 this.adaptee = adaptee; 155 } 156 157 public void actionPerformed(ActionEvent e) 158 { 159 adaptee._butOk_actionPerformed(e); 160 } 161 } 162 163 class OptionsDialog__butCancel_actionAdapter implements java.awt.event.ActionListener 164 { 165 OptionsDialog adaptee; 166 167 OptionsDialog__butCancel_actionAdapter(OptionsDialog adaptee) 168 { 169 this.adaptee = adaptee; 170 } 171 172 public void actionPerformed(ActionEvent e) 173 { 174 adaptee._butCancel_actionPerformed(e); 175 } 176 } | Popular Tags |