svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extGeocoding / src / org / gvsig / geocoding / gui / relation / RelatePanel.java @ 31946
History | View | Annotate | Download (7.73 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 Prodevelop S.L. main developer
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.gui.relation; |
29 |
|
30 |
import java.io.File; |
31 |
|
32 |
import javax.swing.DefaultComboBoxModel; |
33 |
import javax.swing.ImageIcon; |
34 |
import javax.swing.JButton; |
35 |
import javax.swing.JComboBox; |
36 |
import javax.swing.JOptionPane; |
37 |
import javax.swing.JPanel; |
38 |
|
39 |
import org.gvsig.andami.PluginServices; |
40 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
41 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
42 |
import org.gvsig.app.project.documents.table.TableDocument; |
43 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
44 |
import org.gvsig.geocoding.extension.GeocodingController; |
45 |
import org.gvsig.geocoding.utils.GeocodingExtTags; |
46 |
import org.gvsig.geocoding.utils.GeocodingUtils; |
47 |
|
48 |
public class RelatePanel extends JPanel implements IWindow { |
49 |
|
50 |
private static final long serialVersionUID = 1L; |
51 |
|
52 |
private GeocodingController control = null; |
53 |
private FLyrVect lyr = null; |
54 |
|
55 |
private JButton jButRelate; |
56 |
private JButton jButCancel; |
57 |
private JComboBox jComboResultTable; |
58 |
private JPanel jPanButtons; |
59 |
private JPanel jPanResultTable; |
60 |
|
61 |
/**
|
62 |
* Contructor with control
|
63 |
*/
|
64 |
public RelatePanel(GeocodingController control) {
|
65 |
this.control = control;
|
66 |
initComponents(); |
67 |
|
68 |
setImages(); |
69 |
setMesages(); |
70 |
} |
71 |
|
72 |
/**
|
73 |
* initialize panel components
|
74 |
*/
|
75 |
private void initComponents() { |
76 |
java.awt.GridBagConstraints gridBagConstraints; |
77 |
|
78 |
jPanResultTable = new javax.swing.JPanel();
|
79 |
jComboResultTable = new javax.swing.JComboBox();
|
80 |
jPanButtons = new javax.swing.JPanel();
|
81 |
jButRelate = new javax.swing.JButton();
|
82 |
jButCancel = new javax.swing.JButton();
|
83 |
|
84 |
setLayout(new java.awt.GridBagLayout());
|
85 |
|
86 |
jPanResultTable.setBorder(javax.swing.BorderFactory |
87 |
.createTitledBorder("DBF Table All Results"));
|
88 |
jPanResultTable.setLayout(new java.awt.GridBagLayout());
|
89 |
|
90 |
jComboResultTable.setModel(new javax.swing.DefaultComboBoxModel(
|
91 |
new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); |
92 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
93 |
gridBagConstraints.gridx = 0;
|
94 |
gridBagConstraints.gridy = 0;
|
95 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
96 |
gridBagConstraints.weightx = 1.0;
|
97 |
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); |
98 |
jPanResultTable.add(jComboResultTable, gridBagConstraints); |
99 |
|
100 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
101 |
gridBagConstraints.gridx = 0;
|
102 |
gridBagConstraints.gridy = 0;
|
103 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
104 |
gridBagConstraints.weightx = 1.0;
|
105 |
gridBagConstraints.weighty = 1.0;
|
106 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); |
107 |
add(jPanResultTable, gridBagConstraints); |
108 |
|
109 |
jPanButtons.setLayout(new java.awt.GridBagLayout());
|
110 |
|
111 |
jButRelate.setText("Relate");
|
112 |
jButRelate.addActionListener(new java.awt.event.ActionListener() {
|
113 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
114 |
evRelate(evt); |
115 |
} |
116 |
}); |
117 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
118 |
gridBagConstraints.gridx = 0;
|
119 |
gridBagConstraints.gridy = 0;
|
120 |
jPanButtons.add(jButRelate, gridBagConstraints); |
121 |
|
122 |
jButCancel.setText("Cancel");
|
123 |
jButCancel.addActionListener(new java.awt.event.ActionListener() {
|
124 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
125 |
evCancel(evt); |
126 |
} |
127 |
}); |
128 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
129 |
gridBagConstraints.gridx = 1;
|
130 |
gridBagConstraints.gridy = 0;
|
131 |
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); |
132 |
jPanButtons.add(jButCancel, gridBagConstraints); |
133 |
|
134 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
135 |
gridBagConstraints.gridx = 0;
|
136 |
gridBagConstraints.gridy = 1;
|
137 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
138 |
gridBagConstraints.weightx = 1.0;
|
139 |
gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5); |
140 |
add(jPanButtons, gridBagConstraints); |
141 |
} |
142 |
|
143 |
/**
|
144 |
* relate event
|
145 |
*
|
146 |
* @param evt
|
147 |
*/
|
148 |
private void evRelate(java.awt.event.ActionEvent evt) { |
149 |
PluginServices ps = PluginServices.getPluginServices(this);
|
150 |
TableDocument table = (TableDocument) jComboResultTable.getModel() |
151 |
.getSelectedItem(); |
152 |
if (this.lyr != null) { |
153 |
this.lyr.setProperty(GeocodingExtTags.GEOCODINGPROPERTY, table);
|
154 |
String message1 = ps.getText("message1") + " " + table.getName(); |
155 |
String message2 = message1 + " " + ps.getText("message2"); |
156 |
String message3 = message2 + " " + this.lyr.getName(); |
157 |
String title = ps.getText("relatelayer"); |
158 |
|
159 |
JOptionPane.showMessageDialog(null, message3, title, |
160 |
JOptionPane.PLAIN_MESSAGE);
|
161 |
} |
162 |
this.closePanel();
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* cancel event
|
167 |
*
|
168 |
* @param evt
|
169 |
*/
|
170 |
private void evCancel(java.awt.event.ActionEvent evt) { |
171 |
this.closePanel();
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Close panel
|
176 |
*/
|
177 |
private void closePanel() { |
178 |
IWindow[] iws = PluginServices.getMDIManager().getAllWindows();
|
179 |
for (int i = 0; i < iws.length; i++) { |
180 |
if (iws[i] instanceof RelatePanel) { |
181 |
PluginServices.getMDIManager().closeWindow(iws[i]); |
182 |
} |
183 |
} |
184 |
} |
185 |
|
186 |
/**
|
187 |
* set panel icons
|
188 |
*/
|
189 |
private void setImages() { |
190 |
PluginServices ps = PluginServices.getPluginServices(this);
|
191 |
if (ps != null) { |
192 |
String baseDir = ps.getClassLoader().getBaseDir();
|
193 |
jButRelate.setIcon(new ImageIcon(baseDir + File.separator |
194 |
+ "images" + File.separator + "icons16" + File.separator |
195 |
+ "open.png"));
|
196 |
jButCancel.setIcon(new ImageIcon(baseDir + File.separator |
197 |
+ "images" + File.separator + "icons16" + File.separator |
198 |
+ "out.png"));
|
199 |
} |
200 |
} |
201 |
|
202 |
/**
|
203 |
* set panel strings
|
204 |
*/
|
205 |
private void setMesages() { |
206 |
PluginServices ps = PluginServices.getPluginServices(this);
|
207 |
if (ps != null) { |
208 |
jPanResultTable.setBorder(GeocodingUtils.getTitledBorder(ps |
209 |
.getText("pantable")));
|
210 |
this.jButRelate.setText(ps.getText("butrelate")); |
211 |
this.jButCancel.setText(ps.getText("butcancel")); |
212 |
} |
213 |
} |
214 |
|
215 |
/**
|
216 |
* get window info
|
217 |
*/
|
218 |
public WindowInfo getWindowInfo() {
|
219 |
PluginServices ps = PluginServices.getPluginServices(this);
|
220 |
WindowInfo info = new WindowInfo(WindowInfo.MODALDIALOG
|
221 |
+ WindowInfo.RESIZABLE); |
222 |
info.setMinimumSize(this.getMinimumSize());
|
223 |
info.setWidth(350);
|
224 |
info.setHeight(80);
|
225 |
String title = ps.getText("relatelayer"); |
226 |
info.setTitle(title); |
227 |
return info;
|
228 |
} |
229 |
|
230 |
public Object getWindowProfile() { |
231 |
|
232 |
return null; |
233 |
} |
234 |
|
235 |
/**
|
236 |
* Put availables project tables in combo
|
237 |
*/
|
238 |
public void putTablesInCombo() { |
239 |
// add tables in combo
|
240 |
DefaultComboBoxModel comboModel = control.getModelgvSIGTables();
|
241 |
if (comboModel == null) { |
242 |
comboModel = new DefaultComboBoxModel(); |
243 |
} |
244 |
jComboResultTable.setModel(comboModel); |
245 |
jComboResultTable.validate(); |
246 |
} |
247 |
|
248 |
/**
|
249 |
* set selected layer with property "GeocodingResult"
|
250 |
*
|
251 |
* @param lyr
|
252 |
*/
|
253 |
public void setLyr(FLyrVect lyr) { |
254 |
this.lyr = lyr;
|
255 |
} |
256 |
|
257 |
} |