svn-gvsig-desktop / trunk / extensions / extTopology / src / com / iver / cit / gvsig / cad / SmoothGeometry.java @ 24091
History | View | Annotate | Download (5.43 KB)
1 |
/*
|
---|---|
2 |
* Created on 10-abr-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id:
|
47 |
* $Log:
|
48 |
*/
|
49 |
package com.iver.cit.gvsig.cad; |
50 |
|
51 |
import java.awt.event.ActionEvent; |
52 |
import java.awt.event.ActionListener; |
53 |
|
54 |
import javax.swing.DefaultComboBoxModel; |
55 |
import javax.swing.JComboBox; |
56 |
import javax.swing.JComponent; |
57 |
import javax.swing.JLabel; |
58 |
|
59 |
import org.gvsig.fmap.core.FGeometryUtil; |
60 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
61 |
import org.gvsig.topology.ui.util.BoxLayoutPanel; |
62 |
|
63 |
import com.iver.andami.PluginServices; |
64 |
import com.iver.andami.ui.mdiManager.IWindow; |
65 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
66 |
import com.iver.cit.gvsig.fmap.core.FCurve; |
67 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
68 |
|
69 |
/**
|
70 |
* Smooths selected geometries (with dimension 1 or 2) applying the
|
71 |
* specified curve.
|
72 |
*
|
73 |
* Supported curves are:
|
74 |
* <ol>
|
75 |
* <li>BEZIER</li>
|
76 |
* <li>B_SPLINE</li>
|
77 |
* <li>CARDINAL SPLINE</li>
|
78 |
* <li>CATMULLROM SPLINE</li>
|
79 |
* <li>CUBIC B_SPLINE</li>
|
80 |
* <li>LAGRANGE</li>
|
81 |
* <li>NATURAL CUBIC SPLINE</li>
|
82 |
* <li>NURBS</li
|
83 |
* </ol>
|
84 |
* @author Alvaro Zabala
|
85 |
*
|
86 |
*/
|
87 |
public class SmoothGeometry extends SimplifyGeometry{ |
88 |
|
89 |
|
90 |
int selectedCurveOption = FCurve.B_SPLINE;
|
91 |
|
92 |
public void execute(String actionCommand) { |
93 |
|
94 |
|
95 |
CurveOptionPanel optionPanel = new CurveOptionPanel();
|
96 |
PluginServices.getMDIManager().addWindow(optionPanel); |
97 |
selectedCurveOption = optionPanel.selectedOption(); |
98 |
if(optionPanel.isAccepted())
|
99 |
super.execute(actionCommand);
|
100 |
} |
101 |
|
102 |
protected IGeometry process(IGeometry originalGeometry, int lyrShapeType){ |
103 |
return FGeometryUtil.smoothGeometry(originalGeometry, selectedCurveOption);
|
104 |
} |
105 |
|
106 |
|
107 |
|
108 |
protected String getName(){ |
109 |
return "SMOOTH_CURVE"; |
110 |
} |
111 |
|
112 |
|
113 |
protected void registerIcons(){ |
114 |
PluginServices.getIconTheme().registerDefault("curve-geometry",
|
115 |
this.getClass().
|
116 |
getClassLoader(). |
117 |
getResource("images/smooth-curve.png")
|
118 |
); |
119 |
} |
120 |
|
121 |
|
122 |
class CurveOptionPanel extends BoxLayoutPanel implements IWindow{ |
123 |
private static final long serialVersionUID = -5996796998659896140L; |
124 |
|
125 |
private JComboBox curveTypes; |
126 |
|
127 |
String[] curveTypesNames = { |
128 |
PluginServices.getText(this, "BEZIER"), |
129 |
PluginServices.getText(this, "B_SPLINE"), |
130 |
PluginServices.getText(this, "CARDINAL_SPLINE"), |
131 |
PluginServices.getText(this, "CATMULLROM_SPLINE"), |
132 |
PluginServices.getText(this, "CUBIC_BSPLINE"), |
133 |
PluginServices.getText(this, "LAGRANGE_CURVE"), |
134 |
PluginServices.getText(this, "NATURAL_CUBIC_SPLINE"), |
135 |
PluginServices.getText(this, "NURB_SPLINE") |
136 |
}; |
137 |
|
138 |
String title = PluginServices.getText(this,"SELECCIONAR_CURVA"); |
139 |
|
140 |
private boolean accepted = false; |
141 |
|
142 |
private WindowInfo viewInfo;
|
143 |
|
144 |
|
145 |
CurveOptionPanel(){ |
146 |
|
147 |
this.addRow(new JComponent[] { |
148 |
new JLabel(title) }); |
149 |
|
150 |
this.addComponent(PluginServices.getText(this, "CURVE_TYPE"), |
151 |
getCurveTypesCb()); |
152 |
|
153 |
ActionListener cancelAction = new ActionListener(){ |
154 |
|
155 |
public void actionPerformed(ActionEvent arg0) { |
156 |
accepted = false;
|
157 |
PluginServices.getMDIManager(). |
158 |
closeWindow(CurveOptionPanel.this); |
159 |
}}; |
160 |
|
161 |
ActionListener okAction = new ActionListener(){ |
162 |
|
163 |
public void actionPerformed(ActionEvent arg0) { |
164 |
accepted = true;
|
165 |
PluginServices.getMDIManager(). |
166 |
closeWindow(CurveOptionPanel.this); |
167 |
}}; |
168 |
|
169 |
AcceptCancelPanel acceptCancelPnl = new AcceptCancelPanel(okAction, cancelAction);
|
170 |
this.addRow(new JComponent[] { acceptCancelPnl }, 600, |
171 |
50);
|
172 |
} |
173 |
|
174 |
public boolean isAccepted(){ |
175 |
return accepted;
|
176 |
} |
177 |
|
178 |
|
179 |
public int selectedOption(){ |
180 |
return getCurveTypesCb().getSelectedIndex();
|
181 |
} |
182 |
|
183 |
|
184 |
JComboBox getCurveTypesCb() {
|
185 |
if (curveTypes == null) { |
186 |
curveTypes = new JComboBox(); |
187 |
DefaultComboBoxModel defaultModel =
|
188 |
new DefaultComboBoxModel( curveTypesNames); |
189 |
curveTypes.setModel(defaultModel); |
190 |
} |
191 |
return curveTypes;
|
192 |
} |
193 |
|
194 |
public WindowInfo getWindowInfo() {
|
195 |
if (viewInfo == null) { |
196 |
viewInfo = new WindowInfo(WindowInfo.MODALDIALOG
|
197 |
| WindowInfo.PALETTE); |
198 |
viewInfo.setTitle(title); |
199 |
viewInfo.setWidth(550);
|
200 |
viewInfo.setHeight(145);
|
201 |
} |
202 |
return viewInfo;
|
203 |
} |
204 |
|
205 |
|
206 |
|
207 |
} |
208 |
|
209 |
} |