Revision 39454

View differences:

tags/v2_0_0_Build_2061/libraries/libFMap_controls/src-test/org/gvsig/fmap/mapcontrol/tools/AreaListenerTest.java
1
package org.gvsig.fmap.mapcontrol.tools;
2

  
3
import java.awt.geom.Point2D;
4

  
5
import org.cresques.cts.IProjection;
6
import org.gvsig.fmap.crs.CRSFactory;
7
import org.gvsig.fmap.mapcontext.MapContext;
8
import org.gvsig.fmap.mapcontext.ViewPort;
9
import org.gvsig.fmap.mapcontrol.MapControl;
10
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
11

  
12

  
13
public class AreaListenerTest extends AbstractLibraryAutoInitTestCase {
14
	private IProjection projectionUTM = CRSFactory.getCRS("EPSG:23030");
15
	private IProjection projectionGeo = CRSFactory.getCRS("EPSG:4230");
16
		
17
	@Override
18
	protected void doSetUp() throws Exception {
19
		// Nothing to do	
20
	}
21

  
22
	public void test1() {
23
		AreaListenerImpl areaListenerUTM=new AreaListenerImpl(newMapControlUTM());
24
		AreaListenerImpl areaListenerGeo=new AreaListenerImpl(newMapControlGeo());
25
		Double[] xsUTM=new Double[] {new Double(731292),new Double(731901),new Double(730138)};
26
		Double[] ysUTM=new Double[] {new Double(4351223),new Double(4350768),new Double(4349232)};
27
		double areaUTM=areaListenerUTM.returnCoordsArea(xsUTM,ysUTM,new Point2D.Double(730138,4349232));
28
		Double[] xsGeo=new Double[] {new Double(-0.31888183),new Double(-0.31173131),new Double(-0.33268401)};
29
		Double[] ysGeo=new Double[] {new Double(39.27871741),new Double(39.27464327),new Double(39.26117368)};
30
		double areaGeo=areaListenerGeo.returnGeoCArea(xsGeo,ysGeo,new Point2D.Double(-0.33268401,39.26117368));
31
		assertTrue("Area UTM igual a Geo",areaUTM<(areaGeo+1000)&& areaUTM>(areaGeo-1000));
32
	}
33
	private MapControl newMapControlUTM() {
34
		ViewPort vp = new ViewPort(projectionUTM);
35
		MapControl mc=new MapControl();
36
		mc.setMapContext(new MapContext(vp));
37
		return mc;
38
	}
39
	private MapControl newMapControlGeo() {
40
		ViewPort vp = new ViewPort(projectionGeo);
41
		MapControl mc=new MapControl();
42
		mc.setMapContext(new MapContext(vp));
43
		return mc;
44
	}
45
}
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/app/gui/JComboBoxUnits.java
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
 * 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 org.gvsig.app.gui;
42

  
43
import org.gvsig.fmap.mapcontext.MapContext;
44
import org.gvsig.i18n.Messages;
45
import org.gvsig.utils.swing.JComboBox;
46

  
47

  
48
/**
49
 * <p>Class representing a JComboBox with the measure units handled by the application.
50
 * It takes values from Attributes.NAMES and Attributes.CHANGE static fields. So, to
51
 * add more measure units, you must edit Attributes class and change will be automatically
52
 * reflected in the combo box.</p>
53
 *
54
 * <p>The internatiolanization of the field is automatically handled by the system</p>
55
 * @author jaume dominguez faus - jaume.dominguez@iver.es
56
 */
57
public class JComboBoxUnits extends JComboBox {
58
	private static final long serialVersionUID = 8015263853737441433L;
59

  
60
	/**
61
	 * Creates a new instance of JUnitComboBox including "pixel" units and
62
	 * setting them as automatically pre-selected.
63
	 */
64
	public JComboBoxUnits() {
65
		this(true);
66
	}
67

  
68
	/**
69
	 *
70
	 * Creates a new instance of JUnitComboBox. If includePixel is true
71
	 * then pixel units are included in the list and they are automatically
72
	 * pre-selected. Otherwise, meters are preselected.
73
	 *
74
	 */
75
	public JComboBoxUnits(boolean includePixel) {
76
		super();
77
		String[] names=MapContext.getDistanceNames();
78

  
79
		for (int i = 0; i < names.length; i++) {
80
			super.addItem(Messages.getText(names[i]));
81
		}
82
		if (includePixel) {
83
			super.addItem(Messages.getText("_Pixels"));
84
			setSelectedItem(Messages.getText("_Pixels"));
85
		} else {
86
			setSelectedIndex(1);
87
		}
88
		setMaximumRowCount(10);
89
	}
90

  
91

  
92
	/**
93
	 * Returns the conversion factor from the <b>unit selected in the combo box</b>
94
	 * to <b>meters</b> or <b>0</b> if pixels have been selected as the size unit.
95
	 * @return
96
	 */
97
	public double getUnitConversionFactor() {
98
			double unitFactor;
99
			try {
100
				unitFactor = MapContext.getDistanceTrans2Meter()[getSelectedIndex()];
101
			} catch (ArrayIndexOutOfBoundsException aioobEx) { //jijiji
102
				unitFactor = 0; // which represents size in pixel
103
			}
104
			return unitFactor;
105

  
106
	}
107

  
108
	/**
109
	 * the use of this method is not allowed in this combo box.
110
	 * @deprecated
111
	 */
112
	public void addItem(Object anObject) {
113
		throw new Error("Operation not allowed");
114
	}
115

  
116
	/**
117
	 * the use of this method is not allowed for this combo box.
118
	 * @deprecated
119
	 */
120
	public void removeAllItems() {
121
		throw new Error("Operation not allowed");
122
	}
123

  
124
	public int getSelectedUnitIndex() {
125
		int i = getSelectedIndex();
126
		if (i>MapContext.getDistanceNames().length-1)
127
			return -1;
128
		else return i;
129
	}
130

  
131
	public void setSelectedUnitIndex(int unitIndex) {
132
		if (unitIndex == -1) {
133
			setSelectedIndex(getItemCount()-1);
134
		} else {
135
			setSelectedIndex(unitIndex);
136
		}
137
	}
138

  
139

  
140

  
141
}
0 142

  
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/IconThemeHelper.java
1
package org.gvsig.fmap;
2

  
3
import java.awt.Image;
4

  
5
import javax.swing.ImageIcon;
6

  
7
import org.gvsig.tools.swing.api.ToolsSwingLocator;
8
import org.gvsig.tools.swing.icontheme.IconTheme;
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

  
12
public class IconThemeHelper {
13

  
14
	private static Logger logger = LoggerFactory.getLogger(IconThemeHelper.class);
15
	
16
	public static void registerIcon(String group, String name, Object obj) {
17
		String resourceName;
18
		ClassLoader loader;
19
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
20
		if( group == null || group.trim().length()==0 ) {
21
			resourceName = "images/"+name+".png";
22
		} else {
23
			resourceName = "images/"+group+"/"+name+".png";
24
		}
25
		if( obj instanceof Class ) {
26
			loader = ((Class) obj).getClassLoader();
27
		} else {
28
			loader = obj.getClass().getClassLoader();
29
		}
30
		try {
31
			iconTheme.registerDefault("mapcontrol", group, name, null, loader.getResource(resourceName));
32
		} catch( Throwable e) {
33
			logger.info(e.getMessage());
34
		}
35
	}
36

  
37
	public static ImageIcon getImageIcon(String iconName) {
38
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
39
		return iconTheme.get(iconName);
40
	}
41
	
42
	public static Image getImage(String iconName) {
43
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
44
		return iconTheme.get(iconName).getImage();
45
	}
46
}
0 47

  
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/impl/DefaultPrimitivesDrawer.java
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.fmap.mapcontrol.impl;
23

  
24
import java.awt.Color;
25
import java.awt.Graphics;
26
import java.awt.Graphics2D;
27
import java.awt.RenderingHints;
28
import java.awt.Stroke;
29
import java.awt.image.BufferedImage;
30

  
31
import org.gvsig.fmap.mapcontrol.MapControl;
32
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer;
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35

  
36
/**
37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
38
 */
39
public class DefaultPrimitivesDrawer implements PrimitivesDrawer {
40

  
41
    private static final Logger LOG = LoggerFactory
42
        .getLogger(DefaultPrimitivesDrawer.class);
43

  
44
    protected Graphics2D graphics = null;
45
    protected Color color = Color.BLACK;
46
    protected Color xorColor = Color.WHITE;
47
    private Object lockObject = null;
48

  
49
    public DefaultPrimitivesDrawer() {
50
        super();
51
    }
52

  
53
    public DefaultPrimitivesDrawer(Graphics2D graphics) {
54
        super();
55
        this.graphics = graphics;
56
    }
57

  
58
    public void drawLine(int x1, int y1, int x2, int y2) {
59
        graphics.setXORMode(xorColor);
60
        graphics.drawLine(x1, y1, x2, y2);
61
        graphics.setPaintMode();
62
    }
63

  
64
    public void drawOval(int x, int y, int width, int height) {
65
        graphics.setXORMode(xorColor);
66
        graphics.drawOval(x, y, width, height);
67
        graphics.setPaintMode();
68
    }
69

  
70
    public void drawRect(int x, int y, int width, int height) {
71
        graphics.setXORMode(xorColor);
72
        graphics.drawRect(x, y, width, height);
73
        graphics.setPaintMode();
74
    }
75

  
76
    public void fillRect(int x, int y, int width, int height) {
77
        graphics.setColor(color);
78
        graphics.fillRect(x, y, width, height);
79
    }
80

  
81
    public void setColor(Color color) {
82
        this.color = color;
83
    }
84

  
85
    public void setGraphics(Graphics graphics) {
86
        this.graphics = (Graphics2D) graphics;
87
    }
88

  
89
    public void stopDrawing(Object obj) {
90
        if (lockObject != obj) {
91
            LOG.warn("Trying to unlock a resource that is not locked");
92
            return;
93
        }
94
        lockObject = null;
95
    }
96

  
97
    public void startDrawing(Object obj) throws InterruptedException {
98
        while ((lockObject != null) && (obj != lockObject)) {
99
            Thread.sleep(100);
100
        }
101
        lockObject = obj;
102
    }
103
    
104
    public void setRenderingHints(RenderingHints hints) {
105
    	this.graphics.setRenderingHints(hints);
106
    }
107
    
108
    public void setStroke(Stroke stroke) {
109
    	this.graphics.setStroke(stroke);
110
    }
111
    
112
    public void cleanCanvas(MapControl mapCtrl) {
113
    	BufferedImage img = mapCtrl.getImage();
114
    	this.graphics.drawImage(img, 0, 0, null);
115
    }
116
}
0 117

  
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/impl/DefaultMapControlLibrary.java
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

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.mapcontrol.impl;
29

  
30
import org.gvsig.fmap.mapcontrol.MapControlLibrary;
31
import org.gvsig.fmap.mapcontrol.MapControlLocator;
32
import org.gvsig.fmap.mapcontrol.MapControlManager;
33
import org.gvsig.tools.library.AbstractLibrary;
34
import org.gvsig.tools.library.LibraryException;
35
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
36

  
37
/**
38
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
39
 */
40
public class DefaultMapControlLibrary extends AbstractLibrary{
41
	
42
    @Override
43
    public void doRegistration() {
44
        registerAsImplementationOf(MapControlLibrary.class);
45
    }
46

  
47
	@Override
48
	protected void doInitialize() throws LibraryException {
49
		MapControlLocator.registerMapControlManager(DefaultMapControlManager.class);
50
	}
51

  
52
	@Override
53
	protected void doPostInitialize() throws LibraryException {
54
		// Validate there is any implementation registered.
55
		MapControlManager mapControlManager = MapControlLocator.getMapControlManager();
56
		if (mapControlManager == null) {
57
			throw new ReferenceNotRegisteredException(
58
					MapControlLocator.MAPCONTROL_MANAGER_NAME, 
59
					MapControlLocator.getInstance());
60
		}
61
		
62
		//Register the default implementation for a view, that will be
63
		//the 2D MapControlDrawer.
64
		mapControlManager.registerDefaultMapControlDrawer(MapControlDrawer2D.class);
65
	}
66
}
67

  
0 68

  
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/impl/MapControlDrawer2D.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.mapcontrol.impl;
29

  
30
import java.awt.Color;
31
import java.awt.Composite;
32
import java.awt.Image;
33
import java.awt.geom.AffineTransform;
34
import java.awt.geom.Point2D;
35

  
36
import org.gvsig.fmap.geom.Geometry;
37
import org.gvsig.fmap.geom.GeometryLocator;
38
import org.gvsig.fmap.geom.GeometryManager;
39
import org.gvsig.fmap.geom.handler.Handler;
40
import org.gvsig.fmap.geom.operation.Draw;
41
import org.gvsig.fmap.geom.operation.DrawOperationContext;
42
import org.gvsig.fmap.geom.operation.GeometryOperationException;
43
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
44
import org.gvsig.fmap.geom.primitive.Curve;
45
import org.gvsig.fmap.geom.primitive.GeneralPathX;
46
import org.gvsig.fmap.mapcontext.MapContextLocator;
47
import org.gvsig.fmap.mapcontext.ViewPort;
48
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
49
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
50
import org.slf4j.Logger;
51
import org.slf4j.LoggerFactory;
52

  
53
/**
54
 * MapControlDrawer for a 2D view.
55
 * 
56
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
57
 */
58
public class MapControlDrawer2D extends DefaultPrimitivesDrawer implements MapControlDrawer{
59
    private static final Logger LOG = LoggerFactory.getLogger(MapControlDrawer2D.class);
60
    
61
	protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
62
	private ViewPort viewPort = null;
63

  
64
	/**
65
	 * @param graphics
66
	 * @param viewPort
67
	 */
68
	public MapControlDrawer2D() {
69
		super();		
70
	}
71

  
72
	/* (non-Javadoc)
73
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#draw(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
74
	 */
75
	public void draw(Geometry geometry, ISymbol symbol) {
76
		if (geometry != null) {
77
		    symbol.draw(graphics, viewPort.getAffineTransform(), geometry, null, null);             
78
		}		
79
	}
80

  
81
	/*
82
	 * (non-Javadoc)
83
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawHandlers(org.gvsig.fmap.geom.Geometry, java.awt.geom.AffineTransform, org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
84
	 */
85
	public void drawHandlers(Handler[] handlers, AffineTransform at, ISymbol symbol) {
86
		for (int i = 0; i < handlers.length; i++) {
87
			Point2D point = handlers[i].getPoint();
88
			at.transform(point, point);
89

  
90
			graphics.setPaintMode();
91
			graphics.setColor(symbol.getColor());
92
			graphics.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7);
93
			graphics.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10);
94
			graphics.drawString( "" + i, (int) (point.getX() - 5), (int) (point.getY() - 5));
95
		}
96
	}
97

  
98
	/* (non-Javadoc)
99
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawLine(java.awt.geom.Point2D, java.awt.geom.Point2D, org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
100
	 */
101
	public void drawLine(Point2D firstPoint, Point2D endPoint, ISymbol symbol) {
102
		GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2);
103
		elShape.moveTo(firstPoint.getX(), firstPoint.getY());
104
		elShape.lineTo(endPoint.getX(), endPoint.getY());
105
		DrawOperationContext doc = new DrawOperationContext();
106
		doc.setGraphics(graphics);
107
		doc.setViewPort(viewPort);
108
		doc.setSymbol(symbol);
109
		try {
110
			Curve curve = (Curve)geomManager.create(Geometry.TYPES.CURVE, Geometry.SUBTYPES.GEOM2D);
111
			curve.setGeneralPath(elShape);
112
			curve.invokeOperation(Draw.CODE, doc);
113
		} catch (GeometryOperationNotSupportedException e) {
114
			e.printStackTrace();
115
		} catch (GeometryOperationException e) {
116
			e.printStackTrace();
117
		} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
118
			e.printStackTrace();
119
		}		
120
	}
121

  
122
	/* (non-Javadoc)
123
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawImage(java.awt.Image, int, int)
124
	 */
125
	public void drawImage(Image img, int x, int y) {
126
		if (img != null){
127
			graphics.drawImage(img, x, y, null);
128
		}		
129
	}	
130

  
131
	/*
132
	 * (non-Javadoc)
133
	 * @see org.gvsig.fmap.mapcontrol.MapControlDrawer#drawHandler(org.gvsig.fmap.geom.handler.Handler, java.awt.geom.AffineTransform)
134
	 */
135
	public void drawHandler(Handler handler, AffineTransform at) {
136
		Point2D point = handler.getPoint();
137
		Point2D dest = (Point2D) point.clone();
138
		at.transform(point, dest);
139
		graphics.setColor(Color.black);
140
		graphics.drawLine((int)dest.getX()-2,(int)dest.getY()-10,(int)dest.getX()-2,(int)dest.getY()+10);
141
		graphics.drawLine((int)dest.getX()+2,(int)dest.getY()-10,(int)dest.getX()+2,(int)dest.getY()+10);
142
		graphics.drawLine((int)dest.getX()-10,(int)dest.getY()-2,(int)dest.getX()+10,(int)dest.getY()-2);
143
		graphics.drawLine((int)dest.getX()-10,(int)dest.getY()+2,(int)dest.getX()+10,(int)dest.getY()+2);
144
		graphics.setColor(Color.red);
145
		graphics.drawLine((int)dest.getX()-1,(int)dest.getY()-10,(int)dest.getX()-1,(int)dest.getY()+10);
146
		graphics.drawLine((int)dest.getX()+1,(int)dest.getY()-10,(int)dest.getX()+1,(int)dest.getY()+10);
147
		graphics.drawLine((int)dest.getX()-10,(int)dest.getY()-1,(int)dest.getX()+10,(int)dest.getY()-1);
148
		graphics.drawLine((int)dest.getX()-10,(int)dest.getY()+1,(int)dest.getX()+10,(int)dest.getY()+1);
149
	}
150

  
151
	/* (non-Javadoc)
152
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawImage(java.awt.Image, java.awt.geom.AffineTransform)
153
	 */
154
	public void drawImage(Image img, AffineTransform xform) {
155
		graphics.drawImage(img, xform, null);		
156
	}
157

  
158
	/* (non-Javadoc)
159
	 * @see org.gvsig.fmap.mapcontext.rendering.Renderer#setViewPort(org.gvsig.fmap.mapcontext.ViewPort)
160
	 */
161
	public void setViewPort(ViewPort viewPort) {
162
		this.viewPort = viewPort;		
163
	}
164

  
165
	/* (non-Javadoc)
166
	 * @see org.gvsig.fmap.mapcontrol.MapControlDrawer#draw(org.gvsig.fmap.geom.Geometry)
167
	 */
168
	public void draw(Geometry geometry) {
169
		draw(geometry, MapContextLocator.getSymbolManager().createSymbol(geometry.getType()));
170
	}
171

  
172
	/* (non-Javadoc)
173
	 * @see org.gvsig.fmap.mapcontrol.MapControlDrawer#setComposite(java.awt.AlphaComposite)
174
	 */
175
	public void setComposite(Composite composite) {
176
		graphics.setComposite(composite);
177
	}
178

  
179
	/* (non-Javadoc)
180
	 * @see org.gvsig.fmap.mapcontrol.MapControlDrawer#transform(java.awt.geom.AffineTransform)
181
	 */
182
	public void transform(AffineTransform at) {
183
		graphics.transform(at);		
184
	}
185

  
186
}
187

  
0 188

  
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/impl/DefaultMapControlManager.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.mapcontrol.impl;
29

  
30
import java.awt.Color;
31
import java.util.ArrayList;
32
import java.util.Iterator;
33
import java.util.Map;
34
import java.util.prefs.Preferences;
35

  
36
import org.gvsig.fmap.geom.Geometry;
37
import org.gvsig.fmap.mapcontext.MapContextLocator;
38
import org.gvsig.fmap.mapcontext.MapContextManager;
39
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
40
import org.gvsig.fmap.mapcontrol.MapControl;
41
import org.gvsig.fmap.mapcontrol.MapControlCreationException;
42
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
43
import org.gvsig.fmap.mapcontrol.MapControlManager;
44
import org.gvsig.fmap.mapcontrol.swing.dynobject.LayersDynObjectSetComponent;
45
import org.gvsig.fmap.mapcontrol.swing.dynobject.impl.DefaultLayersDynObjectSetComponent;
46
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper;
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.dynobject.DynObjectSet;
49
import org.gvsig.tools.extensionpoint.ExtensionPoint;
50
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
51
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
52
import org.slf4j.Logger;
53
import org.slf4j.LoggerFactory;
54

  
55
/**
56
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
57
 */
58
public class DefaultMapControlManager implements MapControlManager{
59
	private static final Logger logger = LoggerFactory.getLogger(MapControlManager.class);
60
	private static final String MAPCONTROL_MANAGER_EXTENSION_POINT = "MapControlManagerExtensionPoint";
61
	private static final String DEFAULT_MAPCONTROLMANAGER_NAME = null;
62
	private static final String SNAPPING_EXTENSION_POINT = "Snapper";
63

  
64
	private ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
65
	private int snappingTolerance = 4;
66
	private ISymbol selectionSymbol = null;	
67
	private ISymbol axisReferencesSymbol = null;
68
	private ISymbol geometrySelectionSymbol = null;
69
	private ISymbol handlerSymbol = null;
70
	private static MapContextManager mapContextManager = MapContextLocator
71
	.getMapContextManager();
72
	private Preferences prefs = Preferences.userRoot().node( "cadtooladapter" );
73
	private static Preferences prefSnappers = Preferences.userRoot().node("snappers");
74
	private ArrayList<ISnapper> snappers = null;	
75

  
76
	public DefaultMapControlManager() {
77
		super();
78
		snappers = new ArrayList<ISnapper>();
79
	}
80

  
81
	/* (non-Javadoc)
82
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#createDefaultMapControlDrawer()
83
	 */
84
	public MapControlDrawer createDefaultMapControlDrawer() throws MapControlCreationException {
85
		ExtensionPoint ep = extensionPoints.add(MAPCONTROL_MANAGER_EXTENSION_POINT);
86
		try {
87
			return (MapControlDrawer)ep.create(DEFAULT_MAPCONTROLMANAGER_NAME);			
88
		} catch (Exception e) {
89
			throw new MapControlCreationException(e);
90
		}	
91
	}
92

  
93
	/*
94
	 * (non-Javadoc)
95
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#createMapControlDrawer(java.lang.String)
96
	 */
97
	public MapControlDrawer createMapControlDrawer(String name) throws MapControlCreationException {
98
		ExtensionPoint ep = extensionPoints.add(MAPCONTROL_MANAGER_EXTENSION_POINT);
99
		try {
100
			return (MapControlDrawer)ep.create(name);			
101
		} catch (Exception e) {
102
			throw new MapControlCreationException(e);
103
		}
104
	}
105

  
106
	/* (non-Javadoc)
107
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#registerDefaultMapControlDrawer(java.lang.Class)
108
	 */
109
	public void registerDefaultMapControlDrawer(Class mapControlDrawerClass) {
110
		if (!MapControlDrawer.class.isAssignableFrom(mapControlDrawerClass)) {
111
			throw new IllegalArgumentException(mapControlDrawerClass.getName()
112
					+ " must implement the MapControlDrawer interface");
113
		}
114

  
115
		ExtensionPoint extensionPoint = extensionPoints.add(MAPCONTROL_MANAGER_EXTENSION_POINT, "");
116
		extensionPoint.append(DEFAULT_MAPCONTROLMANAGER_NAME, "Default MapControl", mapControlDrawerClass);		
117
	}
118

  
119
	/* (non-Javadoc)
120
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#registerMapControlDrawer(int, java.lang.Class)
121
	 */
122
	public void registerMapControlDrawer(String name,
123
			Class mapControlDrawerClass) {
124

  
125
		if (!MapControlDrawer.class.isAssignableFrom(mapControlDrawerClass)) {
126
			throw new IllegalArgumentException(mapControlDrawerClass.getName()
127
					+ " must implement the MapControlDrawer interface");
128
		}
129

  
130
		ExtensionPoint extensionPoint = extensionPoints.add(MAPCONTROL_MANAGER_EXTENSION_POINT, "");
131
		extensionPoint.append(name, "Default MapControl", mapControlDrawerClass);		
132
	}
133

  
134
	/* (non-Javadoc)
135
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getSnappingTolerance()
136
	 */
137
	public int getTolerance() {
138
		return snappingTolerance;
139
	}
140

  
141
	/* (non-Javadoc)
142
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setSnappingTolerance(int)
143
	 */
144
	public void setTolerance(int tolerance) {
145
		snappingTolerance = tolerance;		
146
	}
147

  
148
	/* (non-Javadoc)
149
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#clearSnappers()
150
	 */
151
	public void clearSnappers() {
152
		snappers.clear();		
153
	}
154

  
155
	/* (non-Javadoc)
156
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getAxisReferenceSymbol()
157
	 */
158
	public ISymbol getAxisReferenceSymbol() {
159
		if (axisReferencesSymbol == null){
160
			axisReferencesSymbol =
161
					mapContextManager.getSymbolManager()
162
			.createSymbol(Geometry.TYPES.GEOMETRY,
163
					new Color(100, 100, 100, 100));
164
		}
165
		return axisReferencesSymbol;
166
	}
167

  
168
	/* (non-Javadoc)
169
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getGeometrySelectionSymbol()
170
	 */
171
	public ISymbol getGeometrySelectionSymbol() {
172
		if (geometrySelectionSymbol == null){
173
			geometrySelectionSymbol =
174
					mapContextManager.getSymbolManager()
175
			.createSymbol(Geometry.TYPES.GEOMETRY, Color.RED);
176
		}		
177
		return geometrySelectionSymbol;
178
	}
179

  
180
	/* (non-Javadoc)
181
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getHandlerSymbol()
182
	 */
183
	public ISymbol getHandlerSymbol() {
184
		if (handlerSymbol == null){
185
			handlerSymbol =
186
					mapContextManager.getSymbolManager().createSymbol(
187
					Geometry.TYPES.GEOMETRY, Color.ORANGE);
188
		}
189
		return handlerSymbol;
190
	}
191

  
192
	/* (non-Javadoc)
193
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getSelectionSymbol()
194
	 */
195
	public ISymbol getSelectionSymbol() {
196
		if (selectionSymbol == null){
197
			selectionSymbol =
198
					mapContextManager.getSymbolManager().createSymbol(
199
					Geometry.TYPES.GEOMETRY, new Color(255, 0, 0, 100)); 
200
		}
201
		return selectionSymbol;
202
	}
203

  
204
	/*
205
	 * (non-Javadoc)
206
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setAxisReferenceSymbol(org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
207
	 */
208
	public void setAxisReferenceSymbol(ISymbol axisReferencesSymbol) {
209
		this.axisReferencesSymbol = axisReferencesSymbol;		
210
	}
211

  
212
	/*
213
	 * (non-Javadoc)
214
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setGeometrySelectionSymbol(org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
215
	 */
216
	public void setGeometrySelectionSymbol(ISymbol geometrySelectionSymbol) {
217
		this.geometrySelectionSymbol = geometrySelectionSymbol;		
218
	}
219

  
220
	/*
221
	 * (non-Javadoc)
222
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setHandlerSymbol(org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
223
	 */
224
	public void setHandlerSymbol(ISymbol handlerSymbol) {
225
		this.handlerSymbol = handlerSymbol;		
226
	}
227

  
228
	/*
229
	 * (non-Javadoc)
230
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setSelectionSymbol(org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
231
	 */
232
	public void setSelectionSymbol(ISymbol selectionSymbol) {
233
		this.selectionSymbol = selectionSymbol;		
234
	}
235

  
236
	/* (non-Javadoc)
237
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#addSnapper(org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper)
238
	 */
239
	public void registerSnapper(String name, Class snapperClass) {
240
		if (!ISnapper.class.isAssignableFrom(snapperClass)) {
241
			throw new IllegalArgumentException(snapperClass.getName()
242
					+ " must implement the ISnapper interface");
243
		}		
244

  
245
		ExtensionPoint extensionPoint = extensionPoints.add(SNAPPING_EXTENSION_POINT, "");
246
		Extension extension = extensionPoint.append(name, "", snapperClass);
247

  
248
		ISnapper snapper;
249
		try {
250
			snapper = (ISnapper)extension.create();
251
			snappers.add(snapper);
252
            String nameClass=snapper.getClass().getName();
253
	        nameClass=nameClass.substring(nameClass.lastIndexOf('.'));
254
	        boolean select = prefSnappers.getBoolean("snapper_activated" + nameClass, false);
255
	        int priority = prefs.getInt("snapper_priority" + nameClass,3);
256
	        snapper.setPriority(priority);
257
	        if (select){
258
	          	snapper.setEnabled(select);   
259
	        }           
260
			
261
		} catch (Exception e) {
262
			logger.error("It is not possible to create the snapper");
263
		}       
264
	}
265

  
266
	/* (non-Javadoc)
267
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getSnapperAt(int)
268
	 */
269
	public ISnapper getSnapperAt(int index) {
270
		return snappers.get(index);
271
	}
272

  
273
	/* (non-Javadoc)
274
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getSnapperCount()
275
	 */
276
	public int getSnapperCount() {
277
		return snappers.size();
278
	}
279

  
280
	/* (non-Javadoc)
281
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#disableSnapping()
282
	 */
283
	public void disableSnapping() {
284
		snappers.clear();		
285
	}
286

  
287
	/* (non-Javadoc)
288
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#enableSnapping()
289
	 */
290
	public void enableSnapping() {
291
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
292
		ExtensionPoint ep = extensionPoints.get(SNAPPING_EXTENSION_POINT);
293
		Iterator iterator = ep.iterator();
294

  
295
		while (iterator.hasNext()) {
296
			try {
297
				Extension obj= (Extension)iterator.next();
298
				ISnapper snapper = (ISnapper) ep.create(obj.getName());
299
				snappers.add(snapper);
300
			} catch (Exception e) {
301
				logger.error("Creating a snapper", e);
302
			}
303
		}
304

  
305
		for (int n = 0; n < getSnapperCount(); n++) {
306
			ISnapper snp = getSnapperAt(n);
307
			String nameClass = snp.getClass().getName();
308
			nameClass = nameClass.substring(nameClass.lastIndexOf('.'));
309
			boolean select = prefs.getBoolean("snapper_activated" + nameClass, false);
310
			if (select) {
311
				snp.setEnabled(select);				
312
			}
313
			int priority = prefs.getInt("snapper_priority" + nameClass, 3);
314
			snp.setPriority(priority);
315
		}
316

  
317
	}
318

  
319
	/* (non-Javadoc)
320
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getEditionPreferences()
321
	 */
322
	public Preferences getEditionPreferences() {
323
		return prefs;
324
	}
325

  
326
	public MapControl createJMapControlPanel() throws MapControlCreationException {
327
		MapControl mapControl = new MapControl();
328
		mapControl.setMapControlDrawer(this.createDefaultMapControlDrawer());
329
		return mapControl;
330
	}
331

  
332
    public LayersDynObjectSetComponent createLayersDynObjectSetComponent(
333
        Map<String, DynObjectSet> layerName2InfoByPoint) {
334
        return createLayersDynObjectSetComponent(layerName2InfoByPoint, false);
335
    }
336

  
337
    public LayersDynObjectSetComponent createLayersDynObjectSetComponent(
338
        Map<String, DynObjectSet> layerName2InfoByPoint, boolean writable) {
339
        return new DefaultLayersDynObjectSetComponent(layerName2InfoByPoint,
340
            writable);
341
    }
342
}
0 343

  
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlCreationException.java
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

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.mapcontrol;
29
/**
30
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
31
 */
32
public class MapControlCreationException extends MapControlException {
33
	private static final long serialVersionUID = -7886043430856453161L;
34
	private static final String KEY = "mapcontrol_creatioon_exception";
35
	private static final String MESSAGE = "Error creating a MapControl";
36
    
37
	public MapControlCreationException(Throwable cause) {
38
		super(MESSAGE, cause, KEY, serialVersionUID);
39
	}
40

  
41
}
42

  
0 43

  
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlLocator.java
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

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.mapcontrol;
29

  
30
import org.gvsig.tools.locator.AbstractLocator;
31
import org.gvsig.tools.locator.Locator;
32
import org.gvsig.tools.locator.LocatorException;
33

  
34
/**
35
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
36
 */
37
public class MapControlLocator extends AbstractLocator {
38
	private static final String LOCATOR_NAME = "MapContolLocator";
39
	
40
	/**
41
	 * MapControlManager name used by the locator to access the instance
42
	 */
43
	public static final String MAPCONTROL_MANAGER_NAME = "MapControlManager";
44
	private static final String MAPCONTROL_MANAGER_DESCRIPTION = "MapControlManager of gvSIG";
45

  
46
	/**
47
	 * Unique instance.
48
	 */
49
	private static final MapControlLocator instance = new MapControlLocator();
50
	
51
	/* (non-Javadoc)
52
	 * @see org.gvsig.tools.locator.Locator#getLocatorName()
53
	 */
54
	public String getLocatorName() {
55
		return LOCATOR_NAME;
56
	}
57
	
58
	/**
59
	 * Return a reference to {@link MapControlManager}.
60
	 *
61
	 * @return a reference to MapControlManager
62
	 * @throws LocatorException
63
	 *             if there is no access to the class or the class cannot be
64
	 *             instantiated
65
	 * @see Locator#get(String)
66
	 */
67
	public static MapControlManager getMapControlManager() throws LocatorException {
68
		return (MapControlManager) getInstance().get(MAPCONTROL_MANAGER_NAME);
69
	}
70
	
71
	/**
72
	 * Return the singleton instance.
73
	 *
74
	 * @return the singleton instance
75
	 */
76
	public static MapControlLocator getInstance() {
77
		return instance;
78
	}
79
	
80
	/**
81
	 * Registers the Class implementing the {@link MapControlManager} interface.
82
	 *
83
	 * @param clazz
84
	 *            implementing the MapControlManager interface
85
	 */
86
	public static void registerMapControlManager(Class clazz) {
87
		getInstance().register(MAPCONTROL_MANAGER_NAME, 
88
				MAPCONTROL_MANAGER_DESCRIPTION,
89
				clazz);
90
	}
91
}
92

  
93

  
0 94

  
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlDrawer.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.mapcontrol;
29

  
30
import java.awt.Color;
31
import java.awt.Composite;
32
import java.awt.Image;
33
import java.awt.RenderingHints;
34
import java.awt.Stroke;
35
import java.awt.geom.AffineTransform;
36
import java.awt.geom.Point2D;
37

  
38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.geom.handler.Handler;
40
import org.gvsig.fmap.mapcontext.ViewPort;
41
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
42

  
43
/**
44
 * <p>
45
 * Represents a class that can write objects in a map like a raster image, a
46
 * {@link Geometry} or other graphical objects. This class doesn't depend of the
47
 * dimension of the map (2D or 3D).
48
 * </p>
49
 * <p>
50
 * The Map Control has to have an instance of this class that can be accessed
51
 * using the {@link MapControl#getMapControlDrawer()} method. When a Map Control
52
 * is created some tools are added to this component using the
53
 * {@link MapControl#addBehavior(String, org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior)}
54
 * method. Some of these tools need to draw some objects in the map and they use
55
 * the MapControlDrawer class to do that.
56
 * </p>
57
 * 
58
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
59
 */
60
public interface MapControlDrawer extends PrimitivesDrawer {
61

  
62
    /**
63
     * The <code>ViewPort</code> is used to transform the map
64
     * coordinates in the screen coordinates.
65
     * 
66
     * @param viewPort
67
     *            The <code>ViewPort</code>
68
     */
69
    public void setViewPort(ViewPort viewPort);
70

  
71
    /**
72
     * It draws a <code>Geometry</code> on the map using the color
73
     * specified using the {@link #setColor(Color)} method.
74
     * 
75
     * @param geometry
76
     *            The <code>Geometry</code> to draw.
77
     */
78
    public void draw(Geometry geometry);
79

  
80
    /**
81
     * It draws a <code>Geometry</code> on the map using a concrete
82
     * symbol.
83
     * 
84
     * @param geometry
85
     *            The <code>Geometry</code> to draw.
86
     * @param symbol
87
     *            The symbol used to draw the geometry.
88
     */
89
    public void draw(Geometry geometry, ISymbol symbol);
90

  
91
    /**
92
     * It draws the <code>Handler</code>'s that compose a geometry
93
     * on the map.
94
     * 
95
     * @param handlers
96
     *            An array of <code>Handler</code>'s.
97
     * @param at
98
     *            A transformation that has to be applied to the
99
     *            <code>Handler</code>'s.
100
     * @param symbol
101
     *            The symbol used to draw the handlers.
102
     */
103
    public void drawHandlers(Handler[] handlers, AffineTransform at,
104
        ISymbol symbol);
105

  
106
    /**
107
     * It draws a line using a concrete symbol.
108
     * 
109
     * @param firstPoint
110
     *            The first point of the line.
111
     * @param endPoint
112
     *            The end point of the line.
113
     * @param symbol
114
     *            The symbol used to draw the line.
115
     */
116
    public void drawLine(Point2D firstPoint, Point2D endPoint, ISymbol symbol);
117

  
118
    /**
119
     * It draws an image on a map in a concrete position.
120
     * 
121
     * @param img
122
     *            The image to draw.
123
     * @param x
124
     *            The X coordinate,
125
     * @param y
126
     *            The Y coordinate.
127
     */
128
    public void drawImage(Image img, int x, int y);
129

  
130
    /**
131
     * It draws image, applying a transform from image space
132
     * into user space before drawing.
133
     * 
134
     * @param img
135
     *            The image to draw.
136
     * @param xform
137
     *            The transform to apply.
138
     */
139
    public void drawImage(Image img, AffineTransform xform);
140

  
141
    /**
142
     * It draws a <code>Handler</code> on the map.
143
     * 
144
     * @param handler
145
     *            The <code>Handler</code> to draw.
146
     * @param at
147
     *            A transformation that has to be applied to the
148
     *            <code>Handler</code>.
149
     */
150
    public void drawHandler(Handler handler, AffineTransform at);
151

  
152
    /**
153
     * @param at
154
     */
155
    public void transform(AffineTransform at);
156

  
157
    /**
158
     * @param instance
159
     */
160
    public void setComposite(Composite instance);
161
    
162
    /**
163
     * Replaces the values of all preferences for the rendering algorithms with the specified hints. The existing 
164
     * values for all rendering hints are discarded and the new set of known hints and values are initialized 
165
     * from the specified Map object. Hint categories include controls for rendering quality and overall time/
166
     * quality trade-off in the rendering process. Refer to the RenderingHints class for definitions of some 
167
     * common keys and values.
168
     * @param hints  the rendering hints to be set
169
     */
170
    public void setRenderingHints(RenderingHints hints);
171
    
172
    /**
173
     * Sets the Stroke for the Graphics2D context.
174
     * @param stroke the Stroke object to be used to stroke a Shape during the rendering 
175
     */
176
    public void setStroke(Stroke stroke);
177
    
178
    /**
179
     * Cleans the graphics using the image of the MapControl
180
     * @param mapCtrl
181
     */
182
    public void cleanCanvas(MapControl mapCtrl);
183

  
184
}
0 185

  
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlLibrary.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {DiSiD Technologies}  {Create Library class to initialize the MapControls library}
26
 */
27
package org.gvsig.fmap.mapcontrol;
28

  
29
import java.util.Locale;
30

  
31
import org.gvsig.fmap.IconThemeHelper;
32
import org.gvsig.fmap.mapcontext.MapContextLibrary;
33
import org.gvsig.fmap.mapcontrol.swing.dynfield.factory.GeometryDynFieldComponentFactory;
34
import org.gvsig.i18n.Messages;
35
import org.gvsig.tools.library.AbstractLibrary;
36
import org.gvsig.tools.library.LibraryException;
37
import org.gvsig.tools.service.spi.ServiceManager;
38
import org.gvsig.tools.swing.spi.ToolsSwingServiceLocator;
39

  
40
/**
41
 * Initialization of the MapControls library.
42
 * 
43
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
44
 */
45
public class MapControlLibrary extends AbstractLibrary {
46

  
47
    @Override
48
    public void doRegistration() {
49
        registerAsAPI(MapControlLibrary.class);
50
        require(MapContextLibrary.class);
51
    }
52

  
53
	@Override
54
	protected void doInitialize() throws LibraryException {
55
		if (!Messages.hasLocales()) {
56
			Messages.addLocale(Locale.getDefault());
57
		}
58
		Messages.addResourceFamily(
59
				"org.gvsig.fmap.mapcontrol.i18n.text",
60
				MapControlLibrary.class.getClassLoader(),
61
				MapControlLibrary.class.getClass().getName());
62
	}
63
	
64
	@Override
65
	protected void doPostInitialize() throws LibraryException {
66
	   	IconThemeHelper.registerIcon("cursor", "cursor-crux", this);
67
	   	IconThemeHelper.registerIcon("cursor", "cursor-info-by-point",this);
68
	   	IconThemeHelper.registerIcon("cursor", "cursor-pan", this);
69
	   	IconThemeHelper.registerIcon("cursor", "cursor-query-area", this);
70
	   	IconThemeHelper.registerIcon("cursor", "cursor-select-by-point", this);
71
	   	IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", this);
72
	   	IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", this);
73
	   	IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", this);
74

  
75
	   	IconThemeHelper.registerIcon("layer", "layer-icon", this);
76
	   	IconThemeHelper.registerIcon("layer", "layer-icon-group", this);
77
	   	IconThemeHelper.registerIcon("layer", "layer-icon-vectorial", this);
78
	   	
79
	   	// =================================================
80
	   	// Add factory for creation of
81
	   	// swing component representing geometry
82
        ServiceManager dsManager = ToolsSwingServiceLocator.getServiceManager();
83
        dsManager.addServiceFactory(new GeometryDynFieldComponentFactory());
84
	}
85
}
tags/v2_0_0_Build_2061/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynfield/factory/GeometryDynFieldComponentFactory.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2012 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontrol.swing.dynfield.factory;
24

  
25
import org.gvsig.fmap.geom.DataTypes;
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.fmap.mapcontrol.swing.dynfield.GeometryDynFieldComponent;
28
import org.gvsig.tools.dynobject.DynField;
29
import org.gvsig.tools.service.ServiceException;
30
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
31
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
32
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponentFactory;
33

  
34

  
35
/**
36
 * This factory will create a swing component to represent
37
 * a {@link Geometry} object (for example when opening
38
 * a info by point dialog)
39
 * 
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff