svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / gui / OdMatrixControlPanel.java @ 30840
History | View | Annotate | Download (11.9 KB)
1 |
/*
|
---|---|
2 |
* OdMatrixControlPanel.java
|
3 |
*
|
4 |
* Created on 20 de octubre de 2008, 13:19
|
5 |
*/
|
6 |
|
7 |
package org.gvsig.graph.gui; |
8 |
|
9 |
import java.awt.Component; |
10 |
import java.awt.Dimension; |
11 |
import java.awt.Rectangle; |
12 |
import java.util.Vector; |
13 |
|
14 |
import javax.swing.DefaultComboBoxModel; |
15 |
import javax.swing.JFileChooser; |
16 |
import javax.swing.JFrame; |
17 |
import javax.swing.JPanel; |
18 |
import javax.swing.UIManager; |
19 |
import javax.swing.UnsupportedLookAndFeelException; |
20 |
|
21 |
import org.gvsig.exceptions.BaseException; |
22 |
import org.gvsig.fmap.util.LayerListCellRenderer; |
23 |
import org.gvsig.graph.IODMatrixFileWriter; |
24 |
import org.gvsig.graph.ODMatrixExtension; |
25 |
|
26 |
import com.iver.andami.PluginServices; |
27 |
import com.iver.andami.ui.mdiManager.IWindow; |
28 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
29 |
import com.iver.cit.gvsig.fmap.MapContext; |
30 |
import com.iver.cit.gvsig.fmap.core.FShape; |
31 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
32 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
33 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
34 |
import com.iver.cit.gvsig.fmap.layers.LayersIterator; |
35 |
import javax.swing.JLabel; |
36 |
import javax.swing.SwingConstants; |
37 |
import javax.swing.JTextField; |
38 |
import javax.swing.JTextArea; |
39 |
import java.awt.Font; |
40 |
|
41 |
/**
|
42 |
*
|
43 |
* @author Fjp
|
44 |
*/
|
45 |
public class OdMatrixControlPanel extends JPanel implements IWindow { |
46 |
|
47 |
public static int TIME_SECONDS = 0; |
48 |
public static int TIME_MINUTES = 1; |
49 |
public static int LENGTH_METERS = 0; |
50 |
public static int LENGTH_KILOMETERS = 1; |
51 |
public static int LENGTH_YARDS = 2; |
52 |
public static int LENGTH_MILES = 3; |
53 |
public static int FILE_FORMAT_2_COLS = 0; |
54 |
public static int FILE_FORMAT_MANY_COLS = 1; |
55 |
|
56 |
private MapContext mapContext;
|
57 |
|
58 |
private DefaultComboBoxModel cboLayerOriginsModel; |
59 |
private DefaultComboBoxModel cboLayerDestinationsModel; |
60 |
|
61 |
private WindowInfo wi;
|
62 |
private boolean okPressed = false; |
63 |
|
64 |
/**
|
65 |
* This method initializes txtTolerance
|
66 |
*
|
67 |
* @return javax.swing.JTextField
|
68 |
*/
|
69 |
private JTextField getTxtTolerance() { |
70 |
if (txtTolerance == null) { |
71 |
txtTolerance = new JTextField(); |
72 |
txtTolerance.setBounds(new Rectangle(159, 118, 94, 22)); |
73 |
txtTolerance.setText("50");
|
74 |
} |
75 |
return txtTolerance;
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* This method initializes txtFormatAreaDescription
|
80 |
*
|
81 |
* @return javax.swing.JTextArea
|
82 |
*/
|
83 |
private JTextArea getTxtFormatAreaDescription() { |
84 |
if (txtFormatAreaDescription == null) { |
85 |
txtFormatAreaDescription = new JTextArea(); |
86 |
txtFormatAreaDescription.setBounds(new Rectangle(16, 55, 438, 53)); |
87 |
txtFormatAreaDescription.setRows(3);
|
88 |
txtFormatAreaDescription.setFont(new Font("Arial", Font.PLAIN, 10)); |
89 |
txtFormatAreaDescription.setLineWrap(true);
|
90 |
txtFormatAreaDescription.setEditable(false);
|
91 |
} |
92 |
return txtFormatAreaDescription;
|
93 |
} |
94 |
|
95 |
public static void main(String[] args) throws ClassNotFoundException, |
96 |
InstantiationException, IllegalAccessException { |
97 |
try {
|
98 |
|
99 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
100 |
} catch (UnsupportedLookAndFeelException e) { |
101 |
// TODO Auto-generated catch block
|
102 |
e.printStackTrace(); |
103 |
} |
104 |
OdMatrixControlPanel panel = new OdMatrixControlPanel();
|
105 |
JFrame test = new JFrame(); |
106 |
|
107 |
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
108 |
test.add(panel); |
109 |
test.setBounds(panel.getBounds()); |
110 |
test.setVisible(true);
|
111 |
} |
112 |
|
113 |
/** Creates new form OdMatrixControlPanel */
|
114 |
public OdMatrixControlPanel() {
|
115 |
initComponents(); |
116 |
} |
117 |
|
118 |
/**
|
119 |
* This method is called from within the constructor to initialize the form.
|
120 |
* WARNING: Do NOT modify this code. The content of this method is always
|
121 |
* regenerated by the Form Editor.
|
122 |
*/
|
123 |
@SuppressWarnings("unchecked") |
124 |
// <editor-fold defaultstate="collapsed" desc="Generated Code">
|
125 |
private void initComponents() { |
126 |
|
127 |
jLblToleranceUnits = new JLabel(); |
128 |
jLblToleranceUnits.setBounds(new Rectangle(265, 118, 135, 20)); |
129 |
jLblToleranceUnits.setText(_T("meters"));
|
130 |
jLblTolerance = new JLabel(); |
131 |
jLblTolerance.setBounds(new Rectangle(17, 118, 135, 20)); |
132 |
jLblTolerance.setText(_T("Tolerance") + ":"); |
133 |
jLblTolerance.setHorizontalAlignment(SwingConstants.RIGHT);
|
134 |
this.setLayout(null); |
135 |
this.setSize(new Dimension(499, 350)); |
136 |
jPanel1 = new javax.swing.JPanel();
|
137 |
cboFileFormat = new javax.swing.JComboBox();
|
138 |
jLabel5 = new javax.swing.JLabel();
|
139 |
jPanel2 = new javax.swing.JPanel();
|
140 |
cboLayerOrigins = new javax.swing.JComboBox();
|
141 |
jLblLayerOrigins = new javax.swing.JLabel();
|
142 |
cboLayerDestinations = new javax.swing.JComboBox();
|
143 |
jLblLayerDestinations = new javax.swing.JLabel();
|
144 |
jLblFile = new javax.swing.JLabel();
|
145 |
txtGeneratedFile = new javax.swing.JTextField();
|
146 |
btnSelectFile = new javax.swing.JButton();
|
147 |
btnOk = new javax.swing.JButton();
|
148 |
btnCancel = new javax.swing.JButton();
|
149 |
|
150 |
jPanel1.setLayout(null);
|
151 |
jPanel1.setBorder(javax.swing.BorderFactory |
152 |
.createTitledBorder(_T("Options")));
|
153 |
|
154 |
jPanel1.setBounds(new Rectangle(14, 172, 468, 122)); |
155 |
jPanel1.add(cboFileFormat, null);
|
156 |
jPanel1.add(jLabel5, null);
|
157 |
|
158 |
jPanel1.add(getTxtFormatAreaDescription(), null);
|
159 |
IODMatrixFileWriter[] writers = ODMatrixExtension.getOdMatrixWriters();
|
160 |
String[] formats = new String[writers.length]; |
161 |
for (int i = 0; i < formats.length; i++) { |
162 |
formats[i] = writers[i].getFormatDescription(); |
163 |
} |
164 |
cboFileFormat.setModel(new DefaultComboBoxModel(formats)); |
165 |
cboFileFormat.setSelectedIndex(0);
|
166 |
|
167 |
cboFileFormat.setBounds(new Rectangle(158, 19, 295, 25)); |
168 |
cboFileFormat.addItemListener(new java.awt.event.ItemListener() {
|
169 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
170 |
System.out.println(e.getItem());
|
171 |
|
172 |
txtFormatAreaDescription.setText(e.getItem().toString()); |
173 |
} |
174 |
}); |
175 |
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
176 |
jLabel5.setBounds(new Rectangle(17, 22, 134, 16)); |
177 |
jLabel5.setText(_T("File_Format") + ":"); |
178 |
|
179 |
jPanel2.setLayout(null);
|
180 |
|
181 |
// jPanel2.setLayout(new GridBagLayout(jPanel2, BoxLayout.Y_AXIS));
|
182 |
jPanel2.setBorder(javax.swing.BorderFactory |
183 |
.createTitledBorder(_T("Parameters")));
|
184 |
|
185 |
jPanel2.setBounds(new Rectangle(14, 13, 468, 144)); |
186 |
|
187 |
cboLayerOrigins.setBounds(new Rectangle(158, 32, 259, 22)); |
188 |
jLblLayerOrigins |
189 |
.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
190 |
jLblLayerOrigins.setBounds(new Rectangle(17, 33, 135, 20)); |
191 |
jLblLayerOrigins.setText(_T("Layer_Origins") + ":"); |
192 |
|
193 |
cboLayerDestinations.setBounds(new Rectangle(158, 61, 259, 22)); |
194 |
jLblLayerDestinations |
195 |
.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
196 |
jLblLayerDestinations.setBounds(new Rectangle(17, 59, 135, 20)); |
197 |
jLblLayerDestinations.setText(_T("Layer_Destinations") + ":"); |
198 |
|
199 |
jLblFile.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
200 |
jLblFile.setBounds(new Rectangle(17, 90, 135, 20)); |
201 |
jLblFile.setText(_T("Generated_File") + ":"); |
202 |
|
203 |
txtGeneratedFile.setText("");
|
204 |
|
205 |
txtGeneratedFile.setBounds(new Rectangle(159, 90, 259, 22)); |
206 |
btnSelectFile.setText("...");
|
207 |
|
208 |
btnSelectFile.setBounds(new Rectangle(425, 90, 28, 21)); |
209 |
btnSelectFile.addActionListener(new java.awt.event.ActionListener() {
|
210 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
211 |
System.out.println("actionPerformed()"); // TODO |
212 |
// Auto-generated
|
213 |
// Event stub
|
214 |
// actionPerformed()
|
215 |
} |
216 |
}); |
217 |
btnSelectFile.addActionListener(new java.awt.event.ActionListener() {
|
218 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
219 |
JFileChooser dlg = new JFileChooser(); |
220 |
if (dlg.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) |
221 |
{ |
222 |
txtGeneratedFile.setText(dlg.getSelectedFile().getPath()); |
223 |
} |
224 |
} |
225 |
}); |
226 |
btnSelectFile.addActionListener(new java.awt.event.ActionListener() {
|
227 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
228 |
|
229 |
} |
230 |
}); |
231 |
btnOk.setText(_T("OK"));
|
232 |
btnOk.setBounds(new Rectangle(107, 305, 136, 26)); |
233 |
btnOk.addActionListener(new java.awt.event.ActionListener() {
|
234 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
235 |
btnOkActionPerformed(evt); |
236 |
} |
237 |
}); |
238 |
|
239 |
btnCancel.setText(_T("Cancel"));
|
240 |
btnCancel.setBounds(new Rectangle(257, 305, 136, 26)); |
241 |
jPanel2.add(jLblLayerOrigins, null);
|
242 |
jPanel2.add(cboLayerOrigins, null);
|
243 |
jPanel2.add(jLblLayerDestinations, null);
|
244 |
jPanel2.add(cboLayerDestinations, null);
|
245 |
jPanel2.add(jLblFile, null);
|
246 |
jPanel2.add(txtGeneratedFile, null);
|
247 |
jPanel2.add(btnSelectFile, null);
|
248 |
jPanel2.add(jLblTolerance, null);
|
249 |
jPanel2.add(getTxtTolerance(), null);
|
250 |
jPanel2.add(jLblToleranceUnits, null);
|
251 |
this.add(jPanel2, null); |
252 |
this.add(jPanel1, null); |
253 |
this.add(btnOk, null); |
254 |
this.add(btnCancel, null); |
255 |
btnCancel.addActionListener(new java.awt.event.ActionListener() {
|
256 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
257 |
btnCancelActionPerformed(evt); |
258 |
} |
259 |
}); |
260 |
|
261 |
}// </editor-fold>
|
262 |
|
263 |
private void closeWindow() { |
264 |
if (PluginServices.getMainFrame() != null) { |
265 |
PluginServices.getMDIManager().closeWindow(this);
|
266 |
} |
267 |
} |
268 |
|
269 |
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) { |
270 |
okPressed = true;
|
271 |
closeWindow(); |
272 |
} |
273 |
|
274 |
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) { |
275 |
closeWindow(); |
276 |
} |
277 |
|
278 |
/**
|
279 |
* @return Returns the okPressed.
|
280 |
*/
|
281 |
public boolean isOkPressed() { |
282 |
return okPressed;
|
283 |
} |
284 |
|
285 |
// Variables declaration - do not modify
|
286 |
private javax.swing.JButton btnCancel;
|
287 |
private javax.swing.JButton btnOk;
|
288 |
private javax.swing.JButton btnSelectFile;
|
289 |
private javax.swing.JComboBox cboFileFormat;
|
290 |
private javax.swing.JComboBox cboLayerDestinations;
|
291 |
private javax.swing.JComboBox cboLayerOrigins;
|
292 |
private javax.swing.JLabel jLabel5;
|
293 |
private javax.swing.JLabel jLblFile;
|
294 |
private javax.swing.JLabel jLblLayerDestinations;
|
295 |
private javax.swing.JLabel jLblLayerOrigins;
|
296 |
private javax.swing.JPanel jPanel1;
|
297 |
private javax.swing.JPanel jPanel2;
|
298 |
private javax.swing.JTextField txtGeneratedFile;
|
299 |
private JLabel jLblTolerance = null; |
300 |
private JTextField txtTolerance = null; |
301 |
private JLabel jLblToleranceUnits = null; |
302 |
private JTextArea txtFormatAreaDescription = null; |
303 |
|
304 |
// End of variables declaration
|
305 |
|
306 |
public void setMapContext(MapContext mapContext) throws BaseException { |
307 |
this.mapContext = mapContext;
|
308 |
FLayers layers = mapContext.getLayers(); |
309 |
LayersIterator it = new LayersIterator(layers);
|
310 |
Vector<FLyrVect> arrayLayers = new Vector<FLyrVect>(); |
311 |
while (it.hasNext()) {
|
312 |
FLayer lyr = it.nextLayer(); |
313 |
if (lyr instanceof FLyrVect) { |
314 |
FLyrVect lyrVect = (FLyrVect) lyr; |
315 |
if ((lyrVect.getShapeType() == FShape.POINT)
|
316 |
|| (lyrVect.getShapeType() == FShape.MULTIPOINT)) |
317 |
arrayLayers.add(lyrVect); |
318 |
|
319 |
} |
320 |
} |
321 |
cboLayerOriginsModel = new DefaultComboBoxModel(arrayLayers); |
322 |
cboLayerDestinationsModel = new DefaultComboBoxModel(arrayLayers); |
323 |
cboLayerOrigins.setModel(cboLayerOriginsModel); |
324 |
cboLayerDestinations.setModel(cboLayerDestinationsModel); |
325 |
cboLayerOrigins.setRenderer(new LayerListCellRenderer());
|
326 |
cboLayerDestinations.setRenderer(new LayerListCellRenderer());
|
327 |
|
328 |
} |
329 |
|
330 |
public int getFileFormat() { |
331 |
return cboFileFormat.getSelectedIndex();
|
332 |
} |
333 |
|
334 |
public String getGeneratedFile() { |
335 |
return txtGeneratedFile.getText();
|
336 |
} |
337 |
|
338 |
public FLyrVect getOriginsLayer() {
|
339 |
return (FLyrVect) cboLayerOrigins.getSelectedItem();
|
340 |
} |
341 |
|
342 |
public FLyrVect getDestinationsLayer() {
|
343 |
return (FLyrVect) cboLayerDestinations.getSelectedItem();
|
344 |
} |
345 |
|
346 |
public WindowInfo getWindowInfo() {
|
347 |
if (wi == null) { |
348 |
wi = new WindowInfo(WindowInfo.MODALDIALOG);
|
349 |
wi.setWidth((int) this.getPreferredSize().getWidth()); |
350 |
wi.setHeight((int) this.getPreferredSize().getHeight()); |
351 |
wi.setTitle(_T("odmatrix_control_panel"));
|
352 |
} |
353 |
return wi;
|
354 |
} |
355 |
|
356 |
public Object getWindowProfile(){ |
357 |
return WindowInfo.DIALOG_PROFILE;
|
358 |
} |
359 |
|
360 |
public double getTolerance() { |
361 |
return Double.parseDouble(txtTolerance.getText()); |
362 |
} |
363 |
|
364 |
private String _T(String str) { |
365 |
return PluginServices.getText(this, str); |
366 |
} |
367 |
|
368 |
} // @jve:decl-index=0:visual-constraint="10,10"
|