Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.commons / src / main / java / org / gvsig / gvsig3d / app / listener / Vectorial3DListener.java @ 385

History | View | Annotate | Download (3.5 KB)

1
/* gvSIG 3D extension for gvSIG
2
 *
3
 * Copyright (C) 2012 Prodevelop.
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
 *   Prodevelop, S.L.
22
 *   Pza. Don Juan de Villarrasa, 14 - 5
23
 *   46001 Valencia
24
 *   Spain
25
 *
26
 *   +34 963 510 612
27
 *   +34 963 510 968
28
 *   prode@prodevelop.es
29
 *   http://www.prodevelop.es
30
 */
31
/*
32
 * AUTHORS:
33
 * 2012 AI2 - Instituto Universitario de Automatica e Informatica Industrial.
34
 * Universitat Politecnica de Valencia (UPV)
35
 * http://www.ai2.upv.es
36
 */
37

    
38

    
39
package org.gvsig.gvsig3d.app.listener;
40

    
41
import org.gvsig.fmap.mapcontext.layers.FLayer;
42
import org.gvsig.gvsig3d.app.gui.panels.Vectorial3DPanel;
43
import org.gvsig.gvsig3d.map3d.Layer3DProps;
44
import org.gvsig.gvsig3d.map3d.MapContext3D;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48
/**
49
 * @author Jesus Zarzoso- jzarzoso@ai2.upv.es
50
 * @version $Id$
51
 * 
52
 */
53
public class Vectorial3DListener {
54

    
55
        final static private Logger logger = LoggerFactory
56
                        .getLogger(Vectorial3DListener.class);
57

    
58
        private Vectorial3DPanel vPanel = null;
59
        private Layer3DProps props3D;
60
        private MapContext3D context;
61
        private FLayer flyr;
62

    
63
        public Vectorial3DListener(Vectorial3DPanel panel) {
64
                this.vPanel = panel;
65
                
66
        }
67
        /**
68
         * Actions to execute when the accept option is pressed
69
         */
70
        public void accept() {
71

    
72
                context = vPanel.getMapContext();
73
                props3D = vPanel.getLayer3DProps();
74
                flyr = vPanel.getLayer();
75

    
76
                // Rastering the layer
77
                if (vPanel.isRasterOptionSelected()
78
                                && (props3D.getType() != Layer3DProps.layer3DImage)) {
79
                        context.removeLayerToTerrain(flyr);
80
                        props3D.setType(Layer3DProps.layer3DImage);
81
                        context.addLayerToTerrain(flyr, true);
82
                } else if ((!vPanel.isZValueSelected())
83
                                && (!vPanel.isRasterOptionSelected())) {
84
                        float new_h = 0;
85
                        float actual_h = 0;
86

    
87
                        try {
88
                                actual_h = Float.parseFloat(vPanel.getMyHeight());
89
                                new_h = Float.parseFloat(vPanel.getJTextFieldHeight());
90
                        } catch (NumberFormatException e) {
91
                                logger.error("Command: "
92
                                                + "Error getting maximun range layer elevation value.",
93
                                                e);
94
                        }
95

    
96
                        if ((new_h >= 0 && new_h != actual_h)
97
                                        || (props3D.getType() == Layer3DProps.layer3DImage)) {
98
                                // aplicando una altura distinta, si es la misma no se hace nada
99

    
100
                                context.removeLayerToTerrain(flyr);
101
                                props3D.setZEnable(false);
102
                                props3D.setType(Layer3DProps.layer3DVector);
103
                                props3D.setHeight(new_h);
104
                                context.addLayerToTerrain(flyr, true);
105
                        }
106

    
107
                } else if (vPanel.isZValueSelected()) {// Value Z associated to the
108
                                                                                                // layer
109
                        context.removeLayerToTerrain(flyr);
110
                        props3D.setType(Layer3DProps.layer3DVector);
111
                        props3D.setZEnable(true);
112
                        context.addLayerToTerrain(flyr, true);
113

    
114
                }
115

    
116
        }
117
        
118
        /**
119
         * Actions to execute when the apply option is pressed
120
         */
121

    
122
        public void apply() {
123

    
124
                accept();
125
        }
126
        
127
        /**
128
         * Actions to execute when the cancel option is pressed
129
         */
130
        public void cancel() {
131

    
132
        }
133

    
134

    
135
}