Revision 29086

View differences:

tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/lib3DMap-share/src/test/java/com/iver/ai2/gvsig3d/AppTest.java
1
package com.iver.ai2.gvsig3d;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestCase;
5
import junit.framework.TestSuite;
6

  
7
/**
8
 * Unit test for simple App.
9
 */
10
public class AppTest 
11
    extends TestCase
12
{
13
    /**
14
     * Create the test case
15
     *
16
     * @param testName name of the test case
17
     */
18
    public AppTest( String testName )
19
    {
20
        super( testName );
21
    }
22

  
23
    /**
24
     * @return the suite of tests being tested
25
     */
26
    public static Test suite()
27
    {
28
        return new TestSuite( AppTest.class );
29
    }
30

  
31
    /**
32
     * Rigourous Test :-)
33
     */
34
    public void testApp()
35
    {
36
        assertTrue( true );
37
    }
38
}
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/symbols/BaseExtrusionSymbol.java
1
package com.iver.ai2.gvsig3d.legend.symbols;
2

  
3
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol;
4
import com.iver.utiles.XMLEntity;
5

  
6
public class BaseExtrusionSymbol extends SimpleFillSymbol implements
7
		IExtrusionSymbol {
8

  
9
	private double extrusion = 0.0;
10

  
11
	public double getExtrusion() {
12
		return this.extrusion;
13
	}
14

  
15
	public void setExtrusion(double extrusion) {
16
		this.extrusion = extrusion;
17
	}
18

  
19
	public BaseExtrusionSymbol(double extrusion) {
20
		super();
21
		this.extrusion = extrusion;
22
	}
23
	
24

  
25
	public String getClassName() {
26
		return getClass().getName();
27
	}
28

  
29
	public XMLEntity getXMLEntity() {
30
		XMLEntity xml = super.getXMLEntity();
31
		xml.putProperty("extrusion", this.extrusion);
32
		return xml;
33
	}
34

  
35
	public void setXMLEntity(XMLEntity xml) {
36
		super.setXMLEntity(xml);
37
		if (xml.contains("extrusion"))
38
			extrusion = xml.getDoubleProperty("extrusion");
39
	}
40

  
41
	
42
}
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/symbols/Object3DMarkerSymbol.java
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
/* CVS MESSAGES:
43
 *
44
 * $Id: PictureMarkerSymbol.java 15593 2007-10-29 13:01:13Z jdominguez $
45
 * $Log$
46
 * Revision 1.17  2007-09-21 12:25:32  jaume
47
 * cancellation support extended down to the IGeometry and ISymbol level
48
 *
49
 * Revision 1.16  2007/09/19 16:22:04  jaume
50
 * removed unnecessary imports
51
 *
52
 * Revision 1.15  2007/09/11 07:46:55  jaume
53
 * *** empty log message ***
54
 *
55
 * Revision 1.14  2007/08/16 06:55:19  jvidal
56
 * javadoc updated
57
 *
58
 * Revision 1.13  2007/08/09 06:42:24  jvidal
59
 * javadoc
60
 *
61
 * Revision 1.12  2007/08/08 12:05:17  jvidal
62
 * javadoc
63
 *
64
 * Revision 1.11  2007/07/18 06:54:35  jaume
65
 * continuing with cartographic support
66
 *
67
 * Revision 1.10  2007/07/03 10:58:29  jaume
68
 * first refactor on CartographicSupport
69
 *
70
 * Revision 1.9  2007/06/29 13:07:01  jaume
71
 * +PictureLineSymbol
72
 *
73
 * Revision 1.8  2007/06/11 12:25:48  jaume
74
 * ISymbol drawing integration tests (markers and lines)
75
 *
76
 * Revision 1.7  2007/06/07 06:50:40  jaume
77
 * *** empty log message ***
78
 *
79
 * Revision 1.6  2007/05/29 15:46:37  jaume
80
 * *** empty log message ***
81
 *
82
 * Revision 1.5  2007/05/08 08:47:40  jaume
83
 * *** empty log message ***
84
 *
85
 * Revision 1.4  2007/03/21 17:36:22  jaume
86
 * *** empty log message ***
87
 *
88
 * Revision 1.3  2007/03/09 11:20:57  jaume
89
 * Advanced symbology (start committing)
90
 *
91
 * Revision 1.1.2.4  2007/02/21 07:34:09  jaume
92
 * labeling starts working
93
 *
94
 * Revision 1.1.2.3  2007/02/16 10:54:12  jaume
95
 * multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
96
 *
97
 * Revision 1.1.2.2  2007/02/15 16:23:44  jaume
98
 * *** empty log message ***
99
 *
100
 * Revision 1.1.2.1  2007/02/09 07:47:05  jaume
101
 * Isymbol moved
102
 *
103
 * Revision 1.1  2007/01/24 17:58:22  jaume
104
 * new features and architecture error fixes
105
 *
106
 *
107
 */
108
package com.iver.ai2.gvsig3d.legend.symbols;
109

  
110
import java.awt.Graphics2D;
111
import java.awt.Rectangle;
112
import java.awt.geom.AffineTransform;
113
import java.io.IOException;
114
import java.net.MalformedURLException;
115
import java.net.URL;
116

  
117
import javax.swing.ImageIcon;
118

  
119
import org.apache.log4j.Logger;
120
import org.gvsig.osgvp.Vec3;
121

  
122
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
123
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
124
import com.iver.andami.PluginServices;
125
import com.iver.andami.ui.mdiManager.IWindow;
126
import com.iver.cit.gvsig.fmap.MapContext;
127
import com.iver.cit.gvsig.fmap.Messages;
128
import com.iver.cit.gvsig.fmap.core.FShape;
129
import com.iver.cit.gvsig.fmap.core.IGeometry;
130
import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarkerSymbol;
131
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
132
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException;
133
import com.iver.cit.gvsig.fmap.layers.FLayer;
134
import com.iver.cit.gvsig.fmap.layers.FLayers;
135
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
136
import com.iver.utiles.XMLEntity;
137
import com.iver.utiles.swing.threads.Cancellable;
138

  
139
public class Object3DMarkerSymbol extends AbstractMarkerSymbol {
140
	private static final float SELECTION_OPACITY_FACTOR = .3F;
141
	// transient private Image img;
142
	private String object3DPath;
143
	private boolean selected;
144
	private Vec3 scale;
145
	private Vec3 rotation;
146
	private boolean autoRotate = false;
147
	private String tempScreenshotimage;
148

  
149
	// transient private Image selImg;
150

  
151
	public boolean isAutoRotate() {
152
		return autoRotate;
153
	}
154

  
155
	public void setAutoRotate(boolean autoRotate) {
156
		this.autoRotate = autoRotate;
157
	}
158

  
159
	/**
160
	 * Constructor method
161
	 */
162
	public Object3DMarkerSymbol() {
163
		super();
164
	}
165

  
166
	/**
167
	 * Constructor method
168
	 * 
169
	 * @param imageURL
170
	 *            , URL of the normal image
171
	 * @param selImageURL
172
	 *            , URL of the image when it is selected in the map
173
	 * @throws IOException
174
	 */
175
	public Object3DMarkerSymbol(URL object3DURL) throws IOException {
176
		setObject3DPath(object3DURL);
177
	}
178

  
179
	public Object3DMarkerSymbol(String object3DPath) throws IOException {
180
		this.object3DPath = object3DPath;
181
	}
182

  
183
	/**
184
	 * Sets the file for the image to be used as a marker symbol
185
	 * 
186
	 * @param imageFile
187
	 *            , File
188
	 * @throws IOException
189
	 */
190
	public void setObject3DPath(URL Object3DUrl) throws IOException {
191
		object3DPath = Object3DUrl.toString();
192
	}
193

  
194
	public ISymbol getSymbolForSelection() {
195
		return null;
196
	}
197

  
198
	public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp,
199
			Cancellable cancel) {
200
		// FPoint2D p = (FPoint2D) shp;
201
		// double x, y;
202
		// int size = (int) Math.round(getSize());
203
		// double halfSize = getSize()/2;
204
		// x = p.getX() - halfSize;
205
		// y = p.getY() - halfSize;
206
		// int xOffset = (int) getOffset().getX();
207
		// int yOffset = (int) getOffset().getY();
208
		//
209
		// if (size > 0) {
210
		// BackgroundFileStyle bg = (!selected) ? bgImage : bgSelImage ;
211
		// Rectangle rect = new Rectangle( size, size );
212
		// g.translate(x+xOffset, y+yOffset);
213
		// g.rotate(getRotation(), halfSize, halfSize);
214
		// try {
215
		// bg.drawInsideRectangle(g, rect);
216
		// } catch (SymbolDrawingException e) {
217
		// Logger.getLogger(getClass()).warn(Messages.getString(
218
		// "label_style_could_not_be_painted"), e);
219
		// }
220
		// g.rotate(-getRotation(), halfSize, halfSize);
221
		// g.translate(-(x+xOffset), -(y+yOffset));
222
		//
223
		// }
224

  
225
	}
226

  
227
	public void drawInsideRectangle(Graphics2D g,
228
			AffineTransform scaleInstance, Rectangle r)
229
			throws SymbolDrawingException {
230
		// TODO Auto-generated method stub
231
		// super.drawInsideRectangle(g, scaleInstance, r);
232

  
233
		ImageIcon image;
234
		// Setting the size symbol
235
		int size = 30;
236

  
237
		// Generating the image
238
//		image = new ImageIcon(
239
//				"c:/Documents and Settings/Julio.IVER/Escritorio/img.png");
240
		image = new ImageIcon(tempScreenshotimage);
241
		int x = 0;
242
		int y = 0;
243
		if (g.getClipBounds() != null) {
244
			x = (int) (g.getClipBounds().getCenterX() - (size / 2));
245
			y = (int) (g.getClipBounds().getCenterY() - (size / 2));
246
		}
247
		g.drawImage(image.getImage(), x, y, size, size, null, null);
248

  
249
	}
250

  
251
	public XMLEntity getXMLEntity() {
252
		XMLEntity xml = new XMLEntity();
253
		xml.putProperty("className", getClassName());
254
		xml.putProperty("isShapeVisible", isShapeVisible());
255
		xml.putProperty("desc", getDescription());
256
		xml.putProperty("imagePath", object3DPath);
257
		xml.putProperty("tempScreenshotimage",tempScreenshotimage);
258

  
259
		xml.putProperty("scalex", scale.x());
260
		xml.putProperty("scaley", scale.y());
261
		xml.putProperty("scalez", scale.z());
262
		
263
		xml.putProperty("rotationx", rotation.x());
264
		xml.putProperty("rotationy", rotation.y());
265
		xml.putProperty("rotationz", rotation.z());
266
		
267
		xml.putProperty("autoRotate", isAutoRotate());
268
		
269

  
270
		return xml;
271
	}
272

  
273
	@Override
274
	public boolean isSuitableFor(IGeometry geom) {
275
		boolean suitable = false;
276
		com.iver.andami.ui.mdiManager.IWindow[] f = PluginServices
277
				.getMDIManager().getAllWindows();
278
		if (f == null) {
279
			return false;
280
		}
281
		for (int i = 0; i < f.length; i++) {
282
			if (f[i] instanceof BaseView) {
283
				BaseView view = (BaseView) f[i];
284
				MapContext mapContext = view.getMapControl().getMapContext();
285
				FLayers layer = mapContext.getLayers();
286
				FLayer[] actives = layer.getActives();
287
				if (actives.length == 1) {
288
					Layer3DProps props3D = Layer3DProps
289
							.getLayer3DProps(actives[0]);
290
					if ((props3D != null)
291
							&& (props3D.getType() == Layer3DProps.layer3DVector)) {
292
						suitable = true;
293
					} else {
294
						suitable = false;
295
					}
296
				}
297
			}
298

  
299
		}
300
		System.out.println("is suitable " + suitable);
301
		return suitable;
302
	}
303

  
304
	public String getClassName() {
305
		return getClass().getName();
306
	}
307

  
308
	public void setXMLEntity(XMLEntity xml) {
309
		setDescription(xml.getStringProperty("desc"));
310
		setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
311
		object3DPath = xml.getStringProperty("imagePath");
312
		tempScreenshotimage = xml.getStringProperty("tempScreenshotimage");
313
//		setRotation(xml.getDoubleProperty("rotation"));
314
		
315
		this.scale = new Vec3();
316
		scale.setX(xml.getDoubleProperty("scalex"));
317
		scale.setY(xml.getDoubleProperty("scaley"));
318
		scale.setZ(xml.getDoubleProperty("scalez"));
319

  
320
		this.rotation = new Vec3();
321
		rotation.setX(xml.getDoubleProperty("rotationx"));
322
		rotation.setY(xml.getDoubleProperty("rotationy"));
323
		rotation.setZ(xml.getDoubleProperty("rotationz"));
324
		
325
		setAutoRotate(xml.getBooleanProperty("autoRotate"));
326
		
327

  
328
		try {
329
			setObject3DPath(new URL(object3DPath));
330
		} catch (MalformedURLException e) {
331
			Logger.getLogger(getClass()).error(
332
					Messages.getString("invalid_url"));
333
		} catch (IOException e) {
334
			Logger.getLogger(getClass()).error(
335
					Messages.getString("invalid_url"));
336

  
337
		}
338

  
339
	}
340

  
341
	public void print(Graphics2D g, AffineTransform at, FShape shape)
342
			throws ReadDriverException {
343
		// TODO Implement it
344
		throw new Error("Not yet implemented!");
345

  
346
	}
347

  
348
	/**
349
	 * Returns the path of the image that is used as a marker symbol
350
	 * 
351
	 * @return imagePath,String
352
	 */
353
	public String getObject3DPath() {
354
		return object3DPath;
355
	}
356

  
357
	public void setScale(Vec3 scale) {
358
		this.scale = scale;
359
		
360
	}
361

  
362
	public void setRotation(Vec3 rotation) {
363
		this.rotation = rotation;
364
		
365
	}
366

  
367
	public Vec3 getScale() {
368
		return this.scale;
369
	}
370

  
371
	public Vec3 getRotationObject() {
372
		return this.rotation;
373
	
374
	}
375

  
376
	public void setSnapshot(String tempScreenshotimage) {
377
		this.tempScreenshotimage = tempScreenshotimage;
378
		
379
	}
380

  
381
}
0 382

  
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/symbols/ExtrusionLineSymbol.java
1
package com.iver.ai2.gvsig3d.legend.symbols;
2

  
3
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol;
4

  
5
public class ExtrusionLineSymbol extends SimpleLineSymbol implements IExtrusionSymbol {
6

  
7
	
8
	private double extrusion = 0.0;
9
	
10
	public ExtrusionLineSymbol() {
11
		// TODO Auto-generated constructor stub
12
	}
13
	
14
	public double getExtrusion() {
15
		return this.extrusion;
16
	}
17

  
18
	public void setExtrusion(double extrusion) {
19
		this.extrusion = extrusion;
20
	}
21

  
22

  
23
}
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/symbols/ExtrusionPolygonSymbol.java
1
package com.iver.ai2.gvsig3d.legend.symbols;
2

  
3
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol;
4

  
5
public class ExtrusionPolygonSymbol extends SimpleFillSymbol implements
6
		IExtrusionSymbol {
7

  
8
	private double extrusion = 0.0;
9

  
10
	public ExtrusionPolygonSymbol() {
11
		// TODO Auto-generated constructor stub
12
	}
13
	
14
	public double getExtrusion() {
15
		return this.extrusion;
16
	}
17

  
18
	public void setExtrusion(double extrusion) {
19
		this.extrusion = extrusion;
20
	}
21

  
22
}
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/symbols/IExtrusionSymbol.java
1
package com.iver.ai2.gvsig3d.legend.symbols;
2

  
3
public interface IExtrusionSymbol {
4
	
5
	public void setExtrusion(double extrusion);
6
	
7
	public  double getExtrusion();
8

  
9
}
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/symbols/Object3DMarker.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.ai2.gvsig3d.legend.symbols;
42

  
43
import java.awt.Checkbox;
44
import java.awt.Component;
45
import java.awt.Dimension;
46
import java.awt.Font;
47
import java.awt.GridBagConstraints;
48
import java.awt.GridBagLayout;
49
import java.awt.event.ActionEvent;
50
import java.awt.event.ActionListener;
51
import java.io.File;
52
import java.io.FileNotFoundException;
53
import java.io.IOException;
54
import java.util.ArrayList;
55
import java.util.Iterator;
56
import java.util.List;
57

  
58
import javax.swing.JButton;
59
import javax.swing.JCheckBox;
60
import javax.swing.JFileChooser;
61
import javax.swing.JLabel;
62
import javax.swing.JOptionPane;
63
import javax.swing.JPanel;
64
import javax.swing.JTextField;
65
import javax.swing.filechooser.FileFilter;
66

  
67
import org.gvsig.osgvp.Node;
68
import org.gvsig.osgvp.Vec3;
69
import org.gvsig.osgvp.osgDB;
70
import org.gvsig.osgvp.exceptions.node.LoadNodeException;
71
import org.gvsig.osgvp.viewer.IViewerContainer;
72
import org.gvsig.osgvp.viewer.ViewerFactory;
73

  
74
import com.iver.ai2.gvsig3d.resources.MyFileFilter3D;
75
import com.iver.andami.PluginServices;
76
import com.iver.andami.messages.NotificationManager;
77
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
78
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
79
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException;
80
import com.iver.cit.gvsig.gui.styling.AbstractTypeSymbolEditor;
81
import com.iver.cit.gvsig.gui.styling.EditorTool;
82
import com.iver.cit.gvsig.gui.styling.Mask;
83
import com.iver.cit.gvsig.gui.styling.SymbolEditor;
84

  
85
/**
86
 * PictureMarker allows the user to store and modify the properties that define
87
 * a <b>picture marker symbol</b>.
88
 * <p>
89
 * <p>
90
 * This functionality is carried out thanks to a tab (simple marker)which is
91
 * included in the panel to edit the properities of a symbol (SymbolEditor)how
92
 * is explained in AbstractTypeSymbolEditor.
93
 * <p>
94
 * First of all, in the above mentioned tab the user will have options to change
95
 * the files from where the pictures for the symbol are taken (one for the
96
 * symbol when it is not selected in the map and the other when it is done).
97
 * <p>
98
 * <p>
99
 * Secondly, the user will have options to modify the pictures which had been
100
 * selected before (width and offset) .
101
 * 
102
 *@see AbstractTypeSymbolEditor
103
 *@author jaume dominguez faus - jaume.dominguez@iver.es
104
 */
105
public class Object3DMarker extends AbstractTypeSymbolEditor implements
106
		ActionListener {
107
	protected ArrayList<JPanel> tabs = new ArrayList<JPanel>();
108
	protected Mask mask;
109
	protected JLabel lblFileName;
110
	protected JLabel lblSelFileName;
111
	private JButton btn;
112
	private File fileOSG;
113
	private String filePath = "";
114
	
115
	private static String lastPath = "";
116

  
117
	public String getFilePath() {
118
		return filePath;
119
	}
120

  
121
	public void setFilePath(String filePath) {
122
		this.filePath = filePath;
123
	}
124

  
125
	private ActionListener chooseAction = new ActionListener() {
126

  
127

  
128
		public void actionPerformed(ActionEvent e) {
129

  
130
			JFileChooser jfc = new JFileChooser(lastPath);
131
			jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
132
			
133
			
134
			List filterListFile =  new ArrayList<MyFileFilter3D>();
135
			
136
			filterListFile.add(new MyFileFilter3D("ive",
137
					PluginServices.getText(this, "Ficheros *.ive"), "ive"));
138
			filterListFile.add(new MyFileFilter3D("3ds",
139
					PluginServices.getText(this, "Ficheros *.3ds"), "3ds"));
140
			filterListFile.add(new MyFileFilter3D("obj",
141
					PluginServices.getText(this, "Ficheros *.obj"), "obj"));
142
			filterListFile.add(new MyFileFilter3D("osg",
143
					PluginServices.getText(this, "Ficheros *.osg"), "osg"));
144

  
145
			Iterator iter = filterListFile.iterator();
146
			while (iter.hasNext()) {
147
				jfc.addChoosableFileFilter((FileFilter) iter.next());
148
			}
149

  
150
			if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
151

  
152
				fileOSG = jfc.getSelectedFile();
153
				if (fileOSG.exists()) {// file don't exists in the directory.
154

  
155
					MyFileFilter3D filter = (MyFileFilter3D) jfc
156
							.getFileFilter();
157
					fileOSG = filter.normalizeExtension(fileOSG);
158
					filePath = fileOSG.getAbsolutePath();
159
					filePathTextField.setText(filePath);
160
					updatePreview();
161
					lastPath = fileOSG.getPath();
162
				} else {
163
					JOptionPane.showMessageDialog(null,
164
							"El fichero no existe.", "Fichero no encontrado",
165
							JOptionPane.WARNING_MESSAGE);
166
					return;
167
				}
168
			}// If aprove option.
169

  
170
		}
171

  
172
	};
173
	private IViewerContainer _canvas3d;
174
	private JPanel topPanel;
175
	private JPanel leftBottomPanel;
176
	private JPanel rigthBottomPanel;
177
	private JTextField rotationTextFieldX;
178
	private JTextField scaleTextFieldX;
179
	private JTextField rotationTextFieldZ;
180
	private JTextField rotationTextFieldY;
181
	private JTextField scaleTextFieldY;
182
	private JTextField scaleTextFieldZ;
183
	private JTextField filePathTextField;
184
	private JCheckBox autorotate;
185
	private String tempScreenshotimage;
186

  
187
	public Object3DMarker(SymbolEditor owner) {
188
		super(owner);
189
		initialize();
190
		
191
	
192
	}
193

  
194
	
195
	@Override
196
	protected void finalize() throws Throwable {
197
		// TODO Auto-generated method stub
198
		super.finalize();
199
		// this part is for test
200
		ViewerFactory.getInstance().stopAnimator();
201
		_canvas3d.dispose();
202
		///////////////////////////
203
	}
204

  
205
	/**
206
	 * Initializes the parameters that define a picturmarker.To do it, a tab is
207
	 * created inside the SymbolEditor panel with default values for the
208
	 * different attributes of the picture marker.
209
	 */
210

  
211
	private void initialize() {
212
		JPanel myTab = new JPanel(new GridBagLayout());
213
		myTab.setName("3D Object");
214

  
215
		// Top panel
216
		GridBagConstraints topPanelConstrain = new GridBagConstraints();
217
		topPanelConstrain.gridx = 0;
218
		topPanelConstrain.gridy = 0;
219
		topPanelConstrain.gridwidth = 2;
220
		topPanelConstrain.fill = GridBagConstraints.BOTH;
221
		topPanelConstrain.weightx = 1.0;
222
		topPanelConstrain.weighty = 1.0;
223
		myTab.add(getTopPanel(), topPanelConstrain);
224

  
225
		// bottom left panel
226
		GridBagConstraints leftBottomPanelConstrain = new GridBagConstraints();
227
		leftBottomPanelConstrain.gridx = 0;
228
		leftBottomPanelConstrain.gridy = 1;
229
		leftBottomPanelConstrain.fill = GridBagConstraints.BOTH;
230
		leftBottomPanelConstrain.weightx = 0.5;
231
		leftBottomPanelConstrain.weighty = 1.0;
232
		myTab.add(getLeftBottomPanel(), leftBottomPanelConstrain);
233

  
234
		// Bottom right panel
235
		GridBagConstraints rigthBottomPanelConstrain = new GridBagConstraints();
236
		rigthBottomPanelConstrain.gridx = 1;
237
		rigthBottomPanelConstrain.gridy = 1;
238
		rigthBottomPanelConstrain.fill = GridBagConstraints.BOTH;
239
		rigthBottomPanelConstrain.weightx = 0.5;
240
		rigthBottomPanelConstrain.weighty = 1.0;
241
		myTab.add(getRigthBottomPanel(), rigthBottomPanelConstrain);
242
		
243
	
244
		tabs.add(myTab);
245
		
246
		
247
		PluginServices core = PluginServices.getPluginServices("com.iver.core");
248
		if (core!= null){
249
			if (core.getPersistentXML().contains("DataFolder")){
250
				
251
				lastPath = core.getPersistentXML().getStringProperty("DataFolder");
252
			}
253
		}
254
	}
255

  
256
	private JPanel getTopPanel() {
257
		if (topPanel == null) {
258
			topPanel = new JPanel(new GridBagLayout());
259
			// topPanel.setBorder(new LineBorder(Color.gray));
260
			GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
261
			gridBagConstraints.gridx = 0;
262
			gridBagConstraints.gridy = 0;
263
			gridBagConstraints.anchor = GridBagConstraints.WEST;
264
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
265
			// picture file label
266
			lblFileName = new JLabel("Seleccione fihero :");
267
//			lblFileName.setFont(lblFileName.getFont().deriveFont(Font.BOLD));
268

  
269
			topPanel.add(lblFileName, gridBagConstraints);
270

  
271
			gridBagConstraints = new java.awt.GridBagConstraints();
272
			gridBagConstraints.gridx = 0;
273
			gridBagConstraints.gridy = 1;
274
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
275
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
276
			gridBagConstraints.weightx = 0.75;
277

  
278
			filePathTextField = new JTextField();
279
			topPanel.add(filePathTextField, gridBagConstraints);
280

  
281
			gridBagConstraints.gridx = 1;
282
			gridBagConstraints.gridy = 1;
283
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
284
			gridBagConstraints.weightx = 0.25;
285
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
286

  
287
			// button browse
288
			btn = new JButton(PluginServices.getText(this, "browse"));
289
			btn.addActionListener(chooseAction);
290
			
291
			topPanel.add(btn, gridBagConstraints);
292
			
293
			gridBagConstraints.gridx = 0;
294
			gridBagConstraints.gridy = 2;
295
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
296
//			gridBagConstraints.weightx = 0.25;
297
			
298
			autorotate = new JCheckBox();
299
			autorotate.setSelected(false);
300
			autorotate.setText("Autorotate");
301
			
302
			
303
			topPanel.add(autorotate, gridBagConstraints);
304

  
305
		}
306
		return topPanel;
307
	}
308

  
309
	public JCheckBox getAutorotate() {
310
		return autorotate;
311
	}
312

  
313
	public void setAutorotate(JCheckBox autorotate) {
314
		this.autorotate = autorotate;
315
	}
316

  
317
	private JPanel getLeftBottomPanel() {
318
		if (leftBottomPanel == null) {
319
			leftBottomPanel = new JPanel(new GridBagLayout());
320
			// leftBottomPanel.setBorder(new LineBorder(Color.gray));
321

  
322
			Component transLabel = new JLabel("Transformaciones :");
323
			transLabel.setName("jLabel1"); // NOI18N
324
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
325
			gridBagConstraints.gridx = 0;
326
			gridBagConstraints.gridy = 0;
327
			gridBagConstraints.gridwidth = 2;
328
			gridBagConstraints.anchor = GridBagConstraints.WEST;
329
			leftBottomPanel.add(transLabel, gridBagConstraints);
330

  
331
			// Scale X
332
			Component scaleXLabel = new JLabel("Escalado X");
333
			scaleXLabel.setName("jLabel2"); // NOI18N
334
			gridBagConstraints = new java.awt.GridBagConstraints();
335
			gridBagConstraints.gridx = 0;
336
			gridBagConstraints.gridy = 1;
337
			gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
338
			leftBottomPanel.add(scaleXLabel, gridBagConstraints);
339

  
340
			scaleTextFieldX = new JTextField();
341
			// scaleTextFieldX.setName(); // NOI18N
342
			scaleTextFieldX.setText("1");
343
			gridBagConstraints = new java.awt.GridBagConstraints();
344
			gridBagConstraints.gridx = 1;
345
			gridBagConstraints.gridy = 1;
346
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
347
			gridBagConstraints.weightx = 1.0;
348
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
349
			leftBottomPanel.add(scaleTextFieldX, gridBagConstraints);
350

  
351
			// Rotation Y
352
			Component scaleYLabel = new JLabel("Escalado Y");
353
			scaleYLabel.setName("jLabel5"); // NOI18N
354
			gridBagConstraints = new java.awt.GridBagConstraints();
355
			gridBagConstraints.gridx = 0;
356
			gridBagConstraints.gridy = 2;
357
			gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
358
			leftBottomPanel.add(scaleYLabel, gridBagConstraints);
359

  
360
			scaleTextFieldY = new JTextField();
361
//			scaleTextFieldY.setName("0"); // NOI18N
362
			scaleTextFieldY.setText("1");
363
			gridBagConstraints = new java.awt.GridBagConstraints();
364
			gridBagConstraints.gridx = 1;
365
			gridBagConstraints.gridy = 2;
366
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
367
			gridBagConstraints.weightx = 1.0;
368
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
369
			leftBottomPanel.add(scaleTextFieldY, gridBagConstraints);
370

  
371
			// Rotation Z
372
			Component scaleZLabel = new JLabel("Escalado Z");
373
			scaleZLabel.setName("jLabel5"); // NOI18N
374
			gridBagConstraints = new java.awt.GridBagConstraints();
375
			gridBagConstraints.gridx = 0;
376
			gridBagConstraints.gridy = 3;
377
			gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
378
			leftBottomPanel.add(scaleZLabel, gridBagConstraints);
379

  
380
			scaleTextFieldZ = new JTextField();
381
//			scaleTextFieldZ.setName("0"); // NOI18N
382
			scaleTextFieldZ.setText("1");
383
			gridBagConstraints = new java.awt.GridBagConstraints();
384
			gridBagConstraints.gridx = 1;
385
			gridBagConstraints.gridy = 3;
386
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
387
			gridBagConstraints.weightx = 1.0;
388
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
389
			leftBottomPanel.add(scaleTextFieldZ, gridBagConstraints);
390

  
391
			// Rotation X
392
			Component rotationXLabel = new JLabel("Rotacion X");
393
			rotationXLabel.setName("jLabel5"); // NOI18N
394
			gridBagConstraints = new java.awt.GridBagConstraints();
395
			gridBagConstraints.gridx = 0;
396
			gridBagConstraints.gridy = 4;
397
			gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
398
			leftBottomPanel.add(rotationXLabel, gridBagConstraints);
399

  
400
			rotationTextFieldX = new JTextField();
401
//			rotationTextFieldX.setName("0"); // NOI18N
402
			rotationTextFieldX.setText("0");
403
			gridBagConstraints = new java.awt.GridBagConstraints();
404
			gridBagConstraints.gridx = 1;
405
			gridBagConstraints.gridy = 4;
406
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
407
			gridBagConstraints.weightx = 1.0;
408
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
409
			leftBottomPanel.add(rotationTextFieldX, gridBagConstraints);
410

  
411
			// Rotation Y
412
			Component rotationYLabel = new JLabel("Rotacion Y");
413
			rotationYLabel.setName("jLabel3"); // NOI18N
414
			gridBagConstraints = new java.awt.GridBagConstraints();
415
			gridBagConstraints.gridx = 0;
416
			gridBagConstraints.gridy = 5;
417
			gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
418
			leftBottomPanel.add(rotationYLabel, gridBagConstraints);
419

  
420
			rotationTextFieldY = new JTextField();
421
			rotationTextFieldY.setName("0"); // NOI18N
422
			rotationTextFieldY.setText("0");
423
			gridBagConstraints = new java.awt.GridBagConstraints();
424
			gridBagConstraints.gridx = 1;
425
			gridBagConstraints.gridy = 5;
426
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
427
			gridBagConstraints.weightx = 1.0;
428
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
429
			leftBottomPanel.add(rotationTextFieldY, gridBagConstraints);
430

  
431
			// Rotation Z
432
			Component rotationZlabel = new JLabel("Rotacion Z");
433
			rotationZlabel.setName("jLabel4"); // NOI18N
434
			gridBagConstraints = new java.awt.GridBagConstraints();
435
			gridBagConstraints.gridx = 0;
436
			gridBagConstraints.gridy = 6;
437
			gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
438
			leftBottomPanel.add(rotationZlabel, gridBagConstraints);
439

  
440
			rotationTextFieldZ = new JTextField();
441
//			rotationTextFieldZ.setName("0"); // NOI18N
442
			rotationTextFieldZ.setText("0");
443
			gridBagConstraints = new java.awt.GridBagConstraints();
444
			gridBagConstraints.gridx = 1;
445
			gridBagConstraints.gridy = 6;
446
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
447
			gridBagConstraints.weightx = 1.0;
448
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
449
			leftBottomPanel.add(rotationTextFieldZ, gridBagConstraints);
450
		}
451
		return leftBottomPanel;
452
	}
453

  
454
	private JPanel getRigthBottomPanel() {
455
		if (rigthBottomPanel == null) {
456
			rigthBottomPanel = new JPanel(new GridBagLayout());
457
			// rigthBottomPanel.setBorder(new LineBorder(Color.gray));
458
			GridBagConstraints constrain = new GridBagConstraints();
459
			constrain.gridx = 0;
460
			constrain.gridy = 0;
461
			constrain.anchor = GridBagConstraints.WEST;
462
			// selection picture file
463
			lblSelFileName = new JLabel("Preview:");
464
			rigthBottomPanel.add(lblSelFileName, constrain);
465

  
466
			int size = 150;
467
			JPanel aux3 = new JPanel();
468
			aux3.setPreferredSize(new Dimension(size, size));
469
			_canvas3d = ViewerFactory.getInstance().createViewer(
470
					ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, null);
471
			ViewerFactory.getInstance().startAnimator();
472

  
473
			_canvas3d.setSize(size, size);
474
			
475
			updatePreview();
476

  
477
			constrain.gridx = 0;
478
			constrain.gridy = 1;
479
			aux3.add((Component) _canvas3d);
480
			rigthBottomPanel.add(aux3, constrain);
481
			
482
			
483
		}
484
		return rigthBottomPanel;
485
	}
486
	
487
	
488
	private void updatePreview(){
489
		try {
490
			Node node = null;
491
			if (this.getFilePath() == "") {
492
				node = osgDB.readNodeFile("D:/modelos3d/cow.ive");
493
			} else {
494
				node = osgDB.readNodeFile(filePath);
495
			}
496
			_canvas3d.getOSGViewer().setSceneData(node);
497
			tempScreenshotimage = System.getenv("TMP")+"/tempScreenshotimage.png";
498
			System.err.println("screenshot del simbolo " + tempScreenshotimage);
499
			_canvas3d.getOSGViewer().takeScreenshot(tempScreenshotimage);
500
		} catch (LoadNodeException e) {
501
			// TODO Auto-generated catch block
502
			e.printStackTrace();
503
		} catch (FileNotFoundException e) {
504
			// TODO Auto-generated catch block
505
			e.printStackTrace();
506
		}
507
	}
508

  
509
	public ISymbol getLayer() {
510
		// this method builds the new symbol and returns it to the legend
511
		// manager
512
		try {
513
			Object3DMarkerSymbol symbol = null;
514

  
515
			if (this.getFilePath().equals(""))
516
				symbol = null;
517
			else {
518
				symbol = new Object3DMarkerSymbol(this.getFilePath());
519
				symbol.setScale(new Vec3(Double.parseDouble(scaleTextFieldX
520
						.getText()), Double.parseDouble(scaleTextFieldY
521
						.getText()), Double.parseDouble(scaleTextFieldZ
522
						.getText())));
523
				symbol.setRotation(new Vec3(Double
524
						.parseDouble(rotationTextFieldX.getText()), Double
525
						.parseDouble(rotationTextFieldY.getText()), Double
526
						.parseDouble(rotationTextFieldZ.getText())));
527
				
528
				symbol.setAutoRotate(autorotate.isSelected());
529
				symbol.setSnapshot(tempScreenshotimage);
530
			}
531

  
532
			
533
			return symbol;
534
		} catch (IOException e) {
535
			return SymbologyFactory.getWarningSymbol(PluginServices.getText(
536
					this, "failed_acessing_files"), null,
537
					SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
538
		}
539

  
540
	}
541

  
542
	public void refreshControls(ISymbol layer) {
543

  
544
		// this method gets the simbol from the legend manager
545

  
546
		Object3DMarkerSymbol sym;
547
		try {
548
			String fileName = null;
549
			if (layer == null) {
550
				// initialize defaults
551
				System.err.println(getClass().getName()
552
						+ ":: should be unreachable code");
553
				fileName = "-";
554
			} else {
555
				sym = (Object3DMarkerSymbol) layer;
556
				fileName = sym.getObject3DPath();
557
			}
558

  
559
			this.setFilePath(fileName);
560

  
561
		} catch (IndexOutOfBoundsException ioEx) {
562
			NotificationManager.addWarning("Symbol layer index out of bounds",
563
					ioEx);
564
		} catch (ClassCastException ccEx) {
565
			NotificationManager.addWarning("Illegal casting from "
566
					+ layer.getClassName() + " to "
567
					+ getSymbolClass().getName() + ".", ccEx);
568
		}
569
	}
570

  
571
	public String getName() {
572
		return "Object 3D symbol";
573

  
574
	}
575

  
576
	public JPanel[] getTabs() {
577
		return tabs.toArray(new JPanel[tabs.size()]);
578
	}
579

  
580
	public Class getSymbolClass() {
581
		return Object3DMarkerSymbol.class;
582
	}
583

  
584
	public EditorTool[] getEditorTools() {
585
		return null;
586

  
587
	}
588

  
589
	public void actionPerformed(ActionEvent e) {
590
		fireSymbolChangedEvent();
591
	}
592

  
593
}
0 594

  
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/symbols/ExtrusionPointSymbol.java
1
package com.iver.ai2.gvsig3d.legend.symbols;
2

  
3
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol;
4

  
5
public class ExtrusionPointSymbol extends SimpleMarkerSymbol implements IExtrusionSymbol{
6

  
7
	private double extrusion = 0.0;
8
	
9
	public ExtrusionPointSymbol() {
10
		// TODO Auto-generated constructor stub
11
	}
12
	
13
	public double getExtrusion() {
14
		return this.extrusion;
15
	}
16

  
17
	public void setExtrusion(double extrusion) {
18
		this.extrusion = extrusion;
19
	}
20

  
21
}
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/extrusion/SymbolTableExtrusion.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*/
19
package com.iver.ai2.gvsig3d.legend.extrusion;
20

  
21
import java.awt.Component;
22
import java.awt.Dimension;
23
import java.awt.GridLayout;
24
import java.awt.Point;
25
import java.awt.Rectangle;
26
import java.awt.event.ActionListener;
27
import java.awt.event.MouseAdapter;
28
import java.awt.event.MouseEvent;
29
import java.util.ArrayList;
30
import java.util.Hashtable;
31

  
32
import javax.swing.JPanel;
33
import javax.swing.JScrollPane;
34
import javax.swing.event.ChangeEvent;
35
import javax.swing.table.DefaultTableModel;
36
import javax.swing.table.TableCellEditor;
37
import javax.swing.table.TableColumn;
38

  
39
import com.hardcode.gdbms.engine.values.NullValue;
40
import com.iver.andami.PluginServices;
41
import com.iver.andami.ui.mdiFrame.JMenuItem;
42
import com.iver.andami.ui.mdiFrame.JPopUpMenu;
43
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
44
import com.iver.cit.gvsig.fmap.rendering.NullIntervalValue;
45
import com.iver.cit.gvsig.fmap.rendering.NullUniqueValue;
46
import com.iver.cit.gvsig.project.documents.gui.SymbolCellEditor;
47
import com.iver.cit.gvsig.project.documents.gui.TableSymbolCellRenderer;
48
import com.iver.cit.gvsig.project.documents.view.legend.edition.gui.IntervalCellEditor;
49
import com.iver.cit.gvsig.project.documents.view.legend.edition.gui.ValueCellEditor;
50

  
51

  
52
import com.iver.utiles.swing.jtable.JTable;
53
import com.iver.utiles.swing.jtable.TextFieldCellEditor;
54

  
55
public class SymbolTableExtrusion  extends JPanel {
56
	private static final long serialVersionUID = -8694846716328735113L;
57
	private static Hashtable<String,TableCellEditor> cellEditors = new Hashtable<String,TableCellEditor>();
58

  
59
	public static final String VALUES_TYPE = "values";
60
	public static final String INTERVALS_TYPE = "intervals";
61
	private JTable table;
62
	private String type;
63
	private int shapeType;
64
	private OnTableMouseAdapter rightClickActions;
65

  
66
	/**
67
	 * Crea un nuevo FSymbolTable.
68
	 *
69
	 * @param type
70
	 *            tipo de valor si es intervalo: "intervals" y si es por
71
	 *            valores: "values".
72
	 */
73
	public SymbolTableExtrusion(Component ownerComponent, String type, int shapeType) {
74
		super(new GridLayout(1, 0));
75
		this.type = type;
76
		this.shapeType = shapeType;
77

  
78
		rightClickActions = new OnTableMouseAdapter();
79
		table = new JTable();
80
		table.setModel(new MyTableModel());
81
		table.setPreferredScrollableViewportSize(new Dimension(480, 110));
82

  
83
		initializeCellEditors();
84

  
85
		// Create the scroll pane and add the table to it.
86
		JScrollPane scrollPane = new JScrollPane(table);
87

  
88
		// Set up column sizes.
89
		// initColumnSizes(table);
90
		setUpSymbolColumn(table, table.getColumnModel().getColumn(0));
91

  
92
		if(cellEditors.get(type) == null)
93
			throw new Error("Symbol table type not set!");
94

  
95
		setUpValueColumn(table, table.getColumnModel().getColumn(0),cellEditors.get(this.type));
96
		setUpLabelColumn(table, table.getColumnModel().getColumn(1));
97

  
98
		// Add the scroll pane to this panel.
99
		add(scrollPane);
100
		table.setRowSelectionAllowed(true);
101
		table.addMouseListener(rightClickActions);
102
	}
103
	/**
104
	 * Inicializa los valores de los CellEditors que la SymbolTable poseer? por defecto
105
	 */
106
	private void initializeCellEditors() {
107
		this.cellEditors.put(this.INTERVALS_TYPE,new IntervalCellEditor());
108
		this.cellEditors.put(this.VALUES_TYPE, new ValueCellEditor());
109
	}
110
	/**
111
	 * A?ade un nuevo CellEditor a la lista de disponibles
112
	 *
113
	 * @param key String con el nombre identificativo del CellEditor
114
	 * @param cellEditor CellEditor que va a ser a?adido
115
	 */
116
	public static void addCellEditor(String key,TableCellEditor cellEditor ) {
117
		cellEditors.put(key, cellEditor);
118
	}
119
	/**
120
	 * Obtiene el valor de los elementos de una fila seleccionada
121
	 *
122
	 * @return Object[] Array con los objetos de cada una de las columnas de la fila seleccionada
123
	 */
124
	public Object[] getSelectedRowElements() {
125
		Object[] values = new Object[2];
126

  
127
		MyTableModel m = (MyTableModel) table.getModel();
128
		int[] selectedRows = table.getSelectedRows();
129

  
130
		if(selectedRows.length != 1)
131
			return null;
132

  
133
		for (int i = 0; i < 2; i++) {
134
			values[i] = m.getValueAt(selectedRows[0], i);
135
		}
136

  
137
		return values;
138
	}
139
	/**
140
	 * A?ade una fila al modelo.
141
	 *
142
	 * @param vector
143
	 *            Fila en forma de vector de Object para a?adir al modelo.
144
	 */
145
	public void addRow(Object[] vector) {
146
		MyTableModel m = (MyTableModel) table.getModel();
147
		m.addRow(vector);
148

  
149
	}
150

  
151
	/**
152
	 * Elimina la fila que tiene como clave el objeto que se pasa como
153
	 * par?metro.
154
	 *
155
	 * @param obj
156
	 *            clave del objeto a eliminar.
157
	 */
158
	public void removeRow(Object obj) {
159
		MyTableModel m = (MyTableModel) table.getModel();
160

  
161
		for (int i = 0; i < m.getRowCount(); i++) {
162
			if (m.getValueAt(i, 0) instanceof NullUniqueValue
163
					|| m.getValueAt(i, 0) instanceof NullIntervalValue) {
164
				m.removeRow(i);
165
			}
166
		}
167
	}
168

  
169
	/**
170
	 * Elimina las filas que est?n seleccionadas.
171
	 */
172
	public void removeSelectedRows() {
173
		if (table.getCellEditor() != null) {
174
			table.getCellEditor().cancelCellEditing();
175
		}
176

  
177
		MyTableModel m = (MyTableModel) table.getModel();
178
		int[] selectedRows = table.getSelectedRows();
179

  
180
		for (int i = selectedRows.length - 1; i >= 0; i--) {
181
			m.removeRow(selectedRows[i]);
182
		}
183
	}
184

  
185
	/**
186
	 * Rellena la tabla con los s?mbolos valores y descripciones que se pasan
187
	 * como par?metro.
188
	 *
189
	 * @param symbols
190
	 *            Array de s?mbolos
191
	 * @param values
192
	 *            Array de valores.
193
	 * @param descriptions
194
	 *            Array de descripciones.
195
	 */
196
	public void fillTableFromSymbolList(ISymbol[] symbols, Object[] values,
197
			Object[] descriptions) {
198
		ISymbol theSymbol;
199

  
200
		for (int i = 0; i < symbols.length; i++) {
201
			theSymbol = symbols[i];
202
			if(!(values[i] instanceof NullIntervalValue) && !(values[i] instanceof NullUniqueValue))
203
				addTableRecord(theSymbol, values[i], descriptions[i]);
204
		}
205
	}
206

  
207
	/**
208
	 * A?ade una fila con los objetos que se pasan como par?metros.
209
	 *
210
	 * @param symbol
211
	 *            s?mbolo de la fila.
212
	 * @param value
213
	 *            Valor de la fila.
214
	 * @param description
215
	 *            Descripci?n.
216
	 */
217
	public void addTableRecord(ISymbol symbol, Object value, Object description) {
218
		Object[] theRow = new Object[2];
219
		theRow[0] = value;
220
		theRow[1] = description;
221
		addRow(theRow);
222
	}
223

  
224
	/**
225
	 * Devuelve el valor a partie del n?mero de fila y columna.
226
	 *
227
	 * @param row
228
	 *            n?mero de fila.
229
	 * @param col
230
	 *            n?mero de columna.
231
	 *
232
	 * @return Objeto.
233
	 */
234
	public Object getFieldValue(int row, int col) {
235
		MyTableModel m = (MyTableModel) table.getModel();
236

  
237
		return m.getValueAt(row, col);
238
	}
239

  
240
	/**
241
	 * Devuelve el n?mero total de filas que contiene el modelo.
242
	 *
243
	 * @return N?mero de filas.
244
	 */
245
	public int getRowCount() {
246
		MyTableModel m = (MyTableModel) table.getModel();
247

  
248
		return m.getRowCount();
249
	}
250

  
251
	/**
252
	 * Elimina todas las filas del modelo.
253
	 */
254
	public void removeAllItems() {
255
		table.setModel(new MyTableModel());
256
		setUpValueColumn(table, table.getColumnModel().getColumn(0),cellEditors.get(this.type));
257
		setUpLabelColumn(table, table.getColumnModel().getColumn(1));
258
	}
259

  
260
	/**
261
	 * Inicializa el cell editor de tipo descripci?n de la columna que se pasa
262
	 * como par?metro.
263
	 *
264
	 * @param table2
265
	 *            Tabla.
266
	 * @param column
267
	 *            Columna.
268
	 */
269
	public void setUpLabelColumn(JTable table2, TableColumn column) {
270
		TextFieldCellEditor labeleditor = new TextFieldCellEditor();
271
		column.setCellEditor(labeleditor);
272
	}
273

  
274
	/**
275
	 * Inicializa el cell editor de tipo valor de la columna que se pasa como
276
	 * par?metro.
277
	 *
278
	 * @param table2
279
	 *            Tabla.
280
	 * @param column
281
	 *            Columna.
282
	 * @param tableCellEditor
283
	 */
284
	public void setUpValueColumn(JTable table2,TableColumn column, TableCellEditor tableCellEditor) {
285
		column.setCellEditor(tableCellEditor);
286
	}
287
	/**
288
	 * Inicializa el cell editor de tipo s?mbolo de la columna que se pasa como
289
	 * par?metro.
290
	 *
291
	 * @param table2
292
	 *            Tabla.
293
	 * @param column
294
	 *            Columna.
295
	 */
296
	public void setUpSymbolColumn(JTable table2, TableColumn column) {
297
		// Set up the editor
298
		column.setMaxWidth(100);
299
		column.setWidth(60);
300
		column.setPreferredWidth(60);
301
		column.setMinWidth(50);
302

  
303
		// FSymbolCellEditor symboleditor = new FSymbolCellEditor();
304
//		SymbolCellEditor symboleditor = new SymbolCellEditor(shapeType);
305
		SymbolCellEditor symboleditor = new SymbolCellEditor();
306
		column.setCellEditor(symboleditor);
307

  
308
		TableSymbolCellRenderer renderer = new TableSymbolCellRenderer(true);
309
		column.setCellRenderer(renderer);
310
	}
311

  
312
	/**
313
	 * Modelo que propio que se aplica a la tabla.
314
	 *
315
	 * @author Vicente Caballero Navarro
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff