1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
| package ihm;
import dbCreator.*;
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import javax.swing.JProgressBar;
import java.awt.GridBagConstraints;
import javax.swing.JLabel;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import java.awt.FlowLayout;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.ComponentOrientation;
public class CDbCreatorFrame extends JFrame implements IAfficheur,ActionListener,Runnable {
private static final long serialVersionUID = 1L;
private JPanel pnlGeneral = null;
private JProgressBar ProgressDbCreation = null;
private JPanel pnlProgress = null;
private JLabel lblOperationProgress = null;
private JPanel pnlCmd = null;
private JPanel pnlConfiguration = null;
private JButton cmdQuitter = null;
private JButton cmdCreat = null;
private JPanel pnlLogin = null;
private JPanel pnlServeur = null;
private JLabel lblUser = null;
private JTextField txtUser = null;
private JLabel lblPassword = null;
private JTextField txtPassword = null;
private JLabel lblAdressServer = null;
private JTextField txtServerAdress = null;
private JLabel Port = null;
private JTextField txtPort = null;
private JLabel lblDataBaseName = null;
private JTextField txtDataBaseName = null;
private int iEtapes;
/**
* This is the default constructor
*/
public CDbCreatorFrame() {
super();
initialize();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(632, 225);
this.setComponentOrientation(ComponentOrientation.UNKNOWN);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setContentPane(getPnlGeneral());
this.setTitle("Data base creator");
}
/**
* This method initializes pnlGeneral
*
* @return javax.swing.JPanel
*/
private JPanel getPnlGeneral() {
if (pnlGeneral == null) {
pnlGeneral = new JPanel();
pnlGeneral.setLayout(new BorderLayout());
pnlGeneral.add(getPnlProgress(), BorderLayout.CENTER);
pnlGeneral.add(getPnlCmd(), BorderLayout.SOUTH);
pnlGeneral.add(getPnlConfiguration(), BorderLayout.NORTH);
}
return pnlGeneral;
}
public void progress()
{
if ( SwingUtilities.isEventDispatchThread () )
{
this.ProgressDbCreation.setValue (++iEtapes);
}
else
{
Runnable callMAJ = new Runnable ()
{
public void run ()
{
progress();
}
};
SwingUtilities.invokeLater (callMAJ);
}
}
public short initProgressBar(int iEtapesMax){
if (iEtapesMax < 0)
{
return -1;
}
this.ProgressDbCreation.setMinimum(0);
this.ProgressDbCreation.setMaximum(iEtapesMax);
this.iEtapes = 0;
return 0;
}
public short changeLabel(String strLabel){
if (strLabel == null)
{
return -1;
}
this.lblOperationProgress.setText(strLabel);
return 0;
}
private void lunchCreatDb()
{
CDbCreator db = new CDbCreator(this);
db.writeFileConf(this.txtUser.getText(), this.txtPassword.getText(), this.txtServerAdress.getText(), Integer.parseInt(this.txtPort.getText()), this.txtDataBaseName.getText());
db.creatdb();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == this.cmdCreat)
{
Thread t = new Thread(this);
t.start();
}
if(e.getSource() == this.cmdQuitter)
{
this.dispose();
}
}
public void run ()
{
this.lunchCreatDb();
}
/**
* This method initializes ProgressDbCreation
*
* @return javax.swing.JProgressBar
*/
private JProgressBar getProgressDbCreation() {
if (ProgressDbCreation == null) {
ProgressDbCreation = new JProgressBar();
ProgressDbCreation.setPreferredSize(new Dimension(600, 25));
}
return ProgressDbCreation;
}
/**
* This method initializes pnlProgress
*
* @return javax.swing.JPanel
*/
private JPanel getPnlProgress() {
if (pnlProgress == null) {
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 1;
gridBagConstraints1.gridy = 0;
lblOperationProgress = new JLabel();
lblOperationProgress.setText("");
lblOperationProgress.setPreferredSize(new Dimension(600, 20));
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridwidth = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridx = 0;
pnlProgress = new JPanel();
pnlProgress.setLayout(new GridBagLayout());
pnlProgress.add(getProgressDbCreation(), gridBagConstraints);
pnlProgress.add(lblOperationProgress, gridBagConstraints1);
}
return pnlProgress;
}
/**
* This method initializes pnlCmd
*
* @return javax.swing.JPanel
*/
private JPanel getPnlCmd() {
if (pnlCmd == null) {
pnlCmd = new JPanel();
pnlCmd.setLayout(new BorderLayout());
pnlCmd.add(getCmdQuitter(), BorderLayout.WEST);
pnlCmd.add(getCmdCreat(), BorderLayout.EAST);
}
return pnlCmd;
}
/**
* This method initializes pnlConfiguration
*
* @return javax.swing.JPanel
*/
private JPanel getPnlConfiguration() {
if (pnlConfiguration == null) {
pnlConfiguration = new JPanel();
pnlConfiguration.setLayout(new BorderLayout());
pnlConfiguration.add(getPnlLogin(), BorderLayout.WEST);
pnlConfiguration.add(getPnlServeur(), BorderLayout.CENTER);
}
return pnlConfiguration;
}
/**
* This method initializes cmdQuitter
*
* @return javax.swing.JButton
*/
private JButton getCmdQuitter() {
if (cmdQuitter == null) {
cmdQuitter = new JButton();
cmdQuitter.setHorizontalAlignment(SwingConstants.CENTER);
cmdQuitter.setText("Exit");
cmdQuitter.setPreferredSize(new Dimension(90, 20));
cmdQuitter.addActionListener(this);
}
return cmdQuitter;
}
/**
* This method initializes cmdCreat
*
* @return javax.swing.JButton
*/
private JButton getCmdCreat() {
if (cmdCreat == null) {
cmdCreat = new JButton();
cmdCreat.setPreferredSize(new Dimension(90, 20));
cmdCreat.setText("Create DB");
cmdCreat.addActionListener(this);
}
return cmdCreat;
}
/**
* This method initializes pnlLogin
*
* @return javax.swing.JPanel
*/
private JPanel getPnlLogin() {
if (pnlLogin == null) {
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.fill = GridBagConstraints.VERTICAL;
gridBagConstraints5.gridy = 1;
gridBagConstraints5.weightx = 1.0;
gridBagConstraints5.anchor = GridBagConstraints.WEST;
gridBagConstraints5.gridx = 1;
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.gridx = 0;
gridBagConstraints4.anchor = GridBagConstraints.WEST;
gridBagConstraints4.gridy = 1;
lblPassword = new JLabel();
lblPassword.setText(" Password :");
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.gridx = 0;
gridBagConstraints3.anchor = GridBagConstraints.WEST;
gridBagConstraints3.gridy = 0;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.fill = GridBagConstraints.VERTICAL;
gridBagConstraints2.gridy = 0;
gridBagConstraints2.weightx = 1.0;
gridBagConstraints2.anchor = GridBagConstraints.WEST;
gridBagConstraints2.gridx = 1;
lblUser = new JLabel();
lblUser.setText(" User Name :");
lblUser.setHorizontalAlignment(SwingConstants.LEFT);
lblUser.setHorizontalTextPosition(SwingConstants.LEFT);
lblUser.setVerticalTextPosition(SwingConstants.CENTER);
pnlLogin = new JPanel();
pnlLogin.setLayout(new GridBagLayout());
pnlLogin.setPreferredSize(new Dimension(250, 68));
pnlLogin.add(lblUser, gridBagConstraints3);
pnlLogin.add(getTxtUser(), gridBagConstraints2);
pnlLogin.add(lblPassword, gridBagConstraints4);
pnlLogin.add(getTxtPassword(), gridBagConstraints5);
}
return pnlLogin;
}
/**
* This method initializes pnlServeur
*
* @return javax.swing.JPanel
*/
private JPanel getPnlServeur() {
if (pnlServeur == null) {
GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
gridBagConstraints11.anchor = GridBagConstraints.WEST;
GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
gridBagConstraints10.fill = GridBagConstraints.VERTICAL;
gridBagConstraints10.gridy = 2;
gridBagConstraints10.weightx = 1.0;
gridBagConstraints10.anchor = GridBagConstraints.WEST;
gridBagConstraints10.gridx = 1;
GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
gridBagConstraints9.gridx = 0;
gridBagConstraints9.anchor = GridBagConstraints.WEST;
gridBagConstraints9.gridy = 2;
lblDataBaseName = new JLabel();
lblDataBaseName.setText("Data base name :");
GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
gridBagConstraints8.fill = GridBagConstraints.VERTICAL;
gridBagConstraints8.gridy = 1;
gridBagConstraints8.weightx = 1.0;
gridBagConstraints8.anchor = GridBagConstraints.WEST;
gridBagConstraints8.gridx = 1;
GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
gridBagConstraints7.gridx = 0;
gridBagConstraints7.anchor = GridBagConstraints.WEST;
gridBagConstraints7.gridy = 1;
Port = new JLabel();
Port.setText("Port :");
GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
gridBagConstraints6.fill = GridBagConstraints.VERTICAL;
gridBagConstraints6.gridy = 0;
gridBagConstraints6.weightx = 1.0;
gridBagConstraints6.anchor = GridBagConstraints.WEST;
gridBagConstraints6.gridx = 1;
lblAdressServer = new JLabel();
lblAdressServer.setText("Server adress :");
pnlServeur = new JPanel();
pnlServeur.setLayout(new GridBagLayout());
pnlServeur.add(lblAdressServer, gridBagConstraints11);
pnlServeur.add(getTxtServerAdress(), gridBagConstraints6);
pnlServeur.add(Port, gridBagConstraints7);
pnlServeur.add(getTxtPort(), gridBagConstraints8);
pnlServeur.add(lblDataBaseName, gridBagConstraints9);
pnlServeur.add(getTxtDataBaseName(), gridBagConstraints10);
}
return pnlServeur;
}
/**
* This method initializes txtUser
*
* @return javax.swing.JTextField
*/
private JTextField getTxtUser() {
if (txtUser == null) {
txtUser = new JTextField();
txtUser.setPreferredSize(new Dimension(160, 20));
}
return txtUser;
}
/**
* This method initializes txtPassword
*
* @return javax.swing.JTextField
*/
private JTextField getTxtPassword() {
if (txtPassword == null) {
txtPassword = new JTextField();
txtPassword.setPreferredSize(new Dimension(160, 20));
}
return txtPassword;
}
/**
* This method initializes txtServerAdress
*
* @return javax.swing.JTextField
*/
private JTextField getTxtServerAdress() {
if (txtServerAdress == null) {
txtServerAdress = new JTextField();
txtServerAdress.setPreferredSize(new Dimension(200, 20));
}
return txtServerAdress;
}
/**
* This method initializes txtPort
*
* @return javax.swing.JTextField
*/
private JTextField getTxtPort() {
if (txtPort == null) {
txtPort = new JTextField();
txtPort.setPreferredSize(new Dimension(60, 20));
}
return txtPort;
}
/**
* This method initializes txtDataBaseName
*
* @return javax.swing.JTextField
*/
private JTextField getTxtDataBaseName() {
if (txtDataBaseName == null) {
txtDataBaseName = new JTextField();
txtDataBaseName.setPreferredSize(new Dimension(200, 20));
}
return txtDataBaseName;
}
} // @jve:decl-index=0:visual-constraint="10,10" |
Partager