gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.swing / org.gvsig.online.swing.impl / src / main / java / org / gvsig / online / swing / impl / loggin / LogginDialog.java @ 9515
History | View | Annotate | Download (5.16 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.online.swing.impl.loggin; |
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 |
private void translate() { |
66 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
67 |
swingManager.translate(this.lblUser);
|
68 |
swingManager.translate(this.lblPassword);
|
69 |
swingManager.translate(this.lblDescription, true); |
70 |
} |
71 |
|
72 |
private void initComponents() { |
73 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
74 |
|
75 |
this.translate();
|
76 |
|
77 |
toolsSwingManager.addClearButton(this.txtPassword);
|
78 |
toolsSwingManager.addClearButton(this.txtUser);
|
79 |
toolsSwingManager.setDefaultPopupMenu(this.txtPassword);
|
80 |
toolsSwingManager.setDefaultPopupMenu(this.txtUser);
|
81 |
|
82 |
ToolsSwingUtils.ensureRowsCols(this, 6, 55, 10, 70); |
83 |
} |
84 |
|
85 |
|
86 |
public boolean showDialog() { |
87 |
if( !SwingUtilities.isEventDispatchThread() ) { |
88 |
try {
|
89 |
SwingUtilities.invokeAndWait(() -> {
|
90 |
showDialog(); |
91 |
}); |
92 |
return false; |
93 |
} catch (Exception ex) { |
94 |
return false; |
95 |
} |
96 |
} |
97 |
|
98 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
99 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
100 |
Dialog dialog = windowManager.createDialog(
|
101 |
this,
|
102 |
i18n.getTranslation("_User_login"),
|
103 |
null,
|
104 |
WindowManager_v2.BUTTONS_OK_CANCEL |
105 |
); |
106 |
dialog.addActionListener((ActionEvent e) -> {
|
107 |
if( dialog.getAction()==WindowManager_v2.BUTTON_OK) {
|
108 |
this.userId = StringUtils.defaultIfBlank(this.txtUser.getText(), null); |
109 |
this.password = StringUtils.defaultIfBlank(String.valueOf(this.txtPassword.getPassword()), null); |
110 |
actionListenerSupport.fireActionEvent(e); |
111 |
} |
112 |
}); |
113 |
dialog.show(WindowManager.MODE.DIALOG); |
114 |
return dialog.getAction()==WindowManager_v2.BUTTON_OK;
|
115 |
} |
116 |
|
117 |
public String getUserId() { |
118 |
return this.userId; |
119 |
} |
120 |
|
121 |
public String getPassword() { |
122 |
return this.password; |
123 |
} |
124 |
|
125 |
@Override
|
126 |
public void addActionListener(ActionListener listener) { |
127 |
this.actionListenerSupport.addActionListener(listener);
|
128 |
} |
129 |
|
130 |
@Override
|
131 |
public ActionListener[] getActionListeners() { |
132 |
return this.actionListenerSupport.getActionListeners(); |
133 |
} |
134 |
|
135 |
@Override
|
136 |
public void removeActionListener(ActionListener listener) { |
137 |
this.actionListenerSupport.removeActionListener(listener);
|
138 |
} |
139 |
|
140 |
@Override
|
141 |
public void removeAllActionListener() { |
142 |
this.actionListenerSupport.removeAllActionListener();
|
143 |
} |
144 |
|
145 |
@Override
|
146 |
public void fireActionEvent(ActionEvent event) { |
147 |
this.actionListenerSupport.fireActionEvent(event);
|
148 |
} |
149 |
|
150 |
@Override
|
151 |
public boolean hasActionListeners() { |
152 |
return this.actionListenerSupport.hasActionListeners(); |
153 |
} |
154 |
|
155 |
} |