Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.geocoding.extension / src / org / gvsig / geocoding / gui / relation / RelatePanel.java @ 32526

History | View | Annotate | Download (8.77 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.JLabel;
37
import javax.swing.JOptionPane;
38
import javax.swing.JPanel;
39

    
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.andami.ui.mdiManager.IWindow;
42
import org.gvsig.andami.ui.mdiManager.WindowInfo;
43
import org.gvsig.app.project.documents.table.TableDocument;
44
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
45
import org.gvsig.geocoding.extension.GeocodingController;
46
import org.gvsig.geocoding.utils.GeocodingExtTags;
47
import org.gvsig.geocoding.utils.GeocodingUtils;
48

    
49
public class RelatePanel extends JPanel implements IWindow {
50

    
51
        private static final long serialVersionUID = 1L;
52

    
53
        private GeocodingController control = null;
54
        private FLyrVect lyr = null;
55

    
56
        
57
        private JButton jButRelate;
58
        private JButton jButCancel;
59
        private JComboBox jComboResultTable;
60
        private JPanel jPanButtons;
61
        private JPanel jPanResultTable;
62
        private JPanel jPanInfo;
63
        private JLabel jLabInfo;
64

    
65
        /**
66
         * Contructor with geocoding controlller
67
         */
68
        public RelatePanel(GeocodingController control) {
69
                this.control = control;
70
                initComponents();
71

    
72
                setImages();
73
                setMesages();
74
        }
75

    
76
        /**
77
         * initialize panel components
78
         */
79
        private void initComponents() {
80
                java.awt.GridBagConstraints gridBagConstraints;
81

    
82
                jPanResultTable = new JPanel();
83
                jPanInfo = new JPanel();
84
                jLabInfo = new JLabel();
85
                jComboResultTable = new javax.swing.JComboBox();
86
                jPanButtons = new JPanel();
87
                jButRelate = new JButton();
88
                jButCancel = new JButton();
89

    
90
                setLayout(new java.awt.GridBagLayout());
91
                
92
                jLabInfo.setText("Info relation ...");
93
                
94
                gridBagConstraints = new java.awt.GridBagConstraints();
95
                gridBagConstraints.gridx = 0;
96
                gridBagConstraints.gridy = 0;
97
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
98
                gridBagConstraints.weightx = 1.0;
99
                gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
100
                jPanInfo.add(jLabInfo, gridBagConstraints);
101
                
102
                gridBagConstraints = new java.awt.GridBagConstraints();
103
                gridBagConstraints.gridx = 0;
104
                gridBagConstraints.gridy = 0;
105
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
106
                gridBagConstraints.weightx = 1.0;
107
                gridBagConstraints.weighty = 1.0;
108
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
109
                add(jPanInfo, gridBagConstraints);
110

    
111
                jPanResultTable.setBorder(javax.swing.BorderFactory
112
                                .createTitledBorder("DBF Table All Results"));
113
                jPanResultTable.setLayout(new java.awt.GridBagLayout());
114

    
115
                jComboResultTable.setModel(new javax.swing.DefaultComboBoxModel(
116
                                new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
117
                gridBagConstraints = new java.awt.GridBagConstraints();
118
                gridBagConstraints.gridx = 0;
119
                gridBagConstraints.gridy = 0;
120
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
121
                gridBagConstraints.weightx = 1.0;
122
                gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
123
                jPanResultTable.add(jComboResultTable, gridBagConstraints);
124

    
125
                gridBagConstraints = new java.awt.GridBagConstraints();
126
                gridBagConstraints.gridx = 0;
127
                gridBagConstraints.gridy = 1;
128
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
129
                gridBagConstraints.weightx = 1.0;
130
                gridBagConstraints.weighty = 1.0;
131
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
132
                add(jPanResultTable, gridBagConstraints);
133

    
134
                jPanButtons.setLayout(new java.awt.GridBagLayout());
135

    
136
                jButRelate.setText("Relate");
137
                jButRelate.addActionListener(new java.awt.event.ActionListener() {
138
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
139
                                evRelate(evt);
140
                        }
141
                });
142
                gridBagConstraints = new java.awt.GridBagConstraints();
143
                gridBagConstraints.gridx = 0;
144
                gridBagConstraints.gridy = 0;
145
                jPanButtons.add(jButRelate, gridBagConstraints);
146

    
147
                jButCancel.setText("Cancel");
148
                jButCancel.addActionListener(new java.awt.event.ActionListener() {
149
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
150
                                evCancel(evt);
151
                        }
152
                });
153
                gridBagConstraints = new java.awt.GridBagConstraints();
154
                gridBagConstraints.gridx = 1;
155
                gridBagConstraints.gridy = 0;
156
                gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
157
                jPanButtons.add(jButCancel, gridBagConstraints);
158

    
159
                gridBagConstraints = new java.awt.GridBagConstraints();
160
                gridBagConstraints.gridx = 0;
161
                gridBagConstraints.gridy = 2;
162
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
163
                gridBagConstraints.weightx = 1.0;
164
                gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
165
                add(jPanButtons, gridBagConstraints);
166
        }
167

    
168
        /**
169
         * relate event
170
         * 
171
         * @param evt
172
         */
173
        private void evRelate(java.awt.event.ActionEvent evt) {
174
                PluginServices ps = PluginServices.getPluginServices(this);
175
                TableDocument table = (TableDocument) jComboResultTable.getModel()
176
                                .getSelectedItem();
177
                if (this.lyr != null) {
178
                        this.lyr.setProperty(GeocodingExtTags.GEOCODINGPROPERTY, table);
179
                        String message1 = ps.getText("message1") + " " + table.getName();
180
                        String message2 = message1 + " " + ps.getText("message2");
181
                        String message3 = message2 + " " + this.lyr.getName();
182
                        String title = ps.getText("relatelayer");
183

    
184
                        JOptionPane.showMessageDialog(null, message3, title,
185
                                        JOptionPane.PLAIN_MESSAGE);
186
                }
187
                this.closePanel();
188
        }
189

    
190
        /**
191
         * cancel event
192
         * 
193
         * @param evt
194
         */
195
        private void evCancel(java.awt.event.ActionEvent evt) {
196
                this.closePanel();
197
        }
198

    
199
        /**
200
         * Close panel
201
         */
202
        private void closePanel() {
203
                IWindow[] iws = PluginServices.getMDIManager().getAllWindows();
204
                for (int i = 0; i < iws.length; i++) {
205
                        if (iws[i] instanceof RelatePanel) {
206
                                PluginServices.getMDIManager().closeWindow(iws[i]);
207
                        }
208
                }
209
        }
210

    
211
        /**
212
         * set panel icons
213
         */
214
        private void setImages() {
215
                PluginServices ps = PluginServices.getPluginServices(this);
216
                if (ps != null) {
217
                        String baseDir = ps.getClassLoader().getBaseDir();
218
                        jButRelate.setIcon(new ImageIcon(baseDir + File.separator
219
                                        + "images" + File.separator + "icons16" + File.separator
220
                                        + "attachment.png"));
221
                        jButCancel.setIcon(new ImageIcon(baseDir + File.separator
222
                                        + "images" + File.separator + "icons16" + File.separator
223
                                        + "out.png"));
224
                }
225
        }
226

    
227
        /**
228
         * set panel strings
229
         */
230
        private void setMesages() {
231
                PluginServices ps = PluginServices.getPluginServices(this);
232
                if (ps != null) {
233
                        jPanResultTable.setBorder(GeocodingUtils.getTitledBorder(ps
234
                                        .getText("pantable")));
235
                        this.jButRelate.setText(ps.getText("butrelate"));
236
                        this.jButCancel.setText(ps.getText("butcancel"));
237
                        this.jLabInfo.setText(ps.getText("relateInfo"));
238
                }
239
        }
240

    
241
        /**
242
         * get window info
243
         */
244
        public WindowInfo getWindowInfo() {
245
                PluginServices ps = PluginServices.getPluginServices(this);
246
                WindowInfo info = new WindowInfo(WindowInfo.MODALDIALOG
247
                                + WindowInfo.RESIZABLE);
248
                info.setMinimumSize(this.getMinimumSize());
249
                info.setWidth(350);
250
                info.setHeight(80);
251
                String title = ps.getText("relatelayer");
252
                info.setTitle(title);
253
                return info;
254
        }
255

    
256
        public Object getWindowProfile() {
257

    
258
                return null;
259
        }
260

    
261
        /**
262
         * Put availables project tables in combo
263
         */
264
        public void putTablesInCombo() {
265
                // add tables in combo
266
                DefaultComboBoxModel comboModel = control.getModelgvSIGTables();
267
                if (comboModel == null) {
268
                        comboModel = new DefaultComboBoxModel();
269
                }
270
                jComboResultTable.setModel(comboModel);
271
                jComboResultTable.validate();
272
        }
273

    
274
        /**
275
         * set selected layer with property "GeocodingResult"
276
         * 
277
         * @param lyr
278
         */
279
        public void setLyr(FLyrVect lyr) {
280
                this.lyr = lyr;
281
                String text = PluginServices.getPluginServices(this).getText("relateinfo") + " ["+lyr.getName()+"]";
282
                this.jLabInfo.setText(text);
283
        }
284

    
285
}