1 package ch
.cyberduck
.ui
;
4 * ch.cyberduck.ui.LoginPanel.java
11 * Copyright (c) 2003 David Kocher. All rights reserved.
12 * http://icu.unizh.ch/~dkocher/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * Bug fixes, suggestions and comments should be sent to:
25 * dkocher@cyberduck.ch
29 import java
.awt
.BorderLayout
;
30 import java
.awt
.FlowLayout
;
31 import java
.awt
.event
.ActionEvent
;
32 import java
.awt
.event
.ActionListener
;
33 import java
.awt
.event
.ItemEvent
;
34 import java
.awt
.event
.ItemListener
;
35 import java
.util
.Observable
;
36 import java
.util
.Observer
;
38 import ch
.cyberduck
.Cyberduck
;
39 import ch
.cyberduck
.Preferences
;
40 import ch
.cyberduck
.connection
.Bookmark
;
41 import ch
.cyberduck
.connection
.Status
;
42 import ch
.cyberduck
.ui
.common
.DummyVerifier
;
43 import ch
.cyberduck
.ui
.common
.GUIFactory
;
44 import ch
.cyberduck
.ui
.layout
.ParagraphLayout
;
49 public class LoginPanel
extends JPanel
implements Observer
{
51 // The currently selected bookmark
52 private Bookmark selected
;
54 private JTextField nameField
;
55 private JPasswordField passwdField
;
56 private JButton loginButton
;
57 private JButton cancelButton
;
58 private JCheckBox anonymousCheckbox
;
59 private JPanel parameterPanel
;
62 Cyberduck
.DEBUG("[LoginPanel]");
66 public void update(Observable o
, Object arg
) {
67 if(o
instanceof Bookmark
) {
68 if(arg
.equals(Bookmark
.SELECTION
)) {
69 this.selected
= (Bookmark
)o
;
72 if(arg
.equals(Status
.LOGINPANEL
)) {
73 this.setBorder(BorderFactory
.createTitledBorder(BorderFactory
.createEtchedBorder(javax
.swing
.border
.EtchedBorder
.LOWERED
), "Login to " + selected
.getHost()));
74 nameField
.setText(Preferences
.instance().getProperty("ftp.login.name"));
75 nameField
.requestFocus();
76 passwdField
.setText("");
77 anonymousCheckbox
.setSelected(false);
82 public JButton
getDefaultButton() {
83 return this.loginButton
;
86 private class ParameterPanel
extends JPanel
{
87 public ParameterPanel() {
89 this.setLayout(new ParagraphLayout());
92 this.add(GUIFactory
.labelBuilder("User ID: ", GUIFactory
.FONT_SMALL
), ParagraphLayout
.NEW_PARAGRAPH
);
93 this.add(nameField
= GUIFactory
.textFieldBuilder(GUIFactory
.FONT_SMALL
, new DummyVerifier()));
94 nameField
.setColumns(30);
96 this.add(GUIFactory
.labelBuilder("Password: ", GUIFactory
.FONT_SMALL
), ParagraphLayout
.NEW_PARAGRAPH
);
97 this.add(passwdField
= GUIFactory
.passwordFieldBuilder(GUIFactory
.FONT_SMALL
, new DummyVerifier()));
98 passwdField
.setColumns(30);
99 this.add(anonymousCheckbox
= GUIFactory
.checkboxBuilder("Anonymous Login", GUIFactory
.FONT_SMALL
, false), ParagraphLayout
.NEW_LINE
);
100 anonymousCheckbox
.addItemListener(new ItemListener() {
101 public void itemStateChanged(ItemEvent e
) {
102 if(e
.getStateChange() == ItemEvent
.SELECTED
) {
103 nameField
.setText(Preferences
.instance().getProperty("ftp.login.anonymous.name"));
104 passwdField
.setText(Preferences
.instance().getProperty("ftp.login.anonymous.pass"));
107 nameField
.setText("");
108 passwdField
.setText("");
115 private class ButtonPanel
extends JPanel
{
116 public ButtonPanel() {
118 this.setLayout(new FlowLayout(FlowLayout
.RIGHT
));
119 this.add(cancelButton
= GUIFactory
.buttonBuilder("Cancel", GUIFactory
.FONT_SMALL
));
120 cancelButton
.addActionListener(new ActionListener() {
121 public void actionPerformed(ActionEvent e
) {
122 selected
.status
.setPanelProperty(selected
.status
.getLastPanelProperty());
125 this.add(loginButton
= GUIFactory
.buttonBuilder("Login", GUIFactory
.FONT_SMALL
));
126 loginButton
.setDefaultCapable(true);
127 loginButton
.addActionListener(new ActionListener() {
128 public void actionPerformed(ActionEvent ae
) {
129 selected
.setUserInfo(nameField
.getText()+":"+new String(passwdField
.getPassword()));
131 //((Action)ActionMap.instance().get("Connect")).actionPerformed(new ActionEvent(selected, ae.getID(), ae.getActionCommand()));
138 * Initialize the graphical user interface
140 private void init() {
141 this.setLayout(new BorderLayout());
142 this.add(new ParameterPanel(), BorderLayout
.CENTER
);
143 this.add(new ButtonPanel(), BorderLayout
.SOUTH
);