Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / tools / swing / serv / field / crs / JCRSDynFieldComponent.java @ 33414

History | View | Annotate | Download (7.52 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
/*
23
 * AUTHORS (In addition to CIT):
24
 * 2010 Institute of New Imaging Technologies (INIT): 
25
 *   http://www.init.uji.es
26
 * Geographic Information research group: 
27
 *   http://www.geoinfo.uji.es
28
 * Universitat Jaume I, Spain
29
 */
30

    
31
/**
32
 * 
33
 */
34
package org.gvsig.app.tools.swing.serv.field.crs;
35

    
36
import java.awt.event.ActionEvent;
37
import java.awt.event.ActionListener;
38

    
39
import javax.swing.AbstractButton;
40
import javax.swing.JButton;
41
import javax.swing.JComponent;
42
import javax.swing.JTextField;
43

    
44
import org.cresques.cts.IProjection;
45

    
46
import org.gvsig.andami.PluginServices;
47
import org.gvsig.andami.ui.mdiManager.IWindow;
48
import org.gvsig.andami.ui.mdiManager.WindowInfo;
49
import org.gvsig.app.gui.panels.CRSSelectPanel;
50
import org.gvsig.app.gui.panels.ProjChooserPanel;
51
import org.gvsig.app.gui.panels.crs.ISelectCRSButton;
52
import org.gvsig.app.project.documents.layout.Attributes;
53
import org.gvsig.tools.dynobject.DynField;
54
import org.gvsig.tools.service.ServiceException;
55
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
56
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
57
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent;
58
import org.jfree.util.Log;
59
import org.slf4j.Logger;
60
import org.slf4j.LoggerFactory;
61

    
62
/**
63
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
64
 * 
65
 */
66
public class JCRSDynFieldComponent extends AbstractJDynFieldComponent implements
67
    JDynFieldComponent, IWindow, ActionListener {
68

    
69
        private static Logger LOG = LoggerFactory.getLogger(JCRSDynFieldComponent.class);
70

    
71
//    private JTextField projectionField;
72
    private CRSSelectPanel panel;
73
    private JButton button;
74

    
75
    /**
76
     * @param proj
77
     */
78

    
79
    public JCRSDynFieldComponent(DynField dynField, ValueField value)
80
        throws ServiceException {
81
        super(dynField, value);
82
    }
83
    /*
84
     * (non-Javadoc)
85
     * 
86
     * @see
87
     * 
88
     * org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#saveStatus
89
     * ()
90
     */
91
    public void saveStatus() {
92
            Log.warn("Error de sintaxis. Corregirlo porfa");
93
        // setFieldValue(this.getValue(),true);
94
    }
95

    
96
    /*
97
     * (non-Javadoc)
98
     * 
99
     * @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getValue()
100
     */
101
    public Object getValue() {
102
        return this.getCurProj();
103
    }
104

    
105
    /*
106
     * (non-Javadoc)
107
     * 
108
     * @see
109
     * org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setValue(java
110
     * .lang.Object)
111
     */
112
    public void setNullValue() {
113
        this.setCurProj(null);
114
//        getProjectionField().setText("");
115
    }
116

    
117
    public void setNonNullValue(Object value) {
118
        if (value instanceof IProjection) {
119
            setCurProj((IProjection) value);
120
            // this.projectionField.setText(this.getCurProj().getAbrev());
121
        } else {
122
            setNullValue();
123
        }
124
    }
125

    
126
    public void setCurProj(IProjection projection) {
127
        panel.setCurProj(projection);
128
    }
129

    
130
    public IProjection getCurProj() {
131
        return panel.getCurProj();
132
    }
133

    
134
    /*
135
     * (non-Javadoc)
136
     * 
137
     * @see
138
     * org.gvsig.tools.swing.api.dynobject.dynfield.JComponent#getComponent()
139
     */
140
    public Object getComponent() {
141
        return panel;
142
    }
143

    
144
    @Override
145
    protected void setJDynFieldComponentListeners() {
146

    
147
    }
148

    
149
    @Override
150
    protected void afterUI() {
151
        this.panel.getJLabel().setVisible(false);
152
    }
153

    
154
    @Override
155
    protected void initData() {
156
    }
157

    
158
    @Override
159
    protected void initUI() {
160
        IProjection proj = (IProjection) this.getFieldValue();
161
        if (proj==null){
162
            proj = (IProjection) this.getDefaultFieldValue();
163
        }
164
        panel = initJPanelProj(proj);
165
    }
166

    
167
    protected void setReadOnly() {
168
        this.button.setVisible(false);
169
    }
170

    
171
    public void requestFocus() {
172
        this.panel.requestFocus();
173
    }
174

    
175
    public void setEnabled(boolean isEnabled) {
176
        this.panel.setEnabled(isEnabled);
177
    }
178

    
179
    public void actionPerformed(ActionEvent e) {
180
        setValue(panel.getCurProj());
181
    }
182

    
183

    
184
    public WindowInfo getWindowInfo() {
185
        WindowInfo m_ViewInfo =
186
            new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
187
        m_ViewInfo.setTitle(PluginServices.getText(this, "acerca_de"));
188

    
189
        return m_ViewInfo;
190
    }
191

    
192
    public Object getWindowProfile() {
193
        return WindowInfo.DIALOG_PROFILE;
194
    }
195

    
196
    @Override
197
    public void setValue(Object value) {
198
        if (value instanceof IProjection)
199
            setCurProj((IProjection) value);
200
        else
201
            setNullValue();
202
    }
203

    
204
    public JComponent asJComponent() {
205
        return panel;
206
    }
207
    
208
    /**
209
     * This method initializes jPanel4
210
     *
211
     * @return javax.swing.JPanel
212
     */
213
    private CRSSelectPanel initJPanelProj(IProjection proj) {
214
        if (panel == null) {
215
            panel = CRSSelectPanel.getPanel(proj);
216
            panel.setPreferredSize(new java.awt.Dimension(330,35));
217
            panel.addActionListener(new java.awt.event.ActionListener() {
218
                public void actionPerformed(java.awt.event.ActionEvent e) {
219
                    if (panel.isOkPressed()) {
220
//                        if (!panel.getCurProj().isProjected()) {
221
////                          if (getCmbMapUnits().getItemCount()==MapContext.NAMES.length) {
222
////                              getCmbMapUnits().addItem(PluginServices.getText(this, Attributes.DEGREES));
223
////                          }
224
//                            getCmbMapUnits().setSelectedItem(PluginServices.getText(this, Attributes.DEGREES));
225
//                            getCmbMapUnits().setEnabled(false);
226
//                        }else {
227
//                            if (getCmbMapUnits().getSelectedItem().equals(PluginServices.getText(this, Attributes.DEGREES))) {
228
//                                getCmbMapUnits().setSelectedIndex(1);
229
//                            }
230
//                            getCmbMapUnits().setEnabled(true);
231
////                          if (!(getCmbMapUnits().getItemCount()==MapContext.NAMES.length)) {
232
////                              getCmbMapUnits().removeItem(PluginServices.getText(this, Attributes.DEGREES));
233
////                          }
234
//                        }
235
//                        view.setProjection(panel.getCurProj());
236
                    }
237
                }
238
            });
239

    
240
//          panel.add(jLblProjName, null);
241
//          panel.add(jLblProj, null);
242
//          panel.add(getJBtnChangeProj(), null);
243
        }
244
        return panel;
245
    }
246

    
247
}