gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.api / src / main / java / org / gvsig / raster / swing / RasterSwingLibrary.java @ 2125
History | View | Annotate | Download (4.25 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.raster.swing; |
23 |
|
24 |
import java.awt.Component; |
25 |
import java.util.List; |
26 |
|
27 |
import javax.swing.JOptionPane; |
28 |
|
29 |
import org.gvsig.i18n.Messages; |
30 |
import org.gvsig.tools.library.AbstractLibrary; |
31 |
import org.gvsig.tools.library.LibraryException; |
32 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
33 |
import org.slf4j.LoggerFactory; |
34 |
|
35 |
/**
|
36 |
* Library for Swing API initialization and configuration.
|
37 |
*
|
38 |
* @author gvSIG team
|
39 |
* @version $Id$
|
40 |
*/
|
41 |
public class RasterSwingLibrary extends AbstractLibrary { |
42 |
|
43 |
@Override
|
44 |
protected void doInitialize() throws LibraryException { |
45 |
// Do nothing
|
46 |
} |
47 |
|
48 |
@Override
|
49 |
protected void doPostInitialize() throws LibraryException { |
50 |
// Validate there is any implementation registered.
|
51 |
RasterSwingManager manager = |
52 |
RasterSwingLocator.getSwingManager(); |
53 |
if (manager == null) { |
54 |
throw new ReferenceNotRegisteredException( |
55 |
RasterSwingLocator.SWING_MANAGER_NAME, |
56 |
RasterSwingLocator.getInstance()); |
57 |
} |
58 |
} |
59 |
|
60 |
public static boolean messageBoxYesOrNot(String msg, Object parentWindow){ |
61 |
String string1 = Messages.getText("yes"); |
62 |
String string2 = Messages.getText("no"); |
63 |
Object[] options = {string1, string2}; |
64 |
int n = JOptionPane.showOptionDialog((Component)parentWindow, |
65 |
"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>", |
66 |
Messages.getText("confirmacion"),
|
67 |
JOptionPane.YES_NO_OPTION,
|
68 |
JOptionPane.QUESTION_MESSAGE,
|
69 |
null,
|
70 |
options, |
71 |
string1); |
72 |
if (n == JOptionPane.YES_OPTION) |
73 |
return true; |
74 |
else
|
75 |
return false; |
76 |
} |
77 |
|
78 |
public static void messageBoxError(String msg, Object parentWindow) { |
79 |
String string = Messages.getText("accept"); |
80 |
Object[] options = {string}; |
81 |
JOptionPane.showOptionDialog((Component)parentWindow, |
82 |
"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>", |
83 |
Messages.getText("confirmacion"),
|
84 |
JOptionPane.OK_OPTION,
|
85 |
JOptionPane.ERROR_MESSAGE,
|
86 |
null,
|
87 |
options, |
88 |
string); |
89 |
} |
90 |
|
91 |
public static void messageBoxInfo(String msg, Object parentWindow) { |
92 |
String string = Messages.getText("accept"); |
93 |
Object[] options = {string}; |
94 |
JOptionPane.showOptionDialog((Component)parentWindow, |
95 |
"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>", |
96 |
Messages.getText("confirmacion"),
|
97 |
JOptionPane.OK_OPTION,
|
98 |
JOptionPane.INFORMATION_MESSAGE,
|
99 |
null,
|
100 |
options, |
101 |
string); |
102 |
} |
103 |
|
104 |
public static void debug(String msg, Object parent, Exception exception) { |
105 |
if(parent != null) |
106 |
LoggerFactory |
107 |
.getLogger(parent.getClass()).debug(Messages.getText(msg), exception); |
108 |
} |
109 |
|
110 |
public static void messageBoxError(String msg, Object parentWindow, Exception exception) { |
111 |
debug(msg, parentWindow, exception); |
112 |
messageBoxError(msg, parentWindow); |
113 |
} |
114 |
|
115 |
public static void messageBoxError(String msg, Object parentWindow, List<Exception> exception) { |
116 |
for (int i = 0; i < exception.size(); i++) |
117 |
debug(msg, parentWindow, exception.get(i)); |
118 |
messageBoxError(msg, parentWindow); |
119 |
} |
120 |
|
121 |
public static void messageBoxInfo(String msg, Object parentWindow, Exception exception) { |
122 |
debug(msg, parentWindow, exception); |
123 |
messageBoxInfo(msg, parentWindow); |
124 |
} |
125 |
|
126 |
public static boolean messageBoxYesOrNot(String msg, Object parentWindow, Exception exception) { |
127 |
debug(msg, parentWindow, exception); |
128 |
return messageBoxYesOrNot(msg, parentWindow);
|
129 |
} |
130 |
|
131 |
} |