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