svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / ApplicationLibrary.java @ 44129
History | View | Annotate | Download (6.18 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.app; |
25 |
|
26 |
import java.io.File; |
27 |
import java.io.IOException; |
28 |
|
29 |
import javax.swing.JOptionPane; |
30 |
|
31 |
import org.apache.commons.io.FileUtils; |
32 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.andami.PluginsLocator; |
34 |
import org.gvsig.app.extension.InitializeApplicationExtension; |
35 |
import org.gvsig.app.gui.preferencespage.AppSymbolPreferences; |
36 |
import org.gvsig.app.project.DefaultProject; |
37 |
import org.gvsig.app.project.documents.view.expressionevaluator.SavedPointsElementFactory; |
38 |
import org.gvsig.app.project.documents.view.expressionevaluator.ViewElementFactory; |
39 |
import org.gvsig.app.project.symboltables.ProjectSymbolTableFactory; |
40 |
import org.gvsig.app.project.symboltables.functionPanels.area.AreaAditionalPanelFactory; |
41 |
import org.gvsig.app.project.symboltables.functionPanels.firstlayerfeature.FirstLayerFeatureAditionalPanelFactory; |
42 |
import org.gvsig.app.project.symboltables.functionPanels.perimeter.PerimeterAditionalPanelFactory; |
43 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary; |
44 |
import org.gvsig.fmap.mapcontext.MapContextLibrary; |
45 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
46 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
47 |
import org.gvsig.fmap.mapcontrol.MapControlLibrary; |
48 |
import org.gvsig.i18n.Messages; |
49 |
import org.gvsig.installer.lib.api.InstallerLibrary; |
50 |
import org.gvsig.tools.library.AbstractLibrary; |
51 |
import org.gvsig.tools.library.LibraryException; |
52 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
53 |
import org.slf4j.Logger; |
54 |
import org.slf4j.LoggerFactory; |
55 |
|
56 |
/**
|
57 |
* @author 2008-2009 jmvivo
|
58 |
* @author 2009- jjdelcerro
|
59 |
*
|
60 |
*/
|
61 |
public class ApplicationLibrary extends AbstractLibrary { |
62 |
|
63 |
private static final Logger logger = |
64 |
LoggerFactory.getLogger(ApplicationLibrary.class); |
65 |
|
66 |
@Override
|
67 |
public void doRegistration() { |
68 |
registerAsAPI(ApplicationLibrary.class); |
69 |
require(MapContextLibrary.class); |
70 |
require(MapControlLibrary.class); |
71 |
require(InstallerLibrary.class); |
72 |
require(ExpressionEvaluatorLibrary.class); |
73 |
} |
74 |
|
75 |
@Override
|
76 |
protected void doInitialize() throws LibraryException { |
77 |
// Do nothing
|
78 |
} |
79 |
|
80 |
@Override
|
81 |
protected void doPostInitialize() throws LibraryException { |
82 |
ApplicationManager manager = ApplicationLocator.getManager(); |
83 |
if (manager == null) { |
84 |
throw new ReferenceNotRegisteredException( |
85 |
ApplicationLocator.APPGVSIG_MANAGER_NAME, ApplicationLocator |
86 |
.getInstance()); |
87 |
} |
88 |
DefaultProject.registerPersistent(); |
89 |
|
90 |
MapContextManager mapContextManager = MapContextLocator.getMapContextManager(); |
91 |
|
92 |
PluginServices plugin = PluginsLocator.getManager().getPlugin(InitializeApplicationExtension.class); |
93 |
mapContextManager.setColorTableLibraryFolder(new File(plugin.getPluginHomeFolder(),"colortable")); |
94 |
|
95 |
MapContextLocator.getSymbolManager().setSymbolPreferences(new AppSymbolPreferences());
|
96 |
|
97 |
installBaseSymbols(); |
98 |
|
99 |
ProjectSymbolTableFactory.selfRegister(); |
100 |
AreaAditionalPanelFactory.selfRegister(); |
101 |
PerimeterAditionalPanelFactory.selfRegister(); |
102 |
FirstLayerFeatureAditionalPanelFactory.selfRegister(); |
103 |
ViewElementFactory.selfRegister(); |
104 |
SavedPointsElementFactory.selfRegister(); |
105 |
} |
106 |
|
107 |
/**
|
108 |
* Copy symbol folders from this plugin's 'Symbols' folder
|
109 |
* to user's 'Symbols' folder unless a folder with same name
|
110 |
* exists.
|
111 |
*/
|
112 |
private void installBaseSymbols() { |
113 |
PluginServices ps = PluginsLocator.getManager().getPlugin(InitializeApplicationExtension.class); |
114 |
File from_folder = new File( ps.getPluginDirectory(), "Symbols"); |
115 |
String to_folder = MapContextLocator.getSymbolManager().
|
116 |
getSymbolPreferences().getSymbolLibraryPath(); |
117 |
try {
|
118 |
copyMissingFolders(from_folder, new File(to_folder)); |
119 |
} catch (IOException ioe) { |
120 |
ApplicationLocator.getManager().message( |
121 |
Messages.getText("_Unable_to_copy_symbols_from_main_plugin"),
|
122 |
JOptionPane.ERROR_MESSAGE);
|
123 |
} |
124 |
|
125 |
} |
126 |
|
127 |
private void copyMissingFolders(File fromf, File tof) |
128 |
throws IOException { |
129 |
|
130 |
if (fromf == null || tof == null) { |
131 |
return;
|
132 |
} |
133 |
|
134 |
if (!fromf.exists() || !fromf.isDirectory() ||
|
135 |
(tof.exists() && tof.isFile())) { |
136 |
return;
|
137 |
} |
138 |
|
139 |
if (!tof.exists()) {
|
140 |
tof.mkdirs(); |
141 |
} |
142 |
|
143 |
File[] from_subs = fromf.listFiles(); |
144 |
for (int i=0; i<from_subs.length; i++) { |
145 |
if (!folderIsOneIn(from_subs[i], tof)) {
|
146 |
logger.info("Copying symbols subfolder: " + from_subs[i].getName());
|
147 |
FileUtils.copyDirectoryToDirectory(from_subs[i], tof); |
148 |
} else {
|
149 |
logger.info("Symbols subfolder already exists: " + from_subs[i].getName());
|
150 |
} |
151 |
} |
152 |
} |
153 |
|
154 |
|
155 |
/**
|
156 |
* Tells whether <folder> is a folder and <tofolder>
|
157 |
* has a file or subfolder with the same short name as
|
158 |
* <folder>
|
159 |
*
|
160 |
*/
|
161 |
private boolean folderIsOneIn(File folder, File tofolder) { |
162 |
|
163 |
if (!folder.isDirectory()) {
|
164 |
return false; |
165 |
} |
166 |
|
167 |
String name = folder.getName();
|
168 |
String tname = tofolder.getAbsolutePath() + File.separator + name; |
169 |
File tfile = new File(tname); |
170 |
return tfile.exists();
|
171 |
} |
172 |
|
173 |
|
174 |
} |