Statistics
| Revision:

gvsig-projects-pool / org.gvsig.lidar.app / org.gvsig.lidar.app.mainplugin / src / main / java / org / gvsig / exportto / swing / panel / SelectEnvelopeOptionPanel.java @ 281

History | View | Annotate | Download (4.99 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2016 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.exportto.swing.panel;
24

    
25
import java.awt.BorderLayout;
26
import java.awt.Component;
27
import java.io.File;
28

    
29
import javax.swing.JComponent;
30
import javax.swing.JOptionPane;
31
import javax.swing.JPanel;
32

    
33
import org.cresques.cts.ICoordTrans;
34
import org.cresques.cts.IProjection;
35
import org.gvsig.app.ApplicationLocator;
36
import org.gvsig.app.project.documents.Document;
37
import org.gvsig.app.project.documents.view.BaseViewDocument;
38
import org.gvsig.exportto.swing.ExporttoSwingLocator;
39
import org.gvsig.exportto.swing.ExporttoSwingManager;
40
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException;
41
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
42
import org.gvsig.fmap.dal.exception.DataException;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
import org.gvsig.fmap.geom.Geometry;
45
import org.gvsig.fmap.geom.GeometryLocator;
46
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
47
import org.gvsig.fmap.geom.primitive.Envelope;
48
import org.gvsig.fmap.mapcontext.MapContext;
49
import org.gvsig.gui.beans.coordinatespanel.CoordinatesPanel;
50
import org.gvsig.i18n.Messages;
51
import org.gvsig.tools.locator.LocatorException;
52

    
53
/**
54
 * @author gvSIG Team
55
 * @version $Id$
56
 * 
57
 */
58
public class SelectEnvelopeOptionPanel extends JPanel implements ExporttoSwingProviderPanel {
59
        private static final long serialVersionUID = -729071840887099236L;
60

    
61
        private JPanel optionsPanel;
62

    
63
    private static final ExporttoSwingManager EXPORTTO_SWING_MANAGER =
64
        ExporttoSwingLocator.getSwingManager();
65

    
66
    private SelectEnvelopePanel panel;
67

    
68
    /**
69
     * @param dataSourceSRS Data source SRS, used to transform the View
70
     * envelope to the data source projection, if View and data source
71
     * use different projection
72
     */
73
    public SelectEnvelopeOptionPanel(IProjection dataSourceSRS) {
74
        this(dataSourceSRS, null);
75
    }
76

    
77
    /**
78
     * @param dataSourceSRS Data source SRS, used to transform the View
79
     * envelope to the data source projection, if View and data source
80
     * use different projection
81
     */
82
    public SelectEnvelopeOptionPanel(IProjection dataSourceSRS, JPanel optionsPanel) {
83
        super();
84
        this.setLayout(new BorderLayout());
85
        Document d = ApplicationLocator.getManager().getActiveDocument();
86
        if (d instanceof BaseViewDocument) {
87
                BaseViewDocument view = (BaseViewDocument) d;
88
                MapContext mc = view.getMapContext();
89
                ICoordTrans viewTolayerCT = getViewToSourceCoordTrans(dataSourceSRS, mc.getProjection());
90
                panel = new SelectEnvelopePanel(view.getMapContext(), viewTolayerCT);
91
        }
92
        else {
93
                panel = new SelectEnvelopePanel();
94
        }
95
        
96
        add(panel, BorderLayout.NORTH);
97
        if (optionsPanel != null) {
98
            optionsPanel.setBorder(javax.swing.BorderFactory
99
                .createCompoundBorder(javax.swing.BorderFactory
100
                    .createTitledBorder(Messages.getText("options")),
101
                    javax.swing.BorderFactory.createEmptyBorder(10, 5, 5, 5)));
102
            add(optionsPanel, BorderLayout.CENTER);
103
            this.optionsPanel = optionsPanel;
104
        }
105
    }
106
    
107
    protected ICoordTrans getViewToSourceCoordTrans(IProjection sourceSrs,
108
                    IProjection viewSrs) {
109
            ICoordTrans trans = null;
110
            try {
111
                        /***
112
                         * We get the CT from the sourceSRS and then then inverted because
113
                         * data source to View transform is usually stored in the sourceSrs
114
                         * and not in the view SRS
115
                         */
116
                        trans = sourceSrs.getCT(viewSrs).getInverted();
117
                } catch (Exception e) {}
118
            return trans;
119
    }
120

    
121
    public String getPanelTitle() {
122
        return EXPORTTO_SWING_MANAGER.getTranslation("Filter_by_envelope");
123
    }
124

    
125
    public Envelope getEnvelope() {
126
            
127
            return panel.getEnvelope();
128
    }
129

    
130
    public void enterPanel() {
131
        // Default do nothing
132
    }
133
    
134
    public boolean isValidPanel() throws ExporttoPanelValidationException {
135
        return true;
136
    }
137

    
138
    /**
139
     * @return the optionsPanel
140
     */
141
    public JPanel getOptionsPanel() {
142
        return optionsPanel;
143
    }
144

    
145
    public JComponent asJComponent() {
146
        return this;
147
    }
148
}