svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / gui / wizard / servicearea / ServiceAreaPage0.java @ 39203
History | View | Annotate | Download (29.7 KB)
1 |
package org.gvsig.graph.gui.wizard.servicearea; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.GridBagConstraints; |
6 |
import java.awt.GridBagLayout; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.util.logging.Logger; |
10 |
|
11 |
import javax.swing.ButtonGroup; |
12 |
import javax.swing.JButton; |
13 |
import javax.swing.JComboBox; |
14 |
import javax.swing.JLabel; |
15 |
import javax.swing.JOptionPane; |
16 |
import javax.swing.JPanel; |
17 |
import javax.swing.JRadioButton; |
18 |
import javax.swing.JScrollPane; |
19 |
import javax.swing.JTabbedPane; |
20 |
import javax.swing.JTable; |
21 |
import javax.swing.border.TitledBorder; |
22 |
import javax.swing.table.AbstractTableModel; |
23 |
import javax.swing.table.TableColumnModel; |
24 |
|
25 |
import jwizardcomponent.JWizardPanel; |
26 |
|
27 |
import org.gvsig.graph.core.GvFlag; |
28 |
import org.gvsig.graph.core.Network; |
29 |
import org.gvsig.graph.gui.wizard.servicearea.AbstractPointsModel.InvalidCostFieldException; |
30 |
|
31 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
32 |
import com.hardcode.gdbms.engine.values.Value; |
33 |
import com.iver.andami.PluginServices; |
34 |
import com.iver.andami.plugins.IExtension; |
35 |
import com.iver.andami.ui.mdiManager.IWindow; |
36 |
import com.iver.cit.gvsig.AddLayer; |
37 |
import com.iver.cit.gvsig.fmap.MapContext; |
38 |
import com.iver.cit.gvsig.fmap.core.FShape; |
39 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
40 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
41 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
42 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
43 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
44 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
45 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
46 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
47 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
48 |
|
49 |
public class ServiceAreaPage0 extends JWizardPanel implements ActionListener, LayerCollectionListener{ |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = -5424586431273891364L; |
55 |
|
56 |
private Logger logger; |
57 |
private MapContext mc;
|
58 |
private ServiceAreaWizard owner;
|
59 |
private PreviewFLyerVectPointsModel layerModel;
|
60 |
private PreviewNetworkPointsModel networkModel;
|
61 |
private Network network;
|
62 |
|
63 |
private JPanel contentPane; |
64 |
|
65 |
private GridBagLayout gridbagSelection; |
66 |
private GridBagConstraints cSelection; |
67 |
private JPanel panelSourcePointsSelection; |
68 |
private TitledBorder borderSourcePointsSelection; |
69 |
private JLabel labelSourcePointsSelection; |
70 |
private JRadioButton radioSourcePointsSelectionFromLayer; |
71 |
private JRadioButton radioSourcePointsSelectionFromNetwork; |
72 |
private ButtonGroup groupSourcePointsSelection; |
73 |
|
74 |
private JPanel panelSelection; |
75 |
private JTabbedPane tabbedSelection; |
76 |
|
77 |
private JPanel panelSourcePointsSelectionFromLayer; |
78 |
private JPanel panelSourcePointsSelectionFromLayerCombos; |
79 |
private JPanel panelSourcePointsSelectionFromLayerPreview; |
80 |
private TitledBorder borderSourcePointsSelecionFromLayer; |
81 |
private JLabel labelSourcePointsSelectionFromLayerName; |
82 |
private JComboBox comboSourcePointsSelectionFromLayerName; |
83 |
private JButton buttonSourcePointsSelectionFromLayerAdd; |
84 |
private JLabel labelSourcePointsSelectionFromLayerMainCostField; |
85 |
private JComboBox comboSourcePointsSelectionFromLayerMainCostField; |
86 |
private JLabel labelSourcePointsSelectionFromLayerSecondaryCostField; |
87 |
private JComboBox comboSourcePointsSelectionFromLayerSecondaryCostField; |
88 |
private JLabel labelSourcePointsSelectionFromLayerPreview; |
89 |
private JTable tableSourcePointsSelectionFromLayerPreview; |
90 |
private JScrollPane scrollSourcePointsSelectionFromLayerPreview; |
91 |
|
92 |
private JPanel panelSourcePointsSelectionFromNetwork; |
93 |
private TitledBorder borderSourcePointsSelectionFromNetwork; |
94 |
private JLabel labelSourcePointsSelectionFromNetworkList; |
95 |
private JScrollPane scrollSourcePointsSelectionFromNetworkList; |
96 |
private JTable tableSourcePointsSelectionFromNetworkList; |
97 |
private JLabel labelSourcePointsSelectionFromNetworkNote; |
98 |
|
99 |
private static final int BORDER_HGAP = 7; |
100 |
private static final int BORDER_VGAP = 7; |
101 |
private static final int COMPONENT_HGAP = 4; |
102 |
private static final int COMPONENT_VGAP = 4; |
103 |
private static final int PREFERRED_HEIGHT = 23; |
104 |
private static final int PREFERRED_WIDTH = 120; |
105 |
|
106 |
public ServiceAreaPage0(ServiceAreaWizard wizard){
|
107 |
super(wizard.getWizardComponents());
|
108 |
|
109 |
this.logger=Logger.getLogger(this.getClass().getName()); |
110 |
|
111 |
this.owner=wizard;
|
112 |
|
113 |
IWindow window=PluginServices.getMDIManager().getActiveWindow(); |
114 |
this.mc=null; |
115 |
if(window instanceof View){ |
116 |
this.mc=((View)window).getMapControl().getMapContext(); |
117 |
} |
118 |
|
119 |
this.layerModel=null; |
120 |
this.networkModel=null; |
121 |
|
122 |
this.initialize();
|
123 |
|
124 |
if(this.mc!=null){ |
125 |
int layersCount=this.mc.getLayers().getLayersCount(); |
126 |
this.comboSourcePointsSelectionFromLayerName.removeAllItems();
|
127 |
FLayer layer; |
128 |
for (int i = 0; i < layersCount; i++) { |
129 |
this.mc.getLayers().addLayerCollectionListener(this); |
130 |
layer=this.mc.getLayers().getLayer(i);
|
131 |
if(layer instanceof FLyrVect){ |
132 |
try {
|
133 |
if(((FLyrVect)layer).getShapeType()==FShape.POINT){
|
134 |
this.comboSourcePointsSelectionFromLayerName.addItem(layer.getName());
|
135 |
} |
136 |
} catch (ReadDriverException except) {
|
137 |
this.logger.warning(except.getMessage());
|
138 |
} |
139 |
} |
140 |
} |
141 |
} |
142 |
|
143 |
this.comboSourcePointsSelectionFromLayerName.addActionListener(this); |
144 |
if(this.comboSourcePointsSelectionFromLayerName.getItemCount()>0) this.comboSourcePointsSelectionFromLayerName.setSelectedIndex(0); |
145 |
} |
146 |
|
147 |
private void initialize(){ |
148 |
this.contentPane=new JPanel(); |
149 |
|
150 |
this.gridbagSelection=new GridBagLayout(); |
151 |
this.cSelection=new GridBagConstraints(); |
152 |
this.panelSourcePointsSelection=new JPanel(); |
153 |
this.borderSourcePointsSelection=new TitledBorder("Fuente de los puntos"); |
154 |
this.panelSourcePointsSelection.setBorder(this.borderSourcePointsSelection); |
155 |
this.labelSourcePointsSelection=new JLabel("Obtener puntos a partir de:"); |
156 |
this.groupSourcePointsSelection=new ButtonGroup(); |
157 |
this.radioSourcePointsSelectionFromLayer=new JRadioButton("Capa de puntos"); |
158 |
this.radioSourcePointsSelectionFromNetwork=new JRadioButton("Gestor de paradas"); |
159 |
this.groupSourcePointsSelection.add(this.radioSourcePointsSelectionFromLayer); |
160 |
this.groupSourcePointsSelection.add(this.radioSourcePointsSelectionFromNetwork); |
161 |
this.radioSourcePointsSelectionFromLayer.addActionListener(this); |
162 |
this.radioSourcePointsSelectionFromNetwork.addActionListener(this); |
163 |
this.radioSourcePointsSelectionFromLayer.setSelected(true); |
164 |
|
165 |
this.panelSelection=new JPanel(); |
166 |
this.panelSelection.setLayout(new BorderLayout(7, 7)); |
167 |
this.tabbedSelection=new JTabbedPane(); |
168 |
this.panelSelection.add(this.tabbedSelection, BorderLayout.CENTER); |
169 |
|
170 |
this.panelSourcePointsSelectionFromLayer=new JPanel(); |
171 |
this.panelSourcePointsSelectionFromLayerCombos=new JPanel(); |
172 |
this.panelSourcePointsSelectionFromLayerPreview=new JPanel(); |
173 |
this.borderSourcePointsSelecionFromLayer=new TitledBorder("Desde una capa"); |
174 |
this.panelSourcePointsSelectionFromLayer.setBorder(this.borderSourcePointsSelecionFromLayer); |
175 |
this.labelSourcePointsSelectionFromLayerName=new JLabel("Capa:", JLabel.RIGHT); |
176 |
this.comboSourcePointsSelectionFromLayerName=new JComboBox(); |
177 |
this.comboSourcePointsSelectionFromLayerName.setPreferredSize(new Dimension(30, 23)); |
178 |
this.buttonSourcePointsSelectionFromLayerAdd=new JButton(PluginServices.getIconTheme().get("layer-add")); |
179 |
this.buttonSourcePointsSelectionFromLayerAdd.addActionListener(this); |
180 |
this.labelSourcePointsSelectionFromLayerMainCostField=new JLabel("Coste primario:", JLabel.RIGHT); |
181 |
this.comboSourcePointsSelectionFromLayerMainCostField=new JComboBox(); |
182 |
this.labelSourcePointsSelectionFromLayerSecondaryCostField=new JLabel("Coste secundario:", JLabel.RIGHT); |
183 |
this.comboSourcePointsSelectionFromLayerSecondaryCostField=new JComboBox(); |
184 |
this.comboSourcePointsSelectionFromLayerMainCostField.setPreferredSize(new Dimension(30, 23)); |
185 |
this.labelSourcePointsSelectionFromLayerPreview=new JLabel("Vista previa", JLabel.LEFT); |
186 |
this.scrollSourcePointsSelectionFromLayerPreview=new JScrollPane(); |
187 |
this.tableSourcePointsSelectionFromLayerPreview=new JTable(); |
188 |
this.scrollSourcePointsSelectionFromLayerPreview.getViewport().add(this.tableSourcePointsSelectionFromLayerPreview); |
189 |
this.scrollSourcePointsSelectionFromLayerPreview.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
190 |
this.scrollSourcePointsSelectionFromLayerPreview.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
191 |
|
192 |
this.panelSourcePointsSelectionFromNetwork=new JPanel(); |
193 |
this.panelSourcePointsSelectionFromNetwork.setLayout(new BorderLayout(BORDER_HGAP, BORDER_VGAP)); |
194 |
this.borderSourcePointsSelectionFromNetwork=new TitledBorder("Desde el gestor de paradas"); |
195 |
this.panelSourcePointsSelectionFromNetwork.setBorder(this.borderSourcePointsSelectionFromNetwork); |
196 |
this.labelSourcePointsSelectionFromNetworkList=new JLabel("Lista de paradas", JLabel.CENTER); |
197 |
this.scrollSourcePointsSelectionFromNetworkList=new JScrollPane(); |
198 |
this.tableSourcePointsSelectionFromNetworkList=new JTable(); |
199 |
this.scrollSourcePointsSelectionFromNetworkList.getViewport().add(this.tableSourcePointsSelectionFromNetworkList); |
200 |
this.scrollSourcePointsSelectionFromNetworkList.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
201 |
this.scrollSourcePointsSelectionFromNetworkList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
202 |
this.labelSourcePointsSelectionFromNetworkNote=new JLabel("<html><p>NOTA: Las paradas se podr?n gestionar en el siguiente paso</p></html>"); |
203 |
|
204 |
this.contentPane.setLayout(new BorderLayout(7, 7)); |
205 |
|
206 |
this.panelSourcePointsSelection.setLayout(this.gridbagSelection); |
207 |
|
208 |
this.cSelection.fill=GridBagConstraints.NONE; |
209 |
this.cSelection.weightx=1.0; |
210 |
this.cSelection.gridwidth=GridBagConstraints.REMAINDER; |
211 |
|
212 |
this.gridbagSelection.setConstraints(this.labelSourcePointsSelection, this.cSelection); |
213 |
this.cSelection.gridwidth=GridBagConstraints.RELATIVE; |
214 |
this.gridbagSelection.setConstraints(this.radioSourcePointsSelectionFromLayer, this.cSelection); |
215 |
this.cSelection.gridwidth=GridBagConstraints.REMAINDER; |
216 |
this.gridbagSelection.setConstraints(this.radioSourcePointsSelectionFromLayer, this.cSelection); |
217 |
|
218 |
this.panelSourcePointsSelection.add(this.labelSourcePointsSelection); |
219 |
this.panelSourcePointsSelection.add(this.radioSourcePointsSelectionFromLayer); |
220 |
this.panelSourcePointsSelection.add(this.radioSourcePointsSelectionFromNetwork); |
221 |
|
222 |
this.contentPane.add(this.panelSourcePointsSelection, BorderLayout.NORTH); |
223 |
this.contentPane.add(this.panelSelection, BorderLayout.CENTER); |
224 |
|
225 |
this.panelSourcePointsSelectionFromLayerCombos.setLayout(null); |
226 |
this.panelSourcePointsSelectionFromLayerCombos.setSize(0, 30*3); |
227 |
this.panelSourcePointsSelectionFromLayerCombos.setPreferredSize(new Dimension(0, 30*3)); |
228 |
|
229 |
this.labelSourcePointsSelectionFromLayerName.setSize(this.labelSourcePointsSelectionFromLayerName.getFontMetrics(this.labelSourcePointsSelectionFromLayerName.getFont()).stringWidth(this.labelSourcePointsSelectionFromLayerName.getText()), PREFERRED_HEIGHT); |
230 |
this.labelSourcePointsSelectionFromLayerMainCostField.setSize(this.labelSourcePointsSelectionFromLayerMainCostField.getFontMetrics(this.labelSourcePointsSelectionFromLayerMainCostField.getFont()).stringWidth(this.labelSourcePointsSelectionFromLayerMainCostField.getText()), PREFERRED_HEIGHT); |
231 |
this.labelSourcePointsSelectionFromLayerSecondaryCostField.setSize(this.labelSourcePointsSelectionFromLayerSecondaryCostField.getFontMetrics(this.labelSourcePointsSelectionFromLayerSecondaryCostField.getFont()).stringWidth(this.labelSourcePointsSelectionFromLayerSecondaryCostField.getText()), PREFERRED_HEIGHT); |
232 |
|
233 |
if(this.labelSourcePointsSelectionFromLayerName.getWidth()>this.labelSourcePointsSelectionFromLayerMainCostField.getWidth()){ |
234 |
if(this.labelSourcePointsSelectionFromLayerName.getWidth()>this.labelSourcePointsSelectionFromLayerSecondaryCostField.getWidth()){ |
235 |
//Label Name has the biggest width
|
236 |
|
237 |
this.labelSourcePointsSelectionFromLayerName.setLocation(BORDER_HGAP, BORDER_VGAP);
|
238 |
this.labelSourcePointsSelectionFromLayerMainCostField.setLocation((this.labelSourcePointsSelectionFromLayerName.getWidth()-this.labelSourcePointsSelectionFromLayerMainCostField.getWidth())+BORDER_HGAP, this.labelSourcePointsSelectionFromLayerName.getY()+this.labelSourcePointsSelectionFromLayerName.getHeight()+COMPONENT_VGAP); |
239 |
this.labelSourcePointsSelectionFromLayerSecondaryCostField.setLocation(this.labelSourcePointsSelectionFromLayerName.getWidth()-this.labelSourcePointsSelectionFromLayerSecondaryCostField.getWidth()+BORDER_HGAP, this.labelSourcePointsSelectionFromLayerMainCostField.getY()+this.labelSourcePointsSelectionFromLayerMainCostField.getHeight()+COMPONENT_VGAP); |
240 |
} |
241 |
else{
|
242 |
//Label Secondary Cost has the biggest width
|
243 |
|
244 |
this.labelSourcePointsSelectionFromLayerName.setLocation(this.labelSourcePointsSelectionFromLayerSecondaryCostField.getWidth()-this.labelSourcePointsSelectionFromLayerName.getWidth()+BORDER_HGAP, BORDER_VGAP); |
245 |
this.labelSourcePointsSelectionFromLayerMainCostField.setLocation(this.labelSourcePointsSelectionFromLayerSecondaryCostField.getWidth()-this.labelSourcePointsSelectionFromLayerMainCostField.getWidth()+BORDER_HGAP, this.labelSourcePointsSelectionFromLayerSecondaryCostField.getY()+this.labelSourcePointsSelectionFromLayerSecondaryCostField.getHeight()+COMPONENT_VGAP); |
246 |
this.labelSourcePointsSelectionFromLayerSecondaryCostField.setLocation(BORDER_HGAP, this.labelSourcePointsSelectionFromLayerName.getY()+this.labelSourcePointsSelectionFromLayerName.getHeight()+COMPONENT_VGAP); |
247 |
} |
248 |
} |
249 |
else{
|
250 |
if(this.labelSourcePointsSelectionFromLayerMainCostField.getWidth()>this.labelSourcePointsSelectionFromLayerSecondaryCostField.getWidth()){ |
251 |
//Label Main Cost has the biggest width
|
252 |
|
253 |
this.labelSourcePointsSelectionFromLayerName.setLocation(this.labelSourcePointsSelectionFromLayerMainCostField.getWidth()-this.labelSourcePointsSelectionFromLayerName.getWidth()+BORDER_HGAP, BORDER_VGAP); |
254 |
this.labelSourcePointsSelectionFromLayerMainCostField.setLocation(BORDER_HGAP, this.labelSourcePointsSelectionFromLayerName.getY()+this.labelSourcePointsSelectionFromLayerName.getHeight()+COMPONENT_VGAP); |
255 |
this.labelSourcePointsSelectionFromLayerSecondaryCostField.setLocation(this.labelSourcePointsSelectionFromLayerMainCostField.getWidth()-this.labelSourcePointsSelectionFromLayerSecondaryCostField.getWidth()+BORDER_HGAP, this.labelSourcePointsSelectionFromLayerMainCostField.getY()+this.labelSourcePointsSelectionFromLayerMainCostField.getHeight()+COMPONENT_VGAP); |
256 |
} |
257 |
else{
|
258 |
//Label Secondary Cost has the biggest width
|
259 |
|
260 |
this.labelSourcePointsSelectionFromLayerName.setLocation(this.labelSourcePointsSelectionFromLayerSecondaryCostField.getWidth()-this.labelSourcePointsSelectionFromLayerName.getWidth()+BORDER_HGAP, BORDER_VGAP); |
261 |
this.labelSourcePointsSelectionFromLayerMainCostField.setLocation(this.labelSourcePointsSelectionFromLayerSecondaryCostField.getWidth()-this.labelSourcePointsSelectionFromLayerMainCostField.getWidth()+BORDER_HGAP, this.labelSourcePointsSelectionFromLayerName.getY()+this.labelSourcePointsSelectionFromLayerName.getHeight()+COMPONENT_VGAP); |
262 |
this.labelSourcePointsSelectionFromLayerSecondaryCostField.setLocation(BORDER_HGAP, this.labelSourcePointsSelectionFromLayerMainCostField.getY()+this.labelSourcePointsSelectionFromLayerMainCostField.getHeight()+COMPONENT_VGAP); |
263 |
} |
264 |
} |
265 |
|
266 |
this.comboSourcePointsSelectionFromLayerName.setBounds(this.labelSourcePointsSelectionFromLayerName.getX()+this.labelSourcePointsSelectionFromLayerName.getWidth()+COMPONENT_HGAP, this.labelSourcePointsSelectionFromLayerName.getY(), PREFERRED_WIDTH, PREFERRED_HEIGHT); |
267 |
this.comboSourcePointsSelectionFromLayerMainCostField.setBounds(this.labelSourcePointsSelectionFromLayerMainCostField.getX()+this.labelSourcePointsSelectionFromLayerMainCostField.getWidth()+4, this.labelSourcePointsSelectionFromLayerMainCostField.getY(), PREFERRED_WIDTH, PREFERRED_HEIGHT); |
268 |
this.comboSourcePointsSelectionFromLayerSecondaryCostField.setBounds(this.labelSourcePointsSelectionFromLayerSecondaryCostField.getX()+this.labelSourcePointsSelectionFromLayerSecondaryCostField.getWidth()+COMPONENT_HGAP, this.labelSourcePointsSelectionFromLayerSecondaryCostField.getY(), PREFERRED_WIDTH, PREFERRED_HEIGHT); |
269 |
this.buttonSourcePointsSelectionFromLayerAdd.setBounds(this.comboSourcePointsSelectionFromLayerName.getX()+this.comboSourcePointsSelectionFromLayerName.getWidth()+4, this.labelSourcePointsSelectionFromLayerName.getY(), 23, PREFERRED_HEIGHT); |
270 |
this.panelSourcePointsSelectionFromLayerCombos.add(this.labelSourcePointsSelectionFromLayerName); |
271 |
this.panelSourcePointsSelectionFromLayerCombos.add(this.comboSourcePointsSelectionFromLayerName); |
272 |
this.panelSourcePointsSelectionFromLayerCombos.add(this.labelSourcePointsSelectionFromLayerMainCostField); |
273 |
this.panelSourcePointsSelectionFromLayerCombos.add(this.comboSourcePointsSelectionFromLayerMainCostField); |
274 |
this.panelSourcePointsSelectionFromLayerCombos.add(this.labelSourcePointsSelectionFromLayerSecondaryCostField); |
275 |
this.panelSourcePointsSelectionFromLayerCombos.add(this.comboSourcePointsSelectionFromLayerSecondaryCostField); |
276 |
this.panelSourcePointsSelectionFromLayerCombos.add(this.buttonSourcePointsSelectionFromLayerAdd); |
277 |
|
278 |
this.panelSourcePointsSelectionFromLayerPreview.setLayout(new BorderLayout(BORDER_HGAP, BORDER_VGAP)); |
279 |
this.panelSourcePointsSelectionFromLayerPreview.add(this.labelSourcePointsSelectionFromLayerPreview, BorderLayout.NORTH); |
280 |
this.panelSourcePointsSelectionFromLayerPreview.add(this.scrollSourcePointsSelectionFromLayerPreview, BorderLayout.CENTER); |
281 |
|
282 |
this.panelSourcePointsSelectionFromLayer.setLayout(new BorderLayout(BORDER_HGAP, BORDER_VGAP)); |
283 |
this.panelSourcePointsSelectionFromLayer.add(this.panelSourcePointsSelectionFromLayerCombos, BorderLayout.NORTH); |
284 |
this.panelSourcePointsSelectionFromLayer.add(this.panelSourcePointsSelectionFromLayerPreview, BorderLayout.CENTER); |
285 |
|
286 |
this.panelSourcePointsSelectionFromNetwork.add(this.labelSourcePointsSelectionFromNetworkList, BorderLayout.NORTH); |
287 |
this.panelSourcePointsSelectionFromNetwork.add(this.scrollSourcePointsSelectionFromNetworkList, BorderLayout.CENTER); |
288 |
this.panelSourcePointsSelectionFromNetwork.add(this.labelSourcePointsSelectionFromNetworkNote, BorderLayout.SOUTH); |
289 |
|
290 |
this.setLayout(new BorderLayout(BORDER_HGAP, BORDER_VGAP)); |
291 |
this.add(this.contentPane, BorderLayout.CENTER); |
292 |
|
293 |
this.tabbedSelection.addTab("Desde una capa", this.panelSourcePointsSelectionFromLayer); |
294 |
} |
295 |
|
296 |
public void next(){ |
297 |
AbstractPointsModel model=this.owner.getController().getModel();
|
298 |
if(this.radioSourcePointsSelectionFromLayer.isSelected()){ |
299 |
try {
|
300 |
FLayer layer; |
301 |
IWindow window=PluginServices.getMDIManager().getActiveWindow(); |
302 |
if(window instanceof View){ |
303 |
layer=((View)window).getMapControl().getMapContext().getLayers().getLayer(String.valueOf(this.comboSourcePointsSelectionFromLayerName.getSelectedItem())); |
304 |
if(layer!=null && layer instanceof FLyrVect){ |
305 |
if(model==null || !(model instanceof FLyrVectPointsModel) || (model instanceof FLyrVectPointsModel && ((FLyrVectPointsModel)model).getLayer()!=((FLyrVect)layer))){ |
306 |
model=new FLyrVectPointsModel((FLyrVect)layer);
|
307 |
((FLyrVectPointsModel)model).setCostFields( |
308 |
String.valueOf(this.comboSourcePointsSelectionFromLayerMainCostField.getSelectedItem()), |
309 |
String.valueOf(this.comboSourcePointsSelectionFromLayerSecondaryCostField.getSelectedItem()) |
310 |
); |
311 |
this.owner.getController().setModel(model);
|
312 |
} |
313 |
super.next();
|
314 |
} |
315 |
else{
|
316 |
JOptionPane.showMessageDialog(this, "No se ha podido obtener una capa de puntos v?lida", "Error", JOptionPane.ERROR_MESSAGE); |
317 |
} |
318 |
} |
319 |
else{
|
320 |
JOptionPane.showMessageDialog(this, "No se ha podido obtener una capa de puntos v?lida", "Error", JOptionPane.ERROR_MESSAGE); |
321 |
} |
322 |
} |
323 |
catch (InvalidCostFieldException except) {
|
324 |
JOptionPane.showMessageDialog(this, except.getMessage(), "Campo no v?lido", JOptionPane.ERROR_MESSAGE); |
325 |
} |
326 |
catch (ReadDriverException except) {
|
327 |
JOptionPane.showMessageDialog(this, "Se ha producido un error en la lectura de la informaci?n de la capa", "Error", JOptionPane.ERROR_MESSAGE); |
328 |
} |
329 |
} |
330 |
else if(this.radioSourcePointsSelectionFromNetwork.isSelected()){ |
331 |
//OJO: SI SE QUITA EL ACTIONLISTENER AL RADIOBUTTON
|
332 |
//QUE DICE QUE LOS PUNTOS VIENEN DE UNA RED ESTO VA
|
333 |
//A PETAR PORQUE LA RED SE OBTIENE EN ESE EVENTO
|
334 |
model=new NetworkPointsModel(this.network); |
335 |
this.owner.getController().setModel(model);
|
336 |
super.next();
|
337 |
} |
338 |
else{
|
339 |
JOptionPane.showMessageDialog(this, "No se ha encontrado un modelo de datos v?lido", "Error", JOptionPane.ERROR_MESSAGE ); |
340 |
} |
341 |
} |
342 |
|
343 |
public void actionPerformed(ActionEvent e) { |
344 |
if(e.getSource()==this.radioSourcePointsSelectionFromLayer){ |
345 |
this.tabbedSelection.removeAll();
|
346 |
this.tabbedSelection.addTab("Desde una capa", this.panelSourcePointsSelectionFromLayer); |
347 |
} |
348 |
else if(e.getSource()==this.radioSourcePointsSelectionFromNetwork){ |
349 |
this.tabbedSelection.removeAll();
|
350 |
|
351 |
if(this.networkModel==null){ |
352 |
if(this.network==null){ |
353 |
IWindow win = PluginServices.getMDIManager().getActiveWindow(); |
354 |
boolean flagNetworkLayer=false; |
355 |
if (win instanceof View) { |
356 |
View view = (View) win; |
357 |
FLayers fLayers=view.getMapControl().getMapContext().getLayers(); |
358 |
FLayer[] layers = fLayers.getVisibles();
|
359 |
for (int i = 0; i < layers.length; i++) { |
360 |
if(!flagNetworkLayer && layers[i].isActive() && (this.network=(Network)layers[i].getProperty("network"))!=null){ |
361 |
flagNetworkLayer=true;
|
362 |
} |
363 |
} |
364 |
} |
365 |
if(this.network!=null){ |
366 |
this.networkModel=new PreviewNetworkPointsModel(this.tableSourcePointsSelectionFromNetworkList, this.network); |
367 |
} |
368 |
else{
|
369 |
JOptionPane.showMessageDialog(this, "No hay ninguna capa que contenta una red", "Advertencia", JOptionPane.WARNING_MESSAGE); |
370 |
} |
371 |
} |
372 |
} |
373 |
|
374 |
this.tabbedSelection.addTab("Desde el gestor de paradas", this.panelSourcePointsSelectionFromNetwork); |
375 |
} |
376 |
else if(e.getSource()==this.comboSourcePointsSelectionFromLayerName){ |
377 |
FLayer layer=this.mc.getLayers().getLayer(String.valueOf(this.comboSourcePointsSelectionFromLayerName.getSelectedItem())); |
378 |
if(layer instanceof FLyrVect){ |
379 |
try {
|
380 |
String[] fieldsName=((FLyrVect)layer).getRecordset().getFieldNames(); |
381 |
this.comboSourcePointsSelectionFromLayerMainCostField.removeAllItems();
|
382 |
this.comboSourcePointsSelectionFromLayerSecondaryCostField.removeAllItems();
|
383 |
for (int i = 0; i < fieldsName.length; i++) { |
384 |
this.comboSourcePointsSelectionFromLayerMainCostField.addItem(fieldsName[i]);
|
385 |
this.comboSourcePointsSelectionFromLayerSecondaryCostField.addItem(fieldsName[i]);
|
386 |
} |
387 |
if(this.comboSourcePointsSelectionFromLayerSecondaryCostField.getItemCount()>1) |
388 |
this.comboSourcePointsSelectionFromLayerSecondaryCostField.setSelectedIndex(1); |
389 |
|
390 |
if(this.layerModel==null){ |
391 |
this.layerModel=new PreviewFLyerVectPointsModel(this.tableSourcePointsSelectionFromLayerPreview, (FLyrVect)layer); |
392 |
} |
393 |
else{
|
394 |
this.layerModel.setFLyrVect((FLyrVect)layer);
|
395 |
} |
396 |
} catch (ReadDriverException except) {
|
397 |
JOptionPane.showMessageDialog(this, "Ha sido imposible obtener los campos de la capa "+layer.getName(), "Error", JOptionPane.ERROR_MESSAGE); |
398 |
} |
399 |
} |
400 |
} |
401 |
else if(e.getSource()==this.buttonSourcePointsSelectionFromLayerAdd){ |
402 |
IExtension ext=PluginServices.getExtension(AddLayer.class); |
403 |
if(ext!=null){ |
404 |
ext.execute("");
|
405 |
} |
406 |
else{
|
407 |
JOptionPane.showMessageDialog(this, "Imposible a?adir capas", "Error", JOptionPane.ERROR_MESSAGE); |
408 |
} |
409 |
} |
410 |
} |
411 |
|
412 |
public void layerAdded(LayerCollectionEvent e) { |
413 |
this.comboSourcePointsSelectionFromLayerName.addItem(e.getAffectedLayer().getName());
|
414 |
this.comboSourcePointsSelectionFromLayerName.setSelectedIndex(this.comboSourcePointsSelectionFromLayerName.getItemCount()-1); |
415 |
} |
416 |
|
417 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
418 |
|
419 |
} |
420 |
|
421 |
public void layerMoved(LayerPositionEvent e) { |
422 |
|
423 |
} |
424 |
|
425 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
426 |
|
427 |
} |
428 |
|
429 |
public void layerRemoved(LayerCollectionEvent e) { |
430 |
this.comboSourcePointsSelectionFromLayerName.removeItem(e.getAffectedLayer().getName());
|
431 |
} |
432 |
|
433 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
434 |
|
435 |
} |
436 |
|
437 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
438 |
if(e.getAffectedLayer().isVisible()){
|
439 |
this.comboSourcePointsSelectionFromLayerName.addItem(e.getAffectedLayer().getName());
|
440 |
} |
441 |
else{
|
442 |
this.comboSourcePointsSelectionFromLayerName.removeItem(e.getAffectedLayer().getName());
|
443 |
} |
444 |
} |
445 |
|
446 |
class PreviewNetworkPointsModel extends AbstractTableModel{ |
447 |
/**
|
448 |
*
|
449 |
*/
|
450 |
private static final long serialVersionUID = 9021109614225441795L; |
451 |
private JTable solutionTable; |
452 |
private Network network;
|
453 |
|
454 |
public PreviewNetworkPointsModel(JTable table, Network network){ |
455 |
this.solutionTable=table;
|
456 |
this.solutionTable.setModel(this); |
457 |
this.network=network;
|
458 |
|
459 |
//this.solutionTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
|
460 |
TableColumnModel cm = this.solutionTable.getColumnModel(); |
461 |
|
462 |
int tablePreferredWidth = (int) this.solutionTable.getPreferredSize().getWidth(); |
463 |
int colSize = this.solutionTable.getFontMetrics(this.solutionTable.getFont()).stringWidth(this.solutionTable.getModel().getColumnName(0)) * 2; |
464 |
cm.getColumn(0).setPreferredWidth((int) (colSize)); |
465 |
cm.getColumn(0).setMinWidth((int) (colSize)); |
466 |
cm.getColumn(0).setMaxWidth((int) (colSize)); |
467 |
tablePreferredWidth -= colSize; |
468 |
//cm.getColumn(1).setPreferredWidth((int)(tablePreferredWidth * 0.7));
|
469 |
} |
470 |
|
471 |
public int getColumnCount() { |
472 |
return 2; |
473 |
} |
474 |
|
475 |
public int getRowCount() { |
476 |
return this.network.getFlagsCount(); |
477 |
} |
478 |
|
479 |
@SuppressWarnings("unchecked") |
480 |
public Class getColumnClass(int columnIndex) { |
481 |
switch (columnIndex){
|
482 |
case 0: |
483 |
return Integer.class; |
484 |
case 1: |
485 |
return String.class; |
486 |
default:
|
487 |
return String.class; |
488 |
} |
489 |
} |
490 |
|
491 |
public Object getValueAt(int rowIndex, int columnIndex) { |
492 |
try{
|
493 |
switch(columnIndex){
|
494 |
case 0: |
495 |
return ((GvFlag)this.network.getOriginaFlags().get(rowIndex)).getIdFlag(); |
496 |
case 1: |
497 |
return ((GvFlag)this.network.getOriginaFlags().get(rowIndex)).getDescription(); |
498 |
default:
|
499 |
return null; |
500 |
} |
501 |
} |
502 |
catch(IndexOutOfBoundsException except){ |
503 |
return null; |
504 |
} |
505 |
} |
506 |
|
507 |
public String getColumnName(int column) { |
508 |
switch(column){
|
509 |
case 0: |
510 |
return "Id"; |
511 |
case 1: |
512 |
return "Descripci?n"; |
513 |
default:
|
514 |
return String.valueOf((char)(65+column)); //ASCII |
515 |
} |
516 |
} |
517 |
|
518 |
@Override
|
519 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
520 |
return false; |
521 |
} |
522 |
|
523 |
@Override
|
524 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
525 |
//Ninguna celda es editable
|
526 |
} |
527 |
} |
528 |
|
529 |
class PreviewFLyerVectPointsModel extends AbstractTableModel{ |
530 |
|
531 |
/**
|
532 |
*
|
533 |
*/
|
534 |
private static final long serialVersionUID = 6363515496824845366L; |
535 |
private JTable solutionTable; |
536 |
private FLyrVect layer;
|
537 |
private SelectableDataSource recordset;
|
538 |
|
539 |
private int tempRowIndex; |
540 |
private Value[] tempRow; |
541 |
|
542 |
private Logger logger; |
543 |
|
544 |
@SuppressWarnings("static-access") |
545 |
public PreviewFLyerVectPointsModel(JTable table, FLyrVect layer) throws ReadDriverException{ |
546 |
this.logger.getLogger(this.getClass().getName()); |
547 |
|
548 |
this.solutionTable=table;
|
549 |
this.setFLyrVect(layer);
|
550 |
this.solutionTable.setAutoCreateColumnsFromModel(true); |
551 |
this.solutionTable.setModel(this); |
552 |
|
553 |
this.tempRowIndex=-1; |
554 |
this.tempRow=null; |
555 |
|
556 |
/*this.solutionTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
|
557 |
TableColumnModel cm = this.solutionTable.getColumnModel();
|
558 |
|
559 |
int tablePreferredWidth = (int) this.solutionTable.getPreferredSize()
|
560 |
.getWidth();
|
561 |
int colSize = Double.valueOf(this.solutionTable.getFontMetrics(this.solutionTable.getFont()).stringWidth(this.solutionTable.getModel().getColumnName(0)) * 1.5).intValue();
|
562 |
cm.getColumn(0).setPreferredWidth((int) (colSize));
|
563 |
cm.getColumn(0).setMinWidth((int) (colSize));
|
564 |
cm.getColumn(0).setMaxWidth((int) (colSize));
|
565 |
tablePreferredWidth -= colSize;
|
566 |
cm.getColumn(1)
|
567 |
.setPreferredWidth((int) (tablePreferredWidth * 0.9));*/
|
568 |
} |
569 |
|
570 |
public void setFLyrVect(FLyrVect layer) throws ReadDriverException{ |
571 |
this.tempRow=null; |
572 |
this.tempRowIndex=-1; |
573 |
this.layer=layer;
|
574 |
this.recordset=this.layer.getRecordset(); |
575 |
this.fireTableStructureChanged();
|
576 |
} |
577 |
|
578 |
public int getColumnCount() { |
579 |
try {
|
580 |
return this.recordset.getFieldCount(); |
581 |
} |
582 |
catch (ReadDriverException except) {
|
583 |
this.logger.warning(except.getMessage());
|
584 |
return 0; |
585 |
} |
586 |
} |
587 |
|
588 |
public int getRowCount() { |
589 |
try {
|
590 |
return (int)this.recordset.getRowCount(); |
591 |
} |
592 |
catch (ReadDriverException except) {
|
593 |
this.logger.warning(except.getMessage());
|
594 |
return 0; |
595 |
} |
596 |
} |
597 |
|
598 |
@SuppressWarnings("unchecked") |
599 |
public Class getColumnClass(int columnIndex) { |
600 |
return String.class; |
601 |
} |
602 |
|
603 |
public Object getValueAt(int rowIndex, int columnIndex) { |
604 |
try {
|
605 |
if(tempRowIndex==rowIndex){
|
606 |
if(columnIndex>tempRow.length) return null; |
607 |
return tempRow[columnIndex].toString();
|
608 |
} |
609 |
else{
|
610 |
Value[] values=this.recordset.getRow(rowIndex); |
611 |
this.tempRow=values;
|
612 |
this.tempRowIndex=rowIndex;
|
613 |
if(columnIndex>values.length) return null; |
614 |
return values[columnIndex].toString();
|
615 |
} |
616 |
} |
617 |
catch (ReadDriverException except) {
|
618 |
this.logger.warning(except.getMessage());
|
619 |
} |
620 |
|
621 |
return null; |
622 |
} |
623 |
|
624 |
public String getColumnName(int column) { |
625 |
try {
|
626 |
return this.recordset.getFieldName(column); |
627 |
} |
628 |
catch (ReadDriverException except) {
|
629 |
this.logger.warning(except.getMessage());
|
630 |
} |
631 |
catch(Exception except){ |
632 |
this.logger.warning(except.getMessage());
|
633 |
} |
634 |
|
635 |
return String.valueOf((char)(65+column)); //ASCII |
636 |
} |
637 |
|
638 |
@Override
|
639 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
640 |
return false; |
641 |
} |
642 |
|
643 |
@Override
|
644 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
645 |
//Ninguna celda es editable
|
646 |
} |
647 |
} |
648 |
} |