gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / NotificationDialogNew.java @ 682
History | View | Annotate | Download (10.2 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 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, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.coreplugin; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.FlowLayout; |
29 |
import java.awt.GridBagConstraints; |
30 |
import java.awt.GridBagLayout; |
31 |
import java.awt.LayoutManager; |
32 |
import java.awt.event.ActionEvent; |
33 |
import java.awt.event.ActionListener; |
34 |
|
35 |
import javax.swing.BorderFactory; |
36 |
import javax.swing.JButton; |
37 |
import javax.swing.JComponent; |
38 |
import javax.swing.JLabel; |
39 |
import javax.swing.JOptionPane; |
40 |
import javax.swing.JPanel; |
41 |
import javax.swing.JScrollPane; |
42 |
import javax.swing.JTextArea; |
43 |
import javax.swing.SwingUtilities; |
44 |
import javax.swing.border.Border; |
45 |
import javax.swing.border.TitledBorder; |
46 |
|
47 |
import org.gvsig.andami.IconThemeHelper; |
48 |
import org.gvsig.andami.PluginServices; |
49 |
import org.gvsig.andami.messages.MessageEvent; |
50 |
import org.gvsig.andami.messages.NotificationListener; |
51 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
52 |
import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
53 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
54 |
|
55 |
public class NotificationDialogNew extends JPanel implements IWindow, |
56 |
SingletonWindow, NotificationListener {
|
57 |
|
58 |
/**
|
59 |
*
|
60 |
*/
|
61 |
private static final long serialVersionUID = 4363640321917006480L; |
62 |
|
63 |
JPanelConsole console; |
64 |
JPanelButtons buttons; |
65 |
JPanelDescription description; |
66 |
|
67 |
public NotificationDialogNew() {
|
68 |
super();
|
69 |
this.setLayout(new GridBagLayout()); |
70 |
|
71 |
description = new JPanelDescription();
|
72 |
console = new JPanelConsole();
|
73 |
buttons = new JPanelButtons(console);
|
74 |
|
75 |
addComppnent(this, description, 0, 0, 3, 1, 1.0, 1.0, |
76 |
GridBagConstraints.BOTH, GridBagConstraints.CENTER); |
77 |
addComppnent(this, buttons, 0, 1, 3, 1, 0, 0, GridBagConstraints.NONE, |
78 |
GridBagConstraints.NORTHEAST);
|
79 |
addComppnent(this, console, 0, 2, 3, 1, 1.0, 2.0, |
80 |
GridBagConstraints.BOTH, GridBagConstraints.CENTER); |
81 |
this.setVisible(true); |
82 |
this.hideConsole();
|
83 |
} |
84 |
|
85 |
void addComppnent(JPanel panel, JComponent component, int gridx, int gridy, |
86 |
int width, int height, double weightx, double weighty, int fill, |
87 |
int anchor) {
|
88 |
GridBagConstraints constraints = new GridBagConstraints(); |
89 |
constraints.gridx = gridx; |
90 |
constraints.gridy = gridy; |
91 |
constraints.gridwidth = width; |
92 |
constraints.gridheight = height; |
93 |
constraints.weightx = weightx; // 1.0 se estira, 0 no.
|
94 |
constraints.weighty = weighty; // 1.0 se estira, 0 no.
|
95 |
constraints.fill = fill; |
96 |
constraints.anchor = anchor; |
97 |
constraints.ipadx = 2;
|
98 |
constraints.ipady = 2;
|
99 |
|
100 |
panel.add(component, constraints); |
101 |
component.setVisible(true);
|
102 |
} |
103 |
|
104 |
public void setDescription(String description) { |
105 |
this.description.setDescription(description);
|
106 |
} |
107 |
|
108 |
public void closeWindow() { |
109 |
PluginServices.getMDIManager().closeWindow(this);
|
110 |
} |
111 |
|
112 |
public void hideConsole() { |
113 |
this.buttons.hideConsole();
|
114 |
} |
115 |
|
116 |
public void showConsole() { |
117 |
this.buttons.showConsole();
|
118 |
} |
119 |
|
120 |
class JPanelDescription extends JPanel { |
121 |
/**
|
122 |
*
|
123 |
*/
|
124 |
private static final long serialVersionUID = 1529755877776747074L; |
125 |
JTextArea description = null; |
126 |
JLabel image;
|
127 |
|
128 |
JPanelDescription() { |
129 |
LayoutManager layout;
|
130 |
Border border;
|
131 |
|
132 |
layout = new GridBagLayout(); |
133 |
this.setLayout(layout);
|
134 |
|
135 |
// border = BorderFactory.createTitledBorder("Description");
|
136 |
border = BorderFactory.createEmptyBorder();
|
137 |
this.setBorder(border);
|
138 |
|
139 |
this.image = new JLabel(); |
140 |
this.image.setIcon(IconThemeHelper.getImageIcon("show-console") ); |
141 |
addComppnent(this, this.image, 0, 0, 1, 1, 0, 0, |
142 |
GridBagConstraints.NONE, GridBagConstraints.CENTER); |
143 |
|
144 |
this.description = new JTextArea(); |
145 |
this.description.setEditable(false); |
146 |
this.description.setOpaque(false); |
147 |
this.description.setText(""); |
148 |
JScrollPane scrollPanel = new JScrollPane(this.description); |
149 |
scrollPanel.setBorder(BorderFactory.createEmptyBorder());
|
150 |
scrollPanel.setPreferredSize(new Dimension(600, 200)); |
151 |
addComppnent(this, scrollPanel, 1, 0, 1, 1, 1, 1, |
152 |
GridBagConstraints.BOTH, GridBagConstraints.CENTER); |
153 |
} |
154 |
|
155 |
public String getDescription() { |
156 |
return this.description.getText(); |
157 |
} |
158 |
|
159 |
public void setDescription(String description) { |
160 |
this.description.setText(description);
|
161 |
} |
162 |
} |
163 |
|
164 |
class JPanelButtons extends JPanel { |
165 |
/**
|
166 |
*
|
167 |
*/
|
168 |
private static final long serialVersionUID = 1529755877776747074L; |
169 |
JButton close = null; |
170 |
JButton showDetails = null; |
171 |
JButton hideDetails = null; |
172 |
JPanel console = null; |
173 |
|
174 |
JPanelButtons(JPanel console) {
|
175 |
this.console = console;
|
176 |
this.setLayout(new FlowLayout()); |
177 |
this.close = getCloseButton();
|
178 |
this.showDetails = getShowDetailsButton();
|
179 |
this.hideDetails = getHideDetailsButton();
|
180 |
this.add(this.close); |
181 |
this.add(this.showDetails); |
182 |
this.add(this.hideDetails); |
183 |
hideConsole(); |
184 |
} |
185 |
|
186 |
private JButton getCloseButton() { |
187 |
JButton button = new JButton( |
188 |
PluginServices.getText(this, "aceptar")); |
189 |
button.addActionListener(new ActionListener() { |
190 |
public void actionPerformed(ActionEvent e) { |
191 |
closeWindow(); |
192 |
} |
193 |
}); |
194 |
return button;
|
195 |
} |
196 |
|
197 |
private JButton getShowDetailsButton() { |
198 |
JButton button = new JButton(PluginServices.getText(this, |
199 |
"detalles") + " >>>"); |
200 |
button.addActionListener(new ActionListener() { |
201 |
public void actionPerformed(ActionEvent e) { |
202 |
showConsole(); |
203 |
} |
204 |
}); |
205 |
return button;
|
206 |
} |
207 |
|
208 |
private JButton getHideDetailsButton() { |
209 |
JButton button = new JButton(PluginServices.getText(this, |
210 |
"detalles") + " <<<"); |
211 |
button.addActionListener(new ActionListener() { |
212 |
public void actionPerformed(ActionEvent e) { |
213 |
hideConsole(); |
214 |
} |
215 |
}); |
216 |
return button;
|
217 |
} |
218 |
|
219 |
public void hideConsole() { |
220 |
this.showDetails.setVisible(true); |
221 |
this.hideDetails.setVisible(false); |
222 |
this.console.setVisible(false); |
223 |
} |
224 |
|
225 |
public void showConsole() { |
226 |
this.showDetails.setVisible(false); |
227 |
this.hideDetails.setVisible(true); |
228 |
this.console.setVisible(true); |
229 |
} |
230 |
} |
231 |
|
232 |
class JPanelConsole extends JPanel { |
233 |
|
234 |
/**
|
235 |
*
|
236 |
*/
|
237 |
private static final long serialVersionUID = -6651900105647107644L; |
238 |
|
239 |
JPanelConsole() { |
240 |
BorderLayout layout = new BorderLayout(); |
241 |
this.setLayout(new BorderLayout()); |
242 |
TitledBorder border = BorderFactory.createTitledBorder("Console"); |
243 |
this.setBorder(border);
|
244 |
this.setLayout(layout);
|
245 |
this.add(Consola.consolaFrame, BorderLayout.CENTER); |
246 |
} |
247 |
} |
248 |
|
249 |
public Object getWindowModel() { |
250 |
return "notification-dialog"; |
251 |
} |
252 |
|
253 |
public WindowInfo getWindowInfo() {
|
254 |
WindowInfo info = new WindowInfo(WindowInfo.MODELESSDIALOG
|
255 |
| WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE); |
256 |
info.setTitle(PluginServices.getText(this, "Warning")); |
257 |
info.setHeight(this.getPreferredSize().height);
|
258 |
info.setWidth(this.getPreferredSize().width);
|
259 |
return info;
|
260 |
} |
261 |
|
262 |
public Object getWindowProfile() { |
263 |
return WindowInfo.PROPERTIES_PROFILE;
|
264 |
} |
265 |
|
266 |
public void errorEvent(MessageEvent e) { |
267 |
|
268 |
if (e.getMessages() != null) { |
269 |
for (int i = 0; i < e.getMessages().length; i++) { |
270 |
this.setDescription(e.getMessages()[i]);
|
271 |
} |
272 |
} |
273 |
|
274 |
if (!canShowWindow(e.getExceptions())) {
|
275 |
try {
|
276 |
PluginServices.getMainFrame().getStatusBar().message( |
277 |
this.description.getDescription(),
|
278 |
JOptionPane.ERROR_MESSAGE);
|
279 |
} catch(Throwable ex) { |
280 |
// Ignora cualquier error que se produzca intentando mostrar el mensaje de error y nos
|
281 |
// conformaremos con que este en el log.
|
282 |
} |
283 |
return;
|
284 |
} |
285 |
|
286 |
|
287 |
PluginServices.getMDIManager().restoreCursor(); |
288 |
if (SwingUtilities.isEventDispatchThread()) { |
289 |
PluginServices.getMDIManager().addCentredWindow(this);
|
290 |
} else {
|
291 |
final IWindow win = this; |
292 |
SwingUtilities.invokeLater(new Runnable() { |
293 |
public void run() { |
294 |
PluginServices.getMDIManager().addCentredWindow(win); |
295 |
} |
296 |
}); |
297 |
} |
298 |
} |
299 |
|
300 |
public void warningEvent(MessageEvent e) { |
301 |
|
302 |
if (e.getMessages() != null) { |
303 |
for (int i = 0; i < e.getMessages().length; i++) { |
304 |
this.setDescription(e.getMessages()[i]);
|
305 |
} |
306 |
} |
307 |
|
308 |
if (!canShowWindow(e.getExceptions())) {
|
309 |
try {
|
310 |
PluginServices.getMainFrame().getStatusBar().message( |
311 |
this.description.getDescription(),
|
312 |
JOptionPane.ERROR_MESSAGE);
|
313 |
} catch(Throwable ex) { |
314 |
// Ignora cualquier error que se produzca intentando mostrar el mensaje de error y nos
|
315 |
// conformaremos con que este en el log.
|
316 |
} |
317 |
return;
|
318 |
} |
319 |
|
320 |
PluginServices.getMDIManager().restoreCursor(); |
321 |
if (SwingUtilities.isEventDispatchThread()) { |
322 |
PluginServices.getMDIManager().addCentredWindow(this);
|
323 |
} else {
|
324 |
final IWindow win = this; |
325 |
SwingUtilities.invokeLater(new Runnable() { |
326 |
public void run() { |
327 |
PluginServices.getMDIManager().addCentredWindow(win); |
328 |
} |
329 |
}); |
330 |
} |
331 |
} |
332 |
|
333 |
public void infoEvent(MessageEvent e) { |
334 |
// Do nothing, ignore info events
|
335 |
} |
336 |
|
337 |
|
338 |
private boolean canShowWindow(Throwable[] ths) { |
339 |
|
340 |
if (ths == null) { |
341 |
return true; |
342 |
} |
343 |
try {
|
344 |
for (int n=0; n<ths.length; n++) { |
345 |
StackTraceElement[] stack_ee = ths[n].getStackTrace(); |
346 |
for (int i=0; i<stack_ee.length; i++) { |
347 |
StackTraceElement se = stack_ee[i];
|
348 |
if (se.getClassName().startsWith("org.gvsig.fmap.mapcontrol.MapControl")) { |
349 |
return false; |
350 |
} |
351 |
} |
352 |
} |
353 |
} catch (Throwable t) { |
354 |
|
355 |
} |
356 |
return true; |
357 |
|
358 |
} |
359 |
|
360 |
} |