Revision 1729 branches/gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/FFrameGraphics.java

View differences:

FFrameGraphics.java
46 46

  
47 47
import com.iver.andami.PluginServices;
48 48
import com.iver.cit.gvsig.fmap.DriverException;
49
import com.iver.cit.gvsig.fmap.core.FGeometry;
49 50
import com.iver.cit.gvsig.fmap.core.FPoint2D;
50 51
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
51 52
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
52 53
import com.iver.cit.gvsig.fmap.core.FShape;
53 54
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
55
import com.iver.cit.gvsig.fmap.core.Handler;
56
import com.iver.cit.gvsig.fmap.core.IGeometry;
54 57
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
55 58
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
56 59
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
60
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
61
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource;
62
import com.iver.cit.gvsig.fmap.layers.SelectionSupport;
63
import com.iver.cit.gvsig.gui.cad.CADToolAdapter;
64
import com.iver.cit.gvsig.gui.cad.CadTool;
57 65
import com.iver.cit.gvsig.gui.layout.Layout;
58 66

  
59 67
import com.iver.utiles.XMLEntity;
......
62 70
import java.awt.Graphics2D;
63 71
import java.awt.geom.AffineTransform;
64 72
import java.awt.geom.Line2D;
73
import java.awt.geom.NoninvertibleTransformException;
65 74
import java.awt.geom.Point2D;
66 75
import java.awt.geom.Rectangle2D;
67 76
import java.awt.image.BufferedImage;
77
import java.io.IOException;
78
import java.util.ArrayList;
68 79

  
69 80

  
70 81
/**
71
 * FFrame para contener un gr?fico.
82
 * FFrame para contener todos los gr?ficos que se a?adan al Layout.
72 83
 *
73 84
 * @author Vicente Caballero Navarro
74 85
 */
75 86
public class FFrameGraphics extends FFrame {
76
	private int m_type = FConstant.SHAPE_TYPE_POINT;
77
	private FSymbol m_symbol = null;
78
	private Color m_color = null;
79
	private AffineTransform mT = null;
80
	private AffineTransform aT = null;
87
	private ArrayList geometries=new ArrayList();
88
	private CADToolAdapter cta;
89
	private SelectionSupport selectionSupport = new SelectionSupport();
81 90

  
82 91
	/**
83 92
	 * Crea un nuevo FFrameGraphics.
84 93
	 */
85
	public FFrameGraphics() {
94
	public FFrameGraphics(CADToolAdapter c){
95
		cta=c;
96
	}
97
	/*public FFrameGraphics() {
86 98
		mT = new AffineTransform();
87 99
		mT.setToIdentity();
100
	}*/
101
	public int getNumGeom(){
102
		return geometries.size();
88 103
	}
89

  
90
	/**
91
	 * Rellena el color que se utlizar? para dibujar el s?mbolo.
92
	 *
93
	 * @param color
94
	 */
95
	public void setColor(Color color) {
96
		m_color = color;
104
	public IGeometry[] getGeometries(){
105
		return (IGeometry[])geometries.toArray(new IGeometry[0]);
97 106
	}
98

  
99
	/**
100
	 * Actualiza el Fsymbol a partir del tipo de Gr?fico que se pase como
101
	 * par?metro.
102
	 *
103
	 * @param type tipo de gr?fico.
104
	 * @param at Transformada.
105
	 */
106
	public void update(int type, AffineTransform at) {
107
		m_type = type;
108
		aT = at;
109

  
110
		if (m_color == null) {
111
			m_color = Color.red;
112
		}
113

  
114
		switch (m_type) {
115
			case (Layout.POINT):
116
				m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, m_color);
117

  
118
				break;
119

  
120
			case (Layout.RECTANGLESIMPLE):
121
				m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
122
				m_symbol.setColor(null);
123

  
124
				break;
125

  
126
			case (Layout.LINE):
127
				m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
128

  
129
				break;
130

  
131
			case (Layout.POLYLINE):
132
				m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
133

  
134
				break;
135

  
136
			case (Layout.POLYGON):
137
				m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
138

  
139
				break;
140

  
141
			case (Layout.CIRCLE):
142
				m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
143
				m_symbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE);
144
				m_symbol.setOutlined(true);
145
				m_symbol.setOutlineColor(Color.red);
146
				m_symbol.setColor(null);
147

  
148
				break;
149
		}
107
	public void addGeometry(IGeometry g){
108
		geometries.add(g);
150 109
	}
151

  
152 110
	/**
153
	 * Devuelve el FSymbol que se representa.
154
	 *
155
	 * @return DOCUMENT ME!
156
	 */
157
	public FSymbol getFSymbol() {
158
		return m_symbol;
159
	}
160

  
161
	/**
162
	 * Rellena el FSymbol que se representara al dibujar.
163
	 *
164
	 * @param symbol
165
	 */
166
	public void setFSymbol(FSymbol symbol) {
167
		m_symbol = symbol;
168
	}
169

  
170
	/**
171
	 * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
172
	 * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
173
	 * de dibujar.
174
	 *
175
	 * @param g Graphics
176
	 * @param at Transformada afin.
177
	 * @param rv rect?ngulo sobre el que hacer un clip.
178
	 * @param imgBase DOCUMENT ME!
179
	 */
180
	public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
181
		BufferedImage imgBase) {
182
		Rectangle2D.Double rect = getBoundingBox(at);
183

  
184
		if (intersects(rv, rect)) {
185
			g.setColor(Color.black);
186

  
187
			FShape m_shape = null;
188

  
189
			switch (m_type) {
190
				case (Layout.POINT):
191

  
192
					Point2D.Double p = new Point2D.Double((int) rect.getCenterX(),
193
							(int) rect.getCenterY());
194
					m_shape = new FPoint2D(p.x, p.y);
195

  
196
					if (rect.width < rect.height) {
197
						m_symbol.setSize((int) rect.width - 10);
198
					} else {
199
						m_symbol.setSize((int) rect.height - 10);
200
					}
201

  
202
					///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
203
					FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
204

  
205
					break;
206

  
207
				case (Layout.RECTANGLESIMPLE):
208

  
209
					GeneralPathX rectAux = new GeneralPathX(rect);
210
					rectAux.transform(mT);
211
					m_shape = new FPolygon2D(rectAux); //FConstant.SHAPE_TYPE_POLYLINE, rectAux);
212

  
213
					///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
214
					FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
215

  
216
					break;
217

  
218
				case (Layout.LINE):
219

  
220
					Line2D line = new Line2D.Double();
221
					line.setLine(new Point2D.Double(rect.x, rect.y),
222
						new Point2D.Double(rect.getMaxX(), rect.getMaxY()));
223

  
224
					GeneralPathX rectA = new GeneralPathX(line);
225
					rectA.transform(mT);
226
					m_shape = new FPolyline2D(rectA);
227

  
228
					///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
229
					FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
230

  
231
					//g.drawString("POLYLINE",(float)rect.getCenterX(),(float)rect.getCenterY());
232
					break;
233

  
234
				case (Layout.POLYLINE):
235
					g.drawString("POLYLINE", (float) rect.getCenterX(),
236
						(float) rect.getCenterY());
237

  
238
					break;
239

  
240
				case (Layout.POLYGON):
241
					g.drawString("POLYGON", (float) rect.getCenterX(),
242
						(float) rect.getCenterY());
243

  
244
					break;
245

  
246
				case (Layout.CIRCLE):
247

  
248
					Point2D.Double pc = new Point2D.Double((int) rect.getCenterX(),
249
							(int) rect.getCenterY());
250
					m_shape = new FPoint2D(pc.x, pc.y);
251

  
252
					if (rect.width < rect.height) {
253
						m_symbol.setSize((int) rect.width - 10);
254
					} else {
255
						m_symbol.setSize((int) rect.height - 10);
256
					}
257

  
258
					///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
259
					FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
260

  
261
					break;
262
			}
263
		}
264
	}
265

  
266
	/**
267 111
	 * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
268 112
	 */
269 113
	public XMLEntity getXMLEntity() {
270 114
		XMLEntity xml = new XMLEntity();
271
		xml.putProperty("className",this.getClass().getName());
272
		xml.putProperty("m_name", m_name);
273
		xml.putProperty("x", getBoundBox().x);
274
		xml.putProperty("y", getBoundBox().y);
275
		xml.putProperty("w", getBoundBox().width);
276
		xml.putProperty("h", getBoundBox().height);
277
		xml.putProperty("m_Selected", m_Selected);
278
		xml.putProperty("type", Layout.GRAPHICS);
279

  
280
		/// xml.putProperty("m_type", m_type);
281
		xml.putProperty("tag", getTag());
282

  
283
		/// xml.addChild(m_symbol.getXMLEntity());
284 115
		return xml;
285 116
	}
286 117

  
287 118
	/**
288
	 * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
289
	 *
290
	 * @param xml XMLEntity
291
	 *
292
	 * @return Objeto de esta clase.
293
	 */
294
	public static FFrameGraphics createFFrameGraphics(XMLEntity xml) {
295
		FFrameGraphics fframe = new FFrameGraphics();
296

  
297
		if (xml.getIntProperty("m_Selected") != 0) {
298
			fframe.setSelected(true);
299
		} else {
300
			fframe.setSelected(false);
301
		}
302

  
303
		/// fframe.m_type = xml.getIntProperty("m_type");
304
		/// fframe.m_symbol = FSymbol.createFSymbol(xml.getChild(0));
305
		return fframe;
306
	}
307

  
308
	/**
309 119
	 * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
310 120
	 */
311 121
	public void updateNum() {
......
340 150
		throws DriverException {
341 151
		draw(g, at, null, null);
342 152
	}
153
	/**
154
	 * @see com.iver.cit.gvsig.gui.layout.fframes.FFrame#draw(java.awt.Graphics2D, java.awt.geom.AffineTransform, java.awt.geom.Rectangle2D, java.awt.image.BufferedImage)
155
	 */
156
	public void draw(Graphics2D g, AffineTransform at, Rectangle2D r, BufferedImage imgBase) throws DriverException {
157
		EditableFeatureSource efs=cta.getEditableFeatureSource();
158
		try {
159
			for (int i=0;i<efs.getGeometryCount();i++){
160
				try {
161
					IGeometry geometry=efs.getGeometry(i);
162
					geometry.draw(g,at,CadTool.drawingSymbol);//Cada gr?fico tendr? su propio s?mbolo.
163
					if (cta.getSelection().get(i)){
164
						Handler[] handlers=geometry.getHandlers(FGeometry.SELECTHANDLER);
165
							FGraphicUtilities.DrawHandlers((Graphics2D)g,new AffineTransform(),handlers);
166
						
167
					}
168
				} catch (IOException e1) {
169
					e1.printStackTrace();
170
				}
171
			}
172
			
173
		} catch (DriverIOException e) {
174
			e.printStackTrace();
175
		}
176
		
177
	}
178
	public void drawHandlers(Graphics2D g) {
179
		EditableFeatureSource efs=cta.getEditableFeatureSource();
180
	/*	int[] indexes = efs.getGeometriesIndexes(r);
181
		//Recorrer todas las geometrias
182
		for (int i=0;i<geometries.size();i++){
183
			//Recorrer todos los handlers y ver 
184
			//si hay alguno que se ajuste al puntero del rat?n con su tolerancia.
185
			IGeometry ig = efs.getGeometry(indexes[i]);
186
			if (ig == null) continue;
187
			if (selectionSupport.isSelected(indexes[i])){
188
				Handler[] handlers=ig.getHandlers(FGeometry.SELECTHANDLER);
189
				FGraphicUtilities.DrawHandlers((Graphics2D)g,viewPort.getAffineTransform(),handlers);
190
				ig.draw(g, at, symbol);
191
			}
192
		}*/
193
	}
343 194
}

Also available in: Unified diff