root / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / styling / LayerPreview.java @ 29969
History | View | Annotate | Download (3.97 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.symbology.gui.styling; |
20 |
|
21 |
import java.awt.Dimension; |
22 |
import java.awt.Graphics2D; |
23 |
import java.awt.geom.Rectangle2D; |
24 |
import java.awt.image.BufferedImage; |
25 |
import java.io.File; |
26 |
import java.util.Stack; |
27 |
|
28 |
import javax.swing.JFrame; |
29 |
|
30 |
import org.cresques.cts.IProjection; |
31 |
import org.gvsig.gui.beans.imagenavigator.IClientImageNavigator; |
32 |
import org.gvsig.gui.beans.imagenavigator.ImageNavigator; |
33 |
|
34 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
35 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
36 |
import com.iver.cit.gvsig.fmap.MapContext; |
37 |
import com.iver.cit.gvsig.fmap.ViewPort; |
38 |
import com.iver.cit.gvsig.fmap.core.ILabelable; |
39 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
40 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
41 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
42 |
import com.iver.cit.gvsig.fmap.operations.Cancel; |
43 |
|
44 |
public class LayerPreview extends ImageNavigator implements IClientImageNavigator { |
45 |
private static final long serialVersionUID = -7554322442540714114L; |
46 |
private FLayer layer = null; |
47 |
private ViewPort vp;
|
48 |
private Stack<Cancel> cancels = new Stack<Cancel>(); |
49 |
|
50 |
public LayerPreview() {
|
51 |
super(null); |
52 |
setClientImageNavigator(this);
|
53 |
} |
54 |
|
55 |
public void setLayer(FLayer layer) throws ExpansionFileReadException, ReadDriverException { |
56 |
this.layer = layer;
|
57 |
if (layer != null) { |
58 |
vp = new ViewPort(layer.getProjection());
|
59 |
Rectangle2D b = layer.getFullExtent();
|
60 |
setViewDimensions(b.getMinX(), b.getMaxY(), b.getMaxX(), b.getMinY()); |
61 |
} |
62 |
updateBuffer(); |
63 |
setEnabled(true);
|
64 |
} |
65 |
|
66 |
public static void main(String[] args) { |
67 |
JFrame jFrame = new JFrame("test"); |
68 |
String fwAndamiDriverPath = "../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"; |
69 |
IProjection PROJ = CRSFactory.getCRS("EPSG:23030");
|
70 |
try {
|
71 |
LayerFactory.setDriversPath(new File(fwAndamiDriverPath).getAbsolutePath()); |
72 |
LayerPreview prev = new LayerPreview();
|
73 |
|
74 |
prev.setLayer(LayerFactory. |
75 |
createLayer( |
76 |
"line",
|
77 |
"gvSIG shp driver",
|
78 |
new File("/home/jaume/Documents/Cartografia/cv_300_polygons.shp"), |
79 |
PROJ)); |
80 |
|
81 |
jFrame.setSize(new Dimension(598, 167)); |
82 |
|
83 |
jFrame.setContentPane(prev); |
84 |
|
85 |
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
86 |
jFrame.setVisible(true);
|
87 |
} catch (Exception e) { |
88 |
e.printStackTrace(); |
89 |
} |
90 |
} |
91 |
|
92 |
public void drawImage(Graphics2D g, double x1, double y1, double x2, double y2, double zoom, int width, int height) { |
93 |
Cancel c = new Cancel();
|
94 |
while (!cancels.isEmpty()) cancels.pop().setCanceled(true); |
95 |
|
96 |
cancels.push(c); |
97 |
if (layer == null || width <= 0 || height <= 0 || vp == null) |
98 |
return;
|
99 |
vp.setExtent(new Rectangle2D.Double(x1, y2, x2-x1, y1-y2)); |
100 |
vp.setImageSize(new Dimension(width, height)); |
101 |
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); |
102 |
|
103 |
// double scale = vp.getScale();
|
104 |
double scale = layer.getMapContext().getScaleView();
|
105 |
try {
|
106 |
layer.draw(bi, g, vp, c, scale); |
107 |
if (layer instanceof ILabelable && ((ILabelable) layer).isLabeled()) { |
108 |
((ILabelable) layer).drawLabels(bi, g, vp, c, scale, MapContext.getScreenDPI()); |
109 |
} |
110 |
} catch (ReadDriverException e) {
|
111 |
// TODO Auto-generated catch block
|
112 |
e.printStackTrace(); |
113 |
} |
114 |
} |
115 |
|
116 |
|
117 |
} |