Revision 402 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/LayoutMainExtension.java
LayoutMainExtension.java | ||
---|---|---|
104 | 104 |
|
105 | 105 |
/** |
106 | 106 |
* Extension que proporciona controles para crear proyectos nuevos, abrirlos y |
107 |
* guardarlos. Adem?s los tipos de tabla que soporta el proyecto son a?adidos |
|
108 |
* en esta clase.
|
|
107 |
* guardarlos. Adem?s los tipos de tabla que soporta el proyecto son a?adidos en
|
|
108 |
* esta clase. |
|
109 | 109 |
* |
110 | 110 |
* @author Fernando Gonz?lez Cort?s |
111 | 111 |
*/ |
112 | 112 |
public class LayoutMainExtension extends Extension { |
113 |
|
|
113 | 114 |
private static final Logger logger = LoggerFactory |
114 | 115 |
.getLogger(FFrameView.class); |
116 |
|
|
115 | 117 |
private String templatesPath; |
116 |
public static final String LAYOUT_TEMPLATE_FILECHOOSER_ID = |
|
117 |
"LAYOUT_TEMPLATE_FILECHOOSER_ID"; |
|
118 | 118 |
|
119 |
public static final String LAYOUT_TEMPLATE_FILECHOOSER_ID = "LAYOUT_TEMPLATE_FILECHOOSER_ID"; |
|
120 |
|
|
119 | 121 |
private void registerIcons() { |
120 |
|
|
122 |
|
|
121 | 123 |
IconThemeHelper.registerIcon("action", |
122 |
"application-layout-template-open", this); |
|
124 |
"application-layout-template-open", this);
|
|
123 | 125 |
} |
124 | 126 |
|
125 | 127 |
public void initialize() { |
... | ... | |
151 | 153 |
templatesPath = prefs.get("TemplatesFolder", null); |
152 | 154 |
} |
153 | 155 |
|
154 |
JFileChooser jfc = |
|
155 |
new JFileChooser(LAYOUT_TEMPLATE_FILECHOOSER_ID, templatesPath); |
|
156 |
jfc.addChoosableFileFilter(new GenericFileFilter( |
|
157 |
LayoutManager.TEMPLATE_FILE_POINTEXT, |
|
158 |
Messages.getText("_Layout_template") + " (*" |
|
159 |
+ LayoutManager.TEMPLATE_FILE_POINTEXT + ")" |
|
160 |
)); |
|
156 |
JFileChooser jfc = new JFileChooser(LAYOUT_TEMPLATE_FILECHOOSER_ID, |
|
157 |
templatesPath); |
|
158 |
GenericFileFilter layoutMainExtensionFilter = new GenericFileFilter( |
|
159 |
LayoutManager.TEMPLATE_FILE_POINTEXT, |
|
160 |
Messages.getText("_Layout_template") + " (*" |
|
161 |
+ LayoutManager.TEMPLATE_FILE_POINTEXT + ")"); |
|
162 |
jfc.addChoosableFileFilter(layoutMainExtensionFilter); |
|
163 |
jfc.setFileFilter(layoutMainExtensionFilter); |
|
161 | 164 |
|
162 | 165 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
163 | 166 |
File file = jfc.getSelectedFile(); |
164 | 167 |
try { |
165 | 168 |
if (!file.exists()) { |
166 | 169 |
/* |
167 |
* The user has written a file name instead of clicking on one
|
|
168 |
* and it does not exist |
|
170 |
* The user has written a file name instead of clicking on |
|
171 |
* one and it does not exist
|
|
169 | 172 |
*/ |
170 |
File auxfile = new File(file.getPath() + LayoutManager.TEMPLATE_FILE_POINTEXT); |
|
173 |
File auxfile = new File(file.getPath() |
|
174 |
+ LayoutManager.TEMPLATE_FILE_POINTEXT); |
|
171 | 175 |
if (!auxfile.exists()) { |
172 | 176 |
/* |
173 | 177 |
* Not even this one exists: error |
174 | 178 |
*/ |
175 |
throw new IOException("File does not exist: " + file.getName()); |
|
176 |
} else { |
|
179 |
throw new IOException("File does not exist: " |
|
180 |
+ file.getName()); |
|
181 |
} |
|
182 |
else { |
|
177 | 183 |
file = auxfile; |
178 | 184 |
} |
179 | 185 |
} |
... | ... | |
181 | 187 |
File xmlFile = new File(file.getAbsolutePath()); |
182 | 188 |
FileInputStream is = new FileInputStream(xmlFile); |
183 | 189 |
|
184 |
PersistenceManager persistenceManager = |
|
185 |
ToolsLocator.getPersistenceManager();
|
|
186 |
PersistentState persistentState = |
|
187 |
persistenceManager.loadState(is);
|
|
188 |
layout = |
|
189 |
(LayoutPanel) persistenceManager.create(persistentState);
|
|
190 |
PersistenceManager persistenceManager = ToolsLocator
|
|
191 |
.getPersistenceManager();
|
|
192 |
PersistentState persistentState = persistenceManager
|
|
193 |
.loadState(is);
|
|
194 |
layout = (LayoutPanel) persistenceManager
|
|
195 |
.create(persistentState);
|
|
190 | 196 |
|
191 |
} catch (Exception e) { |
|
197 |
} |
|
198 |
catch (Exception e) { |
|
192 | 199 |
String tit = Messages.getText("_Layout_template"); |
193 | 200 |
String msg = null; |
194 |
|
|
201 |
|
|
195 | 202 |
if (e instanceof PersistenceException) { |
196 | 203 |
msg = Messages.getText("_Bad_format_in_layout_template"); |
197 |
} else { |
|
204 |
} |
|
205 |
else { |
|
198 | 206 |
msg = Messages.getText("_Cant_load_layout_template"); |
199 | 207 |
} |
200 |
|
|
208 |
|
|
201 | 209 |
msg = msg + ": " + file.getPath(); |
202 | 210 |
msg = msg + "\n" + e.getMessage(); |
203 | 211 |
logger.warn(msg, e); |
204 |
JOptionPane.showMessageDialog( |
|
205 |
ApplicationLocator.getManager().getRootComponent(),
|
|
206 |
msg, tit, JOptionPane.ERROR_MESSAGE);
|
|
212 |
JOptionPane.showMessageDialog(ApplicationLocator.getManager()
|
|
213 |
.getRootComponent(), msg, tit,
|
|
214 |
JOptionPane.ERROR_MESSAGE);
|
|
207 | 215 |
} |
208 |
|
|
216 |
|
|
209 | 217 |
if (layout == null) { |
210 | 218 |
return; |
211 | 219 |
} |
212 | 220 |
|
213 |
LayoutDocument layoutDocument = (LayoutDocument) layout.getDocument(); |
|
221 |
LayoutDocument layoutDocument = (LayoutDocument) layout |
|
222 |
.getDocument(); |
|
214 | 223 |
/* |
215 |
(LayoutDocument) ProjectManager.getInstance().createDocument(
|
|
216 |
DefaultLayoutManager.TYPENAME, file.getName());
|
|
217 |
*/
|
|
218 |
|
|
224 |
* (LayoutDocument) ProjectManager.getInstance().createDocument(
|
|
225 |
* DefaultLayoutManager.TYPENAME, file.getName());
|
|
226 |
*/ |
|
227 |
|
|
219 | 228 |
Project p = ApplicationLocator.getManager().getProjectManager() |
220 | 229 |
.getCurrentProject(); |
221 | 230 |
p.addDocument(layoutDocument); |
222 |
|
|
231 |
|
|
223 | 232 |
layout.getLayoutControl().setTool("layoutselect"); |
224 |
|
|
233 |
|
|
225 | 234 |
LayoutManager lm = (LayoutManager) layoutDocument.getFactory(); |
226 | 235 |
layout.setLayoutManager(lm); |
227 |
|
|
236 |
|
|
228 | 237 |
PluginServices.getMDIManager().addWindow(layout); |
229 | 238 |
|
230 | 239 |
} |
... | ... | |
233 | 242 |
private void registerDocuments() { |
234 | 243 |
DefaultLayoutManager.register(); |
235 | 244 |
} |
236 |
|
|
245 |
|
|
237 | 246 |
private void registerFFrames() { |
238 |
DefaultLayoutManager layoutManager = |
|
239 |
(DefaultLayoutManager) ProjectManager.getInstance()
|
|
247 |
DefaultLayoutManager layoutManager = (DefaultLayoutManager) ProjectManager
|
|
248 |
.getInstance()
|
|
240 | 249 |
.getDocumentManager(DefaultLayoutManager.TYPENAME); |
241 |
|
|
250 |
|
|
242 | 251 |
// Register Frames |
243 | 252 |
layoutManager.registerFrameFactory(new FFrameBasicFactory()); |
244 | 253 |
layoutManager.registerFrameFactory(new FFrameGraphicsFactory()); |
... | ... | |
256 | 265 |
|
257 | 266 |
// Register FFrameDialogs forms |
258 | 267 |
layoutManager.registerFFrameDialog( |
259 |
FFrameGraphics.PERSISTENCE_DEFINITION_NAME, FFrameGraphicsDialog.class); |
|
268 |
FFrameGraphics.PERSISTENCE_DEFINITION_NAME, |
|
269 |
FFrameGraphicsDialog.class); |
|
260 | 270 |
layoutManager.registerFFrameDialog( |
261 |
FFrameSymbol.PERSISTENCE_DEFINITION_NAME, FFrameGraphicsDialog.class); |
|
271 |
FFrameSymbol.PERSISTENCE_DEFINITION_NAME, |
|
272 |
FFrameGraphicsDialog.class); |
|
262 | 273 |
layoutManager.registerFFrameDialog( |
263 |
FFrameGroup.PERSISTENCE_DEFINITION_NAME, FFrameGroupDialog.class); |
|
274 |
FFrameGroup.PERSISTENCE_DEFINITION_NAME, |
|
275 |
FFrameGroupDialog.class); |
|
264 | 276 |
layoutManager.registerFFrameDialog( |
265 |
FFrameTable.PERSISTENCE_DEFINITION_NAME, FFrameBoxDialog.class); |
|
277 |
FFrameTable.PERSISTENCE_DEFINITION_NAME, FFrameBoxDialog.class);
|
|
266 | 278 |
layoutManager.registerFFrameDialog( |
267 |
FFrameLegend.PERSISTENCE_DEFINITION_NAME, FFrameLegendDialog.class); |
|
279 |
FFrameLegend.PERSISTENCE_DEFINITION_NAME, |
|
280 |
FFrameLegendDialog.class); |
|
268 | 281 |
layoutManager.registerFFrameDialog( |
269 |
FFramePicture.PERSISTENCE_DEFINITION_NAME, FFramePictureDialog.class); |
|
282 |
FFramePicture.PERSISTENCE_DEFINITION_NAME, |
|
283 |
FFramePictureDialog.class); |
|
270 | 284 |
layoutManager.registerFFrameDialog( |
271 |
FFrameNorth.PERSISTENCE_DEFINITION_NAME, FFrameNorthDialog.class); |
|
285 |
FFrameNorth.PERSISTENCE_DEFINITION_NAME, |
|
286 |
FFrameNorthDialog.class); |
|
272 | 287 |
layoutManager.registerFFrameDialog( |
273 |
FFrameScaleBar.PERSISTENCE_DEFINITION_NAME, FFrameScaleBarDialog.class); |
|
288 |
FFrameScaleBar.PERSISTENCE_DEFINITION_NAME, |
|
289 |
FFrameScaleBarDialog.class); |
|
274 | 290 |
layoutManager.registerFFrameDialog( |
275 |
FFrameText.PERSISTENCE_DEFINITION_NAME, FFrameTextDialog.class); |
|
291 |
FFrameText.PERSISTENCE_DEFINITION_NAME, FFrameTextDialog.class);
|
|
276 | 292 |
layoutManager.registerFFrameDialog( |
277 |
FFrameView.PERSISTENCE_DEFINITION_NAME, FFrameViewDialog.class); |
|
293 |
FFrameView.PERSISTENCE_DEFINITION_NAME, FFrameViewDialog.class);
|
|
278 | 294 |
layoutManager.registerFFrameDialog( |
279 |
FFrameOverView.PERSISTENCE_DEFINITION_NAME, FFrameOverViewDialog.class); |
|
295 |
FFrameOverView.PERSISTENCE_DEFINITION_NAME, |
|
296 |
FFrameOverViewDialog.class); |
|
280 | 297 |
layoutManager.registerFFrameDialog( |
281 |
FFrameGrid.PERSISTENCE_DEFINITION_NAME, FFrameGridDialog.class); |
|
282 |
|
|
298 |
FFrameGrid.PERSISTENCE_DEFINITION_NAME, FFrameGridDialog.class);
|
|
299 |
|
|
283 | 300 |
FFrame.initializeIcons(); |
284 | 301 |
FFrameTable.initializeIcons(); |
285 | 302 |
} |
286 |
|
|
303 |
|
|
287 | 304 |
private void registerContextMenuOptions() { |
288 |
LayoutManager layoutManager = |
|
289 |
(LayoutManager) ProjectManager.getInstance() |
|
290 |
.getDocumentManager("project.document.layout"); |
|
291 |
|
|
292 |
layoutManager.registerLayoutMenuAction("Terminate", TerminateLayoutMenuEntry.class); |
|
293 |
layoutManager.registerLayoutMenuAction("Cancel", CancelLayoutMenuEntry.class); |
|
294 |
layoutManager.registerLayoutMenuAction("Copy", CopyLayoutMenuEntry.class); |
|
305 |
LayoutManager layoutManager = (LayoutManager) ProjectManager |
|
306 |
.getInstance().getDocumentManager("project.document.layout"); |
|
307 |
|
|
308 |
layoutManager.registerLayoutMenuAction("Terminate", |
|
309 |
TerminateLayoutMenuEntry.class); |
|
310 |
layoutManager.registerLayoutMenuAction("Cancel", |
|
311 |
CancelLayoutMenuEntry.class); |
|
312 |
layoutManager.registerLayoutMenuAction("Copy", |
|
313 |
CopyLayoutMenuEntry.class); |
|
295 | 314 |
layoutManager.registerLayoutMenuAction("Cut", CutLayoutMenuEntry.class); |
296 |
layoutManager.registerLayoutMenuAction("Paste", PasteLayoutMenuEntry.class); |
|
297 |
layoutManager.registerLayoutMenuAction("Simplify", SimplifyLayoutMenuEntry.class); |
|
298 |
layoutManager.registerLayoutMenuAction("Property",PropertyLayoutMenuEntry.class); |
|
299 |
layoutManager.registerLayoutMenuAction("SelectAll", SelectAllLayoutMenuEntry.class); |
|
300 |
layoutManager.registerLayoutMenuAction("Behind", BehindLayoutMenuEntry.class); |
|
301 |
layoutManager.registerLayoutMenuAction("Before", BeforeLayoutMenuEntry.class); |
|
302 |
layoutManager.registerLayoutMenuAction("Position", PositionLayoutMenuEntry.class); |
|
303 |
layoutManager.registerLayoutMenuAction("Refresh", RefreshLayoutMenuEntry.class); |
|
304 |
|
|
315 |
layoutManager.registerLayoutMenuAction("Paste", |
|
316 |
PasteLayoutMenuEntry.class); |
|
317 |
layoutManager.registerLayoutMenuAction("Simplify", |
|
318 |
SimplifyLayoutMenuEntry.class); |
|
319 |
layoutManager.registerLayoutMenuAction("Property", |
|
320 |
PropertyLayoutMenuEntry.class); |
|
321 |
layoutManager.registerLayoutMenuAction("SelectAll", |
|
322 |
SelectAllLayoutMenuEntry.class); |
|
323 |
layoutManager.registerLayoutMenuAction("Behind", |
|
324 |
BehindLayoutMenuEntry.class); |
|
325 |
layoutManager.registerLayoutMenuAction("Before", |
|
326 |
BeforeLayoutMenuEntry.class); |
|
327 |
layoutManager.registerLayoutMenuAction("Position", |
|
328 |
PositionLayoutMenuEntry.class); |
|
329 |
layoutManager.registerLayoutMenuAction("Refresh", |
|
330 |
RefreshLayoutMenuEntry.class); |
|
331 |
|
|
305 | 332 |
} |
306 | 333 |
|
307 | 334 |
private void initializeDocumentActionsExtensionPoint() { |
308 | 335 |
ExtensionPointManager epMan = ToolsLocator.getExtensionPointManager(); |
309 |
epMan.add("DocumentActions_Map", |
|
310 |
"Context menu options of the map document list" |
|
311 |
+ " in the project window " + "(register instances of " |
|
312 |
+ "org.gvsig.app.project.AbstractDocumentContextMenuAction)"); |
|
336 |
epMan.add( |
|
337 |
"DocumentActions_Map", |
|
338 |
"Context menu options of the map document list" |
|
339 |
+ " in the project window " |
|
340 |
+ "(register instances of " |
|
341 |
+ "org.gvsig.app.project.AbstractDocumentContextMenuAction)"); |
|
313 | 342 |
} |
314 | 343 |
|
315 | 344 |
public boolean isEnabled() { |
Also available in: Unified diff