1 30 31 32 package org.hsqldb.util; 33 34 import java.sql.Connection ; 35 import java.awt.BorderLayout ; 36 import java.awt.Button ; 37 import java.awt.Choice ; 38 import java.awt.Dimension ; 39 import java.awt.Frame ; 40 import java.awt.GridLayout ; 41 import java.awt.Insets ; 42 import java.awt.Label ; 43 import java.awt.Panel ; 44 import java.awt.SystemColor ; 45 import java.awt.TextField ; 46 import java.awt.Toolkit ; 47 import java.awt.event.ActionEvent ; 48 import java.awt.event.ActionListener ; 49 import java.awt.event.ItemEvent ; 50 import java.awt.event.ItemListener ; 51 import java.awt.event.KeyEvent ; 52 import java.awt.event.KeyListener ; 53 import java.awt.event.WindowEvent ; 54 55 62 public class ZaurusConnectionDialog extends ConnectionDialog 63 implements ActionListener , ItemListener , KeyListener { 64 65 static final String [][] sJDBCTypes = { 66 { 67 "HSQL In-Memory", "org.hsqldb.jdbcDriver", "jdbc:hsqldb:." 68 }, { 69 "HSQL Standalone", "org.hsqldb.jdbcDriver", "jdbc:hsqldb:test" 70 }, { 71 "MM.MySQL", "org.gjt.mm.mysql.Driver", "jdbc:mysql://localhost/" 72 }, { 73 "JDBC-ODBC Brigde from Sun", "sun.jdbc.odbc.JdbcOdbcDriver", 74 "jdbc:odbc:test" 75 }, { 76 "Oracle", "oracle.jdbc.driver.OracleDriver", "jdbc:oracle:oci8:@" 77 }, { 78 "IBM DB2", "COM.ibm.db2.jdbc.app.DB2Driver", "jdbc:db2:test" 79 }, { 80 "Cloudscape RMI", "RmiJdbc.RJDriver", 81 "jdbc:rmi://localhost:1099/jdbc:cloudscape:test;create=true" 82 }, { 83 "InstantDb", "jdbc.idbDriver", "jdbc:idb:sample.prp" 84 }, 85 { 86 "PointBase", "com.pointbase.jdbc.jdbcUniversalDriver", 87 "jdbc:pointbase://localhost/sample" 88 }, }; 90 91 98 ZaurusConnectionDialog(Frame owner, String title) { 99 100 super(owner, title); 101 102 addKeyListener(this); 103 } 104 105 109 void create(Insets defInsets) { 110 111 setLayout(new BorderLayout ()); 112 addKeyListener(this); 113 114 Panel p = new Panel (new GridLayout (6, 2, 10, 10)); 115 116 p.addKeyListener(this); 117 p.setBackground(SystemColor.control); 118 p.add(createLabel("Type:")); 119 120 Choice types = new Choice (); 121 122 types.addItemListener(this); 123 types.addKeyListener(this); 124 125 for (int i = 0; i < sJDBCTypes.length; i++) { 126 types.add(sJDBCTypes[i][0]); 127 } 128 129 p.add(types); 130 p.add(createLabel("Driver:")); 131 132 mDriver = new TextField ("org.hsqldb.jdbcDriver"); 133 134 mDriver.addKeyListener(this); 135 p.add(mDriver); 136 p.add(createLabel("URL:")); 137 138 mURL = new TextField ("jdbc:hsqldb:."); 139 140 mURL.addKeyListener(this); 141 p.add(mURL); 142 p.add(createLabel("User:")); 143 144 mUser = new TextField ("sa"); 145 146 mUser.addKeyListener(this); 147 p.add(mUser); 148 p.add(createLabel("Password:")); 149 150 mPassword = new TextField (""); 151 152 mPassword.addKeyListener(this); 153 mPassword.setEchoChar('*'); 154 p.add(mPassword); 155 156 Button b; 157 158 b = new Button ("Cancel"); 159 160 b.setActionCommand("ConnectCancel"); 161 b.addActionListener(this); 162 b.addKeyListener(this); 163 p.add(b); 164 165 b = new Button ("Ok"); 166 167 b.setActionCommand("ConnectOk"); 168 b.addActionListener(this); 169 b.addKeyListener(this); 170 p.add(b); 171 setLayout(new BorderLayout ()); 172 add("East", createLabel(" ")); 173 add("West", createLabel(" ")); 174 175 mError = new Label (""); 176 177 Panel pMessage = createBorderPanel(mError); 178 179 pMessage.addKeyListener(this); 180 add("South", pMessage); 181 add("North", createLabel("")); 182 add("Center", p); 183 doLayout(); 184 pack(); 185 186 Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 187 Dimension size = getSize(); 188 189 if (d.width > 640) { 190 setLocation((d.width - size.width) / 2, 191 (d.height - size.height) / 2); 192 } else if (defInsets.top > 0 && defInsets.left > 0) { 193 setLocation(defInsets.bottom, defInsets.right); 194 setSize(defInsets.top, defInsets.left); 195 196 } else { 198 setLocation(0, 0); 199 setSize(d); 200 } 201 202 show(); 203 } 204 205 211 public void actionPerformed(ActionEvent ev) { 212 213 String s = ev.getActionCommand(); 214 215 if (s.equals("ConnectOk")) { 217 finishCreate(); 218 } else if (s.equals("ConnectCancel")) { 219 dispose(); 220 } 221 } 222 223 public void keyPressed(KeyEvent k) { 225 226 if (k.getKeyCode() == KeyEvent.VK_ENTER) { 228 finishCreate(); 229 } else if (k.getKeyCode() == KeyEvent.VK_ESCAPE) { 230 dispose(); 231 } 232 } 233 234 public void keyTyped(KeyEvent k) {} 235 236 public void keyReleased(KeyEvent k) {} 237 238 244 public void windowClosing(WindowEvent ev) { 245 246 } 248 249 254 protected void finishCreate() { 255 256 try { 257 mConnection = createConnection(mDriver.getText(), mURL.getText(), 258 mUser.getText(), 259 mPassword.getText()); 260 261 dispose(); 262 } catch (Exception e) { 263 e.printStackTrace(); 264 mError.setText(e.toString()); 265 } 266 } 267 268 277 public static Connection createConnection(Frame owner, String title, 278 Insets defInsets) { 279 280 ZaurusConnectionDialog dialog = new ZaurusConnectionDialog(owner, 281 title); 282 283 dialog.create(defInsets); 284 285 return dialog.mConnection; 286 } 287 288 294 public void itemStateChanged(ItemEvent e) { 295 296 String s = (String ) e.getItem(); 297 298 for (int i = 0; i < sJDBCTypes.length; i++) { 299 if (s.equals(sJDBCTypes[i][0])) { 300 mDriver.setText(sJDBCTypes[i][1]); 301 mURL.setText(sJDBCTypes[i][2]); 302 } 303 } 304 } 305 } 306 | Popular Tags |