svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / Layout.java @ 3576
History | View | Annotate | Download (52.4 KB)
1 |
/*
|
---|---|
2 |
* Created on 20-feb-2004
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.gui.layout; |
46 |
|
47 |
import java.awt.Color; |
48 |
import java.awt.Component; |
49 |
import java.awt.Cursor; |
50 |
import java.awt.Graphics; |
51 |
import java.awt.Graphics2D; |
52 |
import java.awt.Image; |
53 |
import java.awt.Point; |
54 |
import java.awt.Rectangle; |
55 |
import java.awt.Toolkit; |
56 |
import java.awt.event.ActionEvent; |
57 |
import java.awt.event.KeyEvent; |
58 |
import java.awt.geom.AffineTransform; |
59 |
import java.awt.geom.Rectangle2D; |
60 |
import java.awt.image.BufferedImage; |
61 |
import java.awt.print.PageFormat; |
62 |
import java.awt.print.Printable; |
63 |
import java.awt.print.PrinterException; |
64 |
import java.awt.print.PrinterJob; |
65 |
import java.beans.PropertyChangeEvent; |
66 |
import java.beans.PropertyChangeListener; |
67 |
import java.io.File; |
68 |
import java.util.ArrayList; |
69 |
import java.util.Hashtable; |
70 |
|
71 |
import javax.print.Doc; |
72 |
import javax.print.DocFlavor; |
73 |
import javax.print.DocPrintJob; |
74 |
import javax.print.PrintException; |
75 |
import javax.print.PrintService; |
76 |
import javax.print.PrintServiceLookup; |
77 |
import javax.print.ServiceUI; |
78 |
import javax.print.SimpleDoc; |
79 |
import javax.print.attribute.PrintRequestAttributeSet; |
80 |
import javax.print.event.PrintJobAdapter; |
81 |
import javax.print.event.PrintJobEvent; |
82 |
import javax.print.event.PrintJobListener; |
83 |
import javax.swing.AbstractAction; |
84 |
import javax.swing.Action; |
85 |
import javax.swing.ImageIcon; |
86 |
import javax.swing.JFileChooser; |
87 |
import javax.swing.JOptionPane; |
88 |
import javax.swing.JPanel; |
89 |
import javax.swing.KeyStroke; |
90 |
import javax.swing.filechooser.FileFilter; |
91 |
|
92 |
import org.apache.log4j.Logger; |
93 |
|
94 |
import com.iver.andami.PluginServices; |
95 |
import com.iver.andami.messages.NotificationManager; |
96 |
import com.iver.andami.ui.mdiManager.SingletonView; |
97 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
98 |
import com.iver.andami.ui.mdiManager.ViewListener; |
99 |
import com.iver.cit.gvsig.AddLayer; |
100 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
101 |
import com.iver.cit.gvsig.fmap.DriverException; |
102 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
103 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
104 |
import com.iver.cit.gvsig.fmap.core.adapter.CircleAdapter; |
105 |
import com.iver.cit.gvsig.fmap.core.adapter.GeometryAdapter; |
106 |
import com.iver.cit.gvsig.fmap.core.adapter.PointAdapter; |
107 |
import com.iver.cit.gvsig.fmap.core.adapter.PolyLineAdapter; |
108 |
import com.iver.cit.gvsig.fmap.core.adapter.PolygonAdapter; |
109 |
import com.iver.cit.gvsig.fmap.core.adapter.RectangleAdapter; |
110 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
111 |
import com.iver.cit.gvsig.gui.layout.commands.DefaultEditableFeatureSource; |
112 |
import com.iver.cit.gvsig.gui.layout.commands.EditableFeatureSource; |
113 |
import com.iver.cit.gvsig.gui.layout.dialogs.FConfigLayoutDialog; |
114 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrame; |
115 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics; |
116 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup; |
117 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend; |
118 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth; |
119 |
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture; |
120 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar; |
121 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText; |
122 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
123 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
124 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameEditable; |
125 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameLayoutDependence; |
126 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameViewDependence; |
127 |
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameGraphicsDialog; |
128 |
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameGroupDialog; |
129 |
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameLegendDialog; |
130 |
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameNorthDialog; |
131 |
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFramePictureDialog; |
132 |
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameScaleBarDialog; |
133 |
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameTextDialog; |
134 |
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameViewDialog; |
135 |
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.IFFrameDialog; |
136 |
import com.iver.cit.gvsig.gui.project.MapProperties; |
137 |
import com.iver.cit.gvsig.gui.project.OpenException; |
138 |
import com.iver.cit.gvsig.gui.project.SaveException; |
139 |
import com.iver.cit.gvsig.project.Project; |
140 |
import com.iver.cit.gvsig.project.ProjectMap; |
141 |
import com.iver.utiles.GenericFileFilter; |
142 |
import com.iver.utiles.XMLEntity; |
143 |
|
144 |
|
145 |
/**
|
146 |
* Mapa.
|
147 |
*
|
148 |
* @author Vicente Caballero Navarro
|
149 |
*/
|
150 |
public class Layout extends JPanel implements SingletonView, ViewPortListener, |
151 |
ViewListener { |
152 |
private static Logger logger = Logger.getLogger(Layout.class.getName()); |
153 |
public static final int ZOOM_MAS = 1; |
154 |
public static final int ZOOM_MENOS = 2; |
155 |
public static final int PAN = 3; |
156 |
public static final int DESACTUALIZADO = 4; |
157 |
public static final int ACTUALIZADO = 5; |
158 |
public static final int SELECT = 6; |
159 |
public static final int RECTANGLE = 10; |
160 |
public static final int RECTANGLEVIEW = 11; |
161 |
public static final int RECTANGLEPICTURE = 12; |
162 |
public static final int RECTANGLESCALEBAR = 13; |
163 |
public static final int RECTANGLELEGEND = 14; |
164 |
public static final int RECTANGLETEXT = 15; |
165 |
public static final int RECTANGLEGROUP = 16; |
166 |
public static final int RECTANGLESYMBOL = 17; |
167 |
public static final int RECTANGLENORTH = 18; |
168 |
|
169 |
public static final int GRAPHICS = 20; |
170 |
public static final int POINT = 21; |
171 |
public static final int LINE = 22; |
172 |
public static final int POLYLINE = 23; |
173 |
public static final int RECTANGLESIMPLE = 24; |
174 |
public static final int CIRCLE = 25; |
175 |
public static final int POLYGON = 26; |
176 |
public static final int VIEW_ZOOMIN = 30; |
177 |
public static final int VIEW_ZOOMOUT = 31; |
178 |
public static final int VIEW_FULL = 32; |
179 |
public static final int VIEW_PAN = 33; |
180 |
public static final int SET_TAG = 34; |
181 |
public static final int EDIT=35; |
182 |
public static final Image iLayoutpan = new ImageIcon(AddLayer.class.getClassLoader() |
183 |
.getResource("images/LayoutHand.gif")).getImage();
|
184 |
public static final Image ipan = new ImageIcon(AddLayer.class.getClassLoader() |
185 |
.getResource("images/Hand.gif")).getImage();
|
186 |
public static final Image iLayoutzoomin = new ImageIcon(AddLayer.class.getClassLoader() |
187 |
.getResource("images/LayoutZoomInCursor.gif")).getImage();
|
188 |
public static final Image izoomin = new ImageIcon(AddLayer.class.getClassLoader() |
189 |
.getResource("images/ZoomInCursor.gif")).getImage();
|
190 |
public static final Image iLayoutzoomout = new ImageIcon(AddLayer.class.getClassLoader() |
191 |
.getResource("images/LayoutZoomOutCursor.gif")).getImage();
|
192 |
public static final Image izoomout = new ImageIcon(AddLayer.class.getClassLoader() |
193 |
.getResource("images/ZoomOutCursor.gif")).getImage();
|
194 |
public static final Image iinfo = new ImageIcon(AddLayer.class.getClassLoader() |
195 |
.getResource("images/InfoCursor.gif")).getImage();
|
196 |
public static final Image icrux = new ImageIcon(AddLayer.class.getClassLoader() |
197 |
.getResource("images/CruxCursor.png")).getImage();
|
198 |
public static final Image itag = new ImageIcon(AddLayer.class.getClassLoader() |
199 |
.getResource("images/tagCursor.gif")).getImage();
|
200 |
public static final Image iPoint = new ImageIcon(AddLayer.class.getClassLoader() |
201 |
.getResource("images/PointCursor.png")).getImage();
|
202 |
public static final Image iRect = new ImageIcon(AddLayer.class.getClassLoader() |
203 |
.getResource("images/RectCursor.png")).getImage();
|
204 |
public static final Image iLine = new ImageIcon(AddLayer.class.getClassLoader() |
205 |
.getResource("images/LineCursor.png")).getImage();
|
206 |
public static final Image iRectangle = new ImageIcon(AddLayer.class.getClassLoader() |
207 |
.getResource("images/RectangleCursor.png")).getImage();
|
208 |
public static final Image iCircle = new ImageIcon(AddLayer.class.getClassLoader() |
209 |
.getResource("images/CircleCursor.png")).getImage();
|
210 |
public static final Image iPoligon = new ImageIcon(AddLayer.class.getClassLoader() |
211 |
.getResource("images/PoligonCursor.png")).getImage();
|
212 |
public static Hashtable nums = new Hashtable(); |
213 |
private Point origin = new Point(50, 50); |
214 |
private Point rectOrigin = new Point(origin); |
215 |
private Rectangle2D.Double rect = new Rectangle2D.Double(rectOrigin.x, |
216 |
rectOrigin.y, 400, 300); |
217 |
private Point m_FirstPoint = new Point(0, 0); |
218 |
private Point m_PointAnt = new Point(0, 0); |
219 |
private Point m_LastPoint = new Point(0, 0); |
220 |
private EventsHandler events;
|
221 |
private int tool = ZOOM_MAS; |
222 |
private int status = DESACTUALIZADO; |
223 |
private BufferedImage img = null; |
224 |
private AffineTransform m_MatrizTransf; |
225 |
private Rectangle2D rectVisible; |
226 |
private IFFrameDialog fframedialog = null; |
227 |
///private ArrayList m_fframes = new ArrayList();
|
228 |
private IFFrame[] fframes; |
229 |
private MapProperties m_propertiesLayout = null; |
230 |
private Attributes m_attributes = null; |
231 |
private PrintService[] m_cachePrintServices = null; |
232 |
private PrintService m_cachePrintService = null; |
233 |
private boolean m_bCancelDrawing = false; |
234 |
private boolean isCuadricula = false; |
235 |
private boolean initial = true; |
236 |
private ProjectMap map = null; |
237 |
private Rectangle reSel = null; |
238 |
private boolean isReSel = true; |
239 |
private boolean m_showRuler = true; |
240 |
private FLayoutDraw layoutDraw = null; |
241 |
private boolean isDrawCuadricula = true; |
242 |
private Doc doc = null; |
243 |
private PrintRequestAttributeSet att = null; |
244 |
private GeometryAdapter geometryAdapter=new PolyLineAdapter(); |
245 |
private DefaultEditableFeatureSource efs;
|
246 |
private boolean isEditable=true; |
247 |
private ViewInfo m_viewinfo = new ViewInfo(ViewInfo.ICONIFIABLE | |
248 |
ViewInfo.MAXIMIZABLE | ViewInfo.RESIZABLE); |
249 |
|
250 |
/**
|
251 |
* Lo usamos cuando estamos haciendo una ficha y asignando tags
|
252 |
* Se pone en modo debug cuando hacemos un VIEW_TAGS
|
253 |
*/
|
254 |
private boolean bModeDebug = false; |
255 |
|
256 |
/**
|
257 |
* Creates a new Layout object.
|
258 |
*/
|
259 |
public Layout() {
|
260 |
efs=new DefaultEditableFeatureSource();
|
261 |
updateFFrames(); |
262 |
this.setLayout(null); |
263 |
events = new EventsHandler(this); |
264 |
layoutDraw = new FLayoutDraw(this); |
265 |
addComponentListener(events); |
266 |
addMouseMotionListener(events); |
267 |
addMouseListener(events); |
268 |
addKeyListener(events); |
269 |
m_MatrizTransf = new AffineTransform(); |
270 |
m_MatrizTransf.setToIdentity(); |
271 |
this.initComponents();
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* Rellena el ProjectMap del Layout.
|
276 |
*
|
277 |
* @param m ProjectMap.
|
278 |
*/
|
279 |
public void setProjectMap(ProjectMap m) { |
280 |
map = m; |
281 |
this.setName(m.getName());
|
282 |
map.addPropertyChangeListener(new PropertyChangeListener() { |
283 |
public void propertyChange(PropertyChangeEvent evt) { |
284 |
if (evt.getPropertyName().equals("name")) { |
285 |
PluginServices.getMDIManager().getViewInfo(Layout.this) |
286 |
.setTitle(PluginServices.getText(this,
|
287 |
"Mapa") + " : " + (String) evt.getNewValue()); |
288 |
} |
289 |
} |
290 |
}); |
291 |
} |
292 |
|
293 |
/**
|
294 |
* Devuelve el rect?ngulo de selecci?n por rect?ngulo.
|
295 |
*
|
296 |
* @return Rect?ngulo de selecci?n.
|
297 |
*/
|
298 |
public Rectangle getReSel() { |
299 |
return reSel;
|
300 |
} |
301 |
|
302 |
/**
|
303 |
* Devuelve true si se debe dibujar el rect?ngulo de selecci?n y realizar
|
304 |
* la sellecci?n.
|
305 |
*
|
306 |
* @return true si se realiza la selecci?n por rect?ngulo.
|
307 |
*/
|
308 |
public boolean isReSel() { |
309 |
return isReSel;
|
310 |
} |
311 |
|
312 |
/**
|
313 |
* Rellena con true si se debe de dibujar y seleccionar por rect?ngulo de
|
314 |
* selecci?n.
|
315 |
*
|
316 |
* @param b boolean.
|
317 |
*/
|
318 |
public void setIsReSel(boolean b) { |
319 |
isReSel = b; |
320 |
} |
321 |
|
322 |
/**
|
323 |
* Devuelve true si el dibujado ha sido cancelado.
|
324 |
*
|
325 |
* @return true si el dibujado ha sido cancelado.
|
326 |
*/
|
327 |
public synchronized boolean isDrawingCancelled() { |
328 |
return m_bCancelDrawing;
|
329 |
} |
330 |
|
331 |
/**
|
332 |
* Pone el dibuja a cancelado o no seg?n se quiera.
|
333 |
*
|
334 |
* @param b true si se quiere cancelar el dibujado.
|
335 |
*/
|
336 |
public synchronized void setCancelDrawing(boolean b) { |
337 |
m_bCancelDrawing = b; |
338 |
|
339 |
for (int i = 0; i < getFFrames().length; i++) { |
340 |
IFFrame fframe = (IFFrame) getFFrame(i); |
341 |
|
342 |
if (fframe instanceof FFrameView && |
343 |
(((FFrameView) fframe).getFMap() != null)) {
|
344 |
////TODO((FFrameView) getFFrames().get(i)).getFMap().setCancelDrawing(b);
|
345 |
} |
346 |
} |
347 |
} |
348 |
|
349 |
/**
|
350 |
* Obtiene el ArrayList con todos los FFrames que se han a?adido al Layout.
|
351 |
*
|
352 |
* @return Array con todos los fframes que contiene el Layout.
|
353 |
*/
|
354 |
public IFFrame[] getFFrames() { |
355 |
return fframes;
|
356 |
} |
357 |
public IFFrame getFFrame(int i){ |
358 |
return fframes[i];
|
359 |
} |
360 |
public void updateFFrames(){ |
361 |
fframes=efs.getFFrames(); |
362 |
} |
363 |
/**
|
364 |
* Obtiene el rect que se ajusta al tama?o de la ventana, para ver el folio
|
365 |
* entero.
|
366 |
*/
|
367 |
public void fullRect() { |
368 |
rect.setRect(origin.x, origin.y, getWidth() - (origin.x * 2),
|
369 |
getHeight() - (origin.x * 2));
|
370 |
|
371 |
if (m_attributes.isLandSpace()) {
|
372 |
rect = m_attributes.getRectangleLandscape(rect, getWidth(), |
373 |
getHeight()); |
374 |
} else {
|
375 |
rect = m_attributes.getRectanglePortrait(rect, getWidth(), |
376 |
getHeight()); |
377 |
} |
378 |
|
379 |
status = DESACTUALIZADO; |
380 |
repaint(); |
381 |
} |
382 |
|
383 |
/**
|
384 |
* M?todo para imprimir el Layout sin modificar la matriz de
|
385 |
* transformaci?n.
|
386 |
*
|
387 |
* @param g2
|
388 |
*/
|
389 |
public void drawLayoutPrint(Graphics2D g2) { |
390 |
setCancelDrawing(false);
|
391 |
|
392 |
setCursor(Cursor.getDefaultCursor());
|
393 |
|
394 |
double scale = 0; |
395 |
|
396 |
///if (rect.width > rect.height) {
|
397 |
/// scale = rect.width / m_attributes.m_sizePaper.getAlto() * 1;
|
398 |
///} else {
|
399 |
scale = rect.height / m_attributes.m_sizePaper.getAlto() * 1;
|
400 |
|
401 |
///}
|
402 |
AffineTransform escalado = new AffineTransform(); |
403 |
AffineTransform translacion = new AffineTransform(); |
404 |
translacion.setToTranslation(rect.getMinX(), rect.getMinY()); |
405 |
escalado.setToScale(scale, scale); |
406 |
m_MatrizTransf.setToIdentity(); |
407 |
m_MatrizTransf.concatenate(translacion); |
408 |
m_MatrizTransf.concatenate(escalado); |
409 |
m_attributes.setDistanceUnitX(rect); |
410 |
m_attributes.setDistanceUnitY(rect); |
411 |
|
412 |
for (int i = 0; i < getFFrames().length; i++) { |
413 |
try {
|
414 |
((IFFrame) getFFrame(i)).print(g2, getAT()); |
415 |
} catch (DriverException e) {
|
416 |
NotificationManager.addError(e.getMessage(), e); |
417 |
} |
418 |
} |
419 |
|
420 |
//TODO Esto es para ver el rect?ngulo que representa el folio en la impresi?n.
|
421 |
g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight()); |
422 |
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
423 |
} |
424 |
|
425 |
/**
|
426 |
* Clip sobre el rect?ngulo visible.
|
427 |
*
|
428 |
* @param g2d Graphics sobre el que hacer el clip.
|
429 |
*/
|
430 |
private void clipVisibleRect(Graphics2D g2d) { |
431 |
rectVisible = this.getVisibleRect();
|
432 |
g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(), |
433 |
(int) rectVisible.getWidth(), (int) rectVisible.getHeight()); |
434 |
} |
435 |
|
436 |
/**
|
437 |
* Inicializa los componentes.
|
438 |
*/
|
439 |
private void initComponents() { |
440 |
m_attributes = new Attributes(); |
441 |
m_attributes.setDistanceUnitX(rect); |
442 |
m_attributes.setDistanceUnitY(rect); |
443 |
actionDelFFrame(); |
444 |
setDoubleBuffered(true);
|
445 |
} |
446 |
|
447 |
/**
|
448 |
* Crea un ActionEvent para controlar las teclas que se pulsen cuando este
|
449 |
* el Layout Focusable a true.
|
450 |
*/
|
451 |
private void actionDelFFrame() { |
452 |
Action doNothing = new AbstractAction() { |
453 |
public void actionPerformed(ActionEvent e) { |
454 |
delFFrameSelected(); |
455 |
refresh(); |
456 |
} |
457 |
}; |
458 |
|
459 |
this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), |
460 |
"doNothing");
|
461 |
this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), |
462 |
"doNothing");
|
463 |
this.getActionMap().put("doNothing", doNothing); |
464 |
} |
465 |
|
466 |
/**
|
467 |
* paintComponent del Layout.
|
468 |
*
|
469 |
* @param g Graphics del Layout.
|
470 |
*/
|
471 |
protected void paintComponent(Graphics g) { |
472 |
super.paintComponent(g);
|
473 |
|
474 |
clipVisibleRect((Graphics2D) g);
|
475 |
|
476 |
Rectangle rClip = g.getClipBounds();
|
477 |
|
478 |
if (rClip == null) { |
479 |
System.err.println("clip = null"); |
480 |
} |
481 |
|
482 |
switch (status) {
|
483 |
case ZOOM_MAS:
|
484 |
logger.debug("zoom mas");
|
485 |
layoutDraw.drawRectangle((Graphics2D) g);
|
486 |
|
487 |
g.drawImage(img, 0, 0, this); |
488 |
|
489 |
g.setClip(rClip); |
490 |
layoutDraw.drawGrid((Graphics2D) g);
|
491 |
layoutDraw.drawRuler((Graphics2D) g, Color.black); |
492 |
g.setColor(Color.black);
|
493 |
g.setXORMode(Color.white);
|
494 |
|
495 |
Rectangle r = new Rectangle(); |
496 |
|
497 |
r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint); |
498 |
g.drawRect(r.x, r.y, r.width, r.height); |
499 |
|
500 |
break;
|
501 |
|
502 |
case RECTANGLE:
|
503 |
logger.debug("rectangle");
|
504 |
layoutDraw.drawRectangle((Graphics2D) g);
|
505 |
|
506 |
g.drawImage(img, 0, 0, this); |
507 |
|
508 |
g.setClip(rClip); |
509 |
layoutDraw.drawGrid((Graphics2D) g);
|
510 |
layoutDraw.drawRuler((Graphics2D) g, Color.black); |
511 |
g.setColor(Color.black);
|
512 |
g.setXORMode(Color.white);
|
513 |
|
514 |
Rectangle re = new Rectangle(); |
515 |
re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint); |
516 |
|
517 |
if (isCuadricula()) {
|
518 |
FLayoutUtilities.setRectGrid(re, |
519 |
m_attributes.getUnitInPixelsX(), |
520 |
m_attributes.getUnitInPixelsY(), m_MatrizTransf); |
521 |
} |
522 |
|
523 |
g.drawRect(re.x, re.y, re.width, re.height); |
524 |
|
525 |
break;
|
526 |
|
527 |
case PAN:
|
528 |
logger.debug("pan");
|
529 |
|
530 |
//g.setXORMode(Color.black);
|
531 |
rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x); |
532 |
rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y); |
533 |
|
534 |
//g.clearRect(0, 0, getWidth(), getHeight());
|
535 |
layoutDraw.drawRectangle((Graphics2D) g);
|
536 |
|
537 |
if (img != null) { |
538 |
g.drawImage(img, (getLastPoint().x - getPointAnt().x), |
539 |
(m_LastPoint.y - m_PointAnt.y), this);
|
540 |
} |
541 |
|
542 |
g.setClip(rClip); |
543 |
layoutDraw.drawGrid((Graphics2D) g);
|
544 |
layoutDraw.drawRuler((Graphics2D) g, Color.black); |
545 |
|
546 |
break;
|
547 |
|
548 |
case VIEW_PAN:
|
549 |
|
550 |
// logger.debug("View pan");
|
551 |
layoutDraw.drawRectangle((Graphics2D) g);
|
552 |
|
553 |
for (int i = 0; i < getFFrames().length; i++) { |
554 |
if (getFFrame(i) instanceof FFrameView) { |
555 |
FFrameView fframe = (FFrameView) getFFrame(i); |
556 |
|
557 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
558 |
Rectangle2D.Double rec = fframe.getBoundingBox(getAT());
|
559 |
|
560 |
if (img != null) { |
561 |
//g.drawImage(img, 0, 0, this);
|
562 |
rec = (Rectangle2D.Double) rec.createIntersection(getVisibleRect());
|
563 |
|
564 |
//((Graphics2D)g).clearRect((int)rec.x,(int)rec.y,(int)rec.width,(int)rec.height);
|
565 |
} |
566 |
|
567 |
if (fframe.getBufferedImage() != null) { |
568 |
layoutDraw.drawHandlers((Graphics2D) g,
|
569 |
Color.black);
|
570 |
g.clipRect((int) rec.x, (int) rec.y, |
571 |
(int) rec.width, (int) rec.height); |
572 |
|
573 |
//g.setColor(Color.gray);
|
574 |
//g.fillRect(0,0,getWidth(),getHeight());
|
575 |
layoutDraw.drawRectangle((Graphics2D) g);
|
576 |
layoutDraw.drawRuler((Graphics2D) g, Color.black); |
577 |
|
578 |
g.drawImage(fframe.getBufferedImage(), |
579 |
m_LastPoint.x - m_PointAnt.x, |
580 |
m_LastPoint.y - m_PointAnt.y, this);
|
581 |
|
582 |
/*System.out.println(
|
583 |
"m_LastPoint.x - m_PointAnt.x" +
|
584 |
(m_LastPoint.x - m_PointAnt.x));
|
585 |
System.out.println(
|
586 |
"m_LastPoint.y - m_PointAnt.y" +
|
587 |
(m_LastPoint.y - m_PointAnt.y));
|
588 |
*/
|
589 |
} |
590 |
} |
591 |
} |
592 |
} |
593 |
|
594 |
g.setClip(rClip); |
595 |
layoutDraw.drawGrid((Graphics2D) g);
|
596 |
layoutDraw.drawRuler((Graphics2D) g, Color.black); |
597 |
|
598 |
//g.setXORMode(Color.black);
|
599 |
break;
|
600 |
|
601 |
case SELECT:
|
602 |
logger.debug("select");
|
603 |
layoutDraw.drawRectangle((Graphics2D) g);
|
604 |
|
605 |
g.drawImage(img, 0, 0, this); |
606 |
|
607 |
if (isReSel) {
|
608 |
reSel = new Rectangle(); |
609 |
reSel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint); |
610 |
g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height); |
611 |
} |
612 |
IFFrame[] frames=getFFrameSelected();
|
613 |
for (int i = 0; i < frames.length; i++) { |
614 |
//IFFrame fframe = (IFFrame) getFFrames().get(i);
|
615 |
|
616 |
//if (fframe.getSelected() != IFFrame.NOSELECT) {
|
617 |
g.setColor(Color.black);
|
618 |
frames[i].drawHandlers((Graphics2D) g);
|
619 |
|
620 |
int difx = (m_LastPoint.x - m_FirstPoint.x);
|
621 |
int dify = (m_LastPoint.y - m_FirstPoint.y);
|
622 |
// System.out.println(m_FirstPoint);
|
623 |
// System.out.println(m_LastPoint);
|
624 |
if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) { |
625 |
Rectangle2D rectangle = frames[i].getMovieRect(difx,
|
626 |
dify); |
627 |
((Graphics2D) g).rotate(Math.toRadians( |
628 |
frames[i].getRotation()), |
629 |
rectangle.getX() + (rectangle.getWidth() / 2),
|
630 |
rectangle.getY() + (rectangle.getHeight() / 2));
|
631 |
|
632 |
if (rectangle != null) { |
633 |
if (isCuadricula) {
|
634 |
FLayoutUtilities.setRectGrid(rectangle, |
635 |
m_attributes.getUnitInPixelsX(), |
636 |
m_attributes.getUnitInPixelsY(), |
637 |
m_MatrizTransf); |
638 |
} |
639 |
|
640 |
g.drawRect((int) rectangle.getMinX(),
|
641 |
(int) rectangle.getMinY(),
|
642 |
(int) rectangle.getWidth(),
|
643 |
(int) rectangle.getHeight());
|
644 |
} |
645 |
|
646 |
((Graphics2D) g).rotate(Math.toRadians( |
647 |
-frames[i].getRotation()), |
648 |
rectangle.getX() + (rectangle.getWidth() / 2),
|
649 |
rectangle.getY() + (rectangle.getHeight() / 2));
|
650 |
} |
651 |
//}
|
652 |
} |
653 |
|
654 |
g.setClip(rClip); |
655 |
layoutDraw.drawGrid((Graphics2D) g);
|
656 |
layoutDraw.drawRuler((Graphics2D) g, Color.black); |
657 |
|
658 |
break;
|
659 |
case GRAPHICS:
|
660 |
logger.debug("graphics");
|
661 |
layoutDraw.drawRectangle((Graphics2D) g);
|
662 |
g.drawImage(img, 0, 0, this); |
663 |
g.setClip(rClip); |
664 |
layoutDraw.drawGrid((Graphics2D) g);
|
665 |
layoutDraw.drawHandlers((Graphics2D) g, Color.black); |
666 |
layoutDraw.drawRuler((Graphics2D) g, Color.black); |
667 |
|
668 |
if (getTool()==EDIT){
|
669 |
IFFrame[] fframeSelect=getFFrameSelected();
|
670 |
for(int i=0;i<fframeSelect.length;i++){ |
671 |
if (fframeSelect[i] instanceof IFFrameEditable){ |
672 |
((IFFrameEditable)fframeSelect[i]).paint((Graphics2D)g,getAT());
|
673 |
} |
674 |
} |
675 |
}else{
|
676 |
geometryAdapter.paint((Graphics2D)g,getAT());
|
677 |
} |
678 |
break;
|
679 |
|
680 |
case DESACTUALIZADO:
|
681 |
logger.debug("desactualizado");
|
682 |
img = new BufferedImage(getWidth(), getHeight(), |
683 |
BufferedImage.TYPE_INT_ARGB);
|
684 |
|
685 |
Graphics gimag = img.getGraphics();
|
686 |
clipVisibleRect((Graphics2D) gimag);
|
687 |
|
688 |
if (initial) {
|
689 |
fullRect(); |
690 |
initial = false;
|
691 |
} |
692 |
|
693 |
try {
|
694 |
layoutDraw.drawLayout((Graphics2D) gimag, img);
|
695 |
} catch (DriverException e) {
|
696 |
e.printStackTrace(); |
697 |
} |
698 |
|
699 |
g.setClip(rClip); |
700 |
layoutDraw.drawRectangle((Graphics2D) g);
|
701 |
|
702 |
g.drawImage(img, 0, 0, this); |
703 |
g.setClip(rClip); |
704 |
layoutDraw.drawGrid((Graphics2D) g);
|
705 |
layoutDraw.drawHandlers((Graphics2D) g, Color.black); |
706 |
layoutDraw.drawRuler((Graphics2D) g, Color.black); |
707 |
|
708 |
break;
|
709 |
|
710 |
case ACTUALIZADO:
|
711 |
logger.debug("actualizado");
|
712 |
layoutDraw.drawRectangle((Graphics2D) g);
|
713 |
|
714 |
g.drawImage(img, 0, 0, this); |
715 |
|
716 |
g.setClip(rClip); |
717 |
layoutDraw.drawGrid((Graphics2D) g);
|
718 |
|
719 |
layoutDraw.drawHandlers((Graphics2D) g, Color.black); |
720 |
layoutDraw.drawRuler((Graphics2D) g, Color.black); |
721 |
} |
722 |
} |
723 |
|
724 |
/**
|
725 |
* A?ade un fframe al Arraylist m_fframes.
|
726 |
*
|
727 |
* @param frame fframe a a?adir.
|
728 |
* @param clearSelection para que se quede seleccionado ?nicamente el que
|
729 |
* a?adimos y false si lo que se pretende es que no se
|
730 |
* deseleccionen lo que ya est?n seleccionados.
|
731 |
* @param select Booleano que indica si se tiene que quedar seleccionado el
|
732 |
* FFrame que se a?ade o no.
|
733 |
*/
|
734 |
public void addFFrame(IFFrame frame, boolean clearSelection, boolean select) { |
735 |
if (clearSelection) {
|
736 |
for (int i = getFFrames().length - 1; i >= 0; i--) { |
737 |
IFFrame fframe1 = (IFFrame) getFFrame(i); |
738 |
fframe1.setSelected(false);
|
739 |
} |
740 |
} |
741 |
|
742 |
/*if (frame instanceof FFrameView &&
|
743 |
(((FFrameView) frame).getFMap() != null)) {
|
744 |
((FFrameView) frame).getFMap().getViewPort().addViewPortListener(this);
|
745 |
}
|
746 |
*/
|
747 |
if (nums.containsKey(frame.getClass())) {
|
748 |
nums.put(frame.getClass(), |
749 |
new Integer(Integer.parseInt(nums.get(frame.getClass()) |
750 |
.toString()) + 1));
|
751 |
} else {
|
752 |
nums.put(frame.getClass(), new Integer(0)); |
753 |
} |
754 |
|
755 |
frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
|
756 |
efs.addFFrame(frame); |
757 |
///getFFrames().add(frame);
|
758 |
frame.setSelected(select); |
759 |
updateFFrames(); |
760 |
} |
761 |
|
762 |
/**
|
763 |
* Abre el di?logo de propiedades del folio, pasando como par?metro el
|
764 |
* PrinterJob.
|
765 |
*
|
766 |
* @param job
|
767 |
*/
|
768 |
public void showPagePropertiesWindow(PrinterJob job) { |
769 |
PageFormat pf1; //=new PageFormat(); |
770 |
|
771 |
pf1 = m_attributes.getPageFormat(); |
772 |
pf1 = job.pageDialog(pf1); |
773 |
m_attributes.setPageFormat(pf1); |
774 |
refresh(); |
775 |
} |
776 |
|
777 |
/**
|
778 |
* Refresca el Layout.
|
779 |
*/
|
780 |
public void refresh() { |
781 |
//rect = m_attributes.obtainRect(false, rect, getWidth(), getHeight());
|
782 |
setStatus(DESACTUALIZADO); |
783 |
repaint(); |
784 |
} |
785 |
|
786 |
/**
|
787 |
* Obtiene el rect?ngulo que representa el folio con las caracter?sticas
|
788 |
* que contiene attributes y diferenciando si es para visualizar en
|
789 |
* pantalla o para imprimir.
|
790 |
*
|
791 |
* @param isPrint si es para imprimir.
|
792 |
*/
|
793 |
public void obtainRect(boolean isPrint) { |
794 |
m_attributes.obtainRect(isPrint, rect, getWidth(), getHeight()); |
795 |
} |
796 |
|
797 |
/**
|
798 |
* Muestra el di?logo de configuraci?n del Layout.
|
799 |
*/
|
800 |
public void showFConfig() { |
801 |
FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this); |
802 |
PluginServices.getMDIManager().addView(m_configLayout); |
803 |
} |
804 |
|
805 |
/**
|
806 |
* Mestra el di?logo de propiedades del Layout.
|
807 |
*/
|
808 |
public void showFProperties() { |
809 |
if (map == null) { |
810 |
map = new ProjectMap();
|
811 |
map.setModel(this);
|
812 |
map.setName(getName()); |
813 |
} |
814 |
|
815 |
m_propertiesLayout = new MapProperties(map);
|
816 |
PluginServices.getMDIManager().addView(m_propertiesLayout); |
817 |
} |
818 |
|
819 |
/**
|
820 |
* Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
|
821 |
*
|
822 |
* @param job
|
823 |
*/
|
824 |
public void showPrintDialog(PrinterJob job) { |
825 |
if (job != null) { |
826 |
job.printDialog(); |
827 |
|
828 |
try {
|
829 |
job.setPrintable((Printable) PluginServices.getExtension(
|
830 |
com.iver.cit.gvsig.Print.class)); |
831 |
job.print(); |
832 |
} catch (PrinterException e) { |
833 |
e.printStackTrace(); |
834 |
} |
835 |
} else {
|
836 |
//Actualizar attributes
|
837 |
att = m_attributes.toPrintAttributes(); |
838 |
|
839 |
//------------------ The Printing things --------------------- //
|
840 |
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; |
841 |
|
842 |
// returns the set of printers that support printing a specific document type (such as GIF)
|
843 |
// with a specific set of attributes (such as two sided).
|
844 |
// PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
|
845 |
// interestingly, the printer dialog's default behavior has changed with the new API: by default the dialog is not shown.
|
846 |
// So we must use the ServiceUI class to create a print dialog
|
847 |
// returns the default print service.
|
848 |
if (m_cachePrintServices == null) { |
849 |
m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor,
|
850 |
null);
|
851 |
} |
852 |
|
853 |
PrintService defaultService = null; |
854 |
|
855 |
if (m_cachePrintService == null) { |
856 |
defaultService = PrintServiceLookup.lookupDefaultPrintService();
|
857 |
} |
858 |
|
859 |
if ((defaultService == null) && (m_cachePrintService == null)) { |
860 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
861 |
"ninguna_impresora_configurada");
|
862 |
|
863 |
return;
|
864 |
} |
865 |
|
866 |
if (m_cachePrintService == null) { |
867 |
m_cachePrintService = ServiceUI.printDialog(null, 200, 200, |
868 |
m_cachePrintServices, defaultService, flavor, att); |
869 |
|
870 |
// m_cachePrintRequestAtributeSet = new HashPrintRequestAttributeSet();
|
871 |
// m_cachePrintRequestAtributeSet.addAll(pras);
|
872 |
} else {
|
873 |
m_cachePrintService = ServiceUI.printDialog(null, 200, 200, |
874 |
m_cachePrintServices, m_cachePrintService, flavor, att); |
875 |
} |
876 |
|
877 |
if (m_cachePrintService != null) { |
878 |
DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
|
879 |
PrintJobListener pjlistener = new PrintJobAdapter() { |
880 |
public void printDataTransferCompleted(PrintJobEvent e) { |
881 |
System.out.println("Fin de impresi?n"); |
882 |
fullRect(); |
883 |
} |
884 |
}; |
885 |
|
886 |
jobNuevo.addPrintJobListener(pjlistener); |
887 |
|
888 |
// DocAttributeSet das = new HashDocAttributeSet();
|
889 |
doc = new SimpleDoc((Printable) PluginServices.getExtension( |
890 |
com.iver.cit.gvsig.Print.class), flavor, null);
|
891 |
|
892 |
try {
|
893 |
jobNuevo.print(doc, att); |
894 |
|
895 |
// m_attributes.
|
896 |
} catch (PrintException pe) { |
897 |
pe.printStackTrace(); |
898 |
} |
899 |
} |
900 |
} |
901 |
|
902 |
/* try {
|
903 |
print = job.printDialog(att);
|
904 |
} catch (Exception e) {
|
905 |
logger.error("Abriendo el Di?logo de imprimir"); //System.out.println("Excepci?n "+e);
|
906 |
}
|
907 |
if (print) {
|
908 |
job.setPrintable((Printable) App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
|
909 |
try {
|
910 |
job.print(att);
|
911 |
} catch (Exception ex) {
|
912 |
ex.printStackTrace();
|
913 |
}
|
914 |
} */
|
915 |
} |
916 |
|
917 |
/**
|
918 |
* Sustituye el puntero del rat?n por la imagen que se le pasa como
|
919 |
* par?metro.
|
920 |
*
|
921 |
* @param image
|
922 |
*/
|
923 |
public void setMapCursor(Image image) { |
924 |
Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(image, |
925 |
new Point(16, 16), ""); |
926 |
setCursor(cur); |
927 |
} |
928 |
|
929 |
/**
|
930 |
* Cambia el puntero del raton al cusor que se le introduce como par?metro.
|
931 |
*
|
932 |
* @param cursor cursor a mostrar en el puntero del rat?n.
|
933 |
*/
|
934 |
public void setMapCursor(Cursor cursor) { |
935 |
setCursor(cursor); |
936 |
} |
937 |
|
938 |
/**
|
939 |
* Pone como seleccionada a la herramienta a partir de su n?mero.
|
940 |
*
|
941 |
* @param i
|
942 |
*/
|
943 |
public void setTool(int i) { |
944 |
tool = i; |
945 |
|
946 |
if (getTool() == PAN) {
|
947 |
setMapCursor(ipan); |
948 |
} else if (getTool() == ZOOM_MAS) { |
949 |
setMapCursor(izoomin); |
950 |
} else if (getTool() == ZOOM_MENOS) { |
951 |
setMapCursor(izoomout); |
952 |
} else if (getTool() == RECTANGLEVIEW) { |
953 |
setMapCursor(icrux); |
954 |
} else if (getTool() == RECTANGLEPICTURE) { |
955 |
setMapCursor(icrux); |
956 |
} else if (getTool() == RECTANGLESCALEBAR) { |
957 |
setMapCursor(icrux); |
958 |
} else if (getTool() == RECTANGLELEGEND) { |
959 |
setMapCursor(icrux); |
960 |
} else if (getTool() == RECTANGLETEXT) { |
961 |
setMapCursor(icrux); |
962 |
} else if (getTool() == RECTANGLENORTH) { |
963 |
setMapCursor(icrux); |
964 |
} else if (getTool() == SELECT) { |
965 |
setCursor(Cursor.getDefaultCursor());
|
966 |
} else if (getTool() == SET_TAG) { |
967 |
setMapCursor(itag); |
968 |
} else if (getTool() == POINT) { |
969 |
setMapCursor(iPoint); |
970 |
} else if (getTool() == LINE) { |
971 |
setMapCursor(iRect); |
972 |
} else if (getTool() == RECTANGLESIMPLE) { |
973 |
setMapCursor(iRectangle); |
974 |
} else if (getTool() == POLYLINE) { |
975 |
setMapCursor(iLine); |
976 |
} else if (getTool() == POLYGON) { |
977 |
setMapCursor(iPoligon); |
978 |
} else if (getTool() == CIRCLE) { |
979 |
setMapCursor(iCircle); |
980 |
} |
981 |
if (getTool() == EDIT){
|
982 |
setMapCursor(icrux); |
983 |
startEdit(); |
984 |
}else{
|
985 |
stopEdit(); |
986 |
} |
987 |
initGeometryAdapter(); |
988 |
} |
989 |
|
990 |
/**
|
991 |
* Se crean aqu? los dialogos cada vez que se necesitan.
|
992 |
*
|
993 |
* @param fframe Rectangle que representa el lugar que ocupara el elemento
|
994 |
* a?adido.
|
995 |
*
|
996 |
* @return true si se debe de a?adir el fframe.
|
997 |
*/
|
998 |
public boolean openFFrameDialog(IFFrame fframe) { |
999 |
switch (tool) {
|
1000 |
case RECTANGLEVIEW:
|
1001 |
fframedialog = new FFrameViewDialog(this, (FFrameView) fframe); |
1002 |
|
1003 |
break;
|
1004 |
|
1005 |
case RECTANGLEPICTURE:
|
1006 |
fframedialog = new FFramePictureDialog(this, |
1007 |
(FFramePicture) fframe); |
1008 |
|
1009 |
break;
|
1010 |
|
1011 |
case RECTANGLESCALEBAR:
|
1012 |
fframedialog = new FFrameScaleBarDialog(this, |
1013 |
(FFrameScaleBar) fframe); |
1014 |
|
1015 |
break;
|
1016 |
|
1017 |
case RECTANGLELEGEND:
|
1018 |
fframedialog = new FFrameLegendDialog(this, |
1019 |
(FFrameLegend) fframe); |
1020 |
|
1021 |
break;
|
1022 |
|
1023 |
case RECTANGLETEXT:
|
1024 |
fframedialog = new FFrameTextDialog(this, (FFrameText) fframe); |
1025 |
|
1026 |
break;
|
1027 |
|
1028 |
case GRAPHICS:
|
1029 |
fframedialog = new FFrameGraphicsDialog(this, |
1030 |
(FFrameGraphics) fframe); |
1031 |
|
1032 |
break;
|
1033 |
|
1034 |
case RECTANGLEGROUP:
|
1035 |
fframedialog = new FFrameGroupDialog(this, (FFrameGroup) fframe); |
1036 |
|
1037 |
break;
|
1038 |
case RECTANGLENORTH:
|
1039 |
fframedialog = new FFrameNorthDialog(this, (FFrameNorth) fframe); |
1040 |
|
1041 |
break;
|
1042 |
default:
|
1043 |
return true; |
1044 |
} |
1045 |
|
1046 |
if (fframedialog != null) { |
1047 |
fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf)); |
1048 |
PluginServices.getMDIManager().addView(fframedialog); |
1049 |
} |
1050 |
|
1051 |
return fframedialog.getIsAcepted();
|
1052 |
} |
1053 |
|
1054 |
/**
|
1055 |
* Devuelve el Rectangle2D que representa en pixels al folio.
|
1056 |
*
|
1057 |
* @return Rectangle2D.Double
|
1058 |
*/
|
1059 |
public Rectangle2D.Double getRect() { |
1060 |
return rect;
|
1061 |
} |
1062 |
|
1063 |
/**
|
1064 |
* Obtiene un entero que representa la herramienta seleccionada.
|
1065 |
*
|
1066 |
* @return entero.
|
1067 |
*/
|
1068 |
public int getTool() { |
1069 |
return tool;
|
1070 |
} |
1071 |
|
1072 |
/**
|
1073 |
* Devuelve la Matriz transformada que se esta plicando al Layout.
|
1074 |
*
|
1075 |
* @return AffineTransform
|
1076 |
*/
|
1077 |
public AffineTransform getAT() { |
1078 |
return m_MatrizTransf;
|
1079 |
} |
1080 |
|
1081 |
/**
|
1082 |
* Devuelve los atributos del Mapa.
|
1083 |
*
|
1084 |
* @return Attributes.
|
1085 |
*/
|
1086 |
public Attributes getAtributes() { |
1087 |
return m_attributes;
|
1088 |
} |
1089 |
|
1090 |
/**
|
1091 |
* Pone el estado que se quiera.
|
1092 |
*
|
1093 |
* @param s estado.
|
1094 |
*/
|
1095 |
public void setStatus(int s) { |
1096 |
status = s; |
1097 |
} |
1098 |
|
1099 |
/**
|
1100 |
* Devuelve el punto que representa la esquina noroeste del mapa.
|
1101 |
*
|
1102 |
* @return un punto.
|
1103 |
*/
|
1104 |
public Point getRectOrigin() { |
1105 |
return rectOrigin;
|
1106 |
} |
1107 |
|
1108 |
/**
|
1109 |
* Devuelve el punto del primer click de rat?n.
|
1110 |
*
|
1111 |
* @return un punto.
|
1112 |
*/
|
1113 |
public Point getFirstPoint() { |
1114 |
return m_FirstPoint;
|
1115 |
} |
1116 |
|
1117 |
/**
|
1118 |
* Devuelve el punto de click de rat?n anterior.
|
1119 |
*
|
1120 |
* @return un punto.
|
1121 |
*/
|
1122 |
public Point getPointAnt() { |
1123 |
return m_PointAnt;
|
1124 |
} |
1125 |
|
1126 |
/**
|
1127 |
* Devuelve el punto donde se solt? el bot?n del rat?n.
|
1128 |
*
|
1129 |
* @return un punto.
|
1130 |
*/
|
1131 |
public Point getLastPoint() { |
1132 |
return m_LastPoint;
|
1133 |
} |
1134 |
|
1135 |
/**
|
1136 |
* Rellena el primer punto de click de rat?n.
|
1137 |
*
|
1138 |
* @param p punto.
|
1139 |
*/
|
1140 |
public void setFirstPoint(Point p) { |
1141 |
m_FirstPoint = p; |
1142 |
} |
1143 |
|
1144 |
/**
|
1145 |
* Rellena el punto de click de rat?n anterior.
|
1146 |
*
|
1147 |
* @param p punto.
|
1148 |
*/
|
1149 |
public void setPointAnt(Point p) { |
1150 |
m_PointAnt = p; |
1151 |
} |
1152 |
|
1153 |
/**
|
1154 |
* Rellena el punto donde se solto el bot?n del rat?n.
|
1155 |
*
|
1156 |
* @param p punto.
|
1157 |
*/
|
1158 |
public void setLastPoint(Point p) { |
1159 |
m_LastPoint = p; |
1160 |
} |
1161 |
|
1162 |
/**
|
1163 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
1164 |
*/
|
1165 |
public ViewInfo getViewInfo() {
|
1166 |
m_viewinfo.setWidth(500);
|
1167 |
m_viewinfo.setHeight(400);
|
1168 |
|
1169 |
m_viewinfo.setTitle(PluginServices.getText(this, "Mapa") + " : " + |
1170 |
getName()); |
1171 |
|
1172 |
return m_viewinfo;
|
1173 |
} |
1174 |
|
1175 |
/**
|
1176 |
* Inserta si se muestra o no la regla del Layout.
|
1177 |
*
|
1178 |
* @param b True si se muestra la regla.
|
1179 |
*/
|
1180 |
public void setRuler(boolean b) { |
1181 |
m_showRuler = b; |
1182 |
} |
1183 |
|
1184 |
/**
|
1185 |
* Devuelve si se muestra la regla del Layout.
|
1186 |
*
|
1187 |
* @return True si se muestra la regla.
|
1188 |
*/
|
1189 |
public boolean getRuler() { |
1190 |
return m_showRuler;
|
1191 |
} |
1192 |
|
1193 |
/**
|
1194 |
* Devuelve si se esta aplicando en los fframes que se a?den al Layout la
|
1195 |
* cuadr?cula, o no.
|
1196 |
*
|
1197 |
* @return true si se esta aplicando la cuadr?cula.
|
1198 |
*/
|
1199 |
public boolean isCuadricula() { |
1200 |
return isCuadricula;
|
1201 |
} |
1202 |
|
1203 |
/**
|
1204 |
* Se actualiza el estado de la cuadr?cula, si se aplica o no.
|
1205 |
*
|
1206 |
* @param b true si se aplica la cuadr?cula.
|
1207 |
*/
|
1208 |
public void setIsCuadricula(boolean b) { |
1209 |
isCuadricula = b; |
1210 |
} |
1211 |
|
1212 |
/**
|
1213 |
* Realiza una exteni?n completa de las capas que contiene la vista del
|
1214 |
* FFrameView.
|
1215 |
*
|
1216 |
* @throws DriverException
|
1217 |
*/
|
1218 |
public void viewFull() throws DriverException { |
1219 |
for (int i = 0; i < getFFrames().length; i++) { |
1220 |
if (getFFrame(i) instanceof FFrameView) { |
1221 |
FFrameView fframe = (FFrameView) getFFrame(i); |
1222 |
|
1223 |
if ((fframe.getSelected() != IFFrame.NOSELECT) &&
|
1224 |
(fframe.getView() != null)) {
|
1225 |
fframe.getFMap().getViewPort().setExtent(fframe.getFMap() |
1226 |
.getFullExtent()); |
1227 |
} |
1228 |
} |
1229 |
} |
1230 |
|
1231 |
setStatus(DESACTUALIZADO); |
1232 |
repaint(); |
1233 |
} |
1234 |
|
1235 |
/**
|
1236 |
* Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
|
1237 |
* para poder despu?s volver a crear el objeto original.
|
1238 |
*
|
1239 |
* @return XMLEntity.
|
1240 |
*
|
1241 |
* @throws XMLException
|
1242 |
*/
|
1243 |
public XMLEntity getXMLEntity() {
|
1244 |
//getEFS().compact();
|
1245 |
XMLEntity xml = new XMLEntity();
|
1246 |
xml.putProperty("className", this.getClass().getName()); |
1247 |
xml.setName("layout");
|
1248 |
xml.putProperty("isCuadricula", isCuadricula());
|
1249 |
xml.putProperty("m_name", this.getName()); |
1250 |
xml.putProperty("isEditable",isEditable);
|
1251 |
xml.addChild(getAtributes().getXMLEntity()); |
1252 |
|
1253 |
for (int i = 0; i < getFFrames().length; i++) { |
1254 |
try{
|
1255 |
XMLEntity xmlAux=((IFFrame) getFFrame(i)).getXMLEntity(); |
1256 |
xmlAux.putProperty("level",i);
|
1257 |
xml.addChild(xmlAux); |
1258 |
}catch (SaveException e) {
|
1259 |
e.showError(); |
1260 |
} |
1261 |
} |
1262 |
return xml;
|
1263 |
} |
1264 |
/**
|
1265 |
* Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
1266 |
*
|
1267 |
* @param xml XMLEntity
|
1268 |
* @param p Proyecto.
|
1269 |
*
|
1270 |
* @return Objeto de esta clase.
|
1271 |
* @throws OpenException
|
1272 |
*/
|
1273 |
public static Layout createLayout(XMLEntity xml,Project p) throws OpenException { |
1274 |
Layout layout = new Layout();
|
1275 |
try{
|
1276 |
layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
|
1277 |
layout.setName(xml.getStringProperty("m_name"));
|
1278 |
layout.m_attributes = Attributes.createAtributes(xml.getChild(0)); |
1279 |
if (xml.contains("isEditable")){ |
1280 |
layout.setEditable(xml.getBooleanProperty("isEditable"));
|
1281 |
} |
1282 |
layout.getEFS().startComplexCommand(); |
1283 |
for (int i = 1; i < xml.getNumChild(); i++) { |
1284 |
try {
|
1285 |
layout.addFFrame(FFrame.createFFrame(xml.getChild(i),p), |
1286 |
true, false); |
1287 |
} catch (OpenException e) {
|
1288 |
e.showError(); |
1289 |
} |
1290 |
} |
1291 |
layout.getEFS().endComplexCommand(); |
1292 |
IFFrame[] fframes=layout.getAllFFrames();
|
1293 |
for (int i=0;i<fframes.length;i++){ |
1294 |
if (fframes[i] instanceof IFFrameLayoutDependence){ |
1295 |
((IFFrameLayoutDependence)fframes[i]).setLayout(layout); |
1296 |
} |
1297 |
if (fframes[i] instanceof IFFrameViewDependence){ |
1298 |
((IFFrameViewDependence)fframes[i]).initDependence(fframes); |
1299 |
} |
1300 |
} |
1301 |
}catch(Exception e){ |
1302 |
throw new OpenException(e,layout.getClass().getName()); |
1303 |
} |
1304 |
return layout;
|
1305 |
} |
1306 |
|
1307 |
/**
|
1308 |
* Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
1309 |
*
|
1310 |
* @param xml XMLEntity
|
1311 |
* @param p Proyecto.
|
1312 |
*
|
1313 |
* @return Objeto de esta clase.
|
1314 |
*/
|
1315 |
public static Layout createLayout03(XMLEntity xml, Project p) { |
1316 |
Layout layout = new Layout();
|
1317 |
layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
|
1318 |
layout.setName(xml.getStringProperty("m_name"));
|
1319 |
layout.m_attributes = Attributes.createAtributes03(xml.getChild(0)); |
1320 |
|
1321 |
for (int i = 1; i < xml.getNumChild(); i++) { |
1322 |
if (xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) { |
1323 |
layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout, |
1324 |
p), true, false); |
1325 |
} |
1326 |
} |
1327 |
|
1328 |
for (int i = 1; i < xml.getNumChild(); i++) { |
1329 |
if (!xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) { |
1330 |
layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout, |
1331 |
p), true, false); |
1332 |
} |
1333 |
} |
1334 |
|
1335 |
return layout;
|
1336 |
} |
1337 |
|
1338 |
/**
|
1339 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
1340 |
*/
|
1341 |
public void viewActivated() { |
1342 |
repaint(); |
1343 |
PluginServices.getMainFrame().getStatusBar().setMessage("1",
|
1344 |
getAtributes().getNameUnit()); |
1345 |
|
1346 |
///System.out.println("---------- 1 "+ getAtributes().getNameUnit());
|
1347 |
} |
1348 |
|
1349 |
/**
|
1350 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
|
1351 |
*/
|
1352 |
public Object getViewModel() { |
1353 |
return map;
|
1354 |
} |
1355 |
|
1356 |
/**
|
1357 |
* Devuelve si se dibuja el Grid en el Layout o no.
|
1358 |
*
|
1359 |
* @return True si se dibuja el Grid en el Layout.
|
1360 |
*/
|
1361 |
public boolean getIsDrawGrid() { |
1362 |
return isDrawCuadricula;
|
1363 |
} |
1364 |
|
1365 |
/**
|
1366 |
* Inserta si se muestra el Grid del Layout.
|
1367 |
*
|
1368 |
* @param b True si se muestra el Grid del Layout.
|
1369 |
*/
|
1370 |
public void setIsDrawGrid(boolean b) { |
1371 |
isDrawCuadricula = b; |
1372 |
} |
1373 |
|
1374 |
/**
|
1375 |
* @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
|
1376 |
*/
|
1377 |
public void extentChanged(ExtentEvent e) { |
1378 |
} |
1379 |
|
1380 |
/**
|
1381 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
1382 |
*/
|
1383 |
public void viewClosed() { |
1384 |
///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
|
1385 |
} |
1386 |
|
1387 |
/**
|
1388 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
1389 |
*/
|
1390 |
public void backColorChanged(ColorEvent e) { |
1391 |
// refresh();
|
1392 |
} |
1393 |
|
1394 |
/**
|
1395 |
* Devuelve un array con los FFrames seleccionados.
|
1396 |
*
|
1397 |
* @return Array con los FFrames seleccionados.
|
1398 |
*/
|
1399 |
public IFFrame[] getFFrameSelected() { |
1400 |
ArrayList selecList = new ArrayList(); |
1401 |
|
1402 |
for (int i = getFFrames().length - 1; i >= 0; i--) { |
1403 |
IFFrame fframe = (IFFrame) getFFrame(i); |
1404 |
|
1405 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
1406 |
selecList.add(fframe); |
1407 |
} |
1408 |
} |
1409 |
|
1410 |
return (IFFrame[]) selecList.toArray(new IFFrame[0]); |
1411 |
} |
1412 |
|
1413 |
/**
|
1414 |
* Opens a dialog where to pick a PDF-file to save the current Layout
|
1415 |
* suggesting a name for the file given by the first argument
|
1416 |
*
|
1417 |
* @param suggestedName DOCUMENT ME!
|
1418 |
*/
|
1419 |
public void layoutToPDF(String suggestedName) { |
1420 |
FileFilter pdfFilter = new GenericFileFilter("pdf", |
1421 |
PluginServices.getText(this, "pdf")); |
1422 |
|
1423 |
JFileChooser jfc = new JFileChooser(); |
1424 |
if (suggestedName!=null) |
1425 |
jfc.setSelectedFile(new File(suggestedName)); |
1426 |
jfc.addChoosableFileFilter(pdfFilter); |
1427 |
jfc.setFileFilter(pdfFilter); |
1428 |
|
1429 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
1430 |
File f = jfc.getSelectedFile();
|
1431 |
File faux = null; |
1432 |
|
1433 |
if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) { |
1434 |
faux = f; |
1435 |
} else {
|
1436 |
faux = new File(f.getPath() + ".pdf"); |
1437 |
} |
1438 |
|
1439 |
layoutDraw.toPDF(faux); |
1440 |
} |
1441 |
} |
1442 |
|
1443 |
/**
|
1444 |
* Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
|
1445 |
* en este formato.
|
1446 |
*/
|
1447 |
public void layoutToPDF() { |
1448 |
layoutToPDF(null);
|
1449 |
} |
1450 |
|
1451 |
/**
|
1452 |
* @return Returns the bModeDebug.
|
1453 |
*/
|
1454 |
public boolean isModeDebug() { |
1455 |
return bModeDebug;
|
1456 |
} |
1457 |
|
1458 |
/**
|
1459 |
* @param modeDebug The bModeDebug to set.
|
1460 |
*/
|
1461 |
public void setModeDebug(boolean modeDebug) { |
1462 |
bModeDebug = modeDebug; |
1463 |
} |
1464 |
|
1465 |
private ArrayList allFFrames(IFFrame[] fframes, ArrayList all){ |
1466 |
for (int i=0;i<fframes.length;i++){ |
1467 |
if (fframes[i] instanceof FFrameGroup){ |
1468 |
return allFFrames(((FFrameGroup)fframes[i]).getFFrames(),all);
|
1469 |
|
1470 |
}else{
|
1471 |
all.add(fframes[i]); |
1472 |
} |
1473 |
} |
1474 |
return all;
|
1475 |
} |
1476 |
public IFFrame[] getAllFFrames() { |
1477 |
ArrayList all=new ArrayList(); |
1478 |
return (IFFrame[])allFFrames(getFFrames(),all).toArray(new IFFrame[0]); |
1479 |
} |
1480 |
|
1481 |
public GeometryAdapter getGeometryAdapter() {
|
1482 |
return geometryAdapter;
|
1483 |
} |
1484 |
public boolean isEditable(){ |
1485 |
return isEditable;
|
1486 |
} |
1487 |
public void setEditable(boolean b) { |
1488 |
isEditable=b; |
1489 |
} |
1490 |
public void initGeometryAdapter() { |
1491 |
if (getTool() == LINE) {
|
1492 |
geometryAdapter=new PolyLineAdapter();
|
1493 |
} else if (getTool() == RECTANGLESIMPLE) { |
1494 |
geometryAdapter=new RectangleAdapter();
|
1495 |
} else if (getTool() == POLYLINE) { |
1496 |
geometryAdapter=new PolyLineAdapter();
|
1497 |
} else if (getTool() == POLYGON) { |
1498 |
geometryAdapter=new PolygonAdapter();
|
1499 |
} else if (getTool() == CIRCLE) { |
1500 |
geometryAdapter=new CircleAdapter();
|
1501 |
} else if (getTool() == POINT) { |
1502 |
geometryAdapter=new PointAdapter();
|
1503 |
} |
1504 |
} |
1505 |
public void startEdit() { |
1506 |
for(int i=0;i<getFFrames().length;i++){ |
1507 |
IFFrame frame=(IFFrame)getFFrame(i); |
1508 |
if (frame instanceof IFFrameEditable){ |
1509 |
if (frame.getSelected()!=IFFrame.NOSELECT){
|
1510 |
((IFFrameEditable)frame).startEditing(); |
1511 |
}else{
|
1512 |
((IFFrameEditable)frame).stopEditing(); |
1513 |
} |
1514 |
} |
1515 |
|
1516 |
} |
1517 |
refresh(); |
1518 |
} |
1519 |
public void stopEdit(){ |
1520 |
boolean refresh=false; |
1521 |
for(int i=0;i<getFFrames().length;i++){ |
1522 |
IFFrame frame=(IFFrame)getFFrame(i); |
1523 |
if (frame instanceof IFFrameEditable){ |
1524 |
if (((IFFrameEditable)frame).isEditing()){
|
1525 |
((IFFrameEditable)getFFrame(i)).stopEditing(); |
1526 |
refresh=true;
|
1527 |
} |
1528 |
} |
1529 |
} |
1530 |
if (refresh) refresh();
|
1531 |
} |
1532 |
public void delFFrameSelected(){ |
1533 |
efs.startComplexCommand(); |
1534 |
for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) { |
1535 |
IFFrame fframe = (IFFrame) efs.getFFrame(i); |
1536 |
|
1537 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
1538 |
efs.removeFFrame(i); |
1539 |
// getFFrames().remove(i);
|
1540 |
} |
1541 |
} |
1542 |
efs.endComplexCommand(); |
1543 |
updateFFrames(); |
1544 |
} |
1545 |
public void delFFrame(int index){ |
1546 |
for(int i=0;i<getEFS().getAllFFrames().length;i++){ |
1547 |
if (getEFS().getFFrame(i).equals(getFFrame(index))){
|
1548 |
getEFS().removeFFrame(i); |
1549 |
} |
1550 |
} |
1551 |
updateFFrames(); |
1552 |
} |
1553 |
public void delFFrame(IFFrame frame){ |
1554 |
for(int i=0;i<getEFS().getAllFFrames().length;i++){ |
1555 |
if (getEFS().getFFrame(i).equals(frame)){
|
1556 |
getEFS().removeFFrame(i); |
1557 |
} |
1558 |
} |
1559 |
updateFFrames(); |
1560 |
} |
1561 |
public EditableFeatureSource getEFS(){
|
1562 |
return efs;
|
1563 |
} |
1564 |
} |