1 24 25 package org.objectweb.cjdbc.console.gui.frames; 26 27 import java.awt.Dimension ; 28 import java.awt.FlowLayout ; 29 import java.awt.Toolkit ; 30 import java.awt.event.ActionListener ; 31 32 import javax.swing.JButton ; 33 import javax.swing.JDialog ; 34 import javax.swing.JFrame ; 35 import javax.swing.JLabel ; 36 import javax.swing.JPasswordField ; 37 import javax.swing.JTextField ; 38 import javax.swing.WindowConstants ; 39 40 import org.objectweb.cjdbc.common.i18n.GuiTranslate; 41 import org.objectweb.cjdbc.console.gui.FrameConfirmKeyListener; 42 import org.objectweb.cjdbc.console.gui.constants.GuiCommands; 43 import org.objectweb.cjdbc.console.gui.session.GuiSession; 44 45 51 public class GuiVirtualDatabaseLoginFrame extends JDialog 52 { 53 private JPasswordField passwordBox; 54 private JTextField loginBox; 55 private ActionListener actionListener; 56 private String databaseName; 57 private String controllerHost; 58 private String controllerPort; 59 private JButton optionConfirm; 60 private FrameConfirmKeyListener keyListener; 61 62 72 public GuiVirtualDatabaseLoginFrame(JFrame parent, ActionListener listener, 73 String databaseName, String controllerHost, String controllerPort, 74 GuiSession session) 75 76 { 77 super(parent, GuiTranslate.get("frame.database.title", databaseName), true); 78 79 this.actionListener = listener; 80 this.controllerHost = controllerHost; 81 this.controllerPort = controllerPort; 82 Toolkit toolkit = Toolkit.getDefaultToolkit(); 83 Dimension dim = toolkit.getScreenSize(); 84 int screenHeight = dim.height; 85 int screenWidth = dim.width; 86 int frameWidth = 450; 87 int frameHeight = 80; 88 this.setBounds((screenWidth - frameWidth) / 2, 89 (screenHeight - frameHeight) / 2, frameWidth, frameHeight); 90 this.validate(); 91 this.setVisible(false); 92 this.setResizable(false); 93 this.getContentPane().setLayout(new FlowLayout ()); 94 this.databaseName = databaseName; 95 96 optionConfirm = new JButton (GuiTranslate.get("frame.database.approve")); 98 optionConfirm.setActionCommand(GuiCommands.COMMAND_DATABASE_AUTHENTICATE); 99 optionConfirm.addActionListener(actionListener); 100 101 keyListener = new FrameConfirmKeyListener(optionConfirm); 102 this.addKeyListener(keyListener); 103 104 Dimension buttonDim = new Dimension (80, 20); 105 106 this.getContentPane().add( 107 new JLabel (GuiTranslate.get("frame.database.login"))); 108 loginBox = new JTextField (0); 109 loginBox.setAlignmentX(CENTER_ALIGNMENT); 110 String login = session.getAuthenticatedDatabaseLogin(databaseName); 111 if (login != null) 112 loginBox.setText(login); 113 loginBox.setPreferredSize(buttonDim); 114 loginBox.addActionListener(actionListener); 115 loginBox.addKeyListener(keyListener); 116 this.getContentPane().add(loginBox); 117 118 this.getContentPane().add( 119 new JLabel (GuiTranslate.get("frame.database.password"))); 120 passwordBox = new JPasswordField (0); 121 passwordBox.setPreferredSize(buttonDim); 122 String pass = session.getAuthenticatedDatabasePassword(databaseName); 123 if (pass != null) 124 passwordBox.setText(pass); 125 passwordBox.setAlignmentX(CENTER_ALIGNMENT); 126 passwordBox.addKeyListener(keyListener); 127 passwordBox.addActionListener(actionListener); 128 this.getContentPane().add(passwordBox); 129 130 this.getContentPane().add(optionConfirm); 131 this.validate(); 132 setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); 133 } 134 135 140 public JTextField getLoginBox() 141 { 142 return loginBox; 143 } 144 145 150 public JTextField getPasswordBox() 151 { 152 return passwordBox; 153 } 154 155 160 public String getDatabaseName() 161 { 162 return databaseName; 163 } 164 165 170 public String getControllerHost() 171 { 172 return controllerHost; 173 } 174 175 180 public String getControllerPort() 181 { 182 return controllerPort; 183 } 184 } | Popular Tags |