Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.app / org.gvsig.view3d.app.common / src / main / java / org / gvsig / view3d / app / properties / RasterLayerProperties3DPanel.java @ 773

History | View | Annotate | Download (5.28 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2017 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 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
 * 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
package org.gvsig.view3d.app.properties;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Dimension;
28

    
29
import javax.swing.JOptionPane;
30

    
31
import org.gvsig.fmap.mapcontext.layers.FLayer;
32
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.i18n.I18nManager;
35
import org.gvsig.tools.swing.api.ToolsSwingLocator;
36
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
37
import org.gvsig.view3d.lib.api.View3DLocator;
38
import org.gvsig.view3d.lib.api.View3DManager;
39
import org.gvsig.view3d.lib.api.loader.LoaderParameters;
40
import org.gvsig.view3d.swing.api.View3DSwingLocator;
41
import org.gvsig.view3d.swing.api.View3DSwingManager;
42
import org.gvsig.view3d.swing.api.exception.InvalidLoaderParametersException;
43
import org.gvsig.view3d.swing.api.loader.JLoaderParametersSelector;
44
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
46

    
47
/**
48
 * 
49
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
50
 *
51
 */
52
public class RasterLayerProperties3DPanel extends AbstractPanel {
53

    
54
    private static final Logger LOG = LoggerFactory.getLogger(RasterLayerProperties3DPanel.class);
55

    
56
    private static final long serialVersionUID = 5429099827670959087L;
57

    
58
    private FLayer layer;
59
    private JLoaderParametersSelector loaderParametersManager;
60
    private LoaderParameters tmpLoaderParameters;
61

    
62
    /**
63
     * 
64
     */
65
    public RasterLayerProperties3DPanel() {
66
        super();
67
        initialize();
68
    }
69

    
70
    public void accept() {
71
        View3DManager manager = View3DLocator.getManager();
72
        try {
73
            manager.setLoaderParameters(layer, loaderParametersManager
74
                .getSelectedJLoaderParameters().getLoaderParameters());
75
        } catch (InvalidLoaderParametersException e) {
76
            ThreadSafeDialogsManager dialogsManager =
77
                ToolsSwingLocator.getThreadSafeDialogsManager();
78
            I18nManager i18nManager = ToolsLocator.getI18nManager();
79
            dialogsManager.messageDialog(
80
                i18nManager.getTranslation(e.getMessageKey()),
81
                i18nManager.getTranslation("_error"), JOptionPane.ERROR_MESSAGE);
82
            return;
83
        }
84
    }
85

    
86
    public void apply() {
87
        View3DManager manager = View3DLocator.getManager();
88
        try {
89
            if (manager.getLoaderParameters(layer) == null) {
90
                try {
91
                    tmpLoaderParameters =
92
                        (LoaderParameters) loaderParametersManager.getSelectedJLoaderParameters()
93
                            .getLoaderParameters().clone();
94
                } catch (InvalidLoaderParametersException e) {
95
                    ThreadSafeDialogsManager dialogsManager =
96
                        ToolsSwingLocator.getThreadSafeDialogsManager();
97
                    I18nManager i18nManager = ToolsLocator.getI18nManager();
98
                    dialogsManager.messageDialog(
99
                        i18nManager.getTranslation(e.getMessageKey()),
100
                        i18nManager.getTranslation("_error"), JOptionPane.ERROR_MESSAGE);
101
                    return;
102
                }
103
            } else {
104
                tmpLoaderParameters = (LoaderParameters) manager.getLoaderParameters(layer).clone();
105
            }
106
        } catch (CloneNotSupportedException e) {
107
            LOG.error("Parameters can not be cloned", e);
108
            return;
109
        }
110

    
111
        accept();
112
    }
113

    
114
    public void cancel() {
115
        if (tmpLoaderParameters != null) {
116
            View3DManager manager = View3DLocator.getManager();
117
            manager.setLoaderParameters(layer, tmpLoaderParameters);
118
        }
119
        this.loaderParametersManager = null;
120
        this.tmpLoaderParameters = null;
121
    }
122

    
123
    @Override
124
    protected void initialize() {
125
        I18nManager i18nManager = ToolsLocator.getI18nManager();
126
        setLabel(i18nManager.getTranslation("3D"));
127

    
128
        this.setLayout(new BorderLayout());
129
        this.setPreferredSize(new Dimension(100, 80));
130
    }
131

    
132
    public void selected() {
133
    }
134

    
135
    public void setReference(Object ref) {
136
        super.setReference(ref);
137

    
138
        if (ref instanceof FLayer) {
139
            this.layer = (FLayer) ref;
140
            View3DSwingManager swingManager = View3DSwingLocator.getManager();
141
            this.loaderParametersManager = swingManager.createJLoaderParametersManager(layer);
142
            this.add(loaderParametersManager.asJComponent(), BorderLayout.CENTER);
143
        }
144
    }
145

    
146
}