40 |
40 |
*/
|
41 |
41 |
|
42 |
42 |
/* CVS MESSAGES:
|
43 |
|
*
|
44 |
|
* $Id$
|
45 |
|
* $Log$
|
46 |
|
* Revision 1.7 2006-11-06 13:13:53 azabala
|
47 |
|
* *** empty log message ***
|
48 |
|
*
|
49 |
|
* Revision 1.6 2006/11/06 10:29:32 jaume
|
50 |
|
* *** empty log message ***
|
51 |
|
*
|
52 |
|
* Revision 1.5 2006/11/03 19:39:29 azabala
|
53 |
|
* *** empty log message ***
|
54 |
|
*
|
55 |
|
* Revision 1.4 2006/10/27 18:26:22 azabala
|
56 |
|
* added implementation of load stages method
|
57 |
|
*
|
58 |
|
* Revision 1.3 2006/10/27 12:41:09 jaume
|
59 |
|
* GUI
|
60 |
|
*
|
61 |
|
* Revision 1.2 2006/10/26 16:31:21 jaume
|
62 |
|
* GUI
|
63 |
|
*
|
64 |
|
* Revision 1.1 2006/10/25 10:50:41 jaume
|
65 |
|
* movement of classes and gui stuff
|
66 |
|
*
|
67 |
|
* Revision 1.4 2006/10/24 08:04:41 jaume
|
68 |
|
* *** empty log message ***
|
69 |
|
*
|
70 |
|
* Revision 1.3 2006/10/23 16:00:20 jaume
|
71 |
|
* *** empty log message ***
|
72 |
|
*
|
73 |
|
* Revision 1.2 2006/10/23 08:05:39 jaume
|
74 |
|
* GUI
|
75 |
|
*
|
76 |
|
* Revision 1.1 2006/10/20 12:02:50 jaume
|
77 |
|
* GUI
|
78 |
|
*
|
79 |
|
*
|
80 |
|
*/
|
|
43 |
*
|
|
44 |
* $Id$
|
|
45 |
* $Log$
|
|
46 |
* Revision 1.8 2006-11-07 19:49:38 azabala
|
|
47 |
* *** empty log message ***
|
|
48 |
*
|
|
49 |
* Revision 1.7 2006/11/06 13:13:53 azabala
|
|
50 |
* *** empty log message ***
|
|
51 |
*
|
|
52 |
* Revision 1.6 2006/11/06 10:29:32 jaume
|
|
53 |
* *** empty log message ***
|
|
54 |
*
|
|
55 |
* Revision 1.5 2006/11/03 19:39:29 azabala
|
|
56 |
* *** empty log message ***
|
|
57 |
*
|
|
58 |
* Revision 1.4 2006/10/27 18:26:22 azabala
|
|
59 |
* added implementation of load stages method
|
|
60 |
*
|
|
61 |
* Revision 1.3 2006/10/27 12:41:09 jaume
|
|
62 |
* GUI
|
|
63 |
*
|
|
64 |
* Revision 1.2 2006/10/26 16:31:21 jaume
|
|
65 |
* GUI
|
|
66 |
*
|
|
67 |
* Revision 1.1 2006/10/25 10:50:41 jaume
|
|
68 |
* movement of classes and gui stuff
|
|
69 |
*
|
|
70 |
* Revision 1.4 2006/10/24 08:04:41 jaume
|
|
71 |
* *** empty log message ***
|
|
72 |
*
|
|
73 |
* Revision 1.3 2006/10/23 16:00:20 jaume
|
|
74 |
* *** empty log message ***
|
|
75 |
*
|
|
76 |
* Revision 1.2 2006/10/23 08:05:39 jaume
|
|
77 |
* GUI
|
|
78 |
*
|
|
79 |
* Revision 1.1 2006/10/20 12:02:50 jaume
|
|
80 |
* GUI
|
|
81 |
*
|
|
82 |
*
|
|
83 |
*/
|
81 |
84 |
package com.iver.cit.gvsig.graph.gui;
|
82 |
85 |
|
83 |
86 |
import java.awt.BorderLayout;
|
... | ... | |
89 |
92 |
import java.awt.GridLayout;
|
90 |
93 |
import java.awt.event.ActionEvent;
|
91 |
94 |
import java.awt.event.ActionListener;
|
|
95 |
import java.util.ArrayList;
|
|
96 |
import java.util.Arrays;
|
92 |
97 |
import java.util.EventObject;
|
93 |
|
import java.util.Vector;
|
|
98 |
import java.util.List;
|
94 |
99 |
|
95 |
100 |
import javax.swing.ImageIcon;
|
96 |
101 |
import javax.swing.JCheckBox;
|
|
102 |
import javax.swing.JComboBox;
|
97 |
103 |
import javax.swing.JLabel;
|
98 |
104 |
import javax.swing.JPanel;
|
99 |
105 |
import javax.swing.JScrollPane;
|
... | ... | |
107 |
113 |
import javax.swing.table.TableColumnModel;
|
108 |
114 |
import javax.swing.table.TableModel;
|
109 |
115 |
|
|
116 |
import org.cresques.cts.IProjection;
|
110 |
117 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
|
111 |
118 |
import org.gvsig.gui.beans.swing.JBlank;
|
112 |
119 |
import org.gvsig.gui.beans.swing.JButton;
|
113 |
120 |
|
|
121 |
import com.hardcode.gdbms.engine.values.Value;
|
|
122 |
import com.hardcode.gdbms.engine.values.ValueFactory;
|
114 |
123 |
import com.iver.andami.PluginServices;
|
115 |
124 |
import com.iver.andami.ui.mdiManager.IWindow;
|
116 |
125 |
import com.iver.andami.ui.mdiManager.WindowInfo;
|
117 |
126 |
import com.iver.cit.gvsig.fmap.DriverException;
|
118 |
127 |
import com.iver.cit.gvsig.fmap.MapContext;
|
119 |
128 |
import com.iver.cit.gvsig.fmap.MapControl;
|
|
129 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
|
|
130 |
import com.iver.cit.gvsig.fmap.core.FGeometry;
|
|
131 |
import com.iver.cit.gvsig.fmap.core.FPoint2D;
|
120 |
132 |
import com.iver.cit.gvsig.fmap.core.FShape;
|
121 |
133 |
import com.iver.cit.gvsig.fmap.core.IGeometry;
|
122 |
134 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
|
123 |
135 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
|
124 |
136 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
|
125 |
137 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
|
|
138 |
import com.iver.cit.gvsig.fmap.edition.EditionException;
|
126 |
139 |
import com.iver.cit.gvsig.fmap.layers.FLayer;
|
127 |
140 |
import com.iver.cit.gvsig.fmap.layers.FLayers;
|
128 |
141 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
|
129 |
142 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
|
|
143 |
import com.iver.cit.gvsig.fmap.layers.LayerEvent;
|
|
144 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
|
|
145 |
import com.iver.cit.gvsig.fmap.layers.LayerListenerAdapter;
|
130 |
146 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
|
131 |
147 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator;
|
132 |
148 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
|
133 |
149 |
import com.iver.cit.gvsig.graph.GraphException;
|
134 |
150 |
import com.iver.cit.gvsig.graph.core.GvFlag;
|
135 |
151 |
import com.iver.cit.gvsig.graph.core.Network;
|
|
152 |
import com.iver.cit.gvsig.graph.solvers.FlagsMemoryDriver;
|
|
153 |
import com.iver.cit.gvsig.graph.solvers.Route;
|
|
154 |
import com.iver.cit.gvsig.graph.solvers.RouteMemoryDriver;
|
136 |
155 |
import com.iver.cit.gvsig.graph.tools.FlagListener;
|
|
156 |
import com.iver.cit.gvsig.project.documents.gui.FOpenDialog;
|
137 |
157 |
import com.iver.cit.gvsig.project.documents.view.gui.IView;
|
138 |
158 |
import com.iver.cit.gvsig.project.documents.view.gui.View;
|
|
159 |
import com.iver.cit.gvsig.util.GvSession;
|
139 |
160 |
import com.vividsolutions.jts.geom.Coordinate;
|
140 |
161 |
import com.vividsolutions.jts.geom.Geometry;
|
141 |
162 |
import com.vividsolutions.jts.geom.GeometryFactory;
|
... | ... | |
143 |
164 |
import com.vividsolutions.jts.geom.Point;
|
144 |
165 |
import com.vividsolutions.jts.index.ItemVisitor;
|
145 |
166 |
|
|
167 |
public class RouteControlPanel extends JPanel implements IWindow,
|
|
168 |
ActionListener {
|
|
169 |
WindowInfo wi;
|
146 |
170 |
|
147 |
|
public class RouteControlPanel extends JPanel implements IWindow, ActionListener {
|
148 |
|
WindowInfo wi;
|
149 |
|
private JPanel westPanel = null;
|
150 |
|
private JScrollPane scrlStages = null;
|
151 |
|
private JTable tblStages = null;
|
152 |
|
private GridBagLayoutPanel eastPanel = null;
|
153 |
|
private DefaultTableModel tableModel = null; // @jve:decl-index=0:visual-constraint=""
|
154 |
|
private JButton btnLoadStage = null;
|
155 |
|
private JButton btnSaveStage = null;
|
|
171 |
private JPanel westPanel = null;
|
156 |
172 |
|
157 |
|
/**
|
158 |
|
* syncronized list of route flags
|
159 |
|
* */
|
160 |
|
private Vector routeFlags;
|
161 |
|
private JLabel lblCost;
|
|
173 |
private JScrollPane scrlStages = null;
|
|
174 |
|
|
175 |
private JTable tblStages = null;
|
|
176 |
|
|
177 |
private GridBagLayoutPanel eastPanel = null;
|
|
178 |
|
|
179 |
private DefaultTableModel tableModel = null; // @jve:decl-index=0:visual-constraint=""
|
|
180 |
|
|
181 |
private JButton btnLoadStage = null;
|
|
182 |
|
|
183 |
private JButton btnSaveStage = null;
|
|
184 |
|
|
185 |
private Network network;
|
|
186 |
|
|
187 |
private ArrayList routeFlags;
|
|
188 |
|
|
189 |
private JLabel lblCost;
|
|
190 |
|
162 |
191 |
private JLabel lblFlagAmout;
|
|
192 |
|
163 |
193 |
private JButton btnPullDownStage;
|
|
194 |
|
164 |
195 |
private JButton btnPushUpStage;
|
|
196 |
|
165 |
197 |
private JButton btnRemoveStage;
|
|
198 |
|
166 |
199 |
private JPanel southPanel;
|
|
200 |
|
167 |
201 |
private final String[] colName = new String[] {
|
168 |
|
PluginServices.getText(this, "enable"),
|
169 |
|
PluginServices.getText(this, "stage"),
|
170 |
|
PluginServices.getText(this, "cost"),
|
171 |
|
};
|
|
202 |
PluginServices.getText(this, "enable"),
|
|
203 |
PluginServices.getText(this, "stage"),
|
|
204 |
PluginServices.getText(this, "cost"), };
|
|
205 |
|
172 |
206 |
private JButton btnGenerateRoute;
|
|
207 |
|
173 |
208 |
private JButton btnSaveRoute;
|
174 |
209 |
|
|
210 |
private MapControl mapCtrl;
|
175 |
211 |
|
176 |
|
/**
|
177 |
|
* This method initializes
|
178 |
|
*
|
179 |
|
*/
|
180 |
|
public RouteControlPanel(GvFlag[] flags) {
|
181 |
|
super();
|
182 |
|
Vector vflags = _getFlags();
|
183 |
|
for(int i = 0; i < flags.length ; i++){
|
184 |
|
vflags.add(flags[i]);
|
185 |
|
}
|
186 |
|
initialize();
|
187 |
|
}
|
|
212 |
/**
|
|
213 |
* This method initializes
|
|
214 |
*
|
|
215 |
*/
|
|
216 |
public RouteControlPanel(Network network) {
|
|
217 |
super();
|
|
218 |
this.network = network;
|
|
219 |
GvFlag[] flags = network.getFlags();
|
|
220 |
List vflags = _getFlags();
|
|
221 |
for (int i = 0; i < flags.length; i++) {
|
|
222 |
vflags.add(flags[i]);
|
|
223 |
}
|
|
224 |
initialize();
|
|
225 |
}
|
|
226 |
|
|
227 |
/**
|
|
228 |
* Method to remove all flags (use
|
|
229 |
* */
|
|
230 |
public void refresh(){
|
|
231 |
GvFlag[] flags = network.getFlags();
|
|
232 |
List vflags = _getFlags();
|
|
233 |
List tempFlags = Arrays.asList(flags);
|
|
234 |
vflags.addAll(tempFlags);
|
|
235 |
lblFlagAmout.setText(String.valueOf(_getFlags()
|
|
236 |
.size()));
|
|
237 |
updateTotalCost();
|
|
238 |
getTblStages().repaint();
|
|
239 |
}
|
|
240 |
|
|
241 |
public void setMapControl(MapControl mapCtrl) {
|
|
242 |
if (mapCtrl != null) {
|
|
243 |
this.mapCtrl = mapCtrl;
|
|
244 |
LayerListenerAdapter listener = new LayerListenerAdapter() {
|
|
245 |
public void activationChanged(LayerEvent e) {
|
|
246 |
processLayer(e.getSource());
|
|
247 |
}
|
188 |
248 |
|
|
249 |
private void processLayer(FLayer layer) {
|
|
250 |
if (layer.isActive()) {
|
|
251 |
if (layer instanceof FLyrVect) {
|
|
252 |
Network net = (Network) layer
|
|
253 |
.getProperty("network");
|
|
254 |
if (net != null) {
|
|
255 |
if(net == network)
|
|
256 |
return;
|
|
257 |
network = net;
|
|
258 |
GvFlag[] newFlags = net.getFlags();
|
|
259 |
_getFlags().clear();
|
|
260 |
_getFlags().addAll(Arrays.asList(newFlags));
|
|
261 |
refresh();
|
|
262 |
}// if
|
|
263 |
}// if
|
|
264 |
}// if
|
189 |
265 |
|
190 |
|
public RouteControlPanel() {
|
191 |
|
super();
|
192 |
|
// addFlag(new GvFlag(0, 0, "FakeFlag1", 0));
|
193 |
|
// addFlag(new GvFlag(0, 0, "FakeFlag2", 0));
|
194 |
|
// addFlag(new GvFlag(0, 0, "FakeFlag3", 0));
|
195 |
|
// addFlag(new GvFlag(0, 0, "FakeFlag4", 0));
|
196 |
|
// addFlag(new GvFlag(0, 0, "FakeFlag5", 0));
|
197 |
|
initialize();
|
198 |
|
}
|
|
266 |
}
|
|
267 |
};
|
|
268 |
mapCtrl.getMapContext().getLayers().addLayerListener(listener);
|
|
269 |
mapCtrl.getMapContext().getLayers().addLayerCollectionListener(
|
|
270 |
listener);
|
|
271 |
}
|
|
272 |
}
|
199 |
273 |
|
200 |
|
public void setCostUnits(String unitsName) {
|
201 |
|
colName[2] = unitsName;
|
202 |
|
getTblStages().repaint();
|
203 |
|
}
|
|
274 |
public RouteControlPanel() {
|
|
275 |
super();
|
|
276 |
initialize();
|
|
277 |
}
|
204 |
278 |
|
205 |
|
/**
|
206 |
|
* This method initializes this
|
207 |
|
*
|
208 |
|
*/
|
209 |
|
private void initialize() {
|
210 |
|
BorderLayout borderLayout = new BorderLayout();
|
211 |
|
borderLayout.setHgap(10);
|
212 |
|
borderLayout.setVgap(10);
|
213 |
|
JPanel cont = new JPanel(borderLayout);
|
214 |
|
cont.setPreferredSize(new Dimension(400,320));
|
215 |
|
this.setSize(new Dimension(400,320));
|
216 |
|
cont.add(getWestPanel(), BorderLayout.WEST);
|
217 |
|
cont.add(getEastPanel(), BorderLayout.CENTER);
|
218 |
|
cont.add(getSouthPanel(), BorderLayout.SOUTH);
|
219 |
|
this.add(cont);
|
220 |
|
updateFlags();
|
221 |
|
}
|
|
279 |
public void setCostUnits(String unitsName) {
|
|
280 |
colName[2] = unitsName;
|
|
281 |
getTblStages().repaint();
|
|
282 |
}
|
222 |
283 |
|
223 |
|
private void updateFlags(){
|
224 |
|
lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
225 |
|
updateTotalCost();
|
226 |
|
getTblStages().repaint();
|
227 |
|
}
|
|
284 |
/**
|
|
285 |
* This method initializes this
|
|
286 |
*
|
|
287 |
*/
|
|
288 |
private void initialize() {
|
|
289 |
BorderLayout borderLayout = new BorderLayout();
|
|
290 |
borderLayout.setHgap(10);
|
|
291 |
borderLayout.setVgap(10);
|
|
292 |
JPanel cont = new JPanel(borderLayout);
|
|
293 |
cont.setPreferredSize(new Dimension(400, 320));
|
|
294 |
this.setSize(new Dimension(400, 320));
|
|
295 |
cont.add(getWestPanel(), BorderLayout.WEST);
|
|
296 |
cont.add(getEastPanel(), BorderLayout.CENTER);
|
|
297 |
cont.add(getSouthPanel(), BorderLayout.SOUTH);
|
|
298 |
this.add(cont);
|
|
299 |
updateFlags();
|
|
300 |
}
|
228 |
301 |
|
229 |
|
private JPanel getSouthPanel() {
|
230 |
|
if (southPanel == null) {
|
231 |
|
southPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
|
232 |
|
southPanel.add(getBtnRemoveStage());
|
233 |
|
southPanel.add(new JBlank(50, 20));
|
234 |
|
southPanel.add(getBtnPushUpStage());
|
235 |
|
southPanel.add(getBtnPullDownStage());
|
236 |
|
southPanel.add(new JLabel(PluginServices.getText(this, "flag_amount")));
|
237 |
|
lblFlagAmout = new JLabel();
|
238 |
|
lblFlagAmout.setFont(lblFlagAmout.getFont().deriveFont(Font.BOLD));
|
239 |
|
southPanel.add(lblFlagAmout);
|
240 |
|
}
|
241 |
|
return southPanel;
|
242 |
|
}
|
|
302 |
private void updateFlags() {
|
|
303 |
lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
|
304 |
updateTotalCost();
|
|
305 |
getTblStages().repaint();
|
|
306 |
}
|
243 |
307 |
|
|
308 |
private JPanel getSouthPanel() {
|
|
309 |
if (southPanel == null) {
|
|
310 |
southPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
|
|
311 |
southPanel.add(getBtnRemoveStage());
|
|
312 |
southPanel.add(new JBlank(50, 20));
|
|
313 |
southPanel.add(getBtnPushUpStage());
|
|
314 |
southPanel.add(getBtnPullDownStage());
|
|
315 |
southPanel.add(new JLabel(PluginServices.getText(this,
|
|
316 |
"flag_amount")));
|
|
317 |
lblFlagAmout = new JLabel();
|
|
318 |
lblFlagAmout.setFont(lblFlagAmout.getFont().deriveFont(Font.BOLD));
|
|
319 |
southPanel.add(lblFlagAmout);
|
|
320 |
}
|
|
321 |
return southPanel;
|
|
322 |
}
|
|
323 |
|
244 |
324 |
public Object getWindowModel() {
|
245 |
|
return this.getClass();
|
246 |
|
}
|
|
325 |
return this.getClass();
|
|
326 |
}
|
247 |
327 |
|
248 |
|
public WindowInfo getWindowInfo() {
|
249 |
|
if (wi==null) {
|
250 |
|
wi = new WindowInfo(WindowInfo.MODELESSDIALOG |
|
251 |
|
WindowInfo.RESIZABLE |
|
252 |
|
WindowInfo.MAXIMIZABLE |
|
253 |
|
WindowInfo.ICONIFIABLE |
|
254 |
|
WindowInfo.PALETTE);
|
255 |
|
wi.setWidth(450);
|
256 |
|
wi.setHeight(320);
|
257 |
|
wi.setTitle(PluginServices.getText(this, "route_control_panel") + "...");
|
258 |
|
}
|
259 |
|
return wi;
|
260 |
|
}
|
|
328 |
public WindowInfo getWindowInfo() {
|
|
329 |
if (wi == null) {
|
|
330 |
wi = new WindowInfo(WindowInfo.MODELESSDIALOG
|
|
331 |
| WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE
|
|
332 |
| WindowInfo.ICONIFIABLE | WindowInfo.PALETTE);
|
|
333 |
wi.setWidth(450);
|
|
334 |
wi.setHeight(320);
|
|
335 |
wi.setTitle(PluginServices.getText(this, "route_control_panel")
|
|
336 |
+ "...");
|
|
337 |
}
|
|
338 |
return wi;
|
|
339 |
}
|
261 |
340 |
|
262 |
|
/**
|
263 |
|
* This method initializes westPanel
|
264 |
|
*
|
265 |
|
* @return javax.swing.JPanel
|
266 |
|
*/
|
267 |
|
private JPanel getWestPanel() {
|
268 |
|
if (westPanel == null) {
|
269 |
|
westPanel = new JPanel(new BorderLayout(5, 5));
|
270 |
|
lblCost = new JLabel();
|
271 |
|
lblCost.setFont(lblCost.getFont().deriveFont(Font.BOLD));
|
272 |
|
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
273 |
|
aux.addComponent(PluginServices.getText(this, "total_route_cost")+":", lblCost);
|
274 |
|
aux.addComponent(getScrlStages());
|
|
341 |
/**
|
|
342 |
* This method initializes westPanel
|
|
343 |
*
|
|
344 |
* @return javax.swing.JPanel
|
|
345 |
*/
|
|
346 |
private JPanel getWestPanel() {
|
|
347 |
if (westPanel == null) {
|
|
348 |
westPanel = new JPanel(new BorderLayout(5, 5));
|
|
349 |
lblCost = new JLabel();
|
|
350 |
lblCost.setFont(lblCost.getFont().deriveFont(Font.BOLD));
|
|
351 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
|
352 |
aux.addComponent(PluginServices.getText(this, "total_route_cost")
|
|
353 |
+ ":", lblCost);
|
|
354 |
aux.addComponent(getScrlStages());
|
275 |
355 |
|
276 |
|
westPanel.add(aux);
|
277 |
|
}
|
278 |
|
return westPanel;
|
279 |
|
}
|
|
356 |
westPanel.add(aux);
|
|
357 |
}
|
|
358 |
return westPanel;
|
|
359 |
}
|
280 |
360 |
|
281 |
|
private JButton getBtnPullDownStage() {
|
|
361 |
private JButton getBtnPullDownStage() {
|
282 |
362 |
if (btnPullDownStage == null) {
|
283 |
|
btnPullDownStage = new JButton(new ImageIcon(this.getClass().getClassLoader().getResource("images/down-arrow.png")));
|
284 |
|
// btnPullDownStage.setName("btnPullDownStage");
|
|
363 |
btnPullDownStage = new JButton(new ImageIcon(this.getClass()
|
|
364 |
.getClassLoader().getResource("images/down-arrow.png")));
|
|
365 |
// btnPullDownStage.setName("btnPullDownStage");
|
285 |
366 |
btnPullDownStage.addActionListener(this);
|
286 |
367 |
}
|
287 |
368 |
return btnPullDownStage;
|
... | ... | |
289 |
370 |
|
290 |
371 |
private JButton getBtnPushUpStage() {
|
291 |
372 |
if (btnPushUpStage == null) {
|
292 |
|
btnPushUpStage = new JButton(new ImageIcon(this.getClass().getClassLoader().getResource("images/up-arrow.png")));
|
293 |
|
// btnPushUpStage.setName("btnPushUpStage");
|
|
373 |
btnPushUpStage = new JButton(new ImageIcon(this.getClass()
|
|
374 |
.getClassLoader().getResource("images/up-arrow.png")));
|
|
375 |
// btnPushUpStage.setName("btnPushUpStage");
|
294 |
376 |
btnPushUpStage.addActionListener(this);
|
295 |
377 |
}
|
296 |
378 |
return btnPushUpStage;
|
... | ... | |
298 |
380 |
|
299 |
381 |
private JButton getBtnRemoveStage() {
|
300 |
382 |
if (btnRemoveStage == null) {
|
301 |
|
btnRemoveStage = new JButton(new ImageIcon(this.getClass().getClassLoader().getResource("images/delete.png")));
|
302 |
|
// btnRemoveStage.setName("btnRemoveStage");
|
|
383 |
btnRemoveStage = new JButton(new ImageIcon(this.getClass()
|
|
384 |
.getClassLoader().getResource("images/delete.png")));
|
|
385 |
// btnRemoveStage.setName("btnRemoveStage");
|
303 |
386 |
btnRemoveStage.addActionListener(this);
|
304 |
387 |
}
|
305 |
388 |
return btnRemoveStage;
|
306 |
389 |
}
|
307 |
390 |
|
308 |
391 |
/**
|
309 |
|
* This method initializes scrlStages
|
310 |
|
*
|
311 |
|
* @return javax.swing.JScrollPane
|
312 |
|
*/
|
313 |
|
private JScrollPane getScrlStages() {
|
314 |
|
if (scrlStages == null) {
|
315 |
|
scrlStages = new JScrollPane();
|
316 |
|
scrlStages.setViewportView(getTblStages());
|
317 |
|
scrlStages.setPreferredSize(new Dimension(270, 200));
|
318 |
|
}
|
319 |
|
return scrlStages;
|
320 |
|
}
|
|
392 |
* This method initializes scrlStages
|
|
393 |
*
|
|
394 |
* @return javax.swing.JScrollPane
|
|
395 |
*/
|
|
396 |
private JScrollPane getScrlStages() {
|
|
397 |
if (scrlStages == null) {
|
|
398 |
scrlStages = new JScrollPane();
|
|
399 |
scrlStages.setViewportView(getTblStages());
|
|
400 |
scrlStages.setPreferredSize(new Dimension(270, 200));
|
|
401 |
}
|
|
402 |
return scrlStages;
|
|
403 |
}
|
321 |
404 |
|
322 |
|
public void addFlag(GvFlag flag) {
|
323 |
|
_getFlags().add(flag);
|
324 |
|
lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
325 |
|
updateTotalCost();
|
326 |
|
getTblStages().repaint();
|
327 |
|
}
|
|
405 |
public void addFlag(GvFlag flag) {
|
|
406 |
_getFlags().add(flag);
|
|
407 |
lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
|
408 |
updateTotalCost();
|
|
409 |
getTblStages().repaint();
|
|
410 |
}
|
328 |
411 |
|
329 |
|
private void updateTotalCost() {
|
330 |
|
GvFlag[] flags = getFlags();
|
331 |
|
double cost = 0;
|
332 |
|
for (int i = 0; i < flags.length; i++) {
|
|
412 |
private void updateTotalCost() {
|
|
413 |
GvFlag[] flags = getFlags();
|
|
414 |
double cost = 0;
|
|
415 |
for (int i = 0; i < flags.length; i++) {
|
333 |
416 |
cost += flags[i].getCost();
|
334 |
417 |
}
|
335 |
|
lblCost.setText(cost + getCostUnitName());
|
|
418 |
lblCost.setText(cost + getCostUnitName());
|
336 |
419 |
}
|
337 |
420 |
|
338 |
421 |
private String getCostUnitName() {
|
... | ... | |
342 |
425 |
}
|
343 |
426 |
|
344 |
427 |
public void removeFlag(GvFlag flag) {
|
345 |
|
removeFlag(_getFlags().indexOf(flag));
|
346 |
|
}
|
|
428 |
removeFlag(_getFlags().indexOf(flag));
|
|
429 |
}
|
347 |
430 |
|
348 |
|
public void removeFlag(int index) {
|
349 |
|
_getFlags().remove(index);
|
350 |
|
lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
351 |
|
getTblStages().repaint();
|
352 |
|
}
|
353 |
|
/**
|
354 |
|
* This method initializes tblStages
|
355 |
|
*
|
356 |
|
* @return javax.swing.JTable
|
357 |
|
*/
|
358 |
|
private JTable getTblStages() {
|
359 |
|
if (tblStages == null) {
|
360 |
|
tblStages = new JTable();
|
361 |
|
tblStages.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
|
362 |
|
tblStages.setModel(getTableModel());
|
363 |
|
TableCellRenderer tcr = new DefaultTableCellRenderer() {
|
|
431 |
public void removeFlag(int index) {
|
|
432 |
_getFlags().remove(index);
|
|
433 |
lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
|
434 |
getTblStages().repaint();
|
|
435 |
}
|
364 |
436 |
|
365 |
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, final int row, int column) {
|
366 |
|
Object myValue = null;
|
367 |
|
if (row >= getFlagCount())
|
368 |
|
return null;
|
369 |
|
if (column == 0) {
|
370 |
|
JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER, 5,0));
|
|
437 |
/**
|
|
438 |
* This method initializes tblStages
|
|
439 |
*
|
|
440 |
* @return javax.swing.JTable
|
|
441 |
*/
|
|
442 |
private JTable getTblStages() {
|
|
443 |
if (tblStages == null) {
|
|
444 |
tblStages = new JTable();
|
|
445 |
tblStages
|
|
446 |
.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
|
|
447 |
tblStages.setModel(getTableModel());
|
|
448 |
TableCellRenderer tcr = new DefaultTableCellRenderer() {
|
371 |
449 |
|
372 |
|
final JCheckBox chk = new JCheckBox("", isSelected(row));
|
|
450 |
public Component getTableCellRendererComponent(JTable table,
|
|
451 |
Object value, boolean isSelected, boolean hasFocus,
|
|
452 |
final int row, int column) {
|
|
453 |
Object myValue = null;
|
|
454 |
if (row >= getFlagCount())
|
|
455 |
return null;
|
|
456 |
if (column == 0) {
|
|
457 |
JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER,
|
|
458 |
5, 0));
|
373 |
459 |
|
374 |
|
p.setBackground(Color.WHITE);
|
375 |
|
p.add(chk);
|
376 |
|
return p;
|
377 |
|
} else if ( column == 1 ) {
|
378 |
|
myValue = ((GvFlag) _getFlags().get(row)).toString();
|
379 |
|
} else if (column == 2) {
|
380 |
|
myValue = String.valueOf(((GvFlag) _getFlags().get(row)).getCost());
|
381 |
|
}
|
382 |
|
return super.getTableCellRendererComponent(table, myValue, isSelected, hasFocus, row, column);
|
383 |
|
}
|
384 |
|
};
|
385 |
|
TableCellEditor tce = new TableCellEditor() {
|
|
460 |
final JCheckBox chk = new JCheckBox("", isSelected(row));
|
386 |
461 |
|
387 |
|
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, final int row, int column) {
|
388 |
|
if (row > getFlagCount() - 1) {
|
389 |
|
return null;
|
390 |
|
}
|
|
462 |
p.setBackground(Color.WHITE);
|
|
463 |
p.add(chk);
|
|
464 |
return p;
|
|
465 |
} else if (column == 1) {
|
|
466 |
myValue = ((GvFlag) _getFlags().get(row)).toString();
|
|
467 |
} else if (column == 2) {
|
|
468 |
myValue = String
|
|
469 |
.valueOf(((GvFlag) _getFlags().get(row))
|
|
470 |
.getCost());
|
|
471 |
}
|
|
472 |
return super.getTableCellRendererComponent(table, myValue,
|
|
473 |
isSelected, hasFocus, row, column);
|
|
474 |
}
|
|
475 |
};
|
|
476 |
TableCellEditor tce = new TableCellEditor() {
|
391 |
477 |
|
392 |
|
if (column == 0) {
|
393 |
|
JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER, 5,0));
|
394 |
|
final JCheckBox chk = new JCheckBox("", isSelected(row));
|
395 |
|
chk.addActionListener(new ActionListener() {
|
396 |
|
public void actionPerformed(java.awt.event.ActionEvent e) {
|
397 |
|
((GvFlag)_getFlags().get(row)).setEnabled(chk.isSelected());
|
398 |
|
};
|
399 |
|
});
|
400 |
|
p.setBackground(Color.WHITE);
|
401 |
|
p.add(chk);
|
402 |
|
return p;
|
403 |
|
} else if (column == 1) {
|
404 |
|
final JTextField txt = new JTextField(((GvFlag) _getFlags().get(row)).toString());
|
405 |
|
txt.addActionListener(new ActionListener() {
|
406 |
|
public void actionPerformed(ActionEvent e) {
|
407 |
|
GvFlag flag = (GvFlag) _getFlags().get(row);
|
408 |
|
flag.setDescription(txt.getText());
|
409 |
|
}
|
410 |
|
});
|
411 |
|
return txt;
|
412 |
|
}
|
413 |
|
return null;
|
|
478 |
public Component getTableCellEditorComponent(JTable table,
|
|
479 |
Object value, boolean isSelected, final int row,
|
|
480 |
int column) {
|
|
481 |
if (row > getFlagCount() - 1) {
|
|
482 |
return null;
|
|
483 |
}
|
414 |
484 |
|
415 |
|
}
|
416 |
|
public void cancelCellEditing() {}
|
|
485 |
if (column == 0) {
|
|
486 |
JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER,
|
|
487 |
5, 0));
|
|
488 |
final JCheckBox chk = new JCheckBox("", isSelected(row));
|
|
489 |
chk.addActionListener(new ActionListener() {
|
|
490 |
public void actionPerformed(
|
|
491 |
java.awt.event.ActionEvent e) {
|
|
492 |
((GvFlag) _getFlags().get(row)).setEnabled(chk
|
|
493 |
.isSelected());
|
|
494 |
};
|
|
495 |
});
|
|
496 |
p.setBackground(Color.WHITE);
|
|
497 |
p.add(chk);
|
|
498 |
return p;
|
|
499 |
} else if (column == 1) {
|
|
500 |
final JTextField txt = new JTextField(
|
|
501 |
((GvFlag) _getFlags().get(row)).toString());
|
|
502 |
txt.addActionListener(new ActionListener() {
|
|
503 |
public void actionPerformed(ActionEvent e) {
|
|
504 |
GvFlag flag = (GvFlag) _getFlags().get(row);
|
|
505 |
flag.setDescription(txt.getText());
|
|
506 |
}
|
|
507 |
});
|
|
508 |
return txt;
|
|
509 |
}
|
|
510 |
return null;
|
417 |
511 |
|
418 |
|
public boolean stopCellEditing() {
|
419 |
|
return false;
|
420 |
|
}
|
|
512 |
}
|
421 |
513 |
|
422 |
|
public Object getCellEditorValue() {
|
423 |
|
return null;
|
424 |
|
}
|
|
514 |
public void cancelCellEditing() {
|
|
515 |
}
|
425 |
516 |
|
426 |
|
public boolean isCellEditable(EventObject anEvent) {
|
427 |
|
return true;
|
428 |
|
}
|
|
517 |
public boolean stopCellEditing() {
|
|
518 |
return false;
|
|
519 |
}
|
429 |
520 |
|
430 |
|
public boolean shouldSelectCell(EventObject anEvent) {
|
431 |
|
return false;
|
432 |
|
}
|
|
521 |
public Object getCellEditorValue() {
|
|
522 |
return null;
|
|
523 |
}
|
433 |
524 |
|
434 |
|
public void addCellEditorListener(CellEditorListener l) {}
|
|
525 |
public boolean isCellEditable(EventObject anEvent) {
|
|
526 |
return true;
|
|
527 |
}
|
435 |
528 |
|
436 |
|
public void removeCellEditorListener(CellEditorListener l) {}
|
|
529 |
public boolean shouldSelectCell(EventObject anEvent) {
|
|
530 |
return false;
|
|
531 |
}
|
437 |
532 |
|
438 |
|
};
|
439 |
|
TableColumnModel cm = tblStages.getColumnModel();
|
440 |
|
for (int i = 0; i < tblStages.getColumnCount(); i++) {
|
441 |
|
cm.getColumn(0).setCellEditor(tce);
|
442 |
|
cm.getColumn(0).setCellRenderer(tcr);
|
443 |
|
}
|
|
533 |
public void addCellEditorListener(CellEditorListener l) {
|
|
534 |
}
|
444 |
535 |
|
445 |
|
int tablePreferredWidth = (int) tblStages.getPreferredSize().getWidth();
|
446 |
|
int colSize = tblStages.
|
447 |
|
getFontMetrics(tblStages.getFont()).
|
448 |
|
stringWidth(tblStages.getModel().getColumnName(0))*2;
|
449 |
|
cm.getColumn(0).setPreferredWidth((int) (colSize));
|
450 |
|
cm.getColumn(0).setMinWidth((int) (colSize));
|
451 |
|
cm.getColumn(0).setMaxWidth((int) (colSize));
|
452 |
|
tablePreferredWidth -= colSize;
|
453 |
|
cm.getColumn(1).setPreferredWidth((int) (tablePreferredWidth * 0.7));
|
454 |
|
cm.getColumn(2).setPreferredWidth((int) (tablePreferredWidth * 0.3));
|
455 |
|
}
|
456 |
|
return tblStages;
|
457 |
|
}
|
|
536 |
public void removeCellEditorListener(CellEditorListener l) {
|
|
537 |
}
|
458 |
538 |
|
459 |
|
protected int getFlagCount() {
|
460 |
|
return _getFlags().size();
|
461 |
|
}
|
|
539 |
};
|
|
540 |
TableColumnModel cm = tblStages.getColumnModel();
|
|
541 |
for (int i = 0; i < tblStages.getColumnCount(); i++) {
|
|
542 |
cm.getColumn(0).setCellEditor(tce);
|
|
543 |
cm.getColumn(0).setCellRenderer(tcr);
|
|
544 |
}
|
462 |
545 |
|
|
546 |
int tablePreferredWidth = (int) tblStages.getPreferredSize()
|
|
547 |
.getWidth();
|
|
548 |
int colSize = tblStages.getFontMetrics(tblStages.getFont())
|
|
549 |
.stringWidth(tblStages.getModel().getColumnName(0)) * 2;
|
|
550 |
cm.getColumn(0).setPreferredWidth((int) (colSize));
|
|
551 |
cm.getColumn(0).setMinWidth((int) (colSize));
|
|
552 |
cm.getColumn(0).setMaxWidth((int) (colSize));
|
|
553 |
tablePreferredWidth -= colSize;
|
|
554 |
cm.getColumn(1)
|
|
555 |
.setPreferredWidth((int) (tablePreferredWidth * 0.7));
|
|
556 |
cm.getColumn(2)
|
|
557 |
.setPreferredWidth((int) (tablePreferredWidth * 0.3));
|
|
558 |
}
|
|
559 |
return tblStages;
|
|
560 |
}
|
463 |
561 |
|
464 |
|
private Vector _getFlags() {
|
465 |
|
if (routeFlags == null) {
|
466 |
|
routeFlags = new Vector();
|
467 |
|
}
|
468 |
|
return routeFlags;
|
469 |
|
}
|
|
562 |
protected int getFlagCount() {
|
|
563 |
return _getFlags().size();
|
|
564 |
}
|
470 |
565 |
|
471 |
|
protected boolean isSelected(int row) {
|
472 |
|
return ((GvFlag) _getFlags().get(row)).isEnabled();
|
473 |
|
}
|
|
566 |
private List _getFlags() {
|
|
567 |
if (routeFlags == null) {
|
|
568 |
routeFlags = new ArrayList();
|
|
569 |
}
|
|
570 |
return routeFlags;
|
|
571 |
}
|
474 |
572 |
|
475 |
|
/**
|
476 |
|
* This method initializes eastPanel
|
477 |
|
*
|
478 |
|
* @return javax.swing.JPanel
|
479 |
|
*/
|
480 |
|
private JPanel getEastPanel() {
|
481 |
|
if (eastPanel == null) {
|
482 |
|
GridLayout layout = new GridLayout();
|
483 |
|
layout.setColumns(1);
|
484 |
|
layout.setVgap(5);
|
485 |
|
JPanel aux = new JPanel();
|
486 |
|
aux.add(getBtnLoadStage());
|
487 |
|
aux.add(getBtnSaveStage());
|
488 |
|
aux.add(getBtnSaveRoute());
|
489 |
|
aux.add(getBtnGenerateReport());
|
490 |
|
layout.setRows(aux.getComponentCount());
|
491 |
|
aux.setLayout(layout);
|
492 |
|
eastPanel = new GridBagLayoutPanel();
|
493 |
|
eastPanel.addComponent(aux);
|
494 |
|
}
|
495 |
|
return eastPanel;
|
496 |
|
}
|
|
573 |
protected boolean isSelected(int row) {
|
|
574 |
return ((GvFlag) _getFlags().get(row)).isEnabled();
|
|
575 |
}
|
497 |
576 |
|
498 |
|
private JButton getBtnGenerateReport() {
|
499 |
|
if (btnGenerateRoute == null) {
|
500 |
|
btnGenerateRoute = new JButton();
|
501 |
|
btnGenerateRoute.setText(PluginServices.getText(this, "generate_report"));
|
502 |
|
btnGenerateRoute.addActionListener(this);
|
503 |
|
}
|
504 |
|
return btnGenerateRoute;
|
|
577 |
/**
|
|
578 |
* This method initializes eastPanel
|
|
579 |
*
|
|
580 |
* @return javax.swing.JPanel
|
|
581 |
*/
|
|
582 |
private JPanel getEastPanel() {
|
|
583 |
if (eastPanel == null) {
|
|
584 |
GridLayout layout = new GridLayout();
|
|
585 |
layout.setColumns(1);
|
|
586 |
layout.setVgap(5);
|
|
587 |
JPanel aux = new JPanel();
|
|
588 |
aux.add(getBtnLoadStage());
|
|
589 |
aux.add(getBtnSaveStage());
|
|
590 |
aux.add(getBtnSaveRoute());
|
|
591 |
aux.add(getBtnGenerateReport());
|
|
592 |
layout.setRows(aux.getComponentCount());
|
|
593 |
aux.setLayout(layout);
|
|
594 |
eastPanel = new GridBagLayoutPanel();
|
|
595 |
eastPanel.addComponent(aux);
|
|
596 |
}
|
|
597 |
return eastPanel;
|
505 |
598 |
}
|
506 |
599 |
|
|
600 |
private JButton getBtnGenerateReport() {
|
|
601 |
if (btnGenerateRoute == null) {
|
|
602 |
btnGenerateRoute = new JButton();
|
|
603 |
btnGenerateRoute.setText(PluginServices.getText(this,
|
|
604 |
"generate_report"));
|
|
605 |
btnGenerateRoute.addActionListener(this);
|
|
606 |
}
|
|
607 |
return btnGenerateRoute;
|
|
608 |
}
|
|
609 |
|
507 |
610 |
private JButton getBtnSaveRoute() {
|
508 |
|
if (btnSaveRoute == null) {
|
509 |
|
btnSaveRoute = new JButton();
|
510 |
|
btnSaveRoute.setText(PluginServices.getText(this, "save_route"));
|
511 |
|
btnSaveRoute.addActionListener(this);
|
512 |
|
}
|
513 |
|
return btnSaveRoute;
|
514 |
|
}
|
|
611 |
if (btnSaveRoute == null) {
|
|
612 |
btnSaveRoute = new JButton();
|
|
613 |
btnSaveRoute.setText(PluginServices.getText(this, "save_route"));
|
|
614 |
btnSaveRoute.addActionListener(this);
|
|
615 |
}
|
|
616 |
return btnSaveRoute;
|
|
617 |
}
|
515 |
618 |
|
516 |
619 |
/**
|
517 |
|
* This method initializes defaultTableModel
|
518 |
|
*
|
519 |
|
* @return javax.swing.table.DefaultTableModel
|
520 |
|
*/
|
521 |
|
private TableModel getTableModel() {
|
522 |
|
if (tableModel == null) {
|
523 |
|
tableModel = new DefaultTableModel() {
|
|
620 |
* This method initializes defaultTableModel
|
|
621 |
*
|
|
622 |
* @return javax.swing.table.DefaultTableModel
|
|
623 |
*/
|
|
624 |
private TableModel getTableModel() {
|
|
625 |
if (tableModel == null) {
|
|
626 |
tableModel = new DefaultTableModel() {
|
524 |
627 |
|
|
628 |
public String getColumnName(int column) {
|
|
629 |
return colName[column];
|
|
630 |
}
|
525 |
631 |
|
526 |
|
public String getColumnName(int column) {
|
527 |
|
return colName[column];
|
528 |
|
}
|
|
632 |
public Object getValueAt(int row, int column) {
|
|
633 |
if (row > getFlagCount() - 1)
|
|
634 |
return null;
|
529 |
635 |
|
530 |
|
public Object getValueAt(int row, int column) {
|
531 |
|
if (row > getFlagCount() -1)
|
532 |
|
return null;
|
|
636 |
GvFlag flag = (GvFlag) _getFlags().get(row);
|
|
637 |
// azo: I dont know why it returns null in the middle of
|
|
638 |
// addStage operation (synchronized vector doesnt solve it)
|
|
639 |
if (flag == null)
|
|
640 |
return null;
|
533 |
641 |
|
534 |
|
GvFlag flag = (GvFlag) _getFlags().get(row);
|
535 |
|
// azo: I dont know why it returns null in the middle of addStage operation (synchronized vector doesnt solve it)
|
536 |
|
if(flag == null)
|
537 |
|
return null;
|
|
642 |
switch (column) {
|
|
643 |
case 0:
|
|
644 |
return new Boolean(flag.isEnabled());
|
|
645 |
case 1:
|
|
646 |
return flag;
|
|
647 |
case 2:
|
|
648 |
return new Double(flag.getCost());
|
|
649 |
}
|
|
650 |
return null;
|
|
651 |
}
|
538 |
652 |
|
539 |
|
|
540 |
|
switch (column) {
|
541 |
|
case 0:
|
542 |
|
return new Boolean(flag.isEnabled());
|
543 |
|
case 1:
|
544 |
|
return flag;
|
545 |
|
case 2:
|
546 |
|
return new Double(flag.getCost());
|
547 |
|
}
|
548 |
|
return null;
|
549 |
|
}
|
550 |
|
|
551 |
|
public void setValueAt(Object aValue, int row, int column) {
|
552 |
|
if (row > getFlagCount()-1)
|
553 |
|
return;
|
554 |
|
switch (column) {
|
555 |
|
case 0:
|
556 |
|
((GvFlag) _getFlags().get(row)).setEnabled(((Boolean) aValue).booleanValue());
|
557 |
|
break;
|
558 |
|
case 1:
|
559 |
|
((GvFlag) _getFlags().get(row)).setDescription((String) aValue);
|
560 |
|
break;
|
561 |
|
/*case 2:
|
562 |
|
getCosts().set(row, new Double((String) aValue));
|
563 |
|
break;*/
|
564 |
|
}
|
565 |
|
|
566 |
|
}
|
567 |
|
};
|
568 |
|
tableModel.setColumnCount(3);
|
569 |
|
int i = getFlagCount();
|
570 |
|
if (i<10)
|
571 |
|
i = 10;
|
572 |
|
|
573 |
|
tableModel.setRowCount(i);
|
574 |
|
}
|
575 |
|
return tableModel;
|
576 |
|
}
|
577 |
|
|
578 |
|
/**
|
579 |
|
* This method initializes btnLoadStage
|
580 |
|
*
|
581 |
|
* @return javax.swing.JButton
|
582 |
|
*/
|
583 |
|
private JButton getBtnLoadStage() {
|
584 |
|
if (btnLoadStage == null) {
|
585 |
|
btnLoadStage = new JButton();
|
586 |
|
btnLoadStage.setText(PluginServices.getText(this, "load_stages"));
|
587 |
|
btnLoadStage.addActionListener(this);
|
588 |
|
}
|
589 |
|
return btnLoadStage;
|
590 |
|
}
|
591 |
|
|
592 |
|
/**
|
593 |
|
* This method initializes btnSaveStages
|
594 |
|
*
|
595 |
|
* @return javax.swing.JButton
|
596 |
|
*/
|
597 |
|
private JButton getBtnSaveStage() {
|
598 |
|
if (btnSaveStage == null) {
|
599 |
|
btnSaveStage = new JButton();
|
600 |
|
btnSaveStage.setText(PluginServices.getText(this, "save_stages"));
|
601 |
|
btnSaveStage.addActionListener(this);
|
602 |
|
}
|
603 |
|
return btnSaveStage;
|
604 |
|
}
|
605 |
|
|
606 |
|
public void actionPerformed(ActionEvent e) {
|
607 |
|
Component c = (Component) e.getSource();
|
608 |
|
if (c.equals(getBtnLoadStage())) {
|
609 |
|
IView view = (View) PluginServices.getMDIManager().getActiveWindow();
|
610 |
|
MapControl mapControl = view.getMapControl();
|
611 |
|
MapContext map = mapControl.getMapContext();
|
612 |
|
FLayers layers = map.getLayers();
|
613 |
|
|
614 |
|
String title = PluginServices.getText(this,
|
615 |
|
"Seleccionar_capa_con_puntos_de_parada");
|
616 |
|
String introductoryText = PluginServices.getText(this,
|
617 |
|
"Seleccione_una_capa_de_puntos_para_crear_paradas");
|
618 |
|
|
619 |
|
LayerSelectionPanel selectionPanel =
|
620 |
|
new LayerSelectionPanel(layers,
|
621 |
|
title,
|
622 |
|
introductoryText,
|
623 |
|
FLyrVect.class,
|
624 |
|
FShape.POINT);
|
625 |
|
PluginServices.getMDIManager().addWindow(selectionPanel);
|
626 |
|
|
627 |
|
if(!selectionPanel.wasFinishPressed())
|
628 |
|
return;
|
629 |
|
else{
|
630 |
|
FLayer layer = selectionPanel.getLayer();
|
631 |
|
if(layer == null)
|
632 |
|
return;
|
633 |
|
if(! (layer instanceof FLyrVect))
|
634 |
|
return;
|
635 |
|
FLyrVect vectLyr = (FLyrVect) layer;
|
636 |
|
|
637 |
|
try {
|
638 |
|
if(vectLyr.getShapeType() != FShape.POINT)
|
|
653 |
public void setValueAt(Object aValue, int row, int column) {
|
|
654 |
if (row > getFlagCount() - 1)
|
639 |
655 |
return;
|
640 |
|
|
641 |
|
//TODO
|
642 |
|
//Hay que refinar bastante, para que el usuario eliga
|
643 |
|
//con que red y con qu? capa lineal quiere trabajar
|
644 |
|
//tal y como est?, si hubiese varias se trabajaria
|
645 |
|
//con la primera que devuelva el iterador
|
646 |
|
|
647 |
|
Network net = null;
|
648 |
|
SingleLayerIterator it = new SingleLayerIterator(layers);
|
649 |
|
while (it.hasNext() && net == null)
|
650 |
|
{
|
651 |
|
FLayer aux = it.next();
|
652 |
|
if (!aux.isActive())
|
653 |
|
continue;
|
654 |
|
net = (Network) aux.getProperty("network");
|
|
656 |
switch (column) {
|
|
657 |
case 0:
|
|
658 |
((GvFlag) _getFlags().get(row))
|
|
659 |
.setEnabled(((Boolean) aValue).booleanValue());
|
|
660 |
break;
|
|
661 |
case 1:
|
|
662 |
((GvFlag) _getFlags().get(row))
|
|
663 |
.setDescription((String) aValue);
|
|
664 |
break;
|
|
665 |
/*
|
|
666 |
* case 2: getCosts().set(row, new Double((String) aValue));
|
|
667 |
* break;
|
|
668 |
*/
|
655 |
669 |
}
|
656 |
|
if(net == null)
|
657 |
|
return;
|
658 |
670 |
|
659 |
|
_getFlags().clear();
|
660 |
|
double realTol = mapControl.getViewPort().
|
661 |
|
toMapDistance(FlagListener.pixelTolerance);
|
662 |
|
GvFlag flag;
|
663 |
|
ReadableVectorial reader =
|
664 |
|
vectLyr.getSource();
|
665 |
|
int numShapes = reader.getShapeCount();
|
|
671 |
}
|
|
672 |
};
|
|
673 |
tableModel.setColumnCount(3);
|
|
674 |
int i = getFlagCount();
|
|
675 |
if (i < 10)
|
|
676 |
i = 10;
|
666 |
677 |
|
667 |
|
GraphicLayer graphicLayer = map.getGraphicsLayer();
|
668 |
|
FSymbol simFlag = new FSymbol(FShape.POINT, Color.BLUE);
|
669 |
|
simFlag.setSize(24);
|
670 |
|
simFlag.setStyle(FConstant.SYMBOL_STYLE_MARKER_IMAGEN);
|
671 |
|
ImageIcon icon = new ImageIcon(this.getClass().getClassLoader()
|
672 |
|
.getResource("images/pushpin.png"));
|
673 |
|
simFlag.setIcon(icon.getImage());
|
674 |
|
int idSymbolFlag = graphicLayer.addSymbol(simFlag);
|
|
678 |
tableModel.setRowCount(i);
|
|
679 |
}
|
|
680 |
return tableModel;
|
|
681 |
}
|
675 |
682 |
|
676 |
|
for(int i = 0; i < numShapes; i++){
|
677 |
|
Geometry geo = reader.getShape(i).toJTSGeometry();
|
678 |
|
if(! ( (geo instanceof Point) || (geo instanceof MultiPoint) ))
|
679 |
|
continue;
|
|
683 |
/**
|
|
684 |
* This method initializes btnLoadStage
|
|
685 |
*
|
|
686 |
* @return javax.swing.JButton
|
|
687 |
*/
|
|
688 |
private JButton getBtnLoadStage() {
|
|
689 |
if (btnLoadStage == null) {
|
|
690 |
btnLoadStage = new JButton();
|
|
691 |
btnLoadStage.setText(PluginServices.getText(this, "load_stages"));
|
|
692 |
btnLoadStage.addActionListener(this);
|
|
693 |
}
|
|
694 |
return btnLoadStage;
|
|
695 |
}
|
680 |
696 |
|
681 |
|
/*
|
682 |
|
* TODO
|
683 |
|
* Aqui deberiamos comprobar si el registro tiene alguno
|
684 |
|
* de los campos de un Flag. A saber:
|
685 |
|
* ->cost
|
686 |
|
* ->description
|
687 |
|
* */
|
688 |
|
Coordinate[] coords = geo.getCoordinates();
|
689 |
|
for(int j = 0; j < coords.length; j++){
|
690 |
|
flag = net.addFlag(coords[j].x, coords[j].y, realTol);
|
|
697 |
/**
|
|
698 |
* This method initializes btnSaveStages
|
|
699 |
*
|
|
700 |
* @return javax.swing.JButton
|
|
701 |
*/
|
|
702 |
private JButton getBtnSaveStage() {
|
|
703 |
if (btnSaveStage == null) {
|
|
704 |
btnSaveStage = new JButton();
|
|
705 |
btnSaveStage.setText(PluginServices.getText(this, "save_stages"));
|
|
706 |
btnSaveStage.addActionListener(this);
|
|
707 |
}
|
|
708 |
return btnSaveStage;
|
|
709 |
}
|
691 |
710 |
|
692 |
|
if (flag == null)
|
693 |
|
{
|
694 |
|
System.out.println("no esta en la red");
|
|
711 |
class FormatSelectionPanel extends JPanel implements IWindow {
|
695 |
712 |
|
696 |
|
//TODO A?adir a un list, y mostrar todos al final
|
|
713 |
JComboBox formats;
|
|
714 |
WindowInfo wi = null;
|
697 |
715 |
|
698 |
|
|
699 |
|
// JOptionPane.showMessageDialog(null, "No est? sobre la red");
|
700 |
|
continue;
|
701 |
|
}
|
702 |
|
addFlag(flag);
|
703 |
|
IGeometry gAux = ShapeFactory.createPoint2D(coords[j].x, coords[j].y);
|
704 |
|
FGraphic graphic = new FGraphic(gAux, idSymbolFlag);
|
705 |
|
graphicLayer.addGraphic(graphic);
|
706 |
|
|
707 |
|
}
|
708 |
|
mapControl.drawGraphics();
|
709 |
|
PluginServices.getMainFrame().enableControls();
|
710 |
|
}
|
711 |
|
|
712 |
|
} catch (DriverException e1) {
|
713 |
|
return;
|
714 |
|
} catch (DriverIOException e2) {
|
715 |
|
return;
|
716 |
|
} catch (GraphException e3) {
|
717 |
|
return;
|
|
716 |
public FormatSelectionPanel() {
|
|
717 |
super(new BorderLayout());
|
|
718 |
String[] formatos = { "SHP", "DXF", "POSTGIS", "GML" };
|
|
719 |
formats = new JComboBox(formatos);
|
|
720 |
GridBagLayoutPanel contentPanel =
|
|
721 |
new GridBagLayoutPanel();
|
|
722 |
contentPanel.addComponent(new JLabel(PluginServices.getText(null,
|
|
723 |
"Seleccione_un_formato_para_guardar_la_ruta")));
|
|
724 |
contentPanel.addComponent(formats);
|
|
725 |
JButton okButton = new JButton(PluginServices.getText(null,
|
|
726 |
"Aceptar"));
|
|
727 |
okButton.addActionListener(new ActionListener() {
|
|
728 |
public void actionPerformed(ActionEvent arg0) {
|
|
729 |
close();
|
718 |
730 |
}
|
719 |
|
}//else
|
720 |
|
} else if (c.equals(getBtnSaveStage())) {
|
721 |
|
/*
|
722 |
|
* TODO
|
723 |
|
* Tenemos que crear, a partir de la colecci?n
|
724 |
|
* de flags cargados (procedentes de una red)
|
725 |
|
* una capa gvSIG de puntos con la informaci?n del flag
|
726 |
|
* (coste, descripci?n, etc.)
|
727 |
|
* Para el piloto, la capa ser? exclusivamente formato
|
728 |
|
* SHP.
|
729 |
|
* */
|
|
731 |
});
|
|
732 |
contentPanel.addComponent(okButton);
|
|
733 |
|
|
734 |
add(contentPanel);
|
|
735 |
}
|
730 |
736 |
|
|
737 |
void close() {
|
|
738 |
PluginServices.getMDIManager().closeWindow(this);
|
|
739 |
}
|
731 |
740 |
|
|
741 |
public String getSelectedFormat() {
|
|
742 |
return (String) formats.getSelectedItem();
|
|
743 |
}
|
732 |
744 |
|
|
745 |
public WindowInfo getWindowInfo() {
|
|
746 |
if (wi == null) {
|
|
747 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.PALETTE);
|
|
748 |
wi.setTitle(PluginServices
|
|
749 |
.getText(null, "Seleccion_de_formato"));// Internacionalizar
|
|
750 |
// esto
|
|
751 |
wi.setWidth(300);
|
|
752 |
wi.setHeight(65);
|
|
753 |
}
|
|
754 |
return wi;
|
|
755 |
}
|
733 |
756 |
|
|
757 |
}
|
734 |
758 |
|
735 |
|
|
|
759 |
public void actionPerformed(ActionEvent e) {
|
|
760 |
Component c = (Component) e.getSource();
|
|
761 |
if (c.equals(getBtnLoadStage())) {
|
|
762 |
loadStages();
|
|
763 |
} else if (c.equals(getBtnSaveStage())) {
|
|
764 |
saveStage();
|
736 |
765 |
} else if (c.equals(getBtnPushUpStage())) {
|
737 |
|
// push up
|
738 |
766 |
int[] selected = tblStages.getSelectedRows();
|
739 |
767 |
if (selected.length == 0 || selected[0] == 0)
|
740 |
768 |
return;
|
741 |
|
|
742 |
769 |
tblStages.clearSelection();
|
743 |
|
|
744 |
770 |
for (int i = 0; i < selected.length; i++) {
|
745 |
|
Object aux = _getFlags().get(selected[i]-1);
|
746 |
|
_getFlags().set(selected[i]-1, _getFlags().get(selected[i]));
|
|
771 |
Object aux = _getFlags().get(selected[i] - 1);
|
|
772 |
_getFlags().set(selected[i] - 1, _getFlags().get(selected[i]));
|
747 |
773 |
_getFlags().set(selected[i], aux);
|
748 |
774 |
selected[i]--;
|
749 |
775 |
tblStages.addRowSelectionInterval(selected[i], selected[i]);
|
750 |
776 |
}
|
751 |
|
|
752 |
777 |
} else if (c.equals(getBtnPullDownStage())) {
|
753 |
778 |
// pull down
|
754 |
779 |
int[] selected = tblStages.getSelectedRows();
|
755 |
|
if (selected.length == 0 || selected[selected.length-1] >= _getFlags().size()-1)
|
|
780 |
if (selected.length == 0
|
|
781 |
|| selected[selected.length - 1] >= _getFlags().size() - 1)
|
756 |
782 |
return;
|
757 |
783 |
|
758 |
784 |
// move rows
|
759 |
785 |
tblStages.clearSelection();
|
760 |
|
for (int i = selected.length-1; i >=0 ; i--) {
|
761 |
|
Object aux = _getFlags().get(selected[i]+1);
|
762 |
|
_getFlags().set(selected[i]+1, _getFlags().get(selected[i]));
|
|
786 |
for (int i = selected.length - 1; i >= 0; i--) {
|
|
787 |
Object aux = _getFlags().get(selected[i] + 1);
|
|
788 |
_getFlags().set(selected[i] + 1, _getFlags().get(selected[i]));
|
763 |
789 |
_getFlags().set(selected[i], aux);
|
764 |
790 |
selected[i]++;
|
765 |
791 |
tblStages.addRowSelectionInterval(selected[i], selected[i]);
|
766 |
792 |
}
|
767 |
793 |
|
768 |
|
|
769 |
794 |
} else if (c.equals(getBtnRemoveStage())) {
|
770 |
|
// remove
|
771 |
|
int[] selected = tblStages.getSelectedRows();
|
|
795 |
removeStage();
|
|
796 |
} else if (c.equals(getBtnSaveRoute())) {
|
|
797 |
saveRoute();
|
|
798 |
} else if (c.equals(getBtnGenerateReport())) {
|
772 |
799 |
|
773 |
|
Network net = null;
|
774 |
|
MapContext map = null;
|
775 |
|
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.
|
776 |
|
getMDIManager()
|
777 |
|
.getActiveWindow();
|
778 |
|
if (f == null) {
|
779 |
|
return;
|
|
800 |
}
|
|
801 |
repaint();
|
|
802 |
}
|
|
803 |
|
|
804 |
private void saveStage(){
|
|
805 |
IWindow window = PluginServices.getMDIManager().getActiveWindow();
|
|
806 |
if(! (window instanceof IView))
|
|
807 |
return;
|
|
808 |
|
|
809 |
IView view = (View) window;
|
|
810 |
MapControl mapControl = view.getMapControl();
|
|
811 |
MapContext map = mapControl.getMapContext();
|
|
812 |
FLayers layers = map.getLayers();
|
|
813 |
Network net = null;
|
|
814 |
SingleLayerIterator it = new SingleLayerIterator(layers);
|
|
815 |
while (it.hasNext() && net == null) {
|
|
816 |
FLayer aux = it.next();
|
|
817 |
if (!aux.isActive())
|
|
818 |
continue;
|
|
819 |
net = (Network) aux.getProperty("network");
|
|
820 |
}
|
|
821 |
if (net == null)
|
|
822 |
return;
|
|
823 |
List features = new ArrayList();
|
|
824 |
GvFlag[] flags = net.getFlags();
|
|
825 |
for(int i = 0; i < flags.length; i++){
|
|
826 |
GvFlag flag = flags[i];
|
|
827 |
FPoint2D point = new FPoint2D(flag.getOriginalPoint());
|
|
828 |
Value[] values = new Value[6];
|
|
829 |
values[GvFlag.ID_FLAG_INDEX] = ValueFactory.createValue(flag.getIdFlag());
|
|
830 |
values[GvFlag.ID_ARC_INDEX] = ValueFactory.createValue(flag.getIdArc());
|
|
831 |
values[GvFlag.DESCRIPTION_INDEX] = ValueFactory.createValue(flag.getDescription());
|
|
832 |
values[GvFlag.DIREC_INDEX] = ValueFactory.createValue(flag.getDirec());
|
|
833 |
values[GvFlag.PCT_INDEX] = ValueFactory.createValue(flag.getPct());
|
|
834 |
values[GvFlag.COST_INDEX] = ValueFactory.createValue(flag.getCost());
|
|
835 |
IGeometry geo = ShapeFactory.createPoint2D(point);
|
|
836 |
DefaultFeature feature = new DefaultFeature(geo, values, new Integer(flag.getIdFlag()).toString() );
|
|
837 |
features.add(feature);
|
|
838 |
}
|
|
839 |
|
|
840 |
FlagsMemoryDriver driver = new FlagsMemoryDriver(features);
|
|
841 |
IProjection projection = FOpenDialog.getLastProjection();
|
|
842 |
FLyrVect routeLayer = (FLyrVect) LayerFactory.createLayer("Route",
|
|
843 |
driver, projection);
|
|
844 |
|
|
845 |
FormatSelectionPanel selectionPanel = new FormatSelectionPanel();
|
|
846 |
PluginServices.getMDIManager().addWindow(selectionPanel);
|
|
847 |
|
|
848 |
String format = selectionPanel.getSelectedFormat();
|
|
849 |
com.iver.cit.gvsig.ExportTo export = new com.iver.cit.gvsig.ExportTo();
|
|
850 |
MapContext context = mapControl.getMapContext();
|
|
851 |
try {
|
|
852 |
if (format.equalsIgnoreCase("SHP")) {
|
|
853 |
export.saveToShp(context, routeLayer);
|
|
854 |
} else if (format.equalsIgnoreCase("DXF")) {
|
|
855 |
export.saveToDxf(context, routeLayer);
|
|
856 |
} else if (format.equalsIgnoreCase("GML")) {
|
|
857 |
export.saveToGml(context, routeLayer);
|
|
858 |
} else if (format.equalsIgnoreCase("POSTGIS")) {
|
|
859 |
export.saveToPostGIS(context, routeLayer);
|
780 |
860 |
}
|
|
861 |
} catch (EditionException e1) {
|
|
862 |
// TODO Auto-generated catch block
|
|
863 |
e1.printStackTrace();
|
|
864 |
} catch (DriverIOException e1) {
|
|
865 |
// TODO Auto-generated catch block
|
|
866 |
e1.printStackTrace();
|
|
867 |
}
|
781 |
868 |
|
782 |
|
if (f instanceof View) {
|
783 |
|
View v = (View) f;
|
784 |
|
map = v.getMapControl().getMapContext();
|
785 |
|
SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
|
786 |
|
while (it.hasNext())
|