gvsig-3d / 2.1 / branches / org.gvsig.view3d_vector_and_extrusion_2.3 / org.gvsig.view3d / org.gvsig.view3d / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / properties / layer / ExtrudedVectorLayer3DController.java @ 708
History | View | Annotate | Download (9.03 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright © 2007-2016 gvSIG Association
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.view3d.swing.impl.properties.layer; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Component; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.util.ArrayList; |
31 |
import java.util.List; |
32 |
|
33 |
import javax.swing.DefaultComboBoxModel; |
34 |
import javax.swing.JColorChooser; |
35 |
import javax.swing.JComponent; |
36 |
|
37 |
import org.slf4j.Logger; |
38 |
import org.slf4j.LoggerFactory; |
39 |
|
40 |
import org.gvsig.fmap.dal.DataStore; |
41 |
import org.gvsig.fmap.dal.exception.DataException; |
42 |
import org.gvsig.fmap.dal.exception.ReadException; |
43 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
44 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
45 |
import org.gvsig.fmap.dal.feature.FeatureType; |
46 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
47 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
48 |
import org.gvsig.tools.ToolsLocator; |
49 |
import org.gvsig.tools.dataTypes.DataType; |
50 |
import org.gvsig.tools.i18n.I18nManager; |
51 |
import org.gvsig.view3d.lib.api.E3DElevationModes; |
52 |
import org.gvsig.view3d.lib.api.View3DLocator; |
53 |
import org.gvsig.view3d.lib.api.View3DManager; |
54 |
import org.gvsig.view3d.lib.api.properties.ExtrudedVectorLayerProperties3D; |
55 |
import org.gvsig.view3d.lib.api.properties.LayerProperties3D; |
56 |
import org.gvsig.view3d.lib.impl.layers.loaders.ExtrudedVectorLayerLoaderFactory; |
57 |
import org.gvsig.view3d.swing.api.properties.ILayerProperties3DPanel; |
58 |
|
59 |
/**
|
60 |
* Extruded Vector layer properties panel.
|
61 |
*
|
62 |
* @author Andrea Antonello andrea.antonello@gmail.com
|
63 |
*
|
64 |
*/
|
65 |
@SuppressWarnings("serial") |
66 |
public class ExtrudedVectorLayer3DController extends ExtrudedVectorLayer3DPanel |
67 |
implements
|
68 |
ILayerProperties3DPanel |
69 |
{ |
70 |
|
71 |
private static final Logger LOGGER = LoggerFactory.getLogger(ExtrudedVectorLayer3DController.class); |
72 |
|
73 |
private ExtrudedVectorLayerProperties3D mLayerProperties;
|
74 |
|
75 |
private I18nManager i18nManager = ToolsLocator.getI18nManager();
|
76 |
private Color mDefaultColor; |
77 |
|
78 |
private FLayer mLayer;
|
79 |
|
80 |
@Override
|
81 |
public String getName() { |
82 |
return new ExtrudedVectorLayerLoaderFactory().getName(); |
83 |
} |
84 |
|
85 |
@SuppressWarnings("unchecked") |
86 |
public void init( FLayer layer ) throws ReadException { |
87 |
this.mLayer = layer;
|
88 |
View3DManager manager = View3DLocator.getManager(); |
89 |
|
90 |
mLayerProperties = (ExtrudedVectorLayerProperties3D) manager.getLayerProperties(layer, |
91 |
new ExtrudedVectorLayerLoaderFactory());
|
92 |
|
93 |
translateLabels(); |
94 |
int elevationMode = mLayerProperties.getElevationMode();
|
95 |
|
96 |
_elevationModeCombo.setModel(new DefaultComboBoxModel<String>(E3DElevationModes.getExtrudedModeNames((FLyrVect) mLayer))); |
97 |
E3DElevationModes mode = E3DElevationModes.getModeFromValue(elevationMode); |
98 |
_elevationModeCombo.setSelectedItem(mode.getTitle()); |
99 |
|
100 |
mDefaultColor = mLayerProperties.getDefaultColor(); |
101 |
|
102 |
if (_defaultColorButtonPanel.getComponentCount() == 0) { |
103 |
ColorChooserButton colorChooser = new ColorChooserButton(mDefaultColor);
|
104 |
colorChooser.addColorChangedListener(new ColorChooserButton.ColorChangedListener(){
|
105 |
|
106 |
@Override
|
107 |
public void colorChanged( Color newColor ) { |
108 |
if (newColor != null) { |
109 |
mDefaultColor = newColor; |
110 |
} |
111 |
} |
112 |
}); |
113 |
|
114 |
_defaultColorButtonPanel.add(colorChooser); |
115 |
} else {
|
116 |
Component tmpComp = _defaultColorButtonPanel.getComponents()[0]; |
117 |
if (tmpComp instanceof ColorChooserButton) { |
118 |
ColorChooserButton button = (ColorChooserButton) tmpComp; |
119 |
button.setSelectedColor(mDefaultColor); |
120 |
} |
121 |
} |
122 |
|
123 |
String[] items = new String[0]; |
124 |
try {
|
125 |
items = getAttributesNames((FLyrVect) mLayer, true);
|
126 |
} catch (DataException e1) {
|
127 |
LOGGER.error("Error getting field names", e1);
|
128 |
} |
129 |
_heightFieldCombo.setModel(new DefaultComboBoxModel<String>(items)); |
130 |
|
131 |
String extrusionHeightField = mLayerProperties.getExtrusionHeightField();
|
132 |
if (extrusionHeightField != null) { |
133 |
_heightFieldCombo.setSelectedItem(extrusionHeightField); |
134 |
} |
135 |
|
136 |
Double constantExtrusionHeight = mLayerProperties.getConstantHeight();
|
137 |
if (constantExtrusionHeight != null) { |
138 |
_constantHeightTextField.setText(constantExtrusionHeight.toString()); |
139 |
} |
140 |
|
141 |
double verticalExag = mLayerProperties.getVerticalExaggeration();
|
142 |
_verticalExagerationTextField.setText(String.valueOf(verticalExag));
|
143 |
|
144 |
} |
145 |
|
146 |
/**
|
147 |
* Get the list of attributes from a layer.
|
148 |
*
|
149 |
* @param layer
|
150 |
* the layer to get the attributes from.
|
151 |
* @param onlyNumeric
|
152 |
* if <code>true</code>, get only numeric attributes.
|
153 |
* @return the array of field names.
|
154 |
* @throws DataException
|
155 |
*/
|
156 |
private String[] getAttributesNames( FLyrVect layer, boolean onlyNumeric ) throws DataException { |
157 |
List<String> fieldNames = new ArrayList<>(); |
158 |
fieldNames.add("");
|
159 |
DataStore dataStore = layer.getDataStore(); |
160 |
if (dataStore instanceof FeatureStore) { |
161 |
FeatureStore featureStore = (FeatureStore) dataStore; |
162 |
FeatureType defaultFeatureType = featureStore.getDefaultFeatureType(); |
163 |
FeatureAttributeDescriptor[] attributeDescriptors = defaultFeatureType.getAttributeDescriptors();
|
164 |
for( int i = 0; i < attributeDescriptors.length; i++ ) { |
165 |
DataType dataType = attributeDescriptors[i].getDataType(); |
166 |
if (onlyNumeric && !dataType.isNumeric()) {
|
167 |
continue;
|
168 |
} |
169 |
fieldNames.add(attributeDescriptors[i].getName()); |
170 |
} |
171 |
} |
172 |
return fieldNames.toArray(new String[0]); |
173 |
} |
174 |
|
175 |
private void translateLabels() { |
176 |
_elevationModeLabel.setText(i18nManager.getTranslation(_elevationModeLabel.getText())); |
177 |
_defaultColorLabel.setText(i18nManager.getTranslation(_defaultColorLabel.getText())); |
178 |
_constantHeightLabel.setText(i18nManager.getTranslation(_constantHeightLabel.getText())); |
179 |
|
180 |
_extrusionTitleLabel.setText(i18nManager.getTranslation(_extrusionTitleLabel.getText())); |
181 |
_heightFieldLabel.setText(i18nManager.getTranslation(_heightFieldLabel.getText())); |
182 |
_verticalExagerationLabel.setText(i18nManager.getTranslation(_verticalExagerationLabel.getText())); |
183 |
|
184 |
} |
185 |
|
186 |
@Override
|
187 |
public void apply() { |
188 |
mLayerProperties.setDefaultColor(mDefaultColor); |
189 |
|
190 |
try {
|
191 |
String selectedItem = _elevationModeCombo.getSelectedItem().toString();
|
192 |
E3DElevationModes mode = E3DElevationModes.getModeFromTitle(selectedItem); |
193 |
mLayerProperties.setElevationMode(mode.getValue()); |
194 |
} catch (Exception e) { |
195 |
LOGGER.error("ERROR", e);
|
196 |
} |
197 |
|
198 |
String heightFieldString = _heightFieldCombo.getSelectedItem().toString();
|
199 |
if (heightFieldString.length() == 0) { |
200 |
heightFieldString = null;
|
201 |
} |
202 |
mLayerProperties.setExtrusionHeightField(heightFieldString); |
203 |
|
204 |
try {
|
205 |
String constantHeightString = _constantHeightTextField.getText().trim();
|
206 |
if (constantHeightString.length() > 0) { |
207 |
mLayerProperties.setConstantHeight(Double.valueOf(constantHeightString));
|
208 |
} else {
|
209 |
mLayerProperties.setConstantHeight(null);
|
210 |
} |
211 |
} catch (Exception e) { |
212 |
LOGGER.error("ERROR", e);
|
213 |
} |
214 |
|
215 |
try {
|
216 |
String verticalExagerationString = _verticalExagerationTextField.getText().trim();
|
217 |
if (verticalExagerationString.length() > 0) { |
218 |
mLayerProperties.setVerticalExaggeration(Double.valueOf(verticalExagerationString));
|
219 |
} |
220 |
} catch (Exception e) { |
221 |
LOGGER.error("ERROR", e);
|
222 |
} |
223 |
|
224 |
} |
225 |
|
226 |
@Override
|
227 |
public void cancel() { |
228 |
// TODO Auto-generated method stub
|
229 |
|
230 |
} |
231 |
|
232 |
@Override
|
233 |
public FLayer getLayer() {
|
234 |
return mLayer;
|
235 |
} |
236 |
|
237 |
@Override
|
238 |
public LayerProperties3D getProperties() {
|
239 |
return mLayerProperties;
|
240 |
} |
241 |
|
242 |
@Override
|
243 |
public JComponent asJComponent() { |
244 |
return this; |
245 |
} |
246 |
|
247 |
} |