Statistics
| Revision:

gvsig-gazetteer / org.gvsig.gazetteer / trunk / org.gvsig.gazetteer / org.gvsig.gazetteer.lib / src / main / java / org / gvsig / gazetteer / ui / showresults / ShowResultsDialogPanel.java @ 103

History | View | Annotate | Download (5.16 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42
package org.gvsig.gazetteer.ui.showresults;
43
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionListener;
45

    
46
import javax.swing.JButton;
47
import javax.swing.JDialog;
48
import javax.swing.JPanel;
49

    
50
import org.gvsig.fmap.geom.primitive.Point;
51
import org.gvsig.gazetteer.GazetteerClient;
52
import org.gvsig.gazetteer.querys.Feature;
53
import org.gvsig.gazetteer.querys.GazetteerQuery;
54

    
55

    
56
/**
57
 *
58
 *
59
 *
60
 * @author Jorge Piera Llodra (piera_jor@gva.es)
61
 */
62
public class ShowResultsDialogPanel extends JPanel implements ActionListener {
63
        private JDialog parent;
64
        protected ShowResultsPanel ppalPanel = null;
65
        protected GazetteerClient client = null;
66
        private int currentPage = 0;
67
        private int recordsByPage = 0;
68
        private JButton nextButton = null;
69
        private JButton lastButton = null;
70
        private JButton mapButton = null;
71
        private JButton closeButton = null;
72
        private int featuresLength = 0;
73
        protected GazetteerQuery query = null;
74

    
75
        /**
76
         * @param client
77
         * @param features
78
         * @param recordsByPage
79
         * @param translator
80
         */
81
        public ShowResultsDialogPanel(GazetteerClient client, Feature[] features, int recordsByPage, GazetteerQuery query) {
82
                this.client = client;
83
                this.currentPage = 1;
84
                this.recordsByPage = recordsByPage;
85
                this.query = query;
86
                initialize(client,features,recordsByPage);
87
        }
88

    
89
        /**
90
         *
91
         *
92
         *
93
         * @param client
94
         * @param features
95
         * @param recordsByPage
96
         */
97
        public void initialize(GazetteerClient client, Feature[] features, int recordsByPage) {
98
                this.featuresLength = features.length;
99
                this.currentPage = 1;
100
                this.recordsByPage = recordsByPage;
101
                ppalPanel = new ShowResultsPanel(features,getNumPages(),recordsByPage);
102
                setDefaultButtonListeners();
103

    
104
                add(ppalPanel);
105
        }
106

    
107
        /**
108
         *
109
         *
110
         */
111
        private void setDefaultButtonListeners() {
112
                nextButton = ppalPanel.getNextButton();
113
                lastButton = ppalPanel.getLastButton();
114
                mapButton = ppalPanel.getMapButton();
115
                closeButton = ppalPanel.getCloseButton();
116

    
117
                nextButton.addActionListener(this);
118
                lastButton.addActionListener(this);
119
                mapButton.addActionListener(this);
120
                closeButton.addActionListener(this);
121
        }
122

    
123
        /**
124
         *
125
         *
126
         *
127
         * @param e
128
         */
129
        public void actionPerformed(ActionEvent e) {
130
                if (e.getActionCommand().equals("next")) {
131
                        nextButtonActionPerformed();
132
                }
133
                if (e.getActionCommand().equals("last")) {
134
                        lastButtonActionPerformed();
135
                }
136
                if (e.getActionCommand().equals("localize")) {
137
                        loadButtonActionPerformed();
138
                }
139
                if (e.getActionCommand().equals("close")) {
140
                        closeButtonActionPerformed();
141
                }
142

    
143
        }
144

    
145
        /**
146
         *
147
         *
148
         *
149
         * @return
150
         */
151
        private int getNumPages() {
152
                if ((featuresLength % recordsByPage) == 0)
153
                        return featuresLength/recordsByPage;
154
                return (featuresLength/recordsByPage) + 1;
155
        }
156

    
157
        /**
158
         *
159
         *
160
         */
161
        public void nextButtonActionPerformed() {
162
                this.currentPage = this.currentPage + 1;
163

    
164
                if (this.currentPage == getNumPages()) {
165
                        nextButton.setEnabled(false);
166
                } else {
167
                        nextButton.setEnabled(true);
168
                }
169
                lastButton.setEnabled(true);
170
                ppalPanel.actualizaLabel(currentPage,recordsByPage);
171

    
172

    
173
        }
174

    
175
        /**
176
         *
177
         *
178
         */
179
        public void lastButtonActionPerformed() {
180
                this.currentPage = this.currentPage - 1;
181
                if (this.currentPage == 1) {
182
                        lastButton.setEnabled(false);
183
                } else {
184
                        lastButton.setEnabled(true);
185
                }
186
                nextButton.setEnabled(true);
187

    
188
                ppalPanel.actualizaLabel(currentPage,recordsByPage);
189

    
190

    
191
        }
192

    
193
        /**
194
         *
195
         *
196
         */
197
        public void loadButtonActionPerformed() {
198
                Feature feature = ppalPanel.getFeature();
199

    
200
                if (feature != null){
201
                        System.out.println("ID: " + feature.getId());
202
                        System.out.println("NAME: " + feature.getName());
203
                        System.out.println("DESCRIPTION: " + feature.getDescription());
204
                        Point point = feature.getCoordinates();
205
            if (point != null) {
206
                System.out.println(
207
                    "COORDINATES: X=" + point.getX() + " Y=" + point.getY());
208
            }
209
                }
210
        }
211

    
212
        /**
213
         *
214
         *
215
         */
216
        public void closeButtonActionPerformed() {
217
                parent.setVisible(false);
218
        }
219

    
220
        /**
221
         *
222
         *
223
         *
224
         * @param parent The parent to set.
225
         */
226
        public void setParent(JDialog parent) {
227
                this.parent = parent;
228
        }
229
}