root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / LayoutControls.java @ 7304
History | View | Annotate | Download (4.83 KB)
1 |
/*
|
---|---|
2 |
* Created on 05-may-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig; |
48 |
|
49 |
import java.awt.Component; |
50 |
import java.awt.event.KeyEvent; |
51 |
import java.io.File; |
52 |
import java.io.FileWriter; |
53 |
|
54 |
import javax.swing.JFileChooser; |
55 |
import javax.swing.KeyStroke; |
56 |
|
57 |
import org.apache.log4j.Logger; |
58 |
import org.exolab.castor.xml.Marshaller; |
59 |
|
60 |
import com.iver.andami.PluginServices; |
61 |
import com.iver.andami.messages.NotificationManager; |
62 |
import com.iver.andami.plugins.Extension; |
63 |
import com.iver.andami.ui.mdiManager.IWindow; |
64 |
import com.iver.cit.gvsig.gui.layout.Layout; |
65 |
import com.iver.cit.gvsig.project.documents.layout.FLayoutZooms; |
66 |
import com.iver.cit.gvsig.project.documents.layout.LayoutKeyEvent; |
67 |
import com.iver.utiles.GenericFileFilter; |
68 |
|
69 |
|
70 |
/**
|
71 |
* Extensi?n para controlar las operaciones basicas sobre el Layout.
|
72 |
*
|
73 |
* @author Vicente Caballero Navarro
|
74 |
*/
|
75 |
public class LayoutControls extends Extension { |
76 |
private static Logger logger = Logger.getLogger(LayoutControls.class.getName()); |
77 |
private Layout layout = null; |
78 |
|
79 |
/**
|
80 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
81 |
*/
|
82 |
public void execute(String s) { |
83 |
layout = (Layout) PluginServices.getMDIManager().getActiveWindow(); |
84 |
|
85 |
FLayoutZooms zooms = new FLayoutZooms(layout);
|
86 |
logger.debug("Comand : " + s);
|
87 |
|
88 |
if (s.equals("PAN")) { |
89 |
layout.setTool(Layout.PAN); |
90 |
} else if (s.equals("ZOOM_IN")) { |
91 |
layout.setTool(Layout.ZOOM_MAS); |
92 |
} else if (s.equals("ZOOM_OUT")) { |
93 |
layout.setTool(Layout.ZOOM_MENOS); |
94 |
} else if (s.equals("CONFIG")) { |
95 |
layout.showFConfig(); |
96 |
layout.fullRect(); |
97 |
} else if (s.equals("FULL")) { |
98 |
layout.fullRect(); |
99 |
} else if (s.equals("REALZOOM")) { |
100 |
zooms.realZoom(); |
101 |
} else if (s.equals("ZOOMOUT")) { |
102 |
zooms.zoomOut(); |
103 |
} else if (s.equals("ZOOMIN")) { |
104 |
zooms.zoomIn(); |
105 |
} else if (s.equals("ZOOMSELECT")) { |
106 |
zooms.zoomSelect(); |
107 |
} else if (s.equals("PDF")){ |
108 |
layout.layoutToPDF(); |
109 |
} else if (s.equals("PS")){ |
110 |
layout.layoutToPS(); |
111 |
} else if (s.equals("SAVETEMPLATE")){ |
112 |
saveLayout(); |
113 |
} |
114 |
} |
115 |
private void saveLayout() { |
116 |
layout = (Layout) PluginServices.getMDIManager().getActiveWindow(); |
117 |
JFileChooser jfc = new JFileChooser(); |
118 |
jfc.addChoosableFileFilter(new GenericFileFilter("gvt", |
119 |
PluginServices.getText(this, "plantilla"))); |
120 |
|
121 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
122 |
File file=jfc.getSelectedFile();
|
123 |
if (!(file.getPath().endsWith(".gvt") || file.getPath().endsWith(".GVT"))){ |
124 |
file=new File(file.getPath()+".gvt"); |
125 |
} |
126 |
try {
|
127 |
FileWriter writer = new FileWriter(file.getAbsolutePath()); |
128 |
Marshaller m = new Marshaller(writer);
|
129 |
m.setEncoding("ISO-8859-1");
|
130 |
m.marshal(layout.getXMLEntity().getXmlTag()); |
131 |
} catch (Exception e) { |
132 |
NotificationManager.addError(PluginServices.getText(this, "Error_guardando_la_plantilla"), e); |
133 |
} |
134 |
} |
135 |
} |
136 |
/**
|
137 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
138 |
*/
|
139 |
public boolean isVisible() { |
140 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
141 |
|
142 |
if (f == null) { |
143 |
return false; |
144 |
} |
145 |
|
146 |
if (f instanceof Layout) { |
147 |
// Layout layout = (Layout) f;
|
148 |
|
149 |
return true; //layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() > 0; |
150 |
} else {
|
151 |
return false; |
152 |
} |
153 |
} |
154 |
|
155 |
/**
|
156 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
157 |
*/
|
158 |
public void initialize() { |
159 |
} |
160 |
|
161 |
/**
|
162 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
163 |
*/
|
164 |
public boolean isEnabled() { |
165 |
return true; |
166 |
} |
167 |
|
168 |
/**
|
169 |
* Devuelve el Layout sobre el que se opera.
|
170 |
*
|
171 |
* @return Layout.
|
172 |
*/
|
173 |
public Layout getLayout() {
|
174 |
return layout;
|
175 |
} |
176 |
} |