Revision 41327
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
3 |
|
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.desktop.framework</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<name>${project.artifactId}</name> |
|
8 |
<parent> |
|
9 |
<groupId>org.gvsig</groupId> |
|
10 |
<artifactId>org.gvsig.desktop</artifactId> |
|
11 |
<version>2.0.32</version> |
|
12 |
</parent> |
|
13 |
|
|
14 |
<modules> |
|
15 |
<module>org.gvsig.andami</module> |
|
16 |
<module>org.gvsig.andami.updater</module> |
|
17 |
</modules> |
|
18 |
|
|
19 |
<description>Contains the launcher and plugin framework used in gvSIG.</description> |
|
20 |
</project> |
|
21 |
|
|
0 | 22 |
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/org.gvsig.andami/src/test/java/org/gvsig/andami/AllTests.java | ||
---|---|---|
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.andami; |
|
25 |
|
|
26 |
import junit.framework.Test; |
|
27 |
import junit.framework.TestSuite; |
|
28 |
|
|
29 |
public class AllTests { |
|
30 |
|
|
31 |
public static Test suite() { |
|
32 |
TestSuite suite = new TestSuite("Test for com.iver.andami"); |
|
33 |
//$JUnit-BEGIN$ |
|
34 |
|
|
35 |
//$JUnit-END$ |
|
36 |
return suite; |
|
37 |
} |
|
38 |
|
|
39 |
} |
|
0 | 40 |
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/org.gvsig.andami/src/main/assembly/gvsig-andami-package.xml | ||
---|---|---|
1 |
<!-- |
|
2 |
|
|
3 |
gvSIG. Desktop Geographic Information System. |
|
4 |
|
|
5 |
Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
|
8 |
modify it under the terms of the GNU General Public License |
|
9 |
as published by the Free Software Foundation; either version 3 |
|
10 |
of the License, or (at your option) any later version. |
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful, |
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
GNU General Public License for more details. |
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
|
18 |
along with this program; if not, write to the Free Software |
|
19 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
MA 02110-1301, USA. |
|
21 |
|
|
22 |
For any additional information, do not hesitate to contact us |
|
23 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
|
|
25 |
--> |
|
26 |
<assembly> |
|
27 |
<id>gvsig-andami-package</id> |
|
28 |
<formats> |
|
29 |
<format>zip</format> |
|
30 |
</formats> |
|
31 |
<baseDirectory>.</baseDirectory> |
|
32 |
<!-- |
|
33 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
34 |
--> |
|
35 |
<files> |
|
36 |
<file> |
|
37 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
38 |
<outputDirectory>lib</outputDirectory> |
|
39 |
</file> |
|
40 |
<file> |
|
41 |
<source>src/main/resources/default-log4j/log4j.properties</source> |
|
42 |
<outputDirectory>.</outputDirectory> |
|
43 |
</file> |
|
44 |
</files> |
|
45 |
<fileSets> |
|
46 |
<fileSet> |
|
47 |
<directory>src/main/resources-application</directory> |
|
48 |
<outputDirectory>.</outputDirectory> |
|
49 |
</fileSet> |
|
50 |
<fileSet> |
|
51 |
<directory>src/main/resources/org/gvsig/andami</directory> |
|
52 |
<outputDirectory>i18n/andami</outputDirectory> |
|
53 |
</fileSet> |
|
54 |
</fileSets> |
|
55 |
|
|
56 |
<dependencySets> |
|
57 |
<dependencySet> |
|
58 |
<useProjectArtifact>false</useProjectArtifact> |
|
59 |
<useTransitiveDependencies>true</useTransitiveDependencies> |
|
60 |
<outputDirectory>lib</outputDirectory> |
|
61 |
</dependencySet> |
|
62 |
</dependencySets> |
|
63 |
|
|
64 |
</assembly> |
|
65 |
|
|
0 | 66 |
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/preferences/IPreferenceExtension.java | ||
---|---|---|
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.andami.preferences; |
|
25 |
|
|
26 |
public interface IPreferenceExtension { |
|
27 |
public IPreference[] getPreferencesPages(); |
|
28 |
} |
|
0 | 29 |
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/preferences/GenericDlgPreferences.java | ||
---|---|---|
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.andami.preferences; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.Component; |
|
28 |
import java.awt.Dimension; |
|
29 |
import java.awt.FlowLayout; |
|
30 |
import java.awt.Font; |
|
31 |
import java.awt.event.ActionEvent; |
|
32 |
import java.awt.event.ActionListener; |
|
33 |
import java.util.ArrayList; |
|
34 |
import java.util.Enumeration; |
|
35 |
import java.util.Hashtable; |
|
36 |
import java.util.Iterator; |
|
37 |
import java.util.List; |
|
38 |
import java.util.Map; |
|
39 |
|
|
40 |
import javax.swing.JButton; |
|
41 |
import javax.swing.JLabel; |
|
42 |
import javax.swing.JOptionPane; |
|
43 |
import javax.swing.JPanel; |
|
44 |
import javax.swing.JScrollPane; |
|
45 |
import javax.swing.JSeparator; |
|
46 |
import javax.swing.JSplitPane; |
|
47 |
import javax.swing.JTree; |
|
48 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
49 |
import javax.swing.tree.DefaultTreeCellRenderer; |
|
50 |
import javax.swing.tree.DefaultTreeModel; |
|
51 |
import javax.swing.tree.TreeSelectionModel; |
|
52 |
|
|
53 |
import org.gvsig.andami.PluginServices; |
|
54 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
55 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
56 |
import org.gvsig.tools.ToolsLocator; |
|
57 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
58 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
|
59 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
60 |
import org.slf4j.Logger; |
|
61 |
import org.slf4j.LoggerFactory; |
|
62 |
|
|
63 |
|
|
64 |
/** |
|
65 |
* @author fjp |
|
66 |
* |
|
67 |
* The reason behind this class is to have the opportunity of use a DlgPreferences |
|
68 |
* in a local way. Then, you don't need to be a SingletonView. |
|
69 |
*/ |
|
70 |
public class GenericDlgPreferences extends JPanel implements IWindow { |
|
71 |
private static Logger logger = LoggerFactory.getLogger(GenericDlgPreferences.class); |
|
72 |
|
|
73 |
private static final long serialVersionUID = -6561660591523322611L; |
|
74 |
|
|
75 |
private WindowInfo viewInfo = null; |
|
76 |
private IPreference activePreference; |
|
77 |
|
|
78 |
private Map<String, IPreference> preferences = |
|
79 |
new Hashtable<String, IPreference>(); |
|
80 |
DefaultTreeModel treeModel = null; |
|
81 |
|
|
82 |
private JTree jTreePlugins = null; |
|
83 |
|
|
84 |
private JPanel jPanelButtons = null; |
|
85 |
|
|
86 |
private JButton jButtonOK = null; |
|
87 |
|
|
88 |
private JButton jButtonCancel = null; |
|
89 |
private DefaultMutableTreeNode root = new DefaultMutableTreeNode(); |
|
90 |
|
|
91 |
private JPanel jPanelCenter = null; |
|
92 |
|
|
93 |
private JLabel jLabelBigTitle = null; |
|
94 |
|
|
95 |
private JScrollPane jScrollPane = null; |
|
96 |
|
|
97 |
private JSplitPane jSplitPaneCenter = null; |
|
98 |
|
|
99 |
private JPanel jPanelContainer = null; |
|
100 |
private JButton jButtonRestore; |
|
101 |
private ActionListener action; |
|
102 |
private boolean dirtyTree = false; |
|
103 |
private ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager(); |
|
104 |
|
|
105 |
|
|
106 |
private class MyTreeCellRenderer extends DefaultTreeCellRenderer |
|
107 |
{ |
|
108 |
|
|
109 |
private static final long serialVersionUID = 1833782141342096776L; |
|
110 |
|
|
111 |
public MyTreeCellRenderer() { |
|
112 |
} |
|
113 |
|
|
114 |
public Component getTreeCellRendererComponent( |
|
115 |
JTree tree, |
|
116 |
Object value, |
|
117 |
boolean sel, |
|
118 |
boolean expanded, |
|
119 |
boolean leaf, |
|
120 |
int row, |
|
121 |
boolean hasFocus) { |
|
122 |
|
|
123 |
super.getTreeCellRendererComponent( |
|
124 |
tree, value, sel, |
|
125 |
expanded, leaf, row, |
|
126 |
hasFocus); |
|
127 |
if (value instanceof DefaultMutableTreeNode) |
|
128 |
{ |
|
129 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; |
|
130 |
if (node.getUserObject() instanceof IPreference) |
|
131 |
{ |
|
132 |
IPreference pref = (IPreference) node.getUserObject(); |
|
133 |
this.setText(pref.getTitle()); |
|
134 |
} |
|
135 |
} |
|
136 |
return this; |
|
137 |
} |
|
138 |
|
|
139 |
} |
|
140 |
|
|
141 |
|
|
142 |
public GenericDlgPreferences() { |
|
143 |
super(); |
|
144 |
this.action = new ActionListener() { |
|
145 |
public void actionPerformed(ActionEvent e) { |
|
146 |
PluginServices.getMDIManager().setWaitCursor(); |
|
147 |
String actionCommand = e.getActionCommand(); |
|
148 |
if ("RESTORE".equals(actionCommand)) { |
|
149 |
// Restore default values in current page |
|
150 |
if (activePreference!=null) { |
|
151 |
activePreference.initializeDefaults(); |
|
152 |
// bug 240 |
|
153 |
// try { |
|
154 |
// activePreference.saveValues(); |
|
155 |
// } catch (StoreException sEx) { |
|
156 |
// /* |
|
157 |
// * If you reach this code you coded your page |
|
158 |
// * with wrong factory default values. |
|
159 |
// * Check them out. |
|
160 |
// */ |
|
161 |
// PluginServices.getMDIManager().restoreCursor(); |
|
162 |
// |
|
163 |
// // Show error message |
|
164 |
// JOptionPane.showMessageDialog((Component) PluginServices. |
|
165 |
// getMainFrame(),sEx.getMessage()); |
|
166 |
// |
|
167 |
// } |
|
168 |
} |
|
169 |
} else { |
|
170 |
Iterator<String> it = preferences.keySet().iterator(); |
|
171 |
|
|
172 |
if ("CANCEL".equals(actionCommand)) { |
|
173 |
// Restore previous values in all pages |
|
174 |
while (it.hasNext()) { |
|
175 |
IPreference pref = preferences.get(it.next()); |
|
176 |
if (pref.isValueChanged()) { |
|
177 |
pref.initializeValues(); // |
|
178 |
} |
|
179 |
} |
|
180 |
closeView(); |
|
181 |
} else if ("OK".equals(actionCommand)) { |
|
182 |
// Apply values in all pages |
|
183 |
boolean shouldClose = true; |
|
184 |
while (it.hasNext()) { |
|
185 |
IPreference preference = |
|
186 |
preferences.get(it.next()); |
|
187 |
try{ |
|
188 |
if (preference.isValueChanged()) { |
|
189 |
preference.saveValues(); |
|
190 |
preference.initializeValues(); |
|
191 |
} |
|
192 |
}catch (StoreException ex) { |
|
193 |
// Reach this code should mean that the page has wrong values |
|
194 |
shouldClose = false; |
|
195 |
PluginServices.getMDIManager().restoreCursor(); |
|
196 |
|
|
197 |
// Show error message |
|
198 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),ex.getMessage()); |
|
199 |
|
|
200 |
// Focus on error page |
|
201 |
setActivePage(preference); |
|
202 |
} |
|
203 |
} |
|
204 |
if (shouldClose) { |
|
205 |
closeView(); |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
PluginServices.getMDIManager().restoreCursor(); |
|
210 |
} |
|
211 |
}; |
|
212 |
initialize(); |
|
213 |
} |
|
214 |
|
|
215 |
private void initialize() { |
|
216 |
setLayout(new BorderLayout()); |
|
217 |
setSize(new java.awt.Dimension(750,479)); |
|
218 |
super.add(getJPanelButtons(), BorderLayout.SOUTH); |
|
219 |
setPreferredSize(new java.awt.Dimension(390,369)); |
|
220 |
super.add(getJSplitPaneCenter(), java.awt.BorderLayout.CENTER); |
|
221 |
getJSplitPaneCenter().setLeftComponent(getJScrollPane()); |
|
222 |
getJSplitPaneCenter().setRightComponent(getJPanelNorth()); |
|
223 |
treeModel = new DefaultTreeModel(root); |
|
224 |
} |
|
225 |
|
|
226 |
public void refreshExtensionPoints() { |
|
227 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
|
228 |
|
|
229 |
|
|
230 |
@SuppressWarnings("unchecked") |
|
231 |
Iterator<ExtensionPoint.Extension> iterator = ep.iterator(); |
|
232 |
while (iterator.hasNext()) { |
|
233 |
String preferencesPageName = "Unkown"; |
|
234 |
try { |
|
235 |
Object obj = iterator.next(); |
|
236 |
if( obj != null ) { |
|
237 |
preferencesPageName = obj.getClass().getName(); |
|
238 |
} |
|
239 |
ExtensionPoint.Extension epe = (Extension) obj; |
|
240 |
if( epe!=null ) { |
|
241 |
preferencesPageName = epe.getName(); |
|
242 |
} |
|
243 |
IPreference page = (IPreference) (epe.create()); |
|
244 |
if( page != null ) { |
|
245 |
preferencesPageName = page.getID(); |
|
246 |
} |
|
247 |
this.addPreferencePage(page); |
|
248 |
} catch (Exception e) { |
|
249 |
logger.warn("Can't initialice preferences page '"+preferencesPageName+"'.", e); |
|
250 |
} |
|
251 |
} |
|
252 |
List<IPreference> prefList = new ArrayList<IPreference>(preferences.values()); |
|
253 |
addPreferencePages(prefList); |
|
254 |
} |
|
255 |
|
|
256 |
// TODO este m�todo es un parche provisional mientras se hace un refactoring de |
|
257 |
//las PreferencePages para disponer de un m�todo que inicialize las variables |
|
258 |
//a partir de las preferencias. |
|
259 |
public void storeValues() { |
|
260 |
Iterator<IPreference> iter = preferences.values().iterator(); |
|
261 |
|
|
262 |
while (iter.hasNext()) { |
|
263 |
IPreference preference = iter.next(); |
|
264 |
|
|
265 |
try { |
|
266 |
preference.saveValues(); |
|
267 |
} catch (StoreException e) { |
|
268 |
/* |
|
269 |
* If you reach this code you coded your page |
|
270 |
* with wrong factory default values. |
|
271 |
* Check them out. |
|
272 |
*/ |
|
273 |
PluginServices.getMDIManager().restoreCursor(); |
|
274 |
// Show error message |
|
275 |
JOptionPane.showMessageDialog( |
|
276 |
(Component) PluginServices.getMainFrame(), e.getMessage()); |
|
277 |
} |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* It is very common to be confused with this method. But |
|
283 |
* the one you are looking for is addPreferencePage(IPreference) |
|
284 |
*/ |
|
285 |
public Component add(Component c) { |
|
286 |
//throw new Error("Do not use com.iver.cit.gvsig.gui.preferences.DlgPreferences.add(Component) use com.iver.cit.gvsig.gui.preferences.DlgPreferences.addPreferencePage(IPreference) instead"); |
|
287 |
throw new Error("Do not use org.gvsig.app.gui.preferences.DlgPreferences.add(Component) register an extension point instead"); |
|
288 |
} |
|
289 |
|
|
290 |
public Component add(Component c, int i) { |
|
291 |
return add(c); |
|
292 |
} |
|
293 |
|
|
294 |
public void add(Component c, Object o) { |
|
295 |
add(c); |
|
296 |
} |
|
297 |
|
|
298 |
public void add(Component c, Object o, int i) { |
|
299 |
add(c); |
|
300 |
} |
|
301 |
|
|
302 |
public WindowInfo getWindowInfo() { |
|
303 |
if (viewInfo == null) { |
|
304 |
viewInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE | WindowInfo.PALETTE); |
|
305 |
viewInfo.setTitle(PluginServices.getText(this, |
|
306 |
"Preferences")); |
|
307 |
viewInfo.setWidth(this.getWidth()+8); |
|
308 |
viewInfo.setHeight(this.getHeight()); |
|
309 |
} |
|
310 |
return viewInfo; |
|
311 |
} |
|
312 |
|
|
313 |
/** |
|
314 |
* This method initializes jTreePlugins |
|
315 |
* |
|
316 |
* @return javax.swing.JTree |
|
317 |
*/ |
|
318 |
private JTree getJTreePlugins() { |
|
319 |
if (jTreePlugins == null) { |
|
320 |
jTreePlugins = new JTree(); |
|
321 |
jTreePlugins.setRootVisible(false); |
|
322 |
MyTreeCellRenderer treeCellRenderer = new MyTreeCellRenderer(); |
|
323 |
treeCellRenderer.setOpenIcon(null); |
|
324 |
treeCellRenderer.setClosedIcon(null); |
|
325 |
treeCellRenderer.setLeafIcon(null); |
|
326 |
|
|
327 |
jTreePlugins.setCellRenderer(treeCellRenderer); |
|
328 |
jTreePlugins.setShowsRootHandles(true); |
|
329 |
jTreePlugins |
|
330 |
.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { |
|
331 |
public void valueChanged(javax.swing.event.TreeSelectionEvent e) { |
|
332 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) |
|
333 |
jTreePlugins.getLastSelectedPathComponent(); |
|
334 |
|
|
335 |
if (node == null) { |
|
336 |
return; |
|
337 |
} |
|
338 |
setActivePage((IPreference) node.getUserObject()); |
|
339 |
} |
|
340 |
}); |
|
341 |
jTreePlugins.putClientProperty("JTree.linestyle", "Angled"); |
|
342 |
jTreePlugins.getSelectionModel(). |
|
343 |
setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); |
|
344 |
} |
|
345 |
|
|
346 |
return jTreePlugins; |
|
347 |
} |
|
348 |
|
|
349 |
/** |
|
350 |
* It takes an IPreference page and adds it to the application's preferences |
|
351 |
* dialog. The preference page is added in alphabetical order within the |
|
352 |
* branch where the page is hanging on, and defined by its title. |
|
353 |
* @param page |
|
354 |
*/ |
|
355 |
public void addPreferencePage(IPreference page) |
|
356 |
{ |
|
357 |
if (preferences.containsKey(page.getID())) { |
|
358 |
return; |
|
359 |
} |
|
360 |
preferences.put(page.getID(), page); |
|
361 |
page.initializeValues(); // init values from the last settings |
|
362 |
if (dirtyTree) { |
|
363 |
// rebuild page tree |
|
364 |
dirtyTree = false; |
|
365 |
|
|
366 |
DefaultTreeModel model = new DefaultTreeModel(root); |
|
367 |
treeModel = model; |
|
368 |
jTreePlugins.setModel(model); |
|
369 |
} |
|
370 |
|
|
371 |
doInsertNode(treeModel, page); |
|
372 |
getJTreePlugins().setModel(treeModel); |
|
373 |
getJTreePlugins().repaint(); |
|
374 |
} |
|
375 |
private void addPreferencePages(List<IPreference> prefs){ |
|
376 |
while (prefs.size()>0){ |
|
377 |
IPreference pref=prefs.get(0); |
|
378 |
// System.err.println("IPreference a persistir= "+pref.getID()); |
|
379 |
if (pref.getParentID()!=null && preferences.get(pref.getParentID())==null){ |
|
380 |
prefs.remove(pref); |
|
381 |
addPreferencePages(prefs); |
|
382 |
// System.err.println("IPreference = "+pref.getID()); |
|
383 |
addPreference(pref); |
|
384 |
}else{ |
|
385 |
// System.err.println("IPreference = "+pref.getID()); |
|
386 |
addPreference(pref); |
|
387 |
prefs.remove(pref); |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
391 |
private void addPreference(IPreference pref) { |
|
392 |
DefaultTreeModel model = new DefaultTreeModel(root); |
|
393 |
doInsertNode(model, pref); |
|
394 |
} |
|
395 |
|
|
396 |
private DefaultMutableTreeNode findNode(String searchID) |
|
397 |
{ |
|
398 |
@SuppressWarnings("unchecked") |
|
399 |
Enumeration<DefaultMutableTreeNode> e = root.breadthFirstEnumeration(); |
|
400 |
while (e.hasMoreElements()) |
|
401 |
{ |
|
402 |
DefaultMutableTreeNode nodeAux = e.nextElement(); |
|
403 |
if (nodeAux != null) |
|
404 |
{ |
|
405 |
IPreference pref = (IPreference) nodeAux.getUserObject(); |
|
406 |
if (pref == null) { |
|
407 |
continue; // Root node |
|
408 |
} |
|
409 |
if (pref.getID().equals(searchID)) |
|
410 |
{ |
|
411 |
return nodeAux; |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
415 |
return null; |
|
416 |
|
|
417 |
} |
|
418 |
|
|
419 |
private void doInsertNode(DefaultTreeModel treeModel, IPreference page) |
|
420 |
{ |
|
421 |
|
|
422 |
dirtyTree = ((page.getParentID() != null) && (findNode(page.getParentID())==null)); |
|
423 |
if (findNode(page.getID()) != null) { |
|
424 |
return; |
|
425 |
} |
|
426 |
if (page.getParentID() != null) |
|
427 |
{ |
|
428 |
if (preferences.containsKey(page.getParentID())) |
|
429 |
{ |
|
430 |
IPreference parent = (IPreference) preferences.get(page.getParentID()); |
|
431 |
DefaultMutableTreeNode nodeParent = findNode(parent.getID()); |
|
432 |
if (nodeParent == null) // the parent is empty |
|
433 |
{ |
|
434 |
// Recursively add it |
|
435 |
doInsertNode(treeModel, parent); |
|
436 |
} |
|
437 |
else |
|
438 |
{ |
|
439 |
DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(page); |
|
440 |
int children = nodeParent.getChildCount(); |
|
441 |
int pos=0; |
|
442 |
for (int i = 0; i < children; i++) { |
|
443 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeModel.getChild(nodeParent, i); |
|
444 |
if (node.getUserObject() instanceof IPreference) { |
|
445 |
String pageTitle = ((IPreference) node.getUserObject()).getTitle(); |
|
446 |
if (pageTitle.compareTo(page.getTitle()) < 0) { |
|
447 |
++pos; |
|
448 |
} |
|
449 |
} |
|
450 |
} |
|
451 |
treeModel.insertNodeInto(nodeValue, nodeParent, pos); |
|
452 |
} |
|
453 |
} |
|
454 |
} |
|
455 |
else // First level node ("General", "Edition") |
|
456 |
{ |
|
457 |
DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(page); |
|
458 |
int children = root.getChildCount(); |
|
459 |
int pos=0; |
|
460 |
for (int i = 0; i < children; i++) { |
|
461 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeModel.getChild(root, i); |
|
462 |
if (node.getUserObject() instanceof IPreference) { |
|
463 |
String pageTitle = ((IPreference) node.getUserObject()).getTitle(); |
|
464 |
if (pageTitle.compareTo(page.getTitle()) < 0) { |
|
465 |
++pos; |
|
466 |
} |
|
467 |
} |
|
468 |
} |
|
469 |
treeModel.insertNodeInto(nodeValue, root, pos); |
|
470 |
} |
|
471 |
} |
|
472 |
|
|
473 |
/** |
|
474 |
* This method initializes jPanelButtons |
|
475 |
* |
|
476 |
* @return javax.swing.JPanel |
|
477 |
*/ |
|
478 |
private JPanel getJPanelButtons() { |
|
479 |
if (jPanelButtons == null) { |
|
480 |
jPanelButtons = new JPanel(new BorderLayout()); |
|
481 |
JPanel jPanelAux = new JPanel(); |
|
482 |
JLabel l = new JLabel(); |
|
483 |
l.setPreferredSize(new Dimension(40, 20)); |
|
484 |
jPanelButtons.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.NORTH); |
|
485 |
jPanelAux.add(getJButtonRestore(), BorderLayout.WEST); |
|
486 |
jPanelAux.add(l, BorderLayout.CENTER); |
|
487 |
jPanelAux.add(getJButtonOK(), BorderLayout.EAST); |
|
488 |
jPanelAux.add(getJButtonCancel(), BorderLayout.EAST); |
|
489 |
|
|
490 |
jPanelButtons.add(jPanelAux); |
|
491 |
} |
|
492 |
return jPanelButtons; |
|
493 |
} |
|
494 |
|
|
495 |
/** |
|
496 |
* This method initializes jPanelButtons |
|
497 |
* |
|
498 |
* @return javax.swing.JPanel |
|
499 |
*/ |
|
500 |
|
|
501 |
|
|
502 |
/** |
|
503 |
* This method initializes jButtonOK |
|
504 |
* |
|
505 |
* @return JButton |
|
506 |
*/ |
|
507 |
private JButton getJButtonOK() { |
|
508 |
if (jButtonOK == null) { |
|
509 |
jButtonOK = new JButton(); |
|
510 |
jButtonOK.setText(PluginServices.getText(this, "aceptar")); |
|
511 |
jButtonOK.setActionCommand("OK"); |
|
512 |
jButtonOK.addActionListener(action); |
|
513 |
} |
|
514 |
return jButtonOK; |
|
515 |
} |
|
516 |
|
|
517 |
/** |
|
518 |
* This method initializes jButtonOK |
|
519 |
* |
|
520 |
* @return JButton |
|
521 |
*/ |
|
522 |
private JButton getJButtonRestore() { |
|
523 |
if (jButtonRestore == null) { |
|
524 |
jButtonRestore = new JButton(); |
|
525 |
jButtonRestore.setText(PluginServices.getText(this, "restore_defaults")); |
|
526 |
jButtonRestore.setActionCommand("RESTORE"); |
|
527 |
jButtonRestore.addActionListener(action); |
|
528 |
} |
|
529 |
return jButtonRestore; |
|
530 |
} |
|
531 |
|
|
532 |
private void closeView() { |
|
533 |
PluginServices.getMDIManager().closeWindow(this); |
|
534 |
} |
|
535 |
|
|
536 |
/** |
|
537 |
* This method initializes jButtonCancel |
|
538 |
* |
|
539 |
* @return JButton |
|
540 |
*/ |
|
541 |
private JButton getJButtonCancel() { |
|
542 |
if (jButtonCancel == null) { |
|
543 |
jButtonCancel = new JButton(); |
|
544 |
jButtonCancel.setText(PluginServices.getText(this, "cancelar")); |
|
545 |
jButtonCancel.setActionCommand("CANCEL"); |
|
546 |
jButtonCancel.addActionListener(action); |
|
547 |
} |
|
548 |
return jButtonCancel; |
|
549 |
} |
|
550 |
|
|
551 |
/** |
|
552 |
* This method initializes jPanelNorth |
|
553 |
* |
|
554 |
* @return javax.swing.JPanel |
|
555 |
*/ |
|
556 |
private JPanel getJPanelNorth() { |
|
557 |
if (jPanelCenter == null) { |
|
558 |
jLabelBigTitle = new JLabel(); |
|
559 |
jLabelBigTitle.setText("General"); |
|
560 |
Font font = jLabelBigTitle.getFont(); |
|
561 |
font = font.deriveFont(Font.BOLD, font.getSize() + 1.0f); |
|
562 |
jLabelBigTitle.setFont(font); |
|
563 |
jLabelBigTitle.setHorizontalTextPosition(javax.swing.SwingConstants.TRAILING); |
|
564 |
jLabelBigTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); |
|
565 |
jPanelCenter = new JPanel(); |
|
566 |
JPanel jPanelPageTitle = new JPanel(new BorderLayout()); |
|
567 |
JPanel jPanelAux = new JPanel(new BorderLayout()); |
|
568 |
jPanelAux.add(jLabelBigTitle, java.awt.BorderLayout.NORTH); |
|
569 |
jPanelPageTitle.add(jPanelAux, java.awt.BorderLayout.WEST); |
|
570 |
jPanelPageTitle.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH); |
|
571 |
jPanelCenter.setLayout(new BorderLayout()); |
|
572 |
jPanelCenter.add(jPanelPageTitle, BorderLayout.NORTH); |
|
573 |
jPanelCenter.add(getJPanelContainer(), java.awt.BorderLayout.CENTER); |
|
574 |
|
|
575 |
} |
|
576 |
return jPanelCenter; |
|
577 |
} |
|
578 |
|
|
579 |
/** |
|
580 |
* This method initializes jScrollPane |
|
581 |
* |
|
582 |
* @return javax.swing.JScrollPane |
|
583 |
*/ |
|
584 |
private JScrollPane getJScrollPane() { |
|
585 |
if (jScrollPane == null) { |
|
586 |
jScrollPane = new JScrollPane(); |
|
587 |
jScrollPane.setPreferredSize(new java.awt.Dimension(140,322)); |
|
588 |
jScrollPane.setViewportView(getJTreePlugins()); |
|
589 |
} |
|
590 |
return jScrollPane; |
|
591 |
} |
|
592 |
|
|
593 |
/** |
|
594 |
* This method initializes jSplitPaneCenter |
|
595 |
* |
|
596 |
* @return javax.swing.JSplitPane |
|
597 |
*/ |
|
598 |
private JSplitPane getJSplitPaneCenter() { |
|
599 |
if (jSplitPaneCenter == null) { |
|
600 |
jSplitPaneCenter = new JSplitPane(); |
|
601 |
jSplitPaneCenter.setResizeWeight(0.2); |
|
602 |
jSplitPaneCenter.setDividerLocation(200); |
|
603 |
} |
|
604 |
return jSplitPaneCenter; |
|
605 |
} |
|
606 |
|
|
607 |
/** |
|
608 |
* This method initializes jPanelContainer |
|
609 |
* |
|
610 |
* @return javax.swing.JPanel |
|
611 |
*/ |
|
612 |
private JPanel getJPanelContainer() { |
|
613 |
if (jPanelContainer == null) { |
|
614 |
jPanelContainer = new JPanel(); |
|
615 |
} |
|
616 |
return jPanelContainer; |
|
617 |
} |
|
618 |
|
|
619 |
/** |
|
620 |
* |
|
621 |
*/ |
|
622 |
public void setActivePage(IPreference page) { |
|
623 |
activePreference = page; |
|
624 |
jLabelBigTitle.setText(activePreference.getTitle()); |
|
625 |
JPanel prefPanel = activePreference.getPanel(); |
|
626 |
jLabelBigTitle.setIcon(activePreference.getIcon()); |
|
627 |
jPanelContainer.removeAll(); |
|
628 |
if ((prefPanel instanceof AbstractPreferencePage) && |
|
629 |
((AbstractPreferencePage) prefPanel).isResizeable()) { |
|
630 |
jPanelContainer.setLayout(new BorderLayout()); |
|
631 |
jPanelContainer.add(prefPanel, BorderLayout.CENTER); |
|
632 |
} else { |
|
633 |
jPanelContainer.setLayout(new FlowLayout()); |
|
634 |
jPanelContainer.add(prefPanel); |
|
635 |
} |
|
636 |
prefPanel.setVisible(true); |
|
637 |
repaint(); |
|
638 |
} |
|
639 |
|
|
640 |
public Object getWindowProfile() { |
|
641 |
return WindowInfo.DIALOG_PROFILE; |
|
642 |
} |
|
643 |
} |
|
0 | 644 |
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/preferences/IPreference.java | ||
---|---|---|
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.andami.preferences; |
|
25 |
|
|
26 |
import javax.swing.ImageIcon; |
|
27 |
import javax.swing.JPanel; |
|
28 |
|
|
29 |
import org.gvsig.tools.extensionpoint.ExtensionBuilder; |
|
30 |
/** |
|
31 |
* Interface that any entry in the application's preferences dialog must implement. |
|
32 |
* In addition to this interface, an abstract class is supplied to ease the addition |
|
33 |
* of new pages |
|
34 |
* @see org.gvsig.andami.preferences.AbstractPreferencePage |
|
35 |
* |
|
36 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
37 |
* |
|
38 |
*/ |
|
39 |
public interface IPreference extends ExtensionBuilder { |
|
40 |
|
|
41 |
/** |
|
42 |
* Returns an identifier for this preferences page that is used to reference |
|
43 |
* it inside the Map. |
|
44 |
* @return String, you'd typically use any kind of <code>this.getClass().getName();</code> |
|
45 |
*/ |
|
46 |
String getID(); |
|
47 |
|
|
48 |
/** |
|
49 |
* Returns an string containing the title of the preferences page. This string |
|
50 |
* will be shown whether in the tree entry or in the page header. |
|
51 |
* @return String, the title of the page |
|
52 |
*/ |
|
53 |
String getTitle(); |
|
54 |
|
|
55 |
/** |
|
56 |
* The page must be contained in a JPanel and whatever to be shown will be returned |
|
57 |
* by this function.<br> |
|
58 |
* <p> |
|
59 |
* The content is added, removed and repainted automatically upon the events received from |
|
60 |
* the mouse. So, you only have to care about the content and the functionality to make it |
|
61 |
* <br> |
|
62 |
* </p> |
|
63 |
* having sense. |
|
64 |
* @return JPanel holding the contents to be shown in the page. |
|
65 |
*/ |
|
66 |
JPanel getPanel(); |
|
67 |
|
|
68 |
/** |
|
69 |
* Returns the ID of the parent of this layer. If this method returns null, which means |
|
70 |
* that this preferences page has no parent, this is new entry in the preferences |
|
71 |
* tree, otherwise this preferences page will be hanging on the page with the ID |
|
72 |
* returned by this. |
|
73 |
* @return |
|
74 |
*/ |
|
75 |
String getParentID(); |
|
76 |
|
|
77 |
/** |
|
78 |
* Initializes the components of this preferences page to the last settings. |
|
79 |
*/ |
|
80 |
void initializeValues(); |
|
81 |
|
|
82 |
/** |
|
83 |
* Saves the new settings |
|
84 |
* @return <b>true</b> if the values were correctly stored, <b>false</b> otherwise. |
|
85 |
* @throws StoreException |
|
86 |
*/ |
|
87 |
void saveValues() throws StoreException; |
|
88 |
|
|
89 |
/** |
|
90 |
* Restores the default values of this preferences page's settings. Values are not |
|
91 |
* saved until saveValues() is executed |
|
92 |
*/ |
|
93 |
void initializeDefaults(); |
|
94 |
|
|
95 |
/** |
|
96 |
* Returns the image that will be shown in the header of this preferences page |
|
97 |
* @return |
|
98 |
*/ |
|
99 |
ImageIcon getIcon(); |
|
100 |
|
|
101 |
/** |
|
102 |
* Tells if this preference page has changed any value |
|
103 |
* (used for storing values when necessary) |
|
104 |
* @return <b>True</b> if any value has changed, <b>false</b> otherwise. |
|
105 |
*/ |
|
106 |
boolean isValueChanged(); |
|
107 |
|
|
108 |
} |
|
109 |
|
|
110 |
|
|
0 | 111 |
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/preferences/DlgPreferences.java | ||
---|---|---|
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.andami.preferences; |
|
25 |
|
|
26 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
27 |
|
|
28 |
public class DlgPreferences extends GenericDlgPreferences implements IWindow { |
|
29 |
private static DlgPreferences singletonInstance = null; |
|
30 |
|
|
31 |
public static DlgPreferences getInstance() { |
|
32 |
/* |
|
33 |
* if (singletonInstance == null) singletonInstance = new |
|
34 |
* DlgPreferences(); return singletonInstance; |
|
35 |
*/ |
|
36 |
return new DlgPreferences(); |
|
37 |
} |
|
38 |
|
|
39 |
DlgPreferences() { |
|
40 |
super(); |
|
41 |
} |
|
42 |
|
|
43 |
public Object getViewModel() { |
|
44 |
return this.getClass(); |
|
45 |
} |
|
46 |
|
|
47 |
} // @jve:decl-index=0:visual-constraint="10,10" |
|
0 | 48 |
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/preferences/StoreException.java | ||
---|---|---|
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.andami.preferences; |
|
25 |
|
|
26 |
public class StoreException extends Exception { |
|
27 |
|
|
28 |
public StoreException() { |
|
29 |
super(); |
|
30 |
// TODO Auto-generated constructor stub |
|
31 |
} |
|
32 |
|
|
33 |
public StoreException(String arg0, Throwable arg1) { |
|
34 |
super(arg0, arg1); |
|
35 |
// TODO Auto-generated constructor stub |
|
36 |
} |
|
37 |
|
|
38 |
public StoreException(String arg0) { |
|
39 |
super(arg0); |
|
40 |
// TODO Auto-generated constructor stub |
|
41 |
} |
|
42 |
|
|
43 |
public StoreException(Throwable arg0) { |
|
44 |
super(arg0); |
|
45 |
// TODO Auto-generated constructor stub |
|
46 |
} |
|
47 |
} |
|
0 | 48 |
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/preferences/AbstractPreferencePage.java | ||
---|---|---|
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.andami.preferences; |
|
25 |
|
|
26 |
import java.util.Map; |
|
27 |
|
|
28 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
|
29 |
import org.gvsig.tools.extensionpoint.ExtensionBuilder; |
|
30 |
/** |
|
31 |
* The abstract class that any preference page should extend. |
|
32 |
* |
|
33 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
34 |
* |
|
35 |
*/ |
|
36 |
public abstract class AbstractPreferencePage extends GridBagLayoutPanel implements IPreference, ExtensionBuilder{ |
|
37 |
/** |
|
38 |
* The number of components already added to the layout manager. |
|
39 |
*/ |
|
40 |
protected int y; |
|
41 |
|
|
42 |
private String title; |
|
43 |
|
|
44 |
protected String parentID = null; // Por defecto, nodo raiz |
|
45 |
|
|
46 |
|
|
47 |
public final void setParentID(String parentID) { |
|
48 |
this.parentID = parentID; |
|
49 |
} |
|
50 |
|
|
51 |
public String getParentID() { |
|
52 |
return parentID; |
|
53 |
} |
|
54 |
|
|
55 |
public final void setTitle(String title) { |
|
56 |
this.title = title; |
|
57 |
} |
|
58 |
|
|
59 |
public String toString() |
|
60 |
{ |
|
61 |
return getTitle(); |
|
62 |
} |
|
63 |
|
|
64 |
public Object create() { |
|
65 |
return this; |
|
66 |
} |
|
67 |
|
|
68 |
public Object create(Object[] args) { |
|
69 |
return this; |
|
70 |
} |
|
71 |
|
|
72 |
public Object create(Map args) { |
|
73 |
return this; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Devuelve true si el Panel debe estar en un BorderLayout centrado o false si |
|
78 |
* tiene un tama?o fijo. |
|
79 |
* @return |
|
80 |
*/ |
|
81 |
public boolean isResizeable() { |
|
82 |
return false; |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
public final void saveValues() throws StoreException { |
|
87 |
// Store the values. |
|
88 |
storeValues(); |
|
89 |
|
|
90 |
// Tell the page that its changes are already applied |
|
91 |
setChangesApplied(); |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* <p> |
|
96 |
* Gathers the configurations and stores them in the system.<br> |
|
97 |
* </p> |
|
98 |
* <p> |
|
99 |
* <b>storeValues()</b> and <b>setChangesApplied()</b> are methods from <b>AbstractPreferencePage</b> |
|
100 |
* not from <b>IPreference</b>. They both perform in combination what saveValue() should do |
|
101 |
* by itself, but they exist for performance issues. In fact, you <b>should not</b> |
|
102 |
* invoke them outside your PreferencePage class, you only need to code them. |
|
103 |
* </p> |
|
104 |
* @throws StoreException |
|
105 |
*/ |
|
106 |
public abstract void storeValues() throws StoreException; |
|
107 |
|
|
108 |
/** |
|
109 |
* <p> |
|
110 |
* After this method is invoked, the Preference page <b>must</b> return <b>true</b> as the |
|
111 |
* result of invoking isValueChanged() method. It tells that the values have been |
|
112 |
* saved in the system.<br> |
|
113 |
* </p> |
|
114 |
* <p> |
|
115 |
* <b>storeValues()</b> and <b>setChangesApplied()</b> are methods from <b>AbstractPreferencePage</b> |
|
116 |
* not from <b>IPreference</b>. They both perform in combination what storeValue() should |
|
117 |
* by itself, but they exist for performance issues. In fact, you <b>should not</b> |
|
118 |
* invoke them outside your PreferencePage class, you only need to code them. |
|
119 |
* </p> |
|
120 |
*/ |
|
121 |
public abstract void setChangesApplied(); |
|
122 |
} |
|
0 | 123 |
tags/org.gvsig.desktop-2.0.32/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/impl/DefaultPluginsManager.java | ||
---|---|---|
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.andami.impl; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.lang.reflect.InvocationTargetException; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Collections; |
|
30 |
import java.util.Enumeration; |
|
31 |
import java.util.Iterator; |
|
32 |
import java.util.List; |
|
33 |
import java.util.Locale; |
|
34 |
import java.util.logging.Level; |
|
35 |
import javax.swing.JComponent; |
|
36 |
|
|
37 |
import javax.swing.SwingUtilities; |
|
38 |
|
|
39 |
import org.gvsig.andami.Launcher; |
|
40 |
import org.gvsig.andami.PluginServices; |
|
41 |
import org.gvsig.andami.PluginsManager; |
|
42 |
import org.gvsig.andami.config.generate.AndamiConfig; |
|
43 |
import org.gvsig.andami.config.generate.Plugin; |
|
44 |
import org.gvsig.andami.plugins.ExclusiveUIExtension; |
|
45 |
import org.gvsig.andami.plugins.IExtension; |
|
46 |
import org.gvsig.andami.plugins.PluginClassLoader; |
|
47 |
import org.gvsig.installer.lib.api.PackageInfo; |
|
48 |
import org.gvsig.tools.ToolsLocator; |
|
49 |
import org.gvsig.tools.packageutils.PackageManager; |
|
50 |
import org.gvsig.andami.ui.mdiFrame.MDIFrame; |
|
51 |
import org.slf4j.Logger; |
|
52 |
import org.slf4j.LoggerFactory; |
|
53 |
|
|
54 |
public class DefaultPluginsManager implements PluginsManager { |
|
55 |
|
|
56 |
private class Task implements Comparable, Runnable { |
|
57 |
|
|
58 |
private String type = ""; |
|
59 |
private Runnable task = null; |
|
60 |
private boolean in_event_thread = false; |
|
61 |
private int priority = 0; |
|
62 |
private String name = null; |
|
63 |
|
|
64 |
public Task(String type, String name, Runnable task, boolean in_event_thread, int priority) { |
|
65 |
this.type = type; |
|
66 |
this.in_event_thread = in_event_thread; |
|
67 |
this.task = task; |
|
68 |
this.priority = priority; |
|
69 |
this.name = name; |
|
70 |
} |
|
71 |
|
|
72 |
public int compareTo(Object t) { |
|
73 |
return this.priority - ((Task) t).priority; |
|
74 |
} |
|
75 |
|
|
76 |
public boolean equals(Object t) { |
|
77 |
return this.compareTo(t) == 0; |
|
78 |
} |
|
79 |
|
|
80 |
public void run() { |
|
81 |
if ( this.in_event_thread ) { |
|
82 |
if ( !SwingUtilities.isEventDispatchThread() ) { |
|
83 |
try { |
|
84 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
85 |
public void run() { |
|
86 |
Task.this.run(); |
|
87 |
} |
|
88 |
}); |
|
89 |
} catch (InterruptedException ex) { |
|
90 |
// Do nothing |
|
91 |
} catch (Exception ex) { |
|
92 |
logger.warn("Errors in execution of " + type + " task '" + name + "'.", ex); |
|
93 |
|
|
94 |
} |
|
95 |
return; |
|
96 |
} |
|
97 |
} |
|
98 |
logger.info("Running " + type + " task '" + name + "' (priority " + priority + ")."); |
|
99 |
try { |
|
100 |
task.run(); |
|
101 |
logger.info("Terminated " + type + " task '" + name + "'."); |
|
102 |
} catch (Exception ex) { |
|
103 |
logger.warn("Errors in execution of " + type + " task '" + name + "'.", ex); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
private static Logger logger |
|
110 |
= LoggerFactory.getLogger(DefaultPluginsManager.class); |
|
111 |
|
|
112 |
private List<File> pluginsFolders = null; |
|
113 |
private List<Task> startupTasks = new ArrayList<Task>(); |
|
114 |
private List<Task> shutdownTasks = new ArrayList<Task>(); |
|
115 |
|
|
116 |
public ExclusiveUIExtension getExclusiveUIExtension() { |
|
117 |
return PluginServices.getExclusiveUIExtension(); |
|
118 |
} |
|
119 |
|
|
120 |
public IExtension getExtension(Class<? extends IExtension> extension) { |
|
121 |
return PluginServices.getExtension(extension); |
|
122 |
} |
|
123 |
|
|
124 |
@SuppressWarnings("unchecked") |
|
125 |
public Iterator<IExtension> getExtensions() { |
|
126 |
return PluginServices.getExtensions(); |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* Return the associated pluginServices to the extension class passed as |
|
131 |
* parameter. |
|
132 |
* |
|
133 |
*/ |
|
134 |
public PluginServices getPlugin(Class<? extends IExtension> extension) { |
|
135 |
String pluginName = ((PluginClassLoader) extension.getClassLoader()).getPluginName(); |
|
136 |
return this.getPlugin(pluginName); |
|
137 |
} |
|
138 |
|
|
139 |
public PluginServices getPlugin(Object obj) { |
|
140 |
if ( obj instanceof IExtension ) { |
|
141 |
Class<? extends IExtension> klass = (Class<? extends IExtension>) obj.getClass(); |
|
142 |
return this.getPlugin(klass); |
|
143 |
} |
|
144 |
PluginClassLoader loader = (PluginClassLoader) obj.getClass().getClassLoader(); |
|
145 |
String pluginName = loader.getPluginName(); |
|
146 |
return this.getPlugin(pluginName); |
|
147 |
} |
|
148 |
|
|
149 |
public PluginServices getPlugin(String pluginName) { |
|
150 |
return Launcher.getPluginServices(pluginName); |
|
151 |
} |
|
152 |
|
|
153 |
public PackageInfo getPackageInfo(Class<? extends IExtension> extension) { |
|
154 |
PackageManager pkgmgr = ToolsLocator.getPackageManager(); |
|
155 |
File pinfo_file = new File(this.getPlugin(extension).getPluginDirectory(), "package.info"); |
|
156 |
|
|
157 |
PackageInfo packageInfo = null; |
|
158 |
try { |
|
159 |
packageInfo = pkgmgr.createPackageInfo(pinfo_file); |
|
160 |
} catch (Exception e) { |
|
161 |
logger.info("Error while reading package info file from " |
|
162 |
+ pinfo_file.toString(), e); |
|
163 |
} |
|
164 |
return packageInfo; |
|
165 |
} |
|
166 |
|
|
167 |
public PackageInfo getPackageInfo(String pluginName) { |
|
168 |
PackageManager pkgmgr = ToolsLocator.getPackageManager(); |
|
169 |
File pinfo_file = new File(this.getPlugin(pluginName) |
|
170 |
.getPluginDirectory(), "package.info"); |
|
171 |
|
|
172 |
PackageInfo packageInfo = null; |
|
173 |
try { |
|
174 |
packageInfo = pkgmgr.createPackageInfo(pinfo_file); |
|
175 |
} catch (Exception e) { |
|
176 |
logger.info("Error while reading package info file from " |
|
177 |
+ pinfo_file.toString(), e); |
|
178 |
} |
|
179 |
return packageInfo; |
|
180 |
} |
|
181 |
|
|
182 |
public PackageInfo getPackageInfo() { |
|
183 |
PackageManager pkgmgr = ToolsLocator.getPackageManager(); |
|
184 |
File pinfo_file = new File( |
|
185 |
this.getApplicationFolder(), "package.info"); |
|
186 |
PackageInfo packageInfo = null; |
|
187 |
try { |
|
188 |
packageInfo = pkgmgr.createPackageInfo(pinfo_file); |
|
189 |
} catch (Exception e) { |
|
190 |
logger.info("Error while reading package info file from " |
|
191 |
+ pinfo_file.toString(), e); |
|
192 |
} |
|
193 |
return packageInfo; |
|
194 |
} |
|
195 |
|
|
196 |
@SuppressWarnings("unchecked") |
|
197 |
public List<PluginServices> getPlugins() { |
|
198 |
List<PluginServices> pluginServices = new ArrayList<PluginServices>(); |
|
199 |
|
|
200 |
AndamiConfig config = Launcher.getAndamiConfig(); |
|
201 |
Enumeration<Plugin> plugins = config.enumeratePlugin(); |
|
202 |
while ( plugins.hasMoreElements() ) { |
|
203 |
Plugin plugin = plugins.nextElement(); |
|
204 |
pluginServices.add(PluginServices.getPluginServices(plugin.getName())); |
|
205 |
} |
|
206 |
return pluginServices; |
|
207 |
} |
|
208 |
|
|
209 |
public void setExclusiveUIExtension(ExclusiveUIExtension extension) { |
|
210 |
PluginServices.setExclusiveUIExtension(extension); |
|
211 |
} |
|
212 |
|
|
213 |
public String getText(Object obj, String msg) { |
|
214 |
return PluginServices.getText(obj, msg); |
|
215 |
} |
|
216 |
|
|
217 |
public String translate(String msg) { |
|
218 |
return org.gvsig.i18n.Messages.translate(msg); |
|
219 |
} |
|
220 |
|
|
221 |
public File getApplicationFolder() { |
|
222 |
return Launcher.getApplicationFolder(); |
|
223 |
} |
|
224 |
|
|
225 |
/** |
|
226 |
* @deprecated use {@link #getPluginsFolders()} |
|
227 |
*/ |
|
228 |
public File getPluginsDirectory() { |
|
229 |
return getPluginsFolder(); |
|
230 |
} |
|
231 |
|
|
232 |
/** |
|
233 |
* @deprecated use {@link #getPluginsFolders()} |
|
234 |
*/ |
|
235 |
public File getPluginsFolder() { |
|
236 |
List<File> l = this.getPluginsFolders(); |
|
237 |
if ( l == null || l.size() < 1 ) { |
|
238 |
return null; |
|
239 |
} |
|
240 |
return l.get(0); |
|
241 |
} |
|
242 |
|
|
243 |
public List<File> getPluginsFolders() { |
|
244 |
if ( this.pluginsFolders != null ) { |
|
245 |
return this.pluginsFolders; |
|
246 |
} |
|
247 |
String folder = "gvSIG/extensiones"; |
|
248 |
if ( !(Launcher.getAndamiConfig() == null || Launcher.getAndamiConfig().getPluginsDirectory() == null) ) { |
|
249 |
folder = Launcher.getAndamiConfig().getPluginsDirectory(); |
|
250 |
} |
|
251 |
this.pluginsFolders = new ArrayList<File>(); |
|
252 |
this.pluginsFolders.add(new File(getApplicationFolder(), folder)); |
|
253 |
return this.pluginsFolders; |
|
254 |
} |
|
255 |
|
|
256 |
public File getInstallFolder() { |
|
257 |
return new File(getApplicationFolder(), "install"); |
|
258 |
} |
|
259 |
|
|
260 |
public File getApplicationHomeFolder() { |
|
261 |
return Launcher.getApplicationHomeFolder(); |
|
262 |
} |
|
263 |
|
|
264 |
public void addStartupTask(String name, Runnable task, boolean in_event_thread, int priority) { |
|
265 |
this.startupTasks.add(new Task("startup", name, task, in_event_thread, priority)); |
|
266 |
} |
|
267 |
|
|
268 |
public void addShutdownTask(String name, Runnable task, boolean in_event_thread, int priority) { |
|
269 |
this.shutdownTasks.add(new Task("shutdown", name, task, in_event_thread, priority)); |
|
270 |
} |
|
271 |
|
Also available in: Unified diff