Revision 22891

View differences:

trunk/extensions/extTopology/src/com/iver/cit/gvsig/cad/SmoothGeometry.java
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
 * PluginServices.getText(this, "BEZIER"),
76
				PluginServices.getText(this, "B_SPLINE"),
77
				PluginServices.getText(this, "CARDINAL_SPLINE"),
78
				PluginServices.getText(this, "CATMULLROM_SPLINE"),
79
				PluginServices.getText(this, "CUBIC_BSPLINE"),
80
				PluginServices.getText(this, "LAGRANGE_CURVE"),
81
				PluginServices.getText(this, "NATURAL_CUBIC_SPLINE"),
82
				PluginServices.getText(this, "NURB_SPLINE")
83
 * 	<li>BEZIER</li>
84
 *  <li>B_SPLINE</li>
85
 *  <li>CARDINAL SPLINE</li>
86
 *  <li>CATMULLROM SPLINE</li>
87
 *  <li>CUBIC B_SPLINE</li>
88
 *  <li>LAGRANGE</li>
89
 *  <li>NATURAL CUBIC SPLINE</li>
90
 *  <li>NURBS</li
91
 * </ol>
92
 * @author Alvaro Zabala
93
 *
94
 */
95
public class SmoothGeometry extends SimplifyGeometry{
96
	
97
	
98
	int selectedCurveOption = FCurve.B_SPLINE;
99
	
100
	public void execute(String actionCommand) {
101
		
102
		
103
		CurveOptionPanel optionPanel = new CurveOptionPanel();
104
		PluginServices.getMDIManager().addWindow(optionPanel);
105
		selectedCurveOption = optionPanel.selectedOption();
106
		if(optionPanel.isAccepted())
107
			super.execute(actionCommand);
108
	}
109
	
110
	protected IGeometry process(IGeometry originalGeometry, int lyrShapeType){
111
		return FGeometryUtil.smoothGeometry(originalGeometry, selectedCurveOption);
112
	}
113
	
114
	
115

  
116
	protected String getName(){
117
		return "SMOOTH_CURVE";
118
	}
119

  
120
	
121
	protected void registerIcons(){
122
		PluginServices.getIconTheme().registerDefault("smooth-curve",
123
													   this.getClass().
124
													   getClassLoader().
125
													   getResource("images/smooth-curve.jpg")
126
		);
127
	}
128
	
129
	
130
	class CurveOptionPanel extends BoxLayoutPanel implements IWindow{
131
		private static final long serialVersionUID = -5996796998659896140L;
132

  
133
		private JComboBox curveTypes;
134
		
135
		String[] curveTypesNames = {
136
				PluginServices.getText(this, "BEZIER"),
137
				PluginServices.getText(this, "B_SPLINE"),
138
				PluginServices.getText(this, "CARDINAL_SPLINE"),
139
				PluginServices.getText(this, "CATMULLROM_SPLINE"),
140
				PluginServices.getText(this, "CUBIC_BSPLINE"),
141
				PluginServices.getText(this, "LAGRANGE_CURVE"),
142
				PluginServices.getText(this, "NATURAL_CUBIC_SPLINE"),
143
				PluginServices.getText(this, "NURB_SPLINE")
144
		};
145
		
146
		String title = PluginServices.getText(this,"SELECCIONAR_CURVA");
147
		
148
		private boolean accepted = false;
149

  
150
		private WindowInfo viewInfo;
151
		
152
		
153
		CurveOptionPanel(){
154
			
155
			this.addRow(new JComponent[] { 
156
					new JLabel(title) });
157

  
158
			this.addComponent(PluginServices.getText(this, "CURVE_TYPE"),
159
										getCurveTypesCb());
160
			
161
			ActionListener cancelAction = new ActionListener(){
162

  
163
				public void actionPerformed(ActionEvent arg0) {
164
					accepted = false;
165
					PluginServices.getMDIManager().
166
						closeWindow(CurveOptionPanel.this);
167
				}};
168
				
169
			ActionListener okAction = new ActionListener(){
170

  
171
				public void actionPerformed(ActionEvent arg0) {
172
					accepted = true;
173
					PluginServices.getMDIManager().
174
						closeWindow(CurveOptionPanel.this);
175
				}};
176
			
177
			AcceptCancelPanel acceptCancelPnl = new AcceptCancelPanel(okAction, cancelAction);
178
			this.addRow(new JComponent[] { acceptCancelPnl }, 600,
179
					50);
180
		}
181
		
182
		public boolean isAccepted(){
183
			return accepted;
184
		}
185
		
186
		
187
		public int selectedOption(){
188
			return getCurveTypesCb().getSelectedIndex();
189
		}
190
		
191
		
192
		JComboBox getCurveTypesCb() {
193
			if (curveTypes == null) {
194
				curveTypes = new JComboBox();
195
				DefaultComboBoxModel defaultModel = 
196
					new DefaultComboBoxModel( curveTypesNames);
197
				curveTypes.setModel(defaultModel);
198
			}
199
			return curveTypes;
200
		}
201

  
202
		public WindowInfo getWindowInfo() {
203
			if (viewInfo == null) {
204
				viewInfo = new WindowInfo(WindowInfo.MODALDIALOG
205
						 					| WindowInfo.PALETTE);
206
				viewInfo.setTitle(title);
207
				viewInfo.setWidth(550);
208
				viewInfo.setHeight(145);
209
			}
210
			return viewInfo;
211
		}
212
		
213
		
214
		
215
	}
216

  
217
}

Also available in: Unified diff