Statistics
| Revision:

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

History | View | Annotate | Download (6.06 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 CRSSelectPanel panel;
72
    private JButton button;
73

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

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

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

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

    
115
    public void setNonNullValue(Object value) {
116
        if (value instanceof IProjection) {
117
            setCurProj((IProjection) value);
118
        } else {
119
            setNullValue();
120
        }
121
    }
122

    
123
    public void setCurProj(IProjection projection) {
124
        panel.setCurProj(projection);
125
    }
126

    
127
    public IProjection getCurProj() {
128
        return panel.getCurProj();
129
    }
130

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

    
141
    @Override
142
    protected void setJDynFieldComponentListeners() {
143

    
144
    }
145

    
146
    @Override
147
    protected void afterUI() {
148
        this.panel.getJLabel().setVisible(false);
149
    }
150

    
151
    @Override
152
    protected void initData() {
153
    }
154

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

    
164
    protected void setReadOnly() {
165
        this.button.setVisible(false);
166
    }
167

    
168
    public void requestFocus() {
169
        this.panel.requestFocus();
170
    }
171

    
172
    public void setEnabled(boolean isEnabled) {
173
        this.panel.setEnabled(isEnabled);
174
    }
175

    
176
    public void actionPerformed(ActionEvent e) {
177
        setValue(panel.getCurProj());
178
    }
179

    
180

    
181
    public WindowInfo getWindowInfo() {
182
        WindowInfo m_ViewInfo =
183
            new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
184
        m_ViewInfo.setTitle(PluginServices.getText(this, "acerca_de"));
185

    
186
        return m_ViewInfo;
187
    }
188

    
189
    public Object getWindowProfile() {
190
        return WindowInfo.DIALOG_PROFILE;
191
    }
192

    
193
    @Override
194
    public void setValue(Object value) {
195
        if (value instanceof IProjection)
196
            setCurProj((IProjection) value);
197
        else
198
            setNullValue();
199
    }
200

    
201
    public JComponent asJComponent() {
202
        return panel;
203
    }
204
    
205
    /**
206
     * This method initializes jPanel4
207
     *
208
     * @return javax.swing.JPanel
209
     */
210
    private CRSSelectPanel initJPanelProj(IProjection proj) {
211
        if (panel == null) {
212
            panel = CRSSelectPanel.getPanel(proj);
213
            panel.setPreferredSize(new java.awt.Dimension(330,35));
214
            panel.addActionListener(new java.awt.event.ActionListener() {
215
                public void actionPerformed(java.awt.event.ActionEvent e) {
216
                    if (panel.isOkPressed()) {
217
                    }
218
                }
219
            });
220
        }
221
        return panel;
222
    }
223

    
224
}