Statistics
| Revision:

root / trunk / libraries / libCq CMS for java.old / src / org / cresques / ui / cts / CSSelectionPanel.java @ 8120

History | View | Annotate | Download (8.43 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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
 * cresques@gmail.com
23
 */
24
package org.cresques.ui.cts;
25

    
26
import org.cresques.cts.IProjection;
27
import org.cresques.i18n.Messages;
28
import org.cresques.ui.LoadableComboBox;
29

    
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32

    
33

    
34
//import es.gva.cit.geoexplorer.ui.LoadableComboBox;
35

    
36
/**
37
 * Panel de edici?n de Sistemas de referencia
38
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
39
 */
40
public class CSSelectionPanel extends JPanel {
41
    final private static long serialVersionUID = -3370601314380922368L;
42
    private LoadableComboBox datumComboBox = null;
43
    private LoadableComboBox projComboBox = null;
44
    private LoadableComboBox huseComboBox = null;
45
    private JLabel jLabel = null;
46
    private JLabel jLabel1 = null;
47
    private JLabel jLabel2 = null;
48
    private int wDisplay = 335;
49
    private int wCombo = 250;
50
    private int h = 23;
51
    private int x = 14;
52
    private String tit;
53
    private CSSelectionModel model;
54

    
55
    /**
56
     * Constructor de la clase.
57
     */
58
    public CSSelectionPanel(String tit) {
59
        super();
60

    
61
        if (tit == null) {
62
            //tit = "Sistema de referencia";
63
            //TODO: add com.iver.andami.PluginServices to this project
64
            //change all the labels from fix text got from the internationalitation
65
            tit = Messages.getText("reference_system");
66
            if (tit == null) tit="Reference System";
67
        }
68

    
69
        this.tit = tit;
70
        setModel(new CSSelectionModel());
71
        initialize();
72
    }
73

    
74
    /**
75
     * Inicializa el panel.
76
     * @return javax.swing.JPanel
77
     */
78
    private void initialize() {
79
        setPreferredSize(new java.awt.Dimension(295, 170));
80
        setLayout(null);
81

    
82
        /*javax.swing.border.Border border = javax.swing.BorderFactory.createCompoundBorder(
83
        javax.swing. BorderFactory.createTitledBorder("Sistema de coordenadas"),
84
        javax.swing.BorderFactory.createEmptyBorder(5,5,5,5)); */
85
        setBorder(javax.swing.BorderFactory.createCompoundBorder(null,
86
                                                                 javax.swing.BorderFactory.createTitledBorder(null,
87
                                                                                                                                                                 Messages.getText("reference_system"),
88
                                                                                                              javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
89
                                                                                                              javax.swing.border.TitledBorder.DEFAULT_POSITION,
90
                                                                                                              null,
91
                                                                                                              null)));
92

    
93
        jLabel = new JLabel();
94
        jLabel.setBounds(15, 15, 77, 23);
95
        jLabel.setText(Messages.getText("datum") + ":");
96
        add(jLabel, null);
97
        add(getDatumComboBox(), null);
98

    
99
        jLabel1 = new JLabel();
100
        jLabel1.setBounds(15, 60, 77, 23);
101
        jLabel1.setText(Messages.getText("projection") + ":");
102
        add(jLabel1, null);
103
        add(getProjComboBox(), null);
104

    
105
        jLabel2 = new JLabel();
106
        jLabel2.setBounds(15, 105, 77, 23);
107
        jLabel2.setText(Messages.getText("zone") + ":");
108
        add(jLabel2, null);
109
        add(getHuseComboBox(), null);
110

    
111
        setHuseComboBoxEnabled(false);
112
    }
113

    
114
    public void setModel(CSSelectionModel model) {
115
        this.model = model;
116

    
117
        getHuseComboBox().loadData(model.getZoneList());
118
        getDatumComboBox().loadData(model.getDatumList());
119
        getProjComboBox().loadData(model.getProjectionList());
120
    }
121

    
122
    private void setHuseComboBoxEnabled(boolean enabled) {
123
        if (jLabel2 != null) {
124
            jLabel2.setEnabled(enabled);
125
        }
126

    
127
        getHuseComboBox().setEnabled(enabled);
128
    }
129

    
130
    private void setDatumComboBoxEnabled(boolean enabled) {
131
        if (jLabel != null) {
132
            jLabel.setEnabled(enabled);
133
        }
134

    
135
        getDatumComboBox().setEnabled(enabled);
136
    }
137

    
138
    public void setProjection(IProjection proj) {
139
        model.setProjection(proj);
140

    
141
        setDatumComboBoxEnabled(true);
142
        getDatumComboBox().setSelectedIndex(model.getSelectedDatum());
143
 
144
        getProjComboBox().removeAllItems();
145
        getProjComboBox().loadData(model.getProjectionList());
146

    
147
        model.setProjection(proj);
148
        getProjComboBox().setSelectedIndex(model.getSelectedProj());
149
        model.setProjection(proj);
150
        
151
        if (model.getSelectedZone() >= 0) {
152
            setHuseComboBoxEnabled(true);
153
            getHuseComboBox().removeAllItems();
154
            getHuseComboBox().loadData(model.getZoneList());
155

    
156
            model.setProjection(proj);
157
            getHuseComboBox().setSelectedIndex(model.getSelectedZone());
158
        } else {
159
            setHuseComboBoxEnabled(false);
160
            getHuseComboBox().setSelectedIndex(0);
161
        }
162
    }
163

    
164
    /**
165
     * Inicializa datumComboBox
166
     *
167
     * @return javax.swing.JComboBox
168
     */
169
    private LoadableComboBox getDatumComboBox() {
170
        if (datumComboBox == null) {
171
            datumComboBox = new LoadableComboBox();
172
            datumComboBox.setBounds(14, 35, 250, 23);
173

    
174
            //                        ((LoadableComboBox) datumComboBox).loadData(model.getDatumList());
175
            datumComboBox.addItemListener(new java.awt.event.ItemListener() {
176
                    public void itemStateChanged(java.awt.event.ItemEvent e) {
177
                        model.setSelectedDatum(e.getItem());
178
                        getProjComboBox().removeAllItems();
179
                        getProjComboBox().loadData(model.getProjectionList());
180
                    }
181
                });
182
        }
183

    
184
        return datumComboBox;
185
    }
186

    
187
    /**
188
     * Inicializa projComboBox
189
     *
190
     * @return javax.swing.JComboBox
191
     */
192
    private LoadableComboBox getProjComboBox() {
193
        if (projComboBox == null) {
194
            projComboBox = new LoadableComboBox();
195
            projComboBox.setBounds(14, 80, 250, 23);
196
            projComboBox.addItemListener(new java.awt.event.ItemListener() {
197
                    public void itemStateChanged(java.awt.event.ItemEvent e) {
198
                        model.setSelectedProj(e.getItem());
199

    
200
                        if (model.getSelectedProjType() == CSSelectionModel.TRANSVERSAL) {
201
                            setHuseComboBoxEnabled(true);
202
                            getHuseComboBox().removeAllItems();
203
                            getHuseComboBox().loadData(model.getZoneList());
204

    
205
                        } else {
206
                            setHuseComboBoxEnabled(false);
207
                        }
208

    
209
                       // if (model.getSelectedProjType() == CSSelectionModel.NONE) {
210
                       //     setDatumComboBoxEnabled(false);
211
                       // } else {
212
                       //     setDatumComboBoxEnabled(true);
213
                       // }
214
                    }
215
                });
216
        }
217

    
218
        return projComboBox;
219
    }
220

    
221
    /**
222
     * Inicializa usoComboBox
223
     *
224
     * @return javax.swing.JComboBox
225
     */
226
    private LoadableComboBox getHuseComboBox() {
227
        if (huseComboBox == null) {
228
            huseComboBox = new LoadableComboBox();
229
            huseComboBox.setBounds(14, 125, 250, 23);
230
            huseComboBox.addItemListener(new java.awt.event.ItemListener() {
231
                    public void itemStateChanged(java.awt.event.ItemEvent e) {
232
                        model.setSelectedZone(e.getItem());
233
                    }
234
                });
235
        }
236

    
237
        return huseComboBox;
238
    }
239

    
240
    /**
241
     * @return
242
     */
243
    public IProjection getProjection() {
244
        return model.getProjection();
245
    }
246
}