Revision 6771
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/CADToolAdapter.java | ||
---|---|---|
35 | 35 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
36 | 36 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
37 | 37 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
38 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
|
39 | 38 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
40 | 39 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
41 | 40 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
... | ... | |
45 | 44 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
46 | 45 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
47 | 46 |
import com.iver.cit.gvsig.gui.View; |
47 |
import com.iver.cit.gvsig.gui.cad.snapping.FinalPointSnapper; |
|
48 | 48 |
import com.iver.cit.gvsig.gui.cad.snapping.ISnapper; |
49 |
import com.iver.cit.gvsig.gui.cad.snapping.FinalPointSnapper; |
|
49 |
import com.iver.cit.gvsig.gui.cad.snapping.ISnapperRaster; |
|
50 |
import com.iver.cit.gvsig.gui.cad.snapping.ISnapperVectorial; |
|
50 | 51 |
import com.iver.cit.gvsig.gui.cad.snapping.NearestPointSnapper; |
52 |
import com.iver.cit.gvsig.gui.cad.snapping.PixelSnapper; |
|
51 | 53 |
import com.iver.cit.gvsig.gui.cad.snapping.SnappingVisitor; |
52 | 54 |
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
53 | 55 |
import com.iver.cit.gvsig.layers.ILayerEdited; |
... | ... | |
198 | 200 |
// DE CONFIGURACI?N DEL SNAPPING |
199 | 201 |
FinalPointSnapper defaultSnap = new FinalPointSnapper(); |
200 | 202 |
NearestPointSnapper nearestSnap = new NearestPointSnapper(); |
203 |
PixelSnapper pixSnap = new PixelSnapper(); |
|
201 | 204 |
snappers.clear(); |
202 | 205 |
snappers.add(defaultSnap); |
203 | 206 |
snappers.add(nearestSnap); |
207 |
snappers.add(pixSnap); |
|
204 | 208 |
|
205 | 209 |
double mapTolerance = vp.toMapDistance(SelectionCADTool.tolerance); |
206 | 210 |
double minDist = mapTolerance; |
... | ... | |
235 | 239 |
if (theSnapper.getPriority() < usedSnap.getPriority()) |
236 | 240 |
break; |
237 | 241 |
} |
242 |
SnappingVisitor snapVisitor = null; |
|
243 |
Point2D theSnappedPoint = null; |
|
244 |
if (theSnapper instanceof ISnapperVectorial) |
|
245 |
{ |
|
246 |
snapVisitor = new SnappingVisitor((ISnapperVectorial) theSnapper, point, mapTolerance, lastPoint); |
|
247 |
// System.out.println("Cache size = " + cache.size()); |
|
248 |
cache.query(e, snapVisitor); |
|
249 |
theSnappedPoint = snapVisitor.getSnapPoint(); |
|
250 |
} |
|
251 |
if (theSnapper instanceof ISnapperRaster) |
|
252 |
{ |
|
253 |
ISnapperRaster snapRaster = (ISnapperRaster) theSnapper; |
|
254 |
theSnappedPoint = snapRaster.getSnapPoint(getMapControl(), point, mapTolerance, lastPoint); |
|
255 |
} |
|
256 |
|
|
238 | 257 |
|
239 |
SnappingVisitor snapVisitor = new SnappingVisitor(theSnapper, point, mapTolerance, lastPoint); |
|
240 |
// System.out.println("Cache size = " + cache.size()); |
|
241 |
cache.query(e, snapVisitor); |
|
242 |
|
|
243 |
if (snapVisitor.getSnapPoint() != null) { |
|
244 |
if (minDist > snapVisitor.getMinDist()) |
|
258 |
if (theSnappedPoint != null) { |
|
259 |
double distAux = theSnappedPoint.distance(point); |
|
260 |
if (minDist > distAux) |
|
245 | 261 |
{ |
246 |
minDist = snapVisitor.getMinDist();
|
|
262 |
minDist = distAux;
|
|
247 | 263 |
usedSnap = theSnapper; |
248 |
mapHandlerAdjustedPoint.setLocation(snapVisitor.getSnapPoint());
|
|
264 |
mapHandlerAdjustedPoint.setLocation(theSnappedPoint);
|
|
249 | 265 |
} |
250 | 266 |
} |
251 | 267 |
} |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/NearestPointSnapper.java | ||
---|---|---|
10 | 10 |
import com.vividsolutions.jts.geom.Coordinate; |
11 | 11 |
import com.vividsolutions.jts.geom.LineSegment; |
12 | 12 |
|
13 |
public class NearestPointSnapper extends AbstractSnapper { |
|
13 |
public class NearestPointSnapper extends AbstractSnapper implements ISnapperVectorial {
|
|
14 | 14 |
|
15 | 15 |
public Point2D getSnapPoint(Point2D point, IGeometry geom, double tolerance, Point2D lastPointEntered) { |
16 | 16 |
Point2D resul = null; |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/ISnapperVectorial.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.gui.cad.snapping; |
|
42 |
|
|
43 |
import java.awt.geom.Point2D; |
|
44 |
|
|
45 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
46 |
|
|
47 |
public interface ISnapperVectorial extends ISnapper { |
|
48 |
|
|
49 |
Point2D getSnapPoint(Point2D queryPoint, IGeometry geomToSnap, double tolerance, Point2D lastPointEntered); |
|
50 |
|
|
51 |
|
|
52 |
} |
|
53 |
|
|
54 |
|
|
0 | 55 |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/PixelSnapper.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.gui.cad.snapping; |
|
42 |
|
|
43 |
import java.awt.Color; |
|
44 |
import java.awt.Graphics; |
|
45 |
import java.awt.geom.Point2D; |
|
46 |
import java.awt.image.BufferedImage; |
|
47 |
import java.awt.image.ColorModel; |
|
48 |
|
|
49 |
import com.iver.andami.PluginServices; |
|
50 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
51 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
52 |
import com.vividsolutions.jts.geom.Coordinate; |
|
53 |
|
|
54 |
public class PixelSnapper extends AbstractSnapper implements ISnapperRaster { |
|
55 |
|
|
56 |
private Color refColor = Color.BLACK; |
|
57 |
private int tolColorR = 100; |
|
58 |
private int tolColorG = 100; |
|
59 |
private int tolColorB = 100; |
|
60 |
/* (non-Javadoc) |
|
61 |
* @see com.iver.cit.gvsig.gui.cad.snapping.ISnapperRaster#getSnapPoint(java.awt.image.BufferedImage, java.awt.geom.Point2D, double, java.awt.geom.Point2D) |
|
62 |
*/ |
|
63 |
public Point2D getSnapPoint(MapControl mapControl, Point2D point, |
|
64 |
double mapTolerance, Point2D lastPoint) { |
|
65 |
// Miramos dentro del rect?ngulo que define la tolerancia |
|
66 |
// y nos quedamos con el pixel que m?s se acerca al que buscamos |
|
67 |
BufferedImage img = mapControl.getImage(); |
|
68 |
ViewPort vp = mapControl.getViewPort(); |
|
69 |
Point2D pPixel = vp.fromMapPoint(point); |
|
70 |
int xPixel = (int) pPixel.getX(); |
|
71 |
int yPixel = (int) pPixel.getY(); |
|
72 |
// int centerRGB = img.getRGB(xPixel, yPixel); |
|
73 |
int centerRGB = refColor.getRGB(); |
|
74 |
double x1 = ColorModel.getRGBdefault().getRed(centerRGB); |
|
75 |
double y1 = ColorModel.getRGBdefault().getGreen(centerRGB); |
|
76 |
double z1 = ColorModel.getRGBdefault().getBlue(centerRGB); |
|
77 |
Coordinate c = new Coordinate(x1, y1, z1); |
|
78 |
|
|
79 |
int half = vp.fromMapDistance(mapTolerance) / 2; |
|
80 |
double minDistColor = Double.MAX_VALUE; |
|
81 |
int xSnapped = -1; |
|
82 |
int ySnapped = -1; |
|
83 |
int fromX =xPixel -half; |
|
84 |
if (fromX <0) fromX = 0; |
|
85 |
int fromY =yPixel -half; |
|
86 |
if (fromY <0) fromY = 0; |
|
87 |
|
|
88 |
int toX =xPixel + half; |
|
89 |
if (toX > vp.getImageWidth()) toX = vp.getImageWidth(); |
|
90 |
int toY =yPixel + half; |
|
91 |
if (toY > vp.getImageHeight()) toY = vp.getImageHeight(); |
|
92 |
|
|
93 |
for (int testX= fromX; testX< toX; testX++) |
|
94 |
{ |
|
95 |
for (int testY= fromY; testY< toY; testY++) |
|
96 |
{ |
|
97 |
// System.out.println("Testing: " + testX + ", " + testY); |
|
98 |
int testRGB = img.getRGB(testX, testY); |
|
99 |
// TODO: Aqu? deber?amos trabajar con un ColorSpace y usar toCIEXYZ. Por ahora lo calculo con RGB. |
|
100 |
int r = ColorModel.getRGBdefault().getRed(testRGB); |
|
101 |
int g = ColorModel.getRGBdefault().getGreen(testRGB); |
|
102 |
int b = ColorModel.getRGBdefault().getBlue(testRGB); |
|
103 |
Coordinate cAux = new Coordinate(r, g, b); |
|
104 |
|
|
105 |
if (Math.abs(r-x1) < tolColorR) |
|
106 |
if (Math.abs(g-y1) < tolColorG) |
|
107 |
if (Math.abs(b-z1) < tolColorB) |
|
108 |
{ |
|
109 |
double dist = c.distance(cAux); |
|
110 |
if (dist < minDistColor) |
|
111 |
{ |
|
112 |
minDistColor = dist; |
|
113 |
xSnapped = testX; |
|
114 |
ySnapped = testY; |
|
115 |
} |
|
116 |
} |
|
117 |
} |
|
118 |
} |
|
119 |
Point2D pResul = null; |
|
120 |
if (xSnapped != -1) |
|
121 |
{ |
|
122 |
pResul = vp.toMapPoint(xSnapped, ySnapped); |
|
123 |
} |
|
124 |
return pResul; |
|
125 |
} |
|
126 |
|
|
127 |
public void draw(Graphics g, Point2D pPixels) { |
|
128 |
g.setColor(getColor()); |
|
129 |
int half = getSizePixels() / 2; |
|
130 |
g.drawOval((int) (pPixels.getX() - half), |
|
131 |
(int) (pPixels.getY() - half), |
|
132 |
getSizePixels(), getSizePixels()); |
|
133 |
} |
|
134 |
|
|
135 |
public String getToolTipText() { |
|
136 |
return PluginServices.getText(this, "pixel_point"); |
|
137 |
} |
|
138 |
|
|
139 |
public int getPriority() { |
|
140 |
return 3; |
|
141 |
} |
|
142 |
|
|
143 |
} |
|
144 |
|
|
145 |
|
|
0 | 146 |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/IConfigurator.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.gui.cad.snapping; |
|
42 |
|
|
43 |
public interface IConfigurator { |
|
44 |
void setSnapper(ISnapper snapper); |
|
45 |
ISnapper getSnapper(); |
|
46 |
} |
|
47 |
|
|
48 |
|
|
0 | 49 |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/AbstractSnapper.java | ||
---|---|---|
4 | 4 |
import java.awt.Graphics; |
5 | 5 |
import java.awt.geom.Point2D; |
6 | 6 |
|
7 |
import javax.swing.JComponent; |
|
8 |
|
|
7 | 9 |
public abstract class AbstractSnapper implements ISnapper { |
8 | 10 |
|
9 | 11 |
// private Point2D snapPoint = null; |
10 | 12 |
private int sizePixels = 12; |
11 | 13 |
private Color color = Color.MAGENTA; |
14 |
private boolean enabled; |
|
12 | 15 |
// public void setSnapPoint(Point2D snapPoint) { |
13 | 16 |
// this.snapPoint = snapPoint; |
14 | 17 |
// |
... | ... | |
31 | 34 |
this.color = color; |
32 | 35 |
} |
33 | 36 |
|
37 |
public JComponent getConfigurator() |
|
38 |
{ |
|
39 |
return null; // Por defecto no se puede configurar un snapper. |
|
40 |
} |
|
41 |
|
|
42 |
public boolean isEnabled() { |
|
43 |
return enabled; |
|
44 |
} |
|
45 |
|
|
46 |
public void setEnabled(boolean enabled) { |
|
47 |
this.enabled = enabled; |
|
48 |
} |
|
34 | 49 |
} |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/FinalPointSnapper.java | ||
---|---|---|
7 | 7 |
import com.iver.cit.gvsig.fmap.core.Handler; |
8 | 8 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
9 | 9 |
|
10 |
public class FinalPointSnapper extends AbstractSnapper { |
|
10 |
public class FinalPointSnapper extends AbstractSnapper implements ISnapperVectorial {
|
|
11 | 11 |
|
12 | 12 |
public Point2D getSnapPoint(Point2D point, IGeometry geom, double tolerance, Point2D lastPointEntered) { |
13 | 13 |
Point2D resul = null; |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/SnappingVisitor.java | ||
---|---|---|
14 | 14 |
*/ |
15 | 15 |
public class SnappingVisitor implements ItemVisitor { |
16 | 16 |
|
17 |
ISnapper snapper; |
|
17 |
ISnapperVectorial snapper;
|
|
18 | 18 |
Point2D snapPoint = null; |
19 | 19 |
Point2D queryPoint = null; |
20 | 20 |
Point2D lastPointEntered = null; |
... | ... | |
23 | 23 |
double distActual; |
24 | 24 |
double tolerance; |
25 | 25 |
|
26 |
public SnappingVisitor(ISnapper snapper, Point2D queryPoint, double tolerance, Point2D lastPointEntered) |
|
26 |
public SnappingVisitor(ISnapperVectorial snapper, Point2D queryPoint, double tolerance, Point2D lastPointEntered)
|
|
27 | 27 |
{ |
28 | 28 |
this.snapper = snapper; |
29 | 29 |
this.tolerance = tolerance; |
... | ... | |
53 | 53 |
return snapPoint; |
54 | 54 |
} |
55 | 55 |
|
56 |
public double getMinDist() { |
|
57 |
return minDist; |
|
58 |
} |
|
56 |
// public double getMinDist() {
|
|
57 |
// return minDist;
|
|
58 |
// }
|
|
59 | 59 |
|
60 | 60 |
} |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/ISnapper.java | ||
---|---|---|
3 | 3 |
import java.awt.Graphics; |
4 | 4 |
import java.awt.geom.Point2D; |
5 | 5 |
|
6 |
import com.iver.cit.gvsig.fmap.core.IGeometry;
|
|
6 |
import javax.swing.JComponent;
|
|
7 | 7 |
|
8 | 8 |
/** |
9 | 9 |
* @author fjp |
... | ... | |
11 | 11 |
*/ |
12 | 12 |
public interface ISnapper { |
13 | 13 |
|
14 |
Point2D getSnapPoint(Point2D queryPoint, IGeometry geomToSnap, double tolerance, Point2D lastPointEntered); |
|
15 | 14 |
|
16 | 15 |
// void setSnapPoint(Point2D snapPoint); |
17 | 16 |
|
... | ... | |
25 | 24 |
* @return |
26 | 25 |
*/ |
27 | 26 |
int getPriority(); |
27 |
|
|
28 |
boolean isEnabled(); |
|
29 |
public void setEnabled(boolean enabled); |
|
30 |
|
|
31 |
JComponent getConfigurator(); |
|
28 | 32 |
|
29 | 33 |
} |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/ISnapperRaster.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.gui.cad.snapping; |
|
42 |
|
|
43 |
import java.awt.geom.Point2D; |
|
44 |
|
|
45 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
46 |
|
|
47 |
public interface ISnapperRaster extends ISnapper { |
|
48 |
|
|
49 |
Point2D getSnapPoint(MapControl mapControl, Point2D point, double mapTolerance, Point2D lastPoint); |
|
50 |
|
|
51 |
} |
|
52 |
|
|
53 |
|
|
0 | 54 |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/panels/SnapConfig.java | ||
---|---|---|
42 | 42 |
|
43 | 43 |
import java.awt.Component; |
44 | 44 |
import java.util.ArrayList; |
45 |
import java.util.Vector; |
|
45 | 46 |
|
46 | 47 |
import javax.swing.JCheckBox; |
47 | 48 |
import javax.swing.JList; |
48 | 49 |
import javax.swing.JPanel; |
49 | 50 |
import javax.swing.JScrollPane; |
51 |
import javax.swing.JTable; |
|
50 | 52 |
import javax.swing.ListCellRenderer; |
53 |
import javax.swing.table.AbstractTableModel; |
|
54 |
import javax.swing.table.DefaultTableModel; |
|
51 | 55 |
|
52 | 56 |
import com.iver.cit.gvsig.gui.cad.snapping.ISnapper; |
53 |
import com.iver.utiles.DefaultListModel; |
|
54 | 57 |
; |
55 | 58 |
|
59 |
/** |
|
60 |
* @author fjp |
|
61 |
* |
|
62 |
* Necesitamos un sitio donde est?n registrados todos los snappers que |
|
63 |
* se pueden usar. ExtensionPoints es el sitio adecuado. |
|
64 |
* Este di?logo recuperar? esa lista para que el usuario marque los |
|
65 |
* snappers con los que desea trabajar. |
|
66 |
*/ |
|
56 | 67 |
public class SnapConfig extends JPanel { |
57 | 68 |
|
58 | 69 |
private JCheckBox jChkBoxRefentActive = null; |
59 |
private JList jListSnappers = null;
|
|
70 |
private JTable jListSnappers = null;
|
|
60 | 71 |
private JPanel jPanel = null; |
61 | 72 |
private JScrollPane jScrollPane = null; |
62 | 73 |
|
63 | 74 |
private ArrayList snappers; |
64 | 75 |
|
76 |
/** |
|
77 |
* @author fjp |
|
78 |
* primera columna editable con un check box para habilitar/deshabilitar el snapper |
|
79 |
* segunda columna con el s?mbolo del snapper |
|
80 |
* tercera con el tooltip |
|
81 |
* cuarta con un bot?n para configurar el snapper si es necesario. |
|
82 |
*/ |
|
83 |
class MyTableModel extends AbstractTableModel { |
|
84 |
|
|
85 |
public ArrayList mySnappers; |
|
86 |
|
|
87 |
public MyTableModel(ArrayList snappers) |
|
88 |
{ |
|
89 |
this.mySnappers = snappers; |
|
90 |
} |
|
91 |
|
|
92 |
public int getColumnCount() { |
|
93 |
return 4; |
|
94 |
} |
|
95 |
|
|
96 |
public int getRowCount() { |
|
97 |
return mySnappers.size(); |
|
98 |
} |
|
99 |
|
|
100 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
|
101 |
if (columnIndex == 0) |
|
102 |
return true; |
|
103 |
else |
|
104 |
return false; |
|
105 |
} |
|
106 |
|
|
107 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
|
108 |
ISnapper snap = (ISnapper) mySnappers.get(rowIndex); |
|
109 |
switch (columnIndex) |
|
110 |
{ |
|
111 |
case 0: |
|
112 |
snap.setEnabled(((Boolean)aValue).booleanValue()); |
|
113 |
} |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
public Object getValueAt(int rowIndex, int columnIndex) { |
|
118 |
ISnapper snap = (ISnapper) mySnappers.get(rowIndex); |
|
119 |
switch (columnIndex) |
|
120 |
{ |
|
121 |
case 0: |
|
122 |
return new Boolean(snap.isEnabled()); |
|
123 |
case 1: |
|
124 |
return snap; |
|
125 |
case 2: |
|
126 |
return snap.getToolTipText(); |
|
127 |
} |
|
128 |
return null; |
|
129 |
} |
|
130 |
|
|
131 |
public Class getColumnClass(int columnIndex) { |
|
132 |
switch (columnIndex) |
|
133 |
{ |
|
134 |
case 0: |
|
135 |
return Boolean.class; |
|
136 |
case 1: |
|
137 |
return String.class; |
|
138 |
case 2: |
|
139 |
return String.class; |
|
140 |
case 3: |
|
141 |
return String.class; |
|
142 |
} |
|
143 |
return null; |
|
144 |
} |
|
145 |
|
|
146 |
public String getColumnName(int column) { |
|
147 |
// TODO Auto-generated method stub |
|
148 |
return super.getColumnName(column); |
|
149 |
} |
|
150 |
|
|
151 |
} |
|
152 |
|
|
65 | 153 |
class MyCellRenderer extends JCheckBox implements ListCellRenderer { |
66 | 154 |
|
67 | 155 |
// This is the only method defined by ListCellRenderer. |
... | ... | |
142 | 230 |
* |
143 | 231 |
* @return javax.swing.JList |
144 | 232 |
*/ |
145 |
private JList getJListSnappers() {
|
|
233 |
private JTable getJListSnappers() {
|
|
146 | 234 |
if (jListSnappers == null) { |
147 |
jListSnappers = new JList();
|
|
148 |
jListSnappers.setCellRenderer(new MyCellRenderer()); |
|
235 |
jListSnappers = new JTable();
|
|
236 |
// jListSnappers.setCellRenderer(new MyCellRenderer());
|
|
149 | 237 |
} |
150 | 238 |
return jListSnappers; |
151 | 239 |
} |
... | ... | |
185 | 273 |
|
186 | 274 |
public void setSnappers(ArrayList snappers) { |
187 | 275 |
this.snappers = snappers; |
188 |
DefaultListModel listModel = new DefaultListModel(snappers);
|
|
276 |
MyTableModel listModel = new MyTableModel(snappers);
|
|
189 | 277 |
getJListSnappers().setModel(listModel); |
190 | 278 |
} |
191 | 279 |
|
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/panels/SnapConfig2.java | ||
---|---|---|
41 | 41 |
package com.iver.cit.gvsig.gui.cad.snapping.panels; |
42 | 42 |
|
43 | 43 |
import java.awt.Component; |
44 |
import java.awt.Cursor; |
|
44 | 45 |
import java.awt.Dimension; |
46 |
import java.awt.Graphics2D; |
|
45 | 47 |
import java.awt.GridLayout; |
48 |
import java.awt.Point; |
|
49 |
import java.awt.image.BufferedImage; |
|
46 | 50 |
import java.util.ArrayList; |
47 | 51 |
|
52 |
import javax.swing.ImageIcon; |
|
48 | 53 |
import javax.swing.JCheckBox; |
49 | 54 |
import javax.swing.JList; |
50 | 55 |
import javax.swing.JPanel; |
51 | 56 |
import javax.swing.JScrollPane; |
52 | 57 |
import javax.swing.ListCellRenderer; |
53 | 58 |
|
59 |
import com.iver.andami.PluginServices; |
|
54 | 60 |
import com.iver.cit.gvsig.gui.cad.snapping.ISnapper; |
61 |
import com.sun.media.sound.Toolkit; |
|
62 |
import com.sun.medialib.mlib.Image; |
|
55 | 63 |
; |
56 | 64 |
|
57 | 65 |
public class SnapConfig2 extends JPanel { |
... | ... | |
60 | 68 |
private JPanel jPanel = null; |
61 | 69 |
private JScrollPane jScrollPane = null; |
62 | 70 |
|
71 |
private BufferedImage myCanvas = new BufferedImage(12, 12, BufferedImage.TYPE_INT_ARGB); |
|
72 |
|
|
63 | 73 |
private ArrayList snappers; |
64 | 74 |
|
65 | 75 |
class MyCellRenderer extends JCheckBox implements ListCellRenderer { |
... | ... | |
67 | 77 |
// This is the only method defined by ListCellRenderer. |
68 | 78 |
// We just reconfigure the JLabel each time we're called. |
69 | 79 |
|
80 |
|
|
70 | 81 |
public Component getListCellRendererComponent( |
71 | 82 |
JList list, |
72 | 83 |
Object value, // value to display |
... | ... | |
183 | 194 |
ISnapper s = (ISnapper) snappers.get(i); |
184 | 195 |
JCheckBox snapperComponent = new JCheckBox(s.getToolTipText()); |
185 | 196 |
// snapperComponent.setPreferredSize(new Dimension(200, 30)); |
197 |
Graphics2D g2 = myCanvas.createGraphics(); |
|
198 |
g2.clearRect(0,0, 12, 12); |
|
199 |
s.draw(g2, new Point(5,5)); |
|
200 |
g2.dispose(); |
|
201 |
// snapperComponent.getLabel().setIcon(new ImageIcon(myCanvas)); |
|
202 |
|
|
186 | 203 |
newPanel.add(snapperComponent); |
187 | 204 |
} |
188 | 205 |
getJScrollPane().setViewportView(newPanel); |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/snapping/panels/testDialog.java | ||
---|---|---|
53 | 53 |
import javax.swing.Action; |
54 | 54 |
import javax.swing.JButton; |
55 | 55 |
import javax.swing.JDialog; |
56 |
import javax.swing.LookAndFeel; |
|
57 |
import javax.swing.UIManager; |
|
58 |
import javax.swing.UnsupportedLookAndFeelException; |
|
56 | 59 |
|
57 | 60 |
import com.iver.cit.gvsig.gui.cad.snapping.FinalPointSnapper; |
58 | 61 |
|
59 | 62 |
public class testDialog { |
60 | 63 |
public static void main(String[] args) { |
64 |
|
|
65 |
try { |
|
66 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
|
67 |
} catch (ClassNotFoundException e) { |
|
68 |
// TODO Auto-generated catch block |
|
69 |
e.printStackTrace(); |
|
70 |
} catch (InstantiationException e) { |
|
71 |
// TODO Auto-generated catch block |
|
72 |
e.printStackTrace(); |
|
73 |
} catch (IllegalAccessException e) { |
|
74 |
// TODO Auto-generated catch block |
|
75 |
e.printStackTrace(); |
|
76 |
} catch (UnsupportedLookAndFeelException e) { |
|
77 |
// TODO Auto-generated catch block |
|
78 |
e.printStackTrace(); |
|
79 |
} |
|
80 |
|
|
61 | 81 |
JDialog dlg = new JDialog(); |
62 | 82 |
|
63 | 83 |
ArrayList list = new ArrayList(); |
64 | 84 |
for (int i=0; i < 20; i++) |
65 | 85 |
list.add(new FinalPointSnapper()); |
66 |
SnapConfig2 panel = new SnapConfig2();
|
|
86 |
SnapConfig panel = new SnapConfig();
|
|
67 | 87 |
panel.setSnappers(list); |
68 | 88 |
Action act = new AbstractAction(){ |
69 | 89 |
public void actionPerformed(java.awt.event.ActionEvent arg0) { |
70 | 90 |
System.out.println("HOla"); |
71 |
HashPrintRequestAttributeSet att = new HashPrintRequestAttributeSet(); |
|
72 |
|
|
73 |
PrinterJob job = PrinterJob.getPrinterJob(); |
|
74 |
PageFormat defaulFormat = job.defaultPage(); |
|
75 |
// PageFormat selectedFormat = job.pageDialog(defaulFormat); |
|
76 |
Paper paper = new Paper(); |
|
77 |
paper.setSize(MediaSize.ISO.A5.getX(MediaSize.INCH),MediaSize.ISO.A5.getY(MediaSize.INCH)); |
|
78 |
defaulFormat.setPaper(paper); |
|
79 |
job.defaultPage(defaulFormat); |
|
80 |
if (job.printDialog()) { |
|
81 |
// System.out.println(job.) |
|
82 |
} |
|
91 |
// HashPrintRequestAttributeSet att = new HashPrintRequestAttributeSet();
|
|
92 |
// |
|
93 |
// PrinterJob job = PrinterJob.getPrinterJob();
|
|
94 |
// PageFormat defaulFormat = job.defaultPage();
|
|
95 |
// // PageFormat selectedFormat = job.pageDialog(defaulFormat);
|
|
96 |
// Paper paper = new Paper();
|
|
97 |
// paper.setSize(MediaSize.ISO.A5.getX(MediaSize.INCH),MediaSize.ISO.A5.getY(MediaSize.INCH));
|
|
98 |
// defaulFormat.setPaper(paper);
|
|
99 |
// job.defaultPage(defaulFormat);
|
|
100 |
// if (job.printDialog()) {
|
|
101 |
// // System.out.println(job.)
|
|
102 |
// }
|
|
83 | 103 |
}; |
84 | 104 |
}; |
85 | 105 |
JButton btnPrint = new JButton(act); |
Also available in: Unified diff