1 package com.genimen.djeneric.tools.generator.dialogs; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Dimension ; 5 import java.awt.Frame ; 6 import java.awt.Toolkit ; 7 import java.awt.event.ActionEvent ; 8 import java.io.File ; 9 10 import javax.swing.JButton ; 11 import javax.swing.JDialog ; 12 import javax.swing.JFileChooser ; 13 import javax.swing.JLabel ; 14 import javax.swing.JPanel ; 15 import javax.swing.JTextField ; 16 17 import com.genimen.djeneric.tools.generator.Generator; 18 import com.genimen.djeneric.ui.DjVerticalFlowLayout; 19 import com.genimen.djeneric.util.DjLogger; 20 import com.genimen.djeneric.util.DjProperties; 21 22 public class OptionsDialog extends JDialog 23 { 24 private static final long serialVersionUID = 1L; 25 JPanel panel1 = new JPanel (); 26 BorderLayout borderLayout1 = new BorderLayout (); 27 JPanel jPanel1 = new JPanel (); 28 JPanel jPanel2 = new JPanel (); 29 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 30 DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout(); 31 JLabel jLabel1 = new JLabel (); 32 JLabel jLabel2 = new JLabel (); 33 boolean _canceled = true; 34 JPanel jPanel3 = new JPanel (); 35 BorderLayout borderLayout2 = new BorderLayout (); 36 JPanel jPanel4 = new JPanel (); 37 JButton _butOk = new JButton (); 38 JButton _butCancel = new JButton (); 39 DjProperties _props; 40 JButton _butIncludePath = new JButton (); 41 BorderLayout borderLayout4 = new BorderLayout (); 42 JTextField _edtIncludePath = new JTextField (); 43 JPanel jPanel6 = new JPanel (); 44 JButton _butTemplate = new JButton (); 45 BorderLayout borderLayout5 = new BorderLayout (); 46 JTextField _edtTemplateSetPath = new JTextField (); 47 JPanel jPanel7 = new JPanel (); 48 49 public OptionsDialog(Frame frame, DjProperties props) 50 { 51 super(frame, "Options", true); 52 try 53 { 54 _props = props; 55 56 jbInit(); 57 pack(); 58 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 59 Dimension frameSize = getSize(); 60 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 61 62 _edtIncludePath.setText(props.getProperty(Generator.KEY_INCLUDEPATH, "")); 63 _edtTemplateSetPath.setText(props.getProperty(Generator.KEY_TEMPLATEPATH, "")); 64 65 setVisible(true); 66 } 67 catch (Exception ex) 68 { 69 DjLogger.log(ex); 70 } 71 } 72 73 void jbInit() throws Exception 74 { 75 panel1.setLayout(borderLayout1); 76 jPanel1.setLayout(verticalFlowLayout1); 77 jPanel2.setLayout(verticalFlowLayout2); 78 jLabel1.setPreferredSize(new Dimension (102, 21)); 79 jLabel1.setText("Template set path"); 80 jLabel2.setPreferredSize(new Dimension (102, 21)); 81 jLabel2.setText("Include path"); 82 jPanel3.setLayout(borderLayout2); 83 _butOk.setPreferredSize(new Dimension (73, 27)); 84 _butOk.setText("OK"); 85 _butOk.addActionListener(new java.awt.event.ActionListener () 86 { 87 public void actionPerformed(ActionEvent e) 88 { 89 _butOk_actionPerformed(e); 90 } 91 }); 92 _butCancel.setText("Cancel"); 93 _butCancel.addActionListener(new java.awt.event.ActionListener () 94 { 95 public void actionPerformed(ActionEvent e) 96 { 97 _butCancel_actionPerformed(e); 98 } 99 }); 100 _butIncludePath.setText("..."); 101 _butIncludePath.addActionListener(new java.awt.event.ActionListener () 102 { 103 public void actionPerformed(ActionEvent e) 104 { 105 _butIncludePath_actionPerformed(e); 106 } 107 }); 108 _butIncludePath.setPreferredSize(new Dimension (21, 21)); 109 jPanel6.setLayout(borderLayout4); 110 _butTemplate.setPreferredSize(new Dimension (21, 21)); 111 _butTemplate.addActionListener(new java.awt.event.ActionListener () 112 { 113 public void actionPerformed(ActionEvent e) 114 { 115 _butTemplate_actionPerformed(e); 116 } 117 }); 118 _butTemplate.setText("..."); 119 jPanel7.setLayout(borderLayout5); 120 _edtTemplateSetPath.setPreferredSize(new Dimension (300, 21)); 121 getContentPane().add(panel1); 122 panel1.add(jPanel1, BorderLayout.WEST); 123 jPanel1.add(jLabel1, null); 124 jPanel1.add(jLabel2, null); 125 panel1.add(jPanel2, BorderLayout.CENTER); 126 jPanel7.add(_edtTemplateSetPath, BorderLayout.CENTER); 127 jPanel7.add(_butTemplate, BorderLayout.EAST); 128 jPanel2.add(jPanel7, null); 129 jPanel2.add(jPanel6, null); 130 jPanel6.add(_edtIncludePath, BorderLayout.CENTER); 131 jPanel6.add(_butIncludePath, BorderLayout.EAST); 132 this.getContentPane().add(jPanel3, BorderLayout.SOUTH); 133 jPanel3.add(jPanel4, BorderLayout.EAST); 134 jPanel4.add(_butCancel, null); 135 jPanel4.add(_butOk, null); 136 } 137 138 void _butOk_actionPerformed(ActionEvent e) 139 { 140 _canceled = false; 141 _props.setProperty(Generator.KEY_TEMPLATEPATH, _edtTemplateSetPath.getText()); 142 _props.setProperty(Generator.KEY_INCLUDEPATH, _edtIncludePath.getText()); 143 setVisible(false); 144 } 145 146 void _butCancel_actionPerformed(ActionEvent e) 147 { 148 setVisible(false); 149 } 150 151 public boolean wasCancelled() 152 { 153 return _canceled; 154 } 155 156 void _butIncludePath_actionPerformed(ActionEvent e) 157 { 158 _edtIncludePath.setText(getPath("Include path", _edtIncludePath.getText())); 159 160 } 161 162 String getPath(String title, String path) 163 { 164 JFileChooser fc = new JFileChooser (); 165 fc.setDialogTitle(title); 166 167 String startHere = path; 168 169 if (startHere.indexOf(";") != -1) startHere = startHere.substring(0, startHere.indexOf(";")); 170 171 if (startHere.trim().length() == 0) startHere = System.getProperties().getProperty("user.dir"); 172 173 fc.setCurrentDirectory(new File (startHere)); 174 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 175 176 if (fc.showDialog(this, "Add to path") != JFileChooser.CANCEL_OPTION) 177 { 178 String current = path.trim(); 179 if (current.length() != 0) current += ";"; 180 current += fc.getSelectedFile().getAbsolutePath(); 181 182 path = current; 183 } 184 return path; 185 } 186 187 void _butTemplate_actionPerformed(ActionEvent e) 188 { 189 _edtTemplateSetPath.setText(getPath("Template path", _edtTemplateSetPath.getText())); 190 } 191 192 } | Popular Tags |