1 package com.genimen.djeneric.tools.menu; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Dimension ; 5 import java.awt.FlowLayout ; 6 import java.awt.Frame ; 7 import java.awt.event.ActionEvent ; 8 import java.awt.event.ActionListener ; 9 import java.io.File ; 10 import java.util.ArrayList ; 11 12 import javax.swing.DefaultComboBoxModel ; 13 import javax.swing.JButton ; 14 import javax.swing.JComboBox ; 15 import javax.swing.JDialog ; 16 import javax.swing.JFileChooser ; 17 import javax.swing.JLabel ; 18 import javax.swing.JPanel ; 19 20 import com.genimen.djeneric.language.Messages; 21 import com.genimen.djeneric.ui.DjVerticalFlowLayout; 22 import com.genimen.djeneric.ui.Util; 23 import com.genimen.djeneric.util.DjFileFilter; 24 import com.genimen.djeneric.util.DjLogger; 25 26 public class DatabaseSelector extends JDialog 27 { 28 private static final long serialVersionUID = 1L; 29 JPanel panel1 = new JPanel (); 30 BorderLayout borderLayout1 = new BorderLayout (); 31 JPanel jPanel1 = new JPanel (); 32 JPanel jPanel2 = new JPanel (); 33 JPanel jPanel3 = new JPanel (); 34 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 35 BorderLayout borderLayout2 = new BorderLayout (); 36 JPanel jPanel4 = new JPanel (); 37 JButton _butOk = new JButton (); 38 JButton _butCancel = new JButton (); 39 JLabel _jLabel1 = new JLabel (); 40 JComboBox _cbbDatabases = new JComboBox (); 41 boolean _canceled = true; 42 String _selectedName = null; 43 JButton _butBrowse = new JButton (); 44 FlowLayout _flowLayout1 = new FlowLayout (); 45 46 public DatabaseSelector(Frame frame, ArrayList existingNames) 47 { 48 super(frame, Messages.getString("DatabaseSelector.selectDb"), true); try 50 { 51 jbInit(); 52 _cbbDatabases.setModel(new DefaultComboBoxModel (existingNames.toArray())); 53 pack(); 54 setBounds(frame.getX() + 50, frame.getY() + 50, getWidth(), getHeight()); 55 setVisible(true); 56 } 57 catch (Exception ex) 58 { 59 DjLogger.log(ex); 60 } 61 } 62 63 public boolean wasCancelled() 64 { 65 return _canceled; 66 } 67 68 private void jbInit() throws Exception 69 { 70 panel1.setLayout(borderLayout1); 71 jPanel1.setLayout(verticalFlowLayout1); 72 jPanel2.setLayout(_flowLayout1); 73 jPanel3.setLayout(borderLayout2); 74 _butOk.setText(Messages.getString("global.Ok")); _butOk.addActionListener(new DatabaseSelector__butOk_actionAdapter(this)); 76 _butCancel.setText(Messages.getString("global.Cancel")); _butCancel.addActionListener(new DatabaseSelector__butCancel_actionAdapter(this)); 78 _jLabel1.setText(Messages.getString("DatabaseSelector.DatabaseName")); _cbbDatabases.setPreferredSize(new Dimension (200, 19)); 80 _cbbDatabases.setEditable(true); 81 _butBrowse.setPreferredSize(new Dimension (19, 19)); 82 _butBrowse.setText("..."); 83 _butBrowse.addActionListener(new DatabaseSelector__butBrowse_actionAdapter(this)); 84 _flowLayout1.setAlignment(FlowLayout.LEFT); 85 _flowLayout1.setHgap(0); 86 getContentPane().add(panel1); 87 panel1.add(jPanel1, BorderLayout.WEST); 88 jPanel1.add(_jLabel1, null); 89 panel1.add(jPanel2, BorderLayout.CENTER); 90 panel1.add(jPanel3, BorderLayout.SOUTH); 91 jPanel3.add(jPanel4, BorderLayout.EAST); 92 jPanel4.add(_butCancel, null); 93 jPanel4.add(_butOk, null); 94 jPanel2.add(_cbbDatabases, null); 95 jPanel2.add(_butBrowse, null); 96 Util.sizeButtons(jPanel4); 97 98 } 99 100 void _butOk_actionPerformed(ActionEvent e) 101 { 102 String nm = _cbbDatabases.getEditor().getItem().toString(); 103 if (nm == null || nm.trim().length() == 0) return; 104 _selectedName = nm; 105 106 _canceled = false; 107 setVisible(false); 108 } 109 110 void _butCancel_actionPerformed(ActionEvent e) 111 { 112 setVisible(false); 113 114 } 115 116 public String getSelectedName() 117 { 118 return _selectedName; 119 } 120 121 public void _butBrowse_actionPerformed(ActionEvent e) 122 { 123 JFileChooser fc = new JFileChooser (); 124 125 DjFileFilter filter = new DjFileFilter(new String []{"script"}, "Hypersonic Database"); 126 fc.setFileFilter(filter); 127 128 fc.setDialogTitle(Messages.getString("MenuPanel.SelectDatabase")); 129 String path = System.getProperties().getProperty("user.dir"); 130 fc.setCurrentDirectory(new File (path)); 131 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 132 133 if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 134 { 135 String dbname = fc.getSelectedFile().getAbsolutePath(); 136 if (dbname.endsWith(".script")) 137 { 138 dbname = dbname.substring(0, dbname.length() - ".script".length()); 139 _cbbDatabases.getEditor().setItem(dbname); 140 } 141 } 142 } 143 } 144 145 class DatabaseSelector__butBrowse_actionAdapter implements ActionListener 146 { 147 private DatabaseSelector adaptee; 148 149 DatabaseSelector__butBrowse_actionAdapter(DatabaseSelector adaptee) 150 { 151 this.adaptee = adaptee; 152 } 153 154 public void actionPerformed(ActionEvent e) 155 { 156 adaptee._butBrowse_actionPerformed(e); 157 } 158 } 159 160 class DatabaseSelector__butOk_actionAdapter implements java.awt.event.ActionListener 161 { 162 DatabaseSelector adaptee; 163 164 DatabaseSelector__butOk_actionAdapter(DatabaseSelector adaptee) 165 { 166 this.adaptee = adaptee; 167 } 168 169 public void actionPerformed(ActionEvent e) 170 { 171 adaptee._butOk_actionPerformed(e); 172 } 173 } 174 175 class DatabaseSelector__butCancel_actionAdapter implements java.awt.event.ActionListener 176 { 177 DatabaseSelector adaptee; 178 179 DatabaseSelector__butCancel_actionAdapter(DatabaseSelector adaptee) 180 { 181 this.adaptee = adaptee; 182 } 183 184 public void actionPerformed(ActionEvent e) 185 { 186 adaptee._butCancel_actionPerformed(e); 187 } 188 } 189 | Popular Tags |