Statistics
| Revision:

root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / ui / showResults / ShowResultsDialogPanel.java @ 3229

History | View | Annotate | Download (5.55 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package es.gva.cit.gazetteer.ui.showResults;
42

    
43

    
44
import es.gva.cit.catalogClient.traductor.ITranslator;
45
import es.gva.cit.gazetteer.GazetteerClient;
46
import es.gva.cit.gazetteer.querys.Feature;
47

    
48
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionListener;
50

    
51
import javax.swing.JButton;
52
import javax.swing.JDialog;
53
import javax.swing.JPanel;
54

    
55

    
56

    
57
/**
58
 * @author Jorge Piera Llodra (piera_jor@gva.es)
59
 */
60
public class ShowResultsDialogPanel extends JPanel implements ActionListener {
61
    //  It is needed to close the frame
62
    private JDialog parent;
63
    
64

    
65
    protected ShowResultsPanel ppalPanel = null;
66
    protected Feature[] features = null;
67
    protected GazetteerClient client = null;
68
    
69
    private int currentPage = 0;
70
    private int recordsByPage = 0;
71
    
72
    private JButton nextButton = null;
73
    private JButton lastButton = null;
74
    private JButton mapButton = null;
75
    private JButton closeButton = null;
76
    private ITranslator translator = null;
77

    
78
    public ShowResultsDialogPanel(GazetteerClient client, Feature[] features,
79
            int recordsByPage,ITranslator translator) {
80
        this.features = features;
81
        this.client = client;
82
        this.currentPage = 1;
83
        this.recordsByPage = recordsByPage;
84
        this.translator = translator;
85
         initialize(client,features,recordsByPage);     
86
    }
87

    
88
    public void initialize(GazetteerClient client, Feature[] features,
89
            int recordsByPage){
90
        this.features = features;
91
        this.client = client;
92
        this.currentPage = 1;
93
        this.recordsByPage = recordsByPage;
94
        ppalPanel = new ShowResultsPanel(features,getNumPages(),recordsByPage,translator);
95

    
96
        setDefaultButtonListeners();
97
       
98
        add(ppalPanel);
99
    }
100
  
101
    
102
    private void setDefaultButtonListeners() {
103
        nextButton = ppalPanel.getNextButton();
104
        lastButton = ppalPanel.getLastButton();
105
        mapButton = ppalPanel.getMapButton();
106
        closeButton = ppalPanel.getCloseButton();
107
        
108
        nextButton.addActionListener(this);
109
        lastButton.addActionListener(this);
110
        mapButton.addActionListener(this);
111
        closeButton.addActionListener(this);
112
    }
113

    
114
    private JButton getMapButton() {
115
        return mapButton;
116
    }
117
    
118
    private JButton getCloseButton(){
119
        return closeButton;
120
    }
121

    
122
    public void actionPerformed(ActionEvent e) {
123
        if (e.getActionCommand().equals("next")) {
124
            nextButtonActionPerformed();
125
        } 
126
        if (e.getActionCommand().equals("last")) {
127
            lastButtonActionPerformed();
128
        } 
129
        if (e.getActionCommand().equals("localize")) {
130
            loadButtonActionPerformed();
131
        } 
132
        if (e.getActionCommand().equals("close")) {
133
            closeButtonActionPerformed();
134
        }
135
       
136
    }
137
    
138
    private int getNumPages(){
139
        if ((features.length % recordsByPage) == 0)
140
            return features.length/recordsByPage;
141
        return (features.length/recordsByPage) + 1;
142
    }
143

    
144
    public void nextButtonActionPerformed() {
145
        this.currentPage = this.currentPage + 1;
146
             
147
        if (this.currentPage == getNumPages()) {
148
            nextButton.setEnabled(false);
149
        } else {
150
            nextButton.setEnabled(true);
151
        }
152

    
153
        lastButton.setEnabled(true);
154

    
155
        ppalPanel.actualizaLabel(currentPage,recordsByPage);
156
        
157
        
158
    }
159

    
160
    public void lastButtonActionPerformed() {
161
        this.currentPage = this.currentPage - 1;
162

    
163
        if (this.currentPage == 1) {
164
            lastButton.setEnabled(false);
165
        } else {
166
            lastButton.setEnabled(true);
167
        }
168

    
169
        nextButton.setEnabled(true);
170
       
171
        ppalPanel.actualizaLabel(currentPage,recordsByPage);
172
        
173
       
174
    }
175

    
176
    public void loadButtonActionPerformed() {
177
        Feature feature = ppalPanel.getFeature();
178
        
179
        if (feature != null){
180
            System.out.println("ID: " + feature.getId());
181
            System.out.println("NAME: " + feature.getName());
182
            System.out.println("DESCRIPTION: " + feature.getDescription());
183
            System.out.println("COORDINATES: X=" + feature.getCoordinates().getX() + " Y=" + feature.getCoordinates().getY());
184
        }
185
    }
186
    
187
    public void closeButtonActionPerformed() {
188
        parent.setVisible(false);
189
    }
190
    
191
    /**
192
     * @param parent The parent to set.
193
     */
194
    public void setParent(JDialog parent) {
195
        this.parent = parent;
196
    }
197
    
198
    
199
}