svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.downloader / org.gvsig.downloader.lib / org.gvsig.downloader.lib.impl / src / main / java / org / gvsig / downloader / lib / impl / types / httpbasic / LogginDialog.java @ 47821
History | View | Annotate | Download (5.23 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
* For any additional information, do not hesitate to contact us
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.downloader.lib.impl.types.httpbasic; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import javax.swing.SwingUtilities; |
28 |
import org.apache.commons.lang3.StringUtils; |
29 |
import org.gvsig.tools.ToolsLocator; |
30 |
import org.gvsig.tools.i18n.I18nManager; |
31 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
32 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
33 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
34 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
35 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
36 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
37 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
38 |
|
39 |
/**
|
40 |
*
|
41 |
* @author gvSIG Team
|
42 |
*/
|
43 |
@SuppressWarnings("UseSpecificCatch") |
44 |
public class LogginDialog |
45 |
extends LoginDialogView
|
46 |
implements ActionListenerSupport
|
47 |
{ |
48 |
|
49 |
@SuppressWarnings("FieldMayBeFinal") |
50 |
private String userId; |
51 |
@SuppressWarnings("FieldMayBeFinal") |
52 |
private String password; |
53 |
|
54 |
private final ActionListenerSupport actionListenerSupport; |
55 |
|
56 |
public LogginDialog(String userId, String password) { |
57 |
this.password = null; |
58 |
this.userId = null; |
59 |
this.actionListenerSupport = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
|
60 |
this.initComponents();
|
61 |
this.txtUser.setText(userId);
|
62 |
this.txtPassword.setText(password);
|
63 |
} |
64 |
|
65 |
public LogginDialog() {
|
66 |
this(null, null); |
67 |
} |
68 |
|
69 |
private void translate() { |
70 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
71 |
swingManager.translate(this.lblUser);
|
72 |
swingManager.translate(this.lblPassword);
|
73 |
swingManager.translate(this.lblDescription, true); |
74 |
} |
75 |
|
76 |
private void initComponents() { |
77 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
78 |
|
79 |
this.translate();
|
80 |
|
81 |
toolsSwingManager.addClearButton(this.txtPassword);
|
82 |
toolsSwingManager.addClearButton(this.txtUser);
|
83 |
toolsSwingManager.setDefaultPopupMenu(this.txtPassword);
|
84 |
toolsSwingManager.setDefaultPopupMenu(this.txtUser);
|
85 |
|
86 |
ToolsSwingUtils.ensureRowsCols(this, 6, 55, 10, 70); |
87 |
} |
88 |
|
89 |
|
90 |
public boolean showDialog() { |
91 |
if( !SwingUtilities.isEventDispatchThread() ) { |
92 |
try {
|
93 |
SwingUtilities.invokeAndWait(() -> {
|
94 |
showDialog(); |
95 |
}); |
96 |
return false; |
97 |
} catch (Exception ex) { |
98 |
return false; |
99 |
} |
100 |
} |
101 |
|
102 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
103 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
104 |
Dialog dialog = windowManager.createDialog(
|
105 |
this,
|
106 |
i18n.getTranslation("_User_login"),
|
107 |
null,
|
108 |
WindowManager_v2.BUTTONS_OK_CANCEL |
109 |
); |
110 |
dialog.addActionListener((ActionEvent e) -> {
|
111 |
if( dialog.getAction()==WindowManager_v2.BUTTON_OK) {
|
112 |
this.userId = StringUtils.defaultIfBlank(this.txtUser.getText(), null); |
113 |
this.password = StringUtils.defaultIfBlank(String.valueOf(this.txtPassword.getPassword()), null); |
114 |
actionListenerSupport.fireActionEvent(e); |
115 |
} |
116 |
}); |
117 |
dialog.show(WindowManager.MODE.DIALOG); |
118 |
return dialog.getAction()==WindowManager_v2.BUTTON_OK;
|
119 |
} |
120 |
|
121 |
public String getUserId() { |
122 |
return this.userId; |
123 |
} |
124 |
|
125 |
public String getPassword() { |
126 |
return this.password; |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public void addActionListener(ActionListener listener) { |
131 |
this.actionListenerSupport.addActionListener(listener);
|
132 |
} |
133 |
|
134 |
@Override
|
135 |
public ActionListener[] getActionListeners() { |
136 |
return this.actionListenerSupport.getActionListeners(); |
137 |
} |
138 |
|
139 |
@Override
|
140 |
public void removeActionListener(ActionListener listener) { |
141 |
this.actionListenerSupport.removeActionListener(listener);
|
142 |
} |
143 |
|
144 |
@Override
|
145 |
public void removeAllActionListener() { |
146 |
this.actionListenerSupport.removeAllActionListener();
|
147 |
} |
148 |
|
149 |
@Override
|
150 |
public void fireActionEvent(ActionEvent event) { |
151 |
this.actionListenerSupport.fireActionEvent(event);
|
152 |
} |
153 |
|
154 |
@Override
|
155 |
public boolean hasActionListeners() { |
156 |
return this.actionListenerSupport.hasActionListeners(); |
157 |
} |
158 |
|
159 |
} |