Revision 23168

View differences:

trunk/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/resources/MyFileFilter3D.java
1
package com.iver.ai2.gvsig3d.resources;
2

  
3
import java.io.File;
4

  
5
import javax.swing.filechooser.FileFilter;
6

  
7
/**
8
 * 
9
 * @version 14/08/2007
10
 * @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
11
 * 
12
 */
13
public class MyFileFilter3D extends FileFilter {
14

  
15
	private String[] extensiones = new String[1];
16
	private String description;
17
	private boolean dirs = true;
18
	private String info = null;
19

  
20
	public MyFileFilter3D(String[] ext, String desc) {
21
		extensiones = ext;
22
		description = desc;
23
	}
24

  
25
	public MyFileFilter3D(String[] ext, String desc, String info) {
26
		extensiones = ext;
27
		description = desc;
28
		this.info = info;
29
	}
30

  
31
	public MyFileFilter3D(String ext, String desc) {
32
		extensiones[0] = ext;
33
		description = desc;
34
	}
35

  
36
	public MyFileFilter3D(String ext, String desc, String info) {
37
		extensiones[0] = ext;
38
		description = desc;
39
		this.info = info;
40
	}
41

  
42
	public MyFileFilter3D(String ext, String desc, boolean dirs) {
43
		extensiones[0] = ext;
44
		description = desc;
45
		this.dirs = dirs;
46
	}
47

  
48
	public MyFileFilter3D(String ext, String desc, boolean dirs, String info) {
49
		extensiones[0] = ext;
50
		description = desc;
51
		this.dirs = dirs;
52
		this.info = info;
53
	}
54

  
55
	public boolean accept(File f) {
56
		if (f.isDirectory()) {
57
			if (dirs) {
58
				return true;
59
			} else {
60
				return false;
61
			}
62
		}
63
		for (int i = 0; i < extensiones.length; i++) {
64
			if (extensiones[i].equals("")) {
65
				continue;
66
			}
67
			if (getExtensionOfAFile(f).equalsIgnoreCase(extensiones[i])) {
68
				return true;
69
			}
70
		}
71

  
72
		return false;
73
	}
74

  
75
	/**
76
	 * @see javax.swing.filechooser.FileFilter#getDescription()
77
	 */
78
	public String getDescription() {
79
		return description;
80
	}
81

  
82
	public String[] getExtensions() {
83
		return extensiones;
84
	}
85

  
86
	public boolean isDirectory() {
87
		return dirs;
88
	}
89

  
90
	private String getExtensionOfAFile(File file) {
91
		String name;
92
		int dotPos;
93
		name = file.getName();
94
		dotPos = name.lastIndexOf(".");
95
		if (dotPos < 1) {
96
			return "";
97
		}
98
		return name.substring(dotPos + 1);
99
	}
100

  
101
	public File normalizeExtension(File file) {
102
		String ext = getExtensionOfAFile(file);
103
		if (ext.equals("") || !(this.accept(file))) {
104
			return new File(file.getAbsolutePath() + "." + extensiones[0]);
105
		}
106
		return file;
107
	}
108

  
109
	public String getInfo() {
110
		return this.info;
111
	}
112

  
113
	public void setInfo(String info) {
114
		this.info = info;
115
	}
116

  
117
}
118

  
trunk/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/ExtrusionLegend.java
1
package com.iver.ai2.gvsig3d.legend;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.Component;
5
import java.awt.FlowLayout;
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
8
import java.awt.event.KeyEvent;
9
import java.awt.event.KeyListener;
10
import java.util.Random;
11

  
12
import javax.swing.DefaultComboBoxModel;
13
import javax.swing.ImageIcon;
14
import javax.swing.JCheckBox;
15
import javax.swing.JComboBox;
16
import javax.swing.JLabel;
17
import javax.swing.JOptionPane;
18
import javax.swing.JPanel;
19
import javax.swing.JTextField;
20

  
21
import org.gvsig.gui.beans.swing.JButton;
22
import org.gvsig.raster.datastruct.ColorItem;
23

  
24
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
25
import com.hardcode.gdbms.engine.data.DataSource;
26
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException;
27
import com.hardcode.gdbms.engine.values.NullValue;
28
import com.hardcode.gdbms.engine.values.Value;
29
import com.hardcode.gdbms.engine.values.ValueFactory;
30
import com.iver.andami.PluginServices;
31
import com.iver.andami.messages.NotificationManager;
32
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
33
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
34
import com.iver.cit.gvsig.fmap.layers.FLayer;
35
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
36
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
37
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
38
import com.iver.cit.gvsig.fmap.rendering.AbstractClassifiedVectorLegend;
39
import com.iver.cit.gvsig.fmap.rendering.ILegend;
40
import com.iver.cit.gvsig.fmap.rendering.LegendContentsChangedListener;
41
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
42
import com.iver.cit.gvsig.fmap.rendering.NullUniqueValue;
43
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
44
import com.iver.cit.gvsig.fmap.rendering.ZSort;
45
import com.iver.cit.gvsig.gui.styling.JComboBoxColorScheme;
46
import com.iver.cit.gvsig.gui.styling.SymbolLevelsWindow;
47
import com.iver.cit.gvsig.project.documents.view.legend.gui.ILegendPanel;
48
import com.iver.cit.gvsig.project.documents.view.legend.gui.SymbolTable;
49

  
50

  
51
/**
52
 * DOCUMENT ME!
53
 *
54
 * @author fjp To change the template for this generated type comment go to
55
 *         Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and
56
 *         Comments
57
 */
58
public class ExtrusionLegend extends JPanel implements ILegendPanel,ActionListener,KeyListener {
59
  //  private static Logger logger = Logger.getLogger(VectorialUniqueValue.class.getName());
60

  
61
    private VectorialUniqueValueLegend theLegend;
62
    private ClassifiableVectorial layer;
63
    private SymbolTable symbolTable;
64
    private JComboBox cmbFields;
65
    private JButton btnRemoveAll;
66
    private JButton btnRemove;
67
    private JCheckBox chbUseDefault = null;
68
    private VectorialUniqueValueLegend auxLegend;
69
	private JPanel pnlCenter;
70
	private ZSort zSort;
71
	private JButton btnOpenSymbolLevelsEditor;
72
	private JTextField jtf;
73
	private JComboBoxColorScheme cmbColorScheme;
74
	private double extrusionValue;
75

  
76
    /**
77
     *
78
     */
79
    public ExtrusionLegend() {
80
        super();
81
        initialize();
82
    }
83

  
84
    /**
85
     * DOCUMENT ME!
86
     */
87
    protected void initialize() {
88
        /* JLabel label = new JLabel();
89
           label.setIcon(new javax.swing.ImageIcon(Abrir.class.getClassLoader().getResource("images/ValoresUnicos.png")));
90
           limagen[1] = new JLabel();
91
           limagen[1] = label; */
92
        JPanel pnlButtons = new JPanel();
93

  
94
        JButton btnAddAll = new JButton(PluginServices.getText(this,
95
                    "Anadir_todos"));
96
        btnAddAll.setActionCommand("ADD_ALL_VALUES");
97
        btnAddAll.addActionListener(this);
98
        pnlButtons.add(btnAddAll);
99

  
100
        JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir"));
101
        btnAdd.setActionCommand("ADD_VALUE");
102
        btnAdd.addActionListener(this);
103
        pnlButtons.add(btnAdd);
104

  
105
        btnRemoveAll = new JButton(PluginServices.getText(this, "Quitar_todos"));
106
        btnRemoveAll.setActionCommand("REMOVE_ALL");
107
        btnRemoveAll.addActionListener(this);
108
        pnlButtons.add(btnRemoveAll);
109

  
110
        btnRemove = new JButton(PluginServices.getText(this, "Quitar"));
111
        btnRemove.setActionCommand("REMOVE");
112
        btnRemove.addActionListener(this);
113
        pnlButtons.add(btnRemove);
114

  
115
        btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels"));
116
        btnOpenSymbolLevelsEditor.addActionListener(this);
117
        btnOpenSymbolLevelsEditor.setActionCommand("OPEN_SYMBOL_LEVEL_EDITOR");
118
        pnlButtons.add(btnOpenSymbolLevelsEditor);
119

  
120
		pnlCenter = new JPanel();
121
        pnlCenter.setLayout(new BorderLayout());
122

  
123
        cmbFields = new JComboBox();
124
        cmbFields.setActionCommand("FIELD_SELECTED");
125
        cmbFields.addActionListener(this);
126
        cmbFields.setVisible(true);
127

  
128
        JPanel pnlNorth = new JPanel(new FlowLayout(FlowLayout.LEFT, 20, 0));
129
        JPanel pAux1 = new JPanel();
130

  
131
        JLabel lblFieldClassification = new JLabel(PluginServices.getText(
132
                    this, "Campo_de_clasificacion"));
133
        pAux1.add(lblFieldClassification);
134
        pAux1.add(cmbFields);
135
        pAux1.add(getChbUseDefault(), null);
136
        pnlNorth.add(pAux1);
137

  
138
        pAux1 = new JPanel();
139
        pAux1.add(new JLabel(PluginServices.getText(this, "Nivel_de_extrusi?n")+":"));
140
        jtf = new JTextField(PluginServices.getText(this, "0"),3);
141
        jtf.setColumns(3);
142
        jtf.setHorizontalAlignment(JTextField.RIGHT); 
143
        jtf.addKeyListener(this);
144
        pAux1.add(jtf);
145
        
146
        pnlNorth.add(pAux1);
147
        
148
        
149
        pAux1 = new JPanel();
150
        pAux1.add(new JLabel(PluginServices.getText(this, "color_scheme")+":"));
151
        cmbColorScheme = new JComboBoxColorScheme(false);
152

  
153
        pAux1.add(cmbColorScheme);
154
        pnlNorth.add(pAux1);
155
        
156
        
157
        this.setLayout(new BorderLayout());
158
        this.add(pnlNorth, BorderLayout.NORTH);
159
        this.add(pnlCenter, BorderLayout.CENTER);
160
        this.add(pnlButtons, BorderLayout.SOUTH);
161

  
162
    }
163

  
164
    /**
165
     * DOCUMENT ME!
166
     */
167
    private void fillTableValues() {
168
        DataSource elRs;
169

  
170
        try {
171
            elRs = ((FLyrVect) layer).getRecordset();
172
           // logger.debug("elRs.start()");
173
            elRs.start();
174

  
175
            int idField = -1;
176
            String fieldName = (String) cmbFields.getSelectedItem();
177
            if (fieldName==null) {
178
            	JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"no_hay_campo_seleccionado"));
179
            	return;
180
            }
181

  
182
            idField = elRs.getFieldIndexByName(fieldName);
183
            theLegend.setClassifyingFieldNames(new String[] {fieldName});
184

  
185
            //long numReg = elRs.getRowCount();
186
            if (idField == -1) {
187
                NotificationManager.addWarning(
188
                		PluginServices.getText(this, "unrecognized_field_name")+" " + fieldName, null);
189

  
190
                return;
191
            }
192

  
193
            symbolTable.removeAllItems();
194

  
195
            int numSymbols = 0;
196
            ISymbol theSymbol = null;
197

  
198
            //auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend();
199
            auxLegend = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType());
200

  
201
            Value clave;
202

  
203
            //Object resul;
204
            if (chbUseDefault.isSelected()) {
205
                auxLegend.getDefaultSymbol().setDescription("Default");
206
                auxLegend.addSymbol(new NullUniqueValue(),
207
                    auxLegend.getDefaultSymbol());
208
            }
209

  
210
            ColorItem[] colorScheme = cmbColorScheme.getSelectedColors();
211
            Random rand = new Random(System.currentTimeMillis());
212

  
213
            for (int j = 0; j < elRs.getRowCount(); j++) {
214
                clave = elRs.getFieldValue(j, idField);
215

  
216
                if (clave instanceof NullValue) {
217
                    continue;
218
                }
219

  
220
                ////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
221
                if (auxLegend.getSymbolByValue(clave) == null) {
222
                    //si no esta creado el simbolo se crea
223
                    // jaume (moved to ISymbol); theSymbol = new FSymbol(layer.getShapeType());
224
                	theSymbol = SymbologyFactory.
225
                		createDefaultSymbolByShapeType(layer.getShapeType(),
226
                				colorScheme[rand.nextInt(colorScheme.length)].getColor());
227
                    theSymbol.setDescription(clave.toString());
228
                    auxLegend.addSymbol(clave, theSymbol);
229

  
230
                    numSymbols++;
231

  
232
                    if (numSymbols == 100) {
233
                        int resp = JOptionPane.showConfirmDialog(this,
234
                                PluginServices.getText(this,
235
                                    "mas_de_100_simbolos"),
236
                                PluginServices.getText(this, "quiere_continuar"),
237
                                JOptionPane.YES_NO_OPTION,
238
                                JOptionPane.WARNING_MESSAGE);
239

  
240
                        if ((resp == JOptionPane.NO_OPTION) ||
241
                                (resp == JOptionPane.DEFAULT_OPTION)) {
242
                            return;
243
                        }
244
                    }
245
                }
246
            } // for
247

  
248
            
249
            // Ver casos de String.!!!
250
            
251
            Object[] extrudedValue = auxLegend.getValues();
252
            
253
            for (int i = 0; i < extrudedValue.length; i++) {
254
 			
255
	         	try {
256
	         		extrudedValue[i] = ((Value)auxLegend.getValues()[i]).producto(ValueFactory.createValue(extrusionValue));
257
	 			}catch (IncompatibleTypesException e) {
258
	 				// TODO Auto-generated catch block
259
	 				
260
	 				e.printStackTrace();
261
	 			}
262
         	   
263
            }
264
            symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
265
            		extrudedValue, auxLegend.getDescriptions());
266
            elRs.stop();
267
        } catch (ReadDriverException e) {
268
        	NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
269
        }
270

  
271
        btnRemoveAll.setEnabled(true);
272
        btnRemove.setEnabled(true);
273

  
274
        //m_bCacheDirty = false;
275
    }
276

  
277
    /**
278
     * A partir de los registros de la tabla, regenera el FRenderer. (No solo
279
     * el symbolList, si no tambi�n el arrayKeys y el defaultRenderer
280
     */
281
    private void fillSymbolListFromTable() {
282
        Value clave;
283
        ISymbol theSymbol;
284

  
285
        // Borramos las anteriores listas:
286

  
287
        boolean bRestoValores = false; // PONERLO EN UN CHECKBOX
288
        int hasta;
289
        String fieldName = (String) cmbFields.getSelectedItem();
290
        theLegend.setClassifyingFieldNames(new String[] {fieldName} );
291
        /////////////////////////////////////////PEPE
292
        FLyrVect m = (FLyrVect) layer;
293
        try {
294
        	int fieldType = m.getSource().getRecordset().getFieldType((int)cmbFields.getSelectedIndex());
295
        	theLegend.setClassifyingFieldTypes(new int[] {fieldType});
296
        } catch (ReadDriverException e) {
297
        	NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e);
298
        }
299
        /////////////////////////////////////////PEPE
300
        if (bRestoValores) {
301
            hasta = symbolTable.getRowCount() - 1;
302
        } else {
303
            hasta = symbolTable.getRowCount();
304
        }
305

  
306
        for (int row = 0; row < symbolTable.getRowCount(); row++) {
307
            clave = (Value) symbolTable.getFieldValue(row, 1);
308
            theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
309
//            System.err.println("djfslkf" + theSymbol);
310
            theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2));
311
            theLegend.addSymbol(clave, theSymbol);
312
        }
313

  
314
        if (bRestoValores) {
315
            theSymbol = (ISymbol) symbolTable.getFieldValue(hasta, 0);
316
            theLegend.setDefaultSymbol(theSymbol);
317
        }
318
    }
319

  
320
    /**
321
     * DOCUMENT ME!
322
     */
323
    private void fillFieldNames() {
324
        DataSource rs;
325

  
326
        try {
327
            rs = ((AlphanumericData) layer).getRecordset();
328
        //    logger.debug("rs.start()");
329
            rs.start();
330

  
331
            String[] nomFields = new String[rs.getFieldCount()];
332

  
333
            for (int i = 0; i < rs.getFieldCount(); i++) {
334
                nomFields[i] = rs.getFieldName(i).trim();
335
            }
336

  
337
            rs.stop();
338

  
339
            DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields);
340
            cmbFields.setModel(cM);
341

  
342
            // fieldsListValor.setSelectedIndex(0);
343
        } catch (ReadDriverException e) {
344
        	NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
345
        }
346
    }
347

  
348
    public void setData(FLayer layer, ILegend legend) {
349
    	this.layer = (ClassifiableVectorial) layer;
350
      	int shapeType = 0;
351
      	try {
352
      		shapeType = this.layer.getShapeType();
353
      	} catch (ReadDriverException e) {
354
    		NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e);
355
		}
356

  
357
      	if (symbolTable != null)
358
      		pnlCenter.remove(symbolTable);
359
      	symbolTable = new SymbolTable(this, SymbolTable.VALUES_TYPE, shapeType);
360
      	pnlCenter.add(symbolTable, BorderLayout.CENTER);
361

  
362
        fillFieldNames();
363

  
364
        symbolTable.removeAllItems();
365

  
366
        if (legend instanceof VectorialUniqueValueLegend) {
367
            theLegend = (VectorialUniqueValueLegend) legend;
368
            getChbUseDefault().setSelected(theLegend.isUseDefaultSymbol());
369
            cmbFields.getModel().setSelectedItem(theLegend.getClassifyingFieldNames()[0]);
370
            symbolTable.fillTableFromSymbolList(theLegend.getSymbols(),
371
            									theLegend.getValues(),
372
            									theLegend.getDescriptions());
373
            zSort = theLegend.getZSort();
374
        } else {
375
            theLegend = new VectorialUniqueValueLegend(shapeType);
376
        }
377
    }
378

  
379
    /* (non-Javadoc)
380
     * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
381
     */
382
    public ILegend getLegend() {
383
        fillSymbolListFromTable();
384

  
385
        if (auxLegend != null) {
386
        	// your settings that are not the set of symbols must be located here
387
        	auxLegend.setClassifyingFieldNames(
388
        			new String[] {(String) cmbFields.getSelectedItem()});
389
        	auxLegend.setClassifyingFieldTypes(theLegend.getClassifyingFieldTypes());
390
        	
391
        	LegendContentsChangedListener[] l  = theLegend.getListeners();
392
        	for (int i = 0; i < l.length; i++) {
393
        		auxLegend.addLegendListener(l[i]);
394
			};
395
            
396
            theLegend = auxLegend;
397
        }
398
        theLegend.setZSort(zSort);
399

  
400
        return theLegend;
401
    }
402

  
403
    private JCheckBox getChbUseDefault() {
404
        if (chbUseDefault == null) {
405
            chbUseDefault = new JCheckBox();
406
            chbUseDefault.setSelected(true);
407
            chbUseDefault.addActionListener(new java.awt.event.ActionListener() {
408
            	public void actionPerformed(java.awt.event.ActionEvent e) {
409
            		if (auxLegend==null)auxLegend=theLegend;
410
            		if (chbUseDefault.isSelected()) {
411
            			addDefault();
412
            		} else {
413
            			delDefault();
414
            		}
415
            	}
416
            });
417
            chbUseDefault.setText(PluginServices.getText(this, "resto_valores"));
418
        }
419

  
420
        return chbUseDefault;
421
    }
422

  
423
    /**
424
     * A�ade el resto de valores.
425
     */
426
    private void addDefault() {
427
        auxLegend.getDefaultSymbol().setDescription("Default");
428
        auxLegend.addSymbol(new NullUniqueValue(), auxLegend.getDefaultSymbol());
429
        symbolTable.addTableRecord(auxLegend.getDefaultSymbol(),
430
            new NullUniqueValue(), auxLegend.getDefaultSymbol().getDescription());
431
        symbolTable.repaint();
432
    }
433

  
434
    /**
435
     * Elimina el resto de valores que no estan representados por ning�n otro s�mbolo..
436
     */
437
    private void delDefault() {
438
        auxLegend.delSymbol(new NullUniqueValue());
439
        symbolTable.removeRow(new NullUniqueValue());
440
        symbolTable.repaint();
441
    }
442

  
443

  
444
    public void actionPerformed(ActionEvent e) {
445

  
446
    	//modificar el combobox de valor
447
    	if (e.getActionCommand() == "FIELD_SELECTED") {
448
    		JComboBox cb = (JComboBox) e.getSource();
449
    		String fieldName = (String) cb.getSelectedItem();
450
    		symbolTable.removeAllItems();
451

  
452
    	}
453

  
454
    	// add all elements by value
455
    	if (e.getActionCommand() == "ADD_ALL_VALUES") {
456
    		fillTableValues();
457
    	}
458

  
459
    	// add only one value
460
    	if (e.getActionCommand() == "ADD_VALUE") {
461
    		try {
462
    			symbolTable.addTableRecord(SymbologyFactory.
463
    					createDefaultSymbolByShapeType(layer.getShapeType()),
464
    					ValueFactory.createValue(0.0), "0 - 0");
465
    		} catch (ReadDriverException ex) {
466
    			NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), ex);
467
    		}
468
    	}
469

  
470
    	//Vacia la tabla
471
    	if (e.getActionCommand() == "REMOVE_ALL") {
472
    		symbolTable.removeAllItems();
473
    		theLegend.setZSort(null);
474
    		zSort = null;
475
    	}
476

  
477
    	//Quitar solo el elemento seleccionado
478
    	if (e.getActionCommand() == "REMOVE") {
479
    		symbolTable.removeSelectedRows();
480
    	}
481

  
482
    	if (e.getActionCommand() == "OPEN_SYMBOL_LEVEL_EDITOR") {
483

  
484
			if (theLegend != null) {
485
				ZSort myZSort = ((AbstractClassifiedVectorLegend) getLegend()).getZSort();
486
				if (myZSort == null) {
487
						myZSort = new ZSort(theLegend);
488
				}
489
				SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
490
				PluginServices.getMDIManager().addWindow(sl);
491
				zSort = sl.getZSort();
492
				if (auxLegend != null)
493
					auxLegend.setZSort(zSort);
494
			}
495

  
496
    	}
497
    }
498

  
499
	public String getDescription() {
500
		return PluginServices.getText(this,PluginServices.getText(this,"Extension to manage the 3D extrusion"));
501
	}
502

  
503
	public ImageIcon getIcon() {
504
		return null;
505
	}
506

  
507
	public Class getParentClass() {
508
		return null;
509
	}
510

  
511
	public String getTitle() {
512
		
513
		return ("<html><b>"+ PluginServices.getText(this,"Extrusi?n")+ "</b></html>");
514
		//return ("<html><b>"+"Extrusi?n"+"</b></html>");
515
		//return "Extrusion";
516
		
517
	}
518

  
519
	public JPanel getPanel() {
520
		return this;
521
	}
522

  
523
	public Class getLegendClass() {
524
		return VectorialUniqueValueLegend.class;
525
	}
526

  
527

  
528
	public boolean isSuitableFor(FLayer layer) {
529
		return (layer instanceof FLyrVect);
530
	}
531

  
532
	public void keyPressed(KeyEvent e) {
533
		// TODO Auto-generated method stub
534
		
535
	}
536

  
537
	public void keyReleased(KeyEvent e) {
538
	//	System.out.println("Valor de extrusi?n: "+ this.jtf.getText());
539
		extrusionValue = new Double(this.jtf.getText()).doubleValue();
540
		//globalTime = new Double(this.textosegs.getText()).doubleValue();
541
		
542
	}
543

  
544
	public void keyTyped(KeyEvent e) {
545
		// TODO Auto-generated method stub
546
		
547
	}
548
}
trunk/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/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;
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

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

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

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

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

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

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

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

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

  
268
			topPanel.add(lblFileName, gridBagConstraints);
269

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

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

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

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

  
304
		}
305
		return topPanel;
306
	}
307

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
505
	public ISymbol getLayer() {
506
		// this method builds the new symbol and returns it to the legend
507
		// manager
508
		try {
509
			Object3DMarkerSymbol symbol = null;
510

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

  
527
			
528
			return symbol;
529
		} catch (IOException e) {
530
			return SymbologyFactory.getWarningSymbol(PluginServices.getText(
531
					this, "failed_acessing_files"), null,
532
					SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
533
		}
534

  
535
	}
536

  
537
	public void refreshControls(ISymbol layer) {
538

  
539
		// this method gets the simbol from the legend manager
540

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

  
554
			this.setFilePath(fileName);
555

  
556
		} catch (IndexOutOfBoundsException ioEx) {
557
			NotificationManager.addWarning("Symbol layer index out of bounds",
558
					ioEx);
559
		} catch (ClassCastException ccEx) {
560
			NotificationManager.addWarning("Illegal casting from "
561
					+ layer.getClassName() + " to "
562
					+ getSymbolClass().getName() + ".", ccEx);
563
		}
564
	}
565

  
566
	public String getName() {
567
		return "Object 3D symbol";
568

  
569
	}
570

  
571
	public JPanel[] getTabs() {
572
		return tabs.toArray(new JPanel[tabs.size()]);
573
	}
574

  
575
	public Class getSymbolClass() {
576
		return Object3DMarkerSymbol.class;
577
	}
578

  
579
	public EditorTool[] getEditorTools() {
580
		return null;
581

  
582
	}
583

  
584
	public void actionPerformed(ActionEvent e) {
585
		fireSymbolChangedEvent();
586
	}
587

  
588
}
trunk/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/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;
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

  
148
	// transient private Image selImg;
149

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

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

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

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

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

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

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

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

  
224
	}
225

  
226
	@Override
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff