Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / ui / showResults / ShowResultsDialogPanel.java @ 3480

History | View | Annotate | Download (5.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.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
    protected boolean isGotoClicked;
69
    protected boolean isKeepOldClicked;
70

    
71
    
72
    private int currentPage = 0;
73
    private int recordsByPage = 0;
74
    
75
    private JButton nextButton = null;
76
    private JButton lastButton = null;
77
    private JButton mapButton = null;
78
    private JButton closeButton = null;
79
    private ITranslator translator = null;
80

    
81
    public ShowResultsDialogPanel(GazetteerClient client, Feature[] features,
82
            int recordsByPage,ITranslator translator,boolean isGotoClicked, boolean isKeepOldClicked) {
83
        this.features = features;
84
        this.client = client;
85
        this.currentPage = 1;
86
        this.recordsByPage = recordsByPage;
87
        this.translator = translator;
88
        this.isGotoClicked = isGotoClicked;
89
        this.isKeepOldClicked = isKeepOldClicked;
90
         initialize(client,features,recordsByPage);     
91
    }
92

    
93
    public void initialize(GazetteerClient client, Feature[] features,
94
            int recordsByPage){
95
        this.features = features;
96
        this.client = client;
97
        this.currentPage = 1;
98
        this.recordsByPage = recordsByPage;
99
        ppalPanel = new ShowResultsPanel(features,getNumPages(),recordsByPage,translator);
100

    
101
        setDefaultButtonListeners();
102
       
103
        add(ppalPanel);
104
    }
105
  
106
    
107
    private void setDefaultButtonListeners() {
108
        nextButton = ppalPanel.getNextButton();
109
        lastButton = ppalPanel.getLastButton();
110
        mapButton = ppalPanel.getMapButton();
111
        closeButton = ppalPanel.getCloseButton();
112
        
113
        nextButton.addActionListener(this);
114
        lastButton.addActionListener(this);
115
        mapButton.addActionListener(this);
116
        closeButton.addActionListener(this);
117
    }
118

    
119
    private JButton getMapButton() {
120
        return mapButton;
121
    }
122
    
123
    private JButton getCloseButton(){
124
        return closeButton;
125
    }
126

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

    
149
    public void nextButtonActionPerformed() {
150
        this.currentPage = this.currentPage + 1;
151
             
152
        if (this.currentPage == getNumPages()) {
153
            nextButton.setEnabled(false);
154
        } else {
155
            nextButton.setEnabled(true);
156
        }
157

    
158
        lastButton.setEnabled(true);
159

    
160
        ppalPanel.actualizaLabel(currentPage,recordsByPage);
161
        
162
        
163
    }
164

    
165
    public void lastButtonActionPerformed() {
166
        this.currentPage = this.currentPage - 1;
167

    
168
        if (this.currentPage == 1) {
169
            lastButton.setEnabled(false);
170
        } else {
171
            lastButton.setEnabled(true);
172
        }
173

    
174
        nextButton.setEnabled(true);
175
       
176
        ppalPanel.actualizaLabel(currentPage,recordsByPage);
177
        
178
       
179
    }
180

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