gvsig-3d / 2.1 / branches / extrusion / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / properties / layer / VectorLayer3DController.java @ 657
History | View | Annotate | Download (5.53 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 |
|
25 |
package org.gvsig.view3d.swing.impl.properties.layer; |
26 |
|
27 |
import java.awt.Color; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
|
31 |
import javax.swing.DefaultComboBoxModel; |
32 |
import javax.swing.JColorChooser; |
33 |
import javax.swing.JComponent; |
34 |
|
35 |
import org.slf4j.Logger; |
36 |
import org.slf4j.LoggerFactory; |
37 |
|
38 |
import org.gvsig.fmap.dal.exception.ReadException; |
39 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
40 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
41 |
import org.gvsig.tools.ToolsLocator; |
42 |
import org.gvsig.tools.i18n.I18nManager; |
43 |
import org.gvsig.view3d.lib.api.E3DElevationModes; |
44 |
import org.gvsig.view3d.lib.api.View3DLocator; |
45 |
import org.gvsig.view3d.lib.api.View3DManager; |
46 |
import org.gvsig.view3d.lib.api.properties.E3DLayerLoadingModes; |
47 |
import org.gvsig.view3d.lib.api.properties.LayerProperties3D; |
48 |
import org.gvsig.view3d.lib.api.properties.VectorLayerProperties3D; |
49 |
import org.gvsig.view3d.lib.impl.layers.loaders.VectorLayerLoaderFactory; |
50 |
import org.gvsig.view3d.swing.api.properties.ILayerProperties3DPanel; |
51 |
|
52 |
/**
|
53 |
* Vector layer properties panel.
|
54 |
*
|
55 |
* @author Andrea Antonello andrea.antonello@gmail.com
|
56 |
*
|
57 |
*/
|
58 |
@SuppressWarnings("serial") |
59 |
public class VectorLayer3DController extends VectorLayer3DPanel implements ILayerProperties3DPanel { |
60 |
|
61 |
private static final Logger LOGGER = LoggerFactory.getLogger(VectorLayer3DController.class); |
62 |
|
63 |
private VectorLayerProperties3D mLayerProperties;
|
64 |
|
65 |
private I18nManager i18nManager = ToolsLocator.getI18nManager();
|
66 |
private Color mDefaultColor; |
67 |
|
68 |
private FLayer mLayer;
|
69 |
|
70 |
@Override
|
71 |
public String getName() { |
72 |
return new VectorLayerLoaderFactory().getName(); |
73 |
} |
74 |
|
75 |
@SuppressWarnings("unchecked") |
76 |
public void init(FLayer layer) throws ReadException { |
77 |
this.mLayer = layer;
|
78 |
View3DManager manager = View3DLocator.getManager(); |
79 |
|
80 |
mLayerProperties = (VectorLayerProperties3D) manager.getLayerProperties(layer, new VectorLayerLoaderFactory());
|
81 |
|
82 |
translateLabels(); |
83 |
int elevationMode = mLayerProperties.getElevationMode();
|
84 |
_elevationModeCombo |
85 |
.setModel(new DefaultComboBoxModel<String>(E3DElevationModes.getNormalModeNames((FLyrVect) mLayer))); |
86 |
E3DElevationModes mode = E3DElevationModes.getModeFromValue(elevationMode); |
87 |
_elevationModeCombo.setSelectedItem(mode.getTitle()); |
88 |
|
89 |
mDefaultColor = mLayerProperties.getDefaultColor(); |
90 |
_defaultColorButton.setBackground(mDefaultColor); |
91 |
|
92 |
_defaultColorButton.addActionListener(new ActionListener() { |
93 |
|
94 |
@Override
|
95 |
public void actionPerformed(ActionEvent e) { |
96 |
Color color = JColorChooser.showDialog(VectorLayer3DController.this, |
97 |
i18nManager.getTranslation("Choose a Color"), mDefaultColor);
|
98 |
if (color != null) { |
99 |
_defaultColorButton.setBackground(color); |
100 |
mDefaultColor = color; |
101 |
} |
102 |
} |
103 |
}); |
104 |
|
105 |
Double constantHeight = mLayerProperties.getConstantHeight();
|
106 |
if (constantHeight != null) { |
107 |
_constantHeightTextField.setText(constantHeight.toString()); |
108 |
} |
109 |
|
110 |
} |
111 |
|
112 |
private void translateLabels() { |
113 |
_elevationModeLabel.setText(i18nManager.getTranslation(_elevationModeLabel.getText())); |
114 |
_defaultColorLabel.setText(i18nManager.getTranslation(_defaultColorLabel.getText())); |
115 |
_constantHeightLabel.setText(i18nManager.getTranslation(_constantHeightLabel.getText())); |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public void apply() { |
120 |
mLayerProperties.setDefaultColor(mDefaultColor); |
121 |
|
122 |
try {
|
123 |
String selectedItem = (String) _elevationModeCombo.getSelectedItem(); |
124 |
E3DElevationModes mode = E3DElevationModes.getModeFromTitle(selectedItem); |
125 |
mLayerProperties.setElevationMode(mode.getValue()); |
126 |
} catch (Exception e) { |
127 |
LOGGER.error("ERROR", e);
|
128 |
} |
129 |
|
130 |
try {
|
131 |
String constantHeightString = _constantHeightTextField.getText().trim();
|
132 |
if (constantHeightString.length() > 0) { |
133 |
mLayerProperties.setConstantHeight(Double.valueOf(constantHeightString));
|
134 |
} else {
|
135 |
mLayerProperties.setConstantHeight(null);
|
136 |
} |
137 |
} catch (Exception e) { |
138 |
LOGGER.error("ERROR", e);
|
139 |
} |
140 |
|
141 |
} |
142 |
|
143 |
@Override
|
144 |
public void cancel() { |
145 |
// TODO Auto-generated method stub
|
146 |
|
147 |
} |
148 |
|
149 |
@Override
|
150 |
public FLayer getLayer() {
|
151 |
return mLayer;
|
152 |
} |
153 |
|
154 |
@Override
|
155 |
public LayerProperties3D getProperties() {
|
156 |
return mLayerProperties;
|
157 |
} |
158 |
|
159 |
@Override
|
160 |
public JComponent asJComponent() { |
161 |
return this; |
162 |
} |
163 |
|
164 |
} |