gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / saveviewtoraster / tool / SaveRasterRectangleTool.java @ 2176
History | View | Annotate | Download (4.76 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 |
package org.gvsig.raster.tools.app.basic.tool.saveviewtoraster.tool; |
23 |
|
24 |
|
25 |
import java.awt.Image; |
26 |
import java.awt.geom.Point2D; |
27 |
import java.awt.geom.Rectangle2D; |
28 |
import java.text.DecimalFormat; |
29 |
import java.text.NumberFormat; |
30 |
import java.util.Locale; |
31 |
|
32 |
import org.gvsig.andami.IconThemeHelper; |
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
35 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 |
import org.gvsig.fmap.mapcontext.ViewPort; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
38 |
import org.gvsig.fmap.mapcontrol.MapControl; |
39 |
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
40 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener; |
41 |
import org.gvsig.raster.tools.algorithm.swing.saveraster.SaveRasterPanel; |
42 |
import org.gvsig.raster.tools.app.basic.tool.saveviewtoraster.ui.SaveViewToRasterDialog; |
43 |
|
44 |
|
45 |
|
46 |
/**
|
47 |
* Extensi?n de la clase SaveRasterListenerImpl de FMap para poder llamar a m?todos
|
48 |
* de andami o de gvSIG.
|
49 |
*
|
50 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
51 |
*/
|
52 |
public class SaveRasterRectangleTool implements RectangleListener { |
53 |
private final Image isaveraster = IconThemeHelper.getImage("rectangle-select-cursor"); |
54 |
protected MapControl mapCtrl = null; |
55 |
protected Rectangle2D pixelRect = null; |
56 |
protected Envelope rect = null; |
57 |
private String viewName = null; |
58 |
|
59 |
/**
|
60 |
* Crea un nuevo RectangleListenerImpl.
|
61 |
*
|
62 |
* @param mapCtrl MapControl.
|
63 |
*/
|
64 |
public SaveRasterRectangleTool(MapControl mapCtrl, String viewName) { |
65 |
this.mapCtrl = mapCtrl;
|
66 |
this.viewName = viewName;
|
67 |
} |
68 |
|
69 |
public void rectangle(EnvelopeEvent event) { |
70 |
rect = event.getWorldCoordRect(); |
71 |
pixelRect = event.getPixelCoordRect(); |
72 |
|
73 |
if (PluginServices.getMainFrame() != null) |
74 |
PluginServices.getMainFrame().enableControls(); |
75 |
|
76 |
FLayers layers = mapCtrl.getMapContext().getLayers(); |
77 |
|
78 |
SaveViewToRasterDialog saveRaster = null;
|
79 |
boolean open = false; |
80 |
IWindow[] win = PluginServices.getMDIManager().getAllWindows();
|
81 |
for(int i = 0; i < win.length; i++) { |
82 |
if(win[i] instanceof SaveViewToRasterDialog) { |
83 |
saveRaster = (SaveViewToRasterDialog)win[i]; |
84 |
open = true;
|
85 |
} |
86 |
} |
87 |
if(saveRaster == null) |
88 |
saveRaster = new SaveViewToRasterDialog(layers, mapCtrl, viewName);
|
89 |
|
90 |
ViewPort vp = mapCtrl.getViewPort(); |
91 |
Point2D ini = vp.fromMapPoint(rect.getMinimum(0), rect.getMinimum(1)); |
92 |
Point2D fin = vp.fromMapPoint(rect.getMaximum(0), rect.getMaximum(1)); |
93 |
if(Math.abs(fin.getY() - ini.getY()) > 10 && Math.abs(fin.getX() - ini.getX()) > 10) { |
94 |
SaveRasterPanel panel = saveRaster.getSaveRasterPanel(); |
95 |
panel.getBProperties().setEnabled(false);
|
96 |
|
97 |
DecimalFormat nf = (DecimalFormat)NumberFormat.getInstance(Locale.ENGLISH); |
98 |
nf.applyPattern("#.#");
|
99 |
nf.setMaximumFractionDigits(4);
|
100 |
|
101 |
if(!vp.getProjection().isProjected())
|
102 |
nf.setMaximumFractionDigits(6);
|
103 |
|
104 |
try{
|
105 |
panel.setValueLRX(nf.format(rect.getMaximum(0)));
|
106 |
}catch(IndexOutOfBoundsException ex){ |
107 |
panel.setValueLRX(String.valueOf(rect.getMaximum(0))); |
108 |
} |
109 |
|
110 |
try{
|
111 |
panel.setValueLRY(nf.format(rect.getMinimum(1)));
|
112 |
}catch(IndexOutOfBoundsException ex){ |
113 |
panel.setValueLRY(String.valueOf(rect.getMinimum(1))); |
114 |
} |
115 |
|
116 |
try{
|
117 |
panel.setValueULX(nf.format(rect.getMinimum(0)));
|
118 |
}catch(IndexOutOfBoundsException ex){ |
119 |
panel.setValueULX(String.valueOf(rect.getMinimum(0))); |
120 |
} |
121 |
|
122 |
try{
|
123 |
panel.setValueULY(nf.format(rect.getMaximum(1)));
|
124 |
}catch(IndexOutOfBoundsException ex){ |
125 |
panel.setValueULY(String.valueOf(rect.getMaximum(1))); |
126 |
} |
127 |
if(!open) {
|
128 |
PluginServices.getMDIManager().addCentredWindow(saveRaster); |
129 |
} |
130 |
panel.setWidthPxValue(String.valueOf((int)pixelRect.getWidth())); |
131 |
} |
132 |
} |
133 |
|
134 |
/*
|
135 |
* (non-Javadoc)
|
136 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#getImageCursor()
|
137 |
*/
|
138 |
public Image getImageCursor() { |
139 |
return isaveraster;
|
140 |
} |
141 |
|
142 |
public boolean cancelDrawing() { |
143 |
System.out.println("cancelDrawing del SaveRasterListenerImpl"); |
144 |
return true; |
145 |
} |
146 |
|
147 |
} |