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