Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / tools / swing / serv / field / crs / JCRSDynFieldComponent.java @ 40558

History | View | Annotate | Download (6.09 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2010 Institute of New Imaging Technologies (INIT): 
27
 *   http://www.init.uji.es
28
 * Geographic Information research group: 
29
 *   http://www.geoinfo.uji.es
30
 * Universitat Jaume I, Spain
31
 */
32

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

    
38
import java.awt.event.ActionEvent;
39
import java.awt.event.ActionListener;
40

    
41
import javax.swing.JButton;
42
import javax.swing.JComponent;
43

    
44
import org.cresques.cts.IProjection;
45
import org.gvsig.andami.PluginServices;
46
import org.gvsig.andami.ui.mdiManager.IWindow;
47
import org.gvsig.andami.ui.mdiManager.WindowInfo;
48
import org.gvsig.app.gui.panels.CRSSelectPanel;
49
import org.gvsig.tools.dynobject.DynField;
50
import org.gvsig.tools.service.ServiceException;
51
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
52
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
53
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent;
54

    
55
/**
56
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
57
 * 
58
 */
59
public class JCRSDynFieldComponent extends AbstractJDynFieldComponent implements
60
    JDynFieldComponent, IWindow, ActionListener {
61

    
62
    private CRSSelectPanel panel;
63
    private JButton button;
64

    
65
    /**
66
     * @param proj
67
     */
68

    
69
    public JCRSDynFieldComponent(DynField definition, ValueField value, boolean writeable)
70
        throws ServiceException {
71
        super(definition, value, writeable);
72
    }
73
    /*
74
     * (non-Javadoc)
75
     * 
76
     * @see
77
     * 
78
     * org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#saveStatus
79
     * ()
80
     */
81
    public void saveStatus() {
82
            if (isValid()){
83
                setFieldValue(this.getValue());                    
84
            }
85
    }
86

    
87
    /*
88
     * (non-Javadoc)
89
     * 
90
     * @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getValue()
91
     */
92
    public Object getValue() {
93
        return this.getCurProj();
94
    }
95

    
96
    /*
97
     * (non-Javadoc)
98
     * 
99
     * @see
100
     * org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setNullValue(java
101
     * .lang.Object)
102
     */
103
    public void setNullValue() {
104
        this.setCurProj(null);
105
    }
106

    
107
    public void setNonNullValue(Object value) {
108
        if (value instanceof IProjection) {
109
            setCurProj((IProjection) value);
110
        } else {
111
            setNullValue();
112
        }
113
    }
114

    
115
    public void setCurProj(IProjection projection) {
116
        panel.setCurProj(projection);
117
        this.fireValueChangedEvent();
118
    }
119

    
120
    public IProjection getCurProj() {
121
        return panel.getCurProj();
122
    }
123

    
124
    /*
125
     * (non-Javadoc)
126
     * 
127
     * @see
128
     * org.gvsig.tools.swing.api.dynobject.dynfield.JComponent#getComponent()
129
     */
130
    public Object getComponent() {
131
        return panel;
132
    }
133

    
134
    @Override
135
    protected void setJDynFieldComponentListeners() {
136

    
137
    }
138
    
139
    public void setValue(Object value){
140
            Object oldValue = getValue();
141
            if (value == null){
142
                    setNullValue();
143
            }else{
144
                    setNonNullValue(value);
145
            }
146
            if (oldValue!=value){
147
                this.fireValueChangedEvent();                    
148
            }
149
    }
150

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

    
156
    @Override
157
    protected void initData() {
158
    }
159

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

    
169
    protected void setReadOnly() {
170
        this.button.setVisible(false);
171
    }
172

    
173
    public void requestFocus() {
174
        this.panel.requestFocus();
175
    }
176

    
177
    public void setEnabled(boolean isEnabled) {
178
        this.panel.setEnabled(isEnabled);
179
    }
180

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

    
185

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

    
191
        return m_ViewInfo;
192
    }
193

    
194
    public Object getWindowProfile() {
195
        return WindowInfo.DIALOG_PROFILE;
196
    }
197

    
198
    public JComponent asJComponent() {
199
        return panel;
200
    }
201
    
202
    /**
203
     * This method initializes jPanel4
204
     *
205
     * @return javax.swing.JPanel
206
     */
207
    private CRSSelectPanel initJPanelProj(IProjection proj) {
208
        if (panel == null) {
209
            panel = CRSSelectPanel.getPanel(proj);
210
            panel.setTransPanelActive(true);
211
            panel.setPreferredSize(new java.awt.Dimension(330,35));
212
            panel.addActionListener(new java.awt.event.ActionListener() {
213
                public void actionPerformed(java.awt.event.ActionEvent e) {
214
                    if (panel.isOkPressed()) {
215
                        setValue(panel.getCurProj());
216
                        fireValueChangedEvent();
217
                    }
218
                }
219
            });
220
        }
221
        return panel;
222
    }
223
    
224
        @Override
225
        public boolean isValid() {
226
                return this.getValue()!=null;
227
        }
228

    
229
}