Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / cmd / CmdSaveRaster.java @ 2669

History | View | Annotate | Download (5.19 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.ui.cmd;
25

    
26
import org.cresques.cts.IProjection;
27

    
28
import org.cresques.px.PxLayerList;
29

    
30
import org.cresques.ui.CQCursor;
31
import org.cresques.ui.CQMapCanvas;
32
import org.cresques.ui.CQSaveRaster;
33
import org.cresques.ui.raster.DataInputSaveRaster;
34
import org.cresques.ui.raster.SaveRasterDialogPanel;
35
import org.cresques.ui.raster.SaveSetupPanel;
36

    
37
import java.awt.event.MouseEvent;
38
import java.awt.geom.Point2D;
39

    
40

    
41
/**
42
 * Comando save raster.
43
 * Permite seleccionar una zona del canvas para que pueda ser guardado
44
 * a formato raster georeferenciado.
45
 * @see org.cresques.geo.cover.Coverage
46
 * @author "Nacho Brodin" (brodin_ign@gva.es)
47
 */
48
public class CmdSaveRaster extends Cmd {
49
    private Point2D ptIni = null;
50
    private CQSaveRaster saveRaster = null;
51
    private IProjection prj = null;
52
    private PxLayerList layerList = null;
53

    
54
    /**
55
     * Construye un nuevo CmdInfo para el Canvas
56
     * @param canvas
57
     */
58
    public CmdSaveRaster(CQMapCanvas canvas) {
59
        super(canvas);
60
        eventsWanted = (LEFT | RIGHT | PRESS | RELEASE | DRAG);
61
        cursor = CQCursor.getCursor(CQCursor.INFO_CURSOR);
62
    }
63

    
64
    /**
65
     *
66
     * @param saveRaster
67
     */
68
    public void setCQSaveRaster(CQSaveRaster saveRaster) {
69
        System.out.println("setCQSaveRaster");
70
        this.saveRaster = saveRaster;
71
    }
72

    
73
    /**
74
     *
75
     * @param prj
76
     */
77
    public void setProjection(IProjection prj) {
78
        System.out.println("setProjection");
79
        this.prj = prj;
80
    }
81

    
82
    /**
83
     *
84
     * @param layerList
85
     */
86
    public void setLayerList(PxLayerList layerList) {
87
        System.out.println("setLayerList");
88
        this.layerList = layerList;
89
    }
90

    
91
    /**
92
     * Recibe los eventos del rat?n.
93
     */
94
    public void cmd(Point2D pt, int bt, int mouseEvent) {
95
        //System.out.println("Save Raster: Evento = "+ mouseEvent);
96
        if ((mouseEvent == PRESS) && (bt == MouseEvent.BUTTON1)) {
97
            ptIni = pt;
98
        } else if ((mouseEvent == RELEASE) && (bt == MouseEvent.BUTTON1)) {
99
            if ((pt.getX() == ptIni.getX()) || (pt.getY() == ptIni.getY())) {
100
                System.err.println("Ptos coincidentes");
101
            } else {
102
                double iniX;
103
                double iniY;
104
                double finX;
105
                double finY;
106

    
107
                if (pt.getX() > ptIni.getX()) {
108
                    iniX = ptIni.getX();
109
                    finX = pt.getX();
110
                } else {
111
                    finX = ptIni.getX();
112
                    iniX = pt.getX();
113
                }
114

    
115
                if (pt.getY() > ptIni.getY()) {
116
                    iniY = ptIni.getY();
117
                    finY = pt.getY();
118
                } else {
119
                    finY = ptIni.getY();
120
                    iniY = pt.getY();
121
                }
122

    
123
                saveRaster.setProjection(this.prj);
124
                saveRaster.setLayerList(this.layerList);
125

    
126
                DataInputSaveRaster dialog = ((SaveSetupPanel) (((SaveRasterDialogPanel) saveRaster.getContentPane()).getContentPanel())).getSaveParameters();
127
                int indexPoint = String.valueOf(finX).indexOf('.');
128
                dialog.getTinf_derX().setText(String.valueOf(finX).substring(0,
129
                                                                             indexPoint +
130
                                                                             2));
131
                indexPoint = String.valueOf(finY).indexOf('.');
132
                dialog.getTinf_derY().setText(String.valueOf(finY).substring(0,
133
                                                                             indexPoint +
134
                                                                             2));
135
                indexPoint = String.valueOf(iniX).indexOf('.');
136
                dialog.getTsup_izqX().setText(String.valueOf(iniX).substring(0,
137
                                                                             indexPoint +
138
                                                                             2));
139
                indexPoint = String.valueOf(iniY).indexOf('.');
140
                dialog.getTsup_izqY().setText(String.valueOf(iniY).substring(0,
141
                                                                             indexPoint +
142
                                                                             2));
143
                saveRaster.show();
144
            }
145
        }
146
    }
147
}