| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package net.sf.webphotos.gui.util; |
| 17 | |
|
| 18 | |
import java.awt.Container; |
| 19 | |
import java.awt.Frame; |
| 20 | |
import java.awt.event.ActionEvent; |
| 21 | |
import java.awt.event.ActionListener; |
| 22 | |
import javax.swing.JButton; |
| 23 | |
import javax.swing.JDialog; |
| 24 | |
import javax.swing.JLabel; |
| 25 | |
import javax.swing.JOptionPane; |
| 26 | |
import javax.swing.JPasswordField; |
| 27 | |
import javax.swing.JTextField; |
| 28 | |
import net.sf.webphotos.util.Util; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 54 | public final class Login { |
| 35 | |
|
| 36 | 3 | private static final Login instanciaLogin = new Login(); |
| 37 | |
private String usuario; |
| 38 | |
private char[] senha; |
| 39 | 12 | private boolean cancelado = false; |
| 40 | |
|
| 41 | 12 | private JLabel lblNome = new JLabel("Nome:"); |
| 42 | 12 | private JTextField txtNome = new JTextField(8); |
| 43 | 12 | private JLabel lblSenha = new JLabel("Senha:"); |
| 44 | 12 | private JPasswordField txtSenha = new JPasswordField(8); |
| 45 | 12 | private JButton btOk = new JButton("Ok"); |
| 46 | 12 | private JButton btCancelar = new JButton("Cancelar"); |
| 47 | |
private static JDialog telaLogin; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | 0 | public Login(Object title) { |
| 56 | 0 | telaLogin.setTitle((String) title); |
| 57 | 0 | this.startLogin(); |
| 58 | 0 | } |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | 12 | public Login() { |
| 64 | 12 | this.startLogin(); |
| 65 | 12 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
public void startLogin() { |
| 74 | 12 | JDialog.setDefaultLookAndFeelDecorated(true); |
| 75 | 12 | telaLogin = new JDialog((Frame) null, "Identificação", true); |
| 76 | 12 | telaLogin.setResizable(false); |
| 77 | |
|
| 78 | |
|
| 79 | 12 | btOk.addActionListener(new ActionListener() { |
| 80 | |
@Override |
| 81 | |
public void actionPerformed(ActionEvent e) { |
| 82 | |
|
| 83 | 6 | if (txtNome.getText().length() == 0) { |
| 84 | 0 | return; |
| 85 | |
} |
| 86 | 6 | usuario = txtNome.getText(); |
| 87 | 6 | senha = txtSenha.getPassword(); |
| 88 | 6 | telaLogin.setVisible(false); |
| 89 | 6 | cancelado = false; |
| 90 | 6 | } |
| 91 | |
}); |
| 92 | |
|
| 93 | |
|
| 94 | 12 | btCancelar.addActionListener(new ActionListener() { |
| 95 | |
@Override |
| 96 | |
public void actionPerformed(ActionEvent e) { |
| 97 | 3 | usuario = null; |
| 98 | 3 | senha = null; |
| 99 | 3 | telaLogin.setVisible(false); |
| 100 | 3 | cancelado = true; |
| 101 | 3 | } |
| 102 | |
}); |
| 103 | |
|
| 104 | |
|
| 105 | 12 | telaLogin.setSize(200, 123); |
| 106 | 12 | Container cp = telaLogin.getContentPane(); |
| 107 | 12 | cp.setLayout(null); |
| 108 | |
|
| 109 | 12 | cp.add(lblNome); |
| 110 | 12 | cp.add(txtNome); |
| 111 | 12 | cp.add(lblSenha); |
| 112 | 12 | cp.add(txtSenha); |
| 113 | |
|
| 114 | 12 | cp.add(btCancelar); |
| 115 | 12 | cp.add(btOk); |
| 116 | |
|
| 117 | 12 | lblNome.setBounds(8, 8, 40, 20); |
| 118 | 12 | txtNome.setBounds(55, 8, 129, 20); |
| 119 | 12 | lblSenha.setBounds(8, 34, 40, 20); |
| 120 | 12 | txtSenha.setBounds(55, 34, 129, 20); |
| 121 | |
|
| 122 | 12 | btCancelar.setBounds(8, 60, 88, 25); |
| 123 | 12 | btOk.setBounds(104, 60, 80, 25); |
| 124 | |
|
| 125 | |
|
| 126 | 12 | telaLogin.getRootPane().setDefaultButton(btOk); |
| 127 | 12 | telaLogin.setLocationRelativeTo(null); |
| 128 | |
|
| 129 | 12 | } |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
public static Login getLogin(String titulo) { |
| 138 | 0 | telaLogin.setTitle(titulo); |
| 139 | 0 | return instanciaLogin; |
| 140 | |
} |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
public static Login getLogin() { |
| 148 | 0 | return instanciaLogin; |
| 149 | |
} |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
public boolean cancelado() { |
| 157 | 0 | return cancelado; |
| 158 | |
} |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
public String getUser() { |
| 166 | 9 | return usuario; |
| 167 | |
} |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
public char[] getPassword() { |
| 175 | 9 | return senha; |
| 176 | |
} |
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
public void show() { |
| 182 | 9 | show(""); |
| 183 | 9 | } |
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
public void show(String msgErro) { |
| 191 | 9 | if (msgErro != null && !msgErro.isEmpty()) { |
| 192 | 0 | JOptionPane.showMessageDialog(telaLogin, msgErro, "Erro", JOptionPane.ERROR_MESSAGE); |
| 193 | |
} |
| 194 | 9 | txtSenha.setText(""); |
| 195 | 9 | txtSenha.setCaretPosition(0); |
| 196 | |
|
| 197 | 9 | String tempLogin = Util.getConfig().getString("autoPreencher.Login"); |
| 198 | 9 | String tempSenha = Util.getConfig().getString("autoPreencher.Pass"); |
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | 9 | if (tempLogin.length() > 0 && !(txtNome.getText().length() > 0)) { |
| 204 | 9 | txtNome.setText(tempLogin); |
| 205 | |
} |
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | 9 | if (tempSenha.length() > 0 |
| 212 | |
&& txtNome.getText().equals(tempLogin)) { |
| 213 | |
|
| 214 | 9 | txtSenha.setText(tempSenha); |
| 215 | |
} |
| 216 | |
|
| 217 | 9 | usuario = null; |
| 218 | 9 | senha = null; |
| 219 | 9 | telaLogin.setVisible(true); |
| 220 | 9 | } |
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
public static JDialog getTelaLogin() { |
| 228 | 0 | return telaLogin; |
| 229 | |
} |
| 230 | |
} |