Statistics
| Revision:

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

History | View | Annotate | Download (4.77 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;
42

    
43

    
44
import es.gva.cit.gazetteer.GazetteerClient;
45
import es.gva.cit.gazetteer.querys.Feature;
46

    
47

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

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

    
54

    
55
/**
56
 * @author Jorge Piera Llodra (piera_jor@gva.es)
57
 */
58
public class ShowResultsDialogPanel extends JPanel implements ActionListener {
59
    protected ShowResultsPanel ppalPanel = null;
60
    protected Feature[] features = null;
61
    protected GazetteerClient client = null;
62
    int currentPage = 0;
63
    int recordsByPage = 0;
64
    JButton nextButton = null;
65
    JButton lastButton = null;
66
    JButton mapButton = null;
67
    JButton closeButton = null;
68

    
69
    public ShowResultsDialogPanel(GazetteerClient client, Feature[] features,
70
            int recordsByPage) {
71
        this.features = features;
72
        this.client = client;
73
        this.currentPage = 1;
74
        this.recordsByPage = recordsByPage;
75

    
76
        ppalPanel = new ShowResultsPanel(features,getNumPages(),recordsByPage);
77

    
78
        setDefaultButtonListeners();
79
       
80
        add(ppalPanel);
81
    }
82
  
83
    
84
    private void setDefaultButtonListeners() {
85
        nextButton = ppalPanel.getNextButton();
86
        lastButton = ppalPanel.getLastButton();
87
        mapButton = ppalPanel.getMapButton();
88
        closeButton = ppalPanel.getCloseButton();
89

    
90
        nextButton.addActionListener(this);
91
        lastButton.addActionListener(this);
92
        mapButton.addActionListener(this);
93
        closeButton.addActionListener(this);
94
    }
95

    
96
    private JButton getMapButton() {
97
        return mapButton;
98
    }
99
    
100
    private JButton getCloseButton(){
101
        return closeButton;
102
    }
103

    
104
    public void actionPerformed(ActionEvent e) {
105
        if (e.getActionCommand().equals("Siguiente")) {
106
            nextButtonActionPerformed();
107
        } 
108
        if (e.getActionCommand().equals("Anterior")) {
109
            lastButtonActionPerformed();
110
        } 
111
        if (e.getActionCommand().equals("Recursos")) {
112
            loadButtonActionPerformed();
113
        } 
114
        if (e.getActionCommand().equals("Cerrar")) {
115
            closeButtonActionPerformed();
116
        }
117
       
118
    }
119
    
120
    private int getNumPages(){
121
        if ((features.length % recordsByPage) == 0)
122
            return features.length/recordsByPage;
123
        return (features.length/recordsByPage) + 1;
124
    }
125

    
126
    public void nextButtonActionPerformed() {
127
        this.currentPage = this.currentPage + 1;
128
             
129
        if (this.currentPage == getNumPages()) {
130
            nextButton.setEnabled(false);
131
        } else {
132
            nextButton.setEnabled(true);
133
        }
134

    
135
        lastButton.setEnabled(true);
136

    
137
        ppalPanel.actualizaLabel(currentPage,recordsByPage);
138
        
139
        
140
    }
141

    
142
    public void lastButtonActionPerformed() {
143
        this.currentPage = this.currentPage - 1;
144

    
145
        if (this.currentPage == 1) {
146
            lastButton.setEnabled(false);
147
        } else {
148
            lastButton.setEnabled(true);
149
        }
150

    
151
        nextButton.setEnabled(true);
152
       
153
        ppalPanel.actualizaLabel(currentPage,recordsByPage);
154
        
155
       
156
    }
157

    
158
    public void loadButtonActionPerformed() {
159
        Feature feature = ppalPanel.getFeature();
160
        if (feature != null){
161
            System.out.println("ID: " + feature.getId());
162
            System.out.println("NAME: " + feature.getName());
163
            System.out.println("DESCRIPTION: " + feature.getDescription());
164
            System.out.println("COORDINATES: X=" + feature.getCoordinates().getX() + " Y=" + feature.getCoordinates().getY());
165
        }
166
    }
167
    
168
    public void closeButtonActionPerformed() {
169
        setVisible(false);
170
    }
171
    
172
    
173
}