annotate SMART/Java/Installer/Old/PasswordAsker.java @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 import java.awt.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 import java.awt.event.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 import javax.swing.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 import java.util.concurrent.CountDownLatch;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 public class PasswordAsker {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 static String password;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 static JFrame frame;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 static CountDownLatch latch;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 public PasswordAsker() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 password = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 javax.swing.SwingUtilities.invokeLater(new Runnable() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 public void run() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 createAndShowGUI();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 });
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 latch = new CountDownLatch(1);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 private static void createAndShowGUI() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 //Create and set up the window.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 frame = new JFrame("Password");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 frame.setContentPane(setMainPane());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 //Display the window.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 frame.pack();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 frame.setVisible(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 private static JPanel setMainPane() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 JPanel rootPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 rootPanel.setLayout(new GridLayout(0, 1));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 JPanel infoPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 JLabel infoLabel = new JLabel("Please write here the password that you entered for the mySQL root account.\r\nNo information is stored nor sent. I promise.");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 infoPanel.add(infoLabel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 JPanel passPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 passPanel.setLayout(new GridLayout(1, 0));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 JLabel passLabel = new JLabel("password");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 final JTextField passText = new JTextField(20);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 passLabel.setLabelFor(passText);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 passPanel.add(passLabel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 passPanel.add(passText);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 JPanel okPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 JButton okButton = new JButton("OK");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 okPanel.add(okButton);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 okButton.addActionListener(new ActionListener() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 public void actionPerformed(ActionEvent e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 password = passText.getText();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 frame.setVisible(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 frame.dispose();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 latch.countDown();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 });
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 rootPanel.add(infoPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 rootPanel.add(passPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 rootPanel.add(okPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 return rootPanel;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 public boolean waitForPassword() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 latch.await();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 catch (InterruptedException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 public String getPassword() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 return password;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 }