Revision 1074 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/FLayoutFunctions.java

View differences:

FLayoutFunctions.java
1 1
/*
2 2
 * Created on 16-sep-2004
3 3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6 4
 */
7 5
package com.iver.cit.gvsig.gui.layout;
8 6

  
......
29 27
 * @author Vicente Caballero Navarro
30 28
 */
31 29
public class FLayoutFunctions {
32
    private Layout layout = null;
30
	private Layout layout = null;
33 31

  
34
    /**
35
     * Crea un nuevo FLayoutFunctions.
36
     *
37
     * @param l DOCUMENT ME!
38
     */
39
    public FLayoutFunctions(Layout l) {
40
        layout = l;
41
    }
32
	/**
33
	 * Crea un nuevo FLayoutFunctions.
34
	 *
35
	 * @param l Referencia al Layout.
36
	 */
37
	public FLayoutFunctions(Layout l) {
38
		layout = l;
39
	}
42 40

  
43
    /**
44
     * Gestiona la herramienta de selecci?n sobre el Mapa.
45
     */
46
    public void setSelect() {
47
        IFFrame fframe = null;
48
        boolean isUpdate = false;
41
	/**
42
	 * Gestiona la herramienta de selecci?n sobre el Mapa.
43
	 */
44
	public void setSelect() {
45
		IFFrame fframe = null;
46
		boolean isUpdate = false;
49 47

  
50
        for (int i = 0; i < layout.getFFrames().size(); i++) {
51
            fframe = (IFFrame) layout.getFFrames().get(i);
48
		for (int i = 0; i < layout.getFFrames().size(); i++) {
49
			fframe = (IFFrame) layout.getFFrames().get(i);
52 50

  
53
            int difx = (layout.getLastPoint().x - layout.getFirstPoint().x);
54
            int dify = (layout.getLastPoint().y - layout.getFirstPoint().y);
51
			int difx = (layout.getLastPoint().x - layout.getFirstPoint().x);
52
			int dify = (layout.getLastPoint().y - layout.getFirstPoint().y);
55 53

  
56
            if (((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) &&
57
                    (fframe.getSelected() != FFrame.NOSELECT)) {
58
                Rectangle2D rectangle = fframe.getMovieRect(difx, dify);
54
			if (((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) &&
55
					(fframe.getSelected() != FFrame.NOSELECT)) {
56
				Rectangle2D rectangle = fframe.getMovieRect(difx, dify);
59 57

  
60
                if (layout.isCuadricula()) {
61
                    //cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
62
                    FLayoutUtilities.setRectGrid(rectangle,
63
                        layout.getAtributes().getUnitInPixelsX(),
64
                        layout.getAtributes().getUnitInPixelsY(), layout.getAT());
65
                }
58
				if (layout.isCuadricula()) {
59
					//cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
60
					FLayoutUtilities.setRectGrid(rectangle,
61
						layout.getAtributes().getUnitInPixelsX(),
62
						layout.getAtributes().getUnitInPixelsY(), layout.getAT());
63
				}
66 64

  
67
                if (fframe instanceof FFrameGroup) {
68
                    ((FFrameGroup) fframe).setAt(layout.getAT());
69
                }
65
				if (fframe instanceof FFrameGroup) {
66
					((FFrameGroup) fframe).setAt(layout.getAT());
67
				}
70 68

  
71
                fframe.setBoundBox(FLayoutUtilities.toSheetRect(rectangle,
72
                        layout.getAT()));
73
                isUpdate = true;
74
            }
69
				fframe.setBoundBox(FLayoutUtilities.toSheetRect(rectangle,
70
						layout.getAT()));
71
				isUpdate = true;
72
			}
75 73

  
76
            if (layout.isReSel() &&
77
                    (layout.getReSel().contains(fframe.getBoundingBox(
78
                            layout.getAT())))) {
79
                fframe.setSelected(true);
80
            }
74
			if (layout.isReSel() &&
75
					(layout.getReSel().contains(fframe.getBoundingBox(
76
							layout.getAT())))) {
77
				fframe.setSelected(true);
78
			}
81 79

  
82
            if (isUpdate) {
83
                layout.setStatus(Layout.DESACTUALIZADO);
84
            } else {
85
                layout.setStatus(Layout.ACTUALIZADO);
86
            }
87
        }
80
			if (isUpdate) {
81
				layout.setStatus(Layout.DESACTUALIZADO);
82
			} else {
83
				layout.setStatus(Layout.ACTUALIZADO);
84
			}
85
		}
88 86

  
89
        layout.setIsReSel(true);
90
    }
87
		layout.setIsReSel(true);
88
	}
91 89

  
92
    /**
93
     * A?ade un fframe al Layout del tipo preseleccionado  y abre el di?logo
94
     * para configurar las caracter?sticas.
95
     */
96
    public void setFFrame() {
97
        IFFrame fframe = null;
98
        boolean isadd = false;
90
	/**
91
	 * A?ade un fframe al Layout del tipo preseleccionado  y abre el di?logo
92
	 * para configurar las caracter?sticas.
93
	 */
94
	public void setFFrame() {
95
		IFFrame fframe = null;
96
		boolean isadd = false;
99 97

  
100
        if (layout.getTool() == Layout.RECTANGLEVIEW) {
101
            fframe = new FFrameView();
102
            isadd = true;
103
        } else if (layout.getTool() == Layout.RECTANGLEPICTURE) {
104
            fframe = new FFramePicture();
105
            isadd = true;
106
        } else if (layout.getTool() == Layout.RECTANGLESCALEBAR) {
107
            fframe = new FFrameScaleBar();
108
            isadd = true;
109
        } else if (layout.getTool() == Layout.RECTANGLELEGEND) {
110
            fframe = new FFrameLegend();
111
            isadd = true;
112
        } else if (layout.getTool() == Layout.RECTANGLETEXT) {
113
            fframe = new FFrameText();
114
            isadd = true;
115
        } else if ((layout.getTool() == Layout.RECTANGLESIMPLE) ||
116
                (layout.getTool() == Layout.LINE) ||
117
                (layout.getTool() == Layout.POLYLINE) ||
118
                (layout.getTool() == Layout.POLYGON) ||
119
                (layout.getTool() == Layout.CIRCLE)) {
120
            fframe = new FFrameGraphics();
121
            isadd = true;
122
            ((FFrameGraphics) fframe).update(layout.getTool(), layout.getAT());
123
        }
98
		if (layout.getTool() == Layout.RECTANGLEVIEW) {
99
			fframe = new FFrameView();
100
			isadd = true;
101
		} else if (layout.getTool() == Layout.RECTANGLEPICTURE) {
102
			fframe = new FFramePicture();
103
			isadd = true;
104
		} else if (layout.getTool() == Layout.RECTANGLESCALEBAR) {
105
			fframe = new FFrameScaleBar();
106
			isadd = true;
107
		} else if (layout.getTool() == Layout.RECTANGLELEGEND) {
108
			fframe = new FFrameLegend();
109
			isadd = true;
110
		} else if (layout.getTool() == Layout.RECTANGLETEXT) {
111
			fframe = new FFrameText();
112
			isadd = true;
113
		} else if ((layout.getTool() == Layout.RECTANGLESIMPLE) ||
114
				(layout.getTool() == Layout.LINE) ||
115
				(layout.getTool() == Layout.POLYLINE) ||
116
				(layout.getTool() == Layout.POLYGON) ||
117
				(layout.getTool() == Layout.CIRCLE) ||
118
				(layout.getTool() == Layout.POINT)) {
119
			fframe = new FFrameGraphics();
120
			isadd = true;
121
			((FFrameGraphics) fframe).update(layout.getTool(), layout.getAT());
122
		}
124 123

  
125
        if (isadd) {
126
            Rectangle2D r = new Rectangle2D.Double(); //rectOrigin.x+m_PointAnt.x,rectOrigin.y+m_PointAnt.y,m_LastPoint.x-m_PointAnt.x,m_LastPoint.y-m_PointAnt.y);
127
            r.setFrameFromDiagonal(layout.getFirstPoint(), layout.getLastPoint());
124
		if (isadd) {
125
			Rectangle2D r = new Rectangle2D.Double(); //rectOrigin.x+m_PointAnt.x,rectOrigin.y+m_PointAnt.y,m_LastPoint.x-m_PointAnt.x,m_LastPoint.y-m_PointAnt.y);
126
			r.setFrameFromDiagonal(layout.getFirstPoint(), layout.getLastPoint());
128 127

  
129
            if (layout.isCuadricula()) {
130
                //cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
131
                FLayoutUtilities.setRectGrid(r,
132
                    layout.getAtributes().getUnitInPixelsX(),
133
                    layout.getAtributes().getUnitInPixelsY(), layout.getAT());
134
            }
128
			if (layout.isCuadricula()) {
129
				//cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
130
				FLayoutUtilities.setRectGrid(r,
131
					layout.getAtributes().getUnitInPixelsX(),
132
					layout.getAtributes().getUnitInPixelsY(), layout.getAT());
133
			}
135 134

  
136
            fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layout.getAT()));
135
			fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layout.getAT()));
137 136

  
138
            if (layout.openFFrameDialog(fframe)) {
139
                layout.addFFrame(fframe, true);
140
            }
141
        }
142
    }
137
			if (layout.openFFrameDialog(fframe)) {
138
				layout.addFFrame(fframe, true);
139
			}
140
		}
141
	}
143 142

  
144
    /**
145
     * DOCUMENT ME!
146
     *
147
     * @param p1 DOCUMENT ME!
148
     * @param p2 DOCUMENT ME!
149
     */
150
    public void setViewPan(Point p1, Point p2) {
151
        for (int i = 0; i < layout.getFFrames().size(); i++) {
152
            if (layout.getFFrames().get(i) instanceof FFrameView) {
153
                FFrameView fframe = (FFrameView) layout.getFFrames().get(i);
143
	/**
144
	 * Pan sobre la vista del FFrameView.
145
	 *
146
	 * @param p1 Punto inicial del desplazamiento.
147
	 * @param p2 Punto final del desplazamiento.
148
	 */
149
	public void setViewPan(Point p1, Point p2) {
150
		for (int i = 0; i < layout.getFFrames().size(); i++) {
151
			if (layout.getFFrames().get(i) instanceof FFrameView) {
152
				FFrameView fframe = (FFrameView) layout.getFFrames().get(i);
154 153

  
155
                if (fframe.getSelected() != FFrame.NOSELECT) {
156
                    Rectangle2D.Double r = new Rectangle2D.Double();
157
                    Rectangle2D extent = fframe.getFMap().getViewPort().getExtent();
158
                    Point2D mp1 = toMapPoint(p1,fframe.getAt());
159
                    Point2D mp2 = toMapPoint(p2,fframe.getAt());
160
                    r.x = extent.getX() - (mp2.getX() - mp1.getX());
161
                    r.y = extent.getY() - (mp2.getY() - mp1.getY());
162
                    r.width = extent.getWidth();
163
                    r.height = extent.getHeight();
164
                    fframe.getFMap().getViewPort().setExtent(r);
165
                }
166
            }
167
        }
168
    }
169
	public Point2D.Double toMapPoint(Point2D pScreen,AffineTransform at1) {
170
		   Point2D.Double pWorld = new Point2D.Double();
154
				if (fframe.getSelected() != FFrame.NOSELECT) {
155
					Rectangle2D.Double r = new Rectangle2D.Double();
156
					Rectangle2D extent = fframe.getFMap().getViewPort()
157
											   .getExtent();
158
					Point2D mp1 = toMapPoint(p1, fframe.getAt());
159
					Point2D mp2 = toMapPoint(p2, fframe.getAt());
160
					r.x = extent.getX() - (mp2.getX() - mp1.getX());
161
					r.y = extent.getY() - (mp2.getY() - mp1.getY());
162
					r.width = extent.getWidth();
163
					r.height = extent.getHeight();
164
					fframe.getFMap().getViewPort().setExtent(r);
165
				}
166
			}
167
		}
168
	}
171 169

  
172
		   AffineTransform at;
170
	/**
171
	 * Devuelve un punto real a partir de un punto en pixels sobre la vista.
172
	 *
173
	 * @param pScreen Punto en pixels.
174
	 * @param at1 Matriz de transformaci?n.
175
	 *
176
	 * @return Punto real.
177
	 */
178
	public Point2D.Double toMapPoint(Point2D pScreen, AffineTransform at1) {
179
		Point2D.Double pWorld = new Point2D.Double();
173 180

  
174
		   try {
175
			   at = at1.createInverse();
176
			   at.transform(pScreen, pWorld);
177
		   } catch (NoninvertibleTransformException e) {
178
//				 throw new RuntimeException(e);
179
		   }
181
		AffineTransform at;
180 182

  
181
		   return pWorld;
182
	   }
183
		try {
184
			at = at1.createInverse();
185
			at.transform(pScreen, pWorld);
186
		} catch (NoninvertibleTransformException e) {
187
			//				 throw new RuntimeException(e);
188
		}
189

  
190
		return pWorld;
191
	}
183 192
}

Also available in: Unified diff