Revision 29556

View differences:

branches/v2_0_0_prep/templates/maven-archetype-library/src/main/resources/META-INF/maven/archetype.xml
1 1
<?xml version="1.0" encoding="UTF-8"?><archetype>
2 2
  <id>org.gvsig.library</id>
3 3
  <sources>
4
    <source>src/main/java/DefaultExampleManager.java</source>
4
    <source>src/main/java/impl/DefaultExampleManager.java</source>
5
    <source>src/main/java/impl/package.html</source>
6
    <source>src/main/java/impl/ExampleImplLibrary.java</source>
5 7
    <source>src/main/java/package.html</source>
6
    <source>src/main/java/ExampleImplLibrary.java</source>
7
    <source>src/main/java/org/gvsig/example/ExampleLibrary.java</source>
8
    <source>src/main/java/org/gvsig/example/ExampleLocator.java</source>
9
    <source>src/main/java/org/gvsig/example/ExampleException.java</source>
10
    <source>src/main/java/org/gvsig/example/ExampleManager.java</source>
11
    <source>src/main/java/org/gvsig/example/package.html</source>
8
    <source>src/main/java/ExampleLibrary.java</source>
9
    <source>src/main/java/ExampleLocator.java</source>
10
    <source>src/main/java/ExampleException.java</source>
11
    <source>src/main/java/ExampleManager.java</source>
12
    <source>src/main/java/package.html</source>
12 13
  </sources>
13 14
  <testSources>
14
    <source>src/test/java/DefaultExampleManagerTest.java</source>
15
    <source>src/test/java/ExampleImplLibraryTest.java</source>
16
    <source>src/test/java/org/gvsig/example/ExampleLibraryTest.java</source>
15
    <source>src/test/java/impl/DefaultExampleManagerTest.java</source>
16
    <source>src/test/java/impl/ExampleImplLibraryTest.java</source>
17 17
    <source>src/test/java/README.txt</source>
18 18
  </testSources>
19 19
  <resources>
20 20
    <resource>src/main/javadoc/overview.html</resource>
21
    <resource>src/main/resources/org/gvsig/example/i18n/text.properties</resource>
22
    <resource>src/main/resources/org/gvsig/example/i18n/text_en.properties</resource>
21
    <resource>src/main/resources/i18n/text.properties</resource>
22
    <resource>src/main/resources/i18n/text_en.properties</resource>
23 23
    <resource>src/main/resources/README.txt</resource>
24 24
    <resource>README.txt</resource>
25 25
  </resources>
branches/v2_0_0_prep/templates/maven-archetype-library/src/main/resources/archetype-resources/src/test/resources/log4j.xml
22 22
	You can put full classes names or packages instead, to configure
23 23
	logging for all the classes and subpackages of the package.
24 24
	-->
25
	<category name="${package}.DefaultExampleManager">
25
	<category name="${package}.impl.DefaultExampleManager">
26 26
		<priority value="DEBUG" />
27 27
	</category>
28 28

  
branches/v2_0_0_prep/templates/maven-archetype-library/src/main/resources/archetype-resources/src/test/java/impl/DefaultExampleLibraryTest.java
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
/* gvSIG. Geographic Information System of the Valencian Government
5
*
6
* Copyright (C) 2007-2008 Infrastructures and Transports Department
7
* of the Valencian Gobernment (CIT)
8
* 
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version.
13
* 
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
* GNU General Public License for more details.
18
* 
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
22
* MA  02110-1301, USA.
23
* 
24
*/
25

  
26
/*
27
* AUTHORS (In addition to CIT):
28
* 2009 {{Company}}  {{Task}}
29
*/
30
package ${package}.impl;
31

  
32
import ${package}.ExampleLocator;
33

  
34
import ${package}.ExampleManager;
35

  
36
import junit.framework.TestCase;
37

  
38
/**
39
 * {@link DefaultExampleLibrary} unit tests.
40
 * 
41
 * @author <a href="mailto:devel@domain">Name Surname</a>
42
 */
43
public class DefaultExampleLibraryTest extends TestCase {
44
	
45
	private DefaultExampleLibrary library;
46

  
47
	protected void setUp() throws Exception {
48
		super.setUp();
49
		library = new DefaultExampleLibrary();
50
	}
51

  
52
	/**
53
	 * Test method for {@link ${package}.DefaultExampleLibrary${symbol_pound}initialize()}.
54
	 */
55
	public void testInitialize() {
56
		library.initialize();
57
		ExampleManager manager = ExampleLocator.getExampleManager();
58
		assertTrue(manager instanceof DefaultExampleManager);
59
	}
60
}
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/distribution/distribution.xml
24 24
			<outputDirectory>${extension-distribution}
25 25
			</outputDirectory>
26 26
		</fileSet>
27
		<fileSet>
28
			<directory>src/main/resources/locale</directory>
29
			<outputDirectory>${extension-distribution}
30
			</outputDirectory>
31
		</fileSet>
27 32
	</fileSets>
28 33
	<files>
29 34
		<file>
30
			<source>build.number</source>
35
			<source>src/main/resources/build.number</source>
31 36
			<outputDirectory>${extension-distribution}
32 37
			</outputDirectory>
33 38
		</file>
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/test/resources/README.txt
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4 1
Put into this folder the resources needed by your test classes.
5 2

  
6 3
This folder is added to the Tests classpath, so you can load any resources 
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/test/java/README.txt
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4 1
For each class you are going to test, create one Test class with the same
5 2
name as the class to test, ending with Test.
6 3

  
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/resources/locale/text.properties
1
# Resource bundle texts for the Spanish language locale (es)
2
Centrar_la_Vista_sobre_un_punto=Centrar la vista sobre un punto
3
debe_seleccionar_las_capas_de_las_que_quiera_obtener_informacion=Debe seleccionar las capas de las que quiera obtener informaci\u00f3n.
4
formato_de_numero_incorrecto=Formato de n\u00famero incorrecto.
5
no_hay_ninguna_capa_seleccionada=No hay ninguna capa seleccionada
6
Vista=Vista
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/resources/locale/text_en.properties
1
# Resource bundle texts for the English language locale (en)
2
Centrar_la_Vista_sobre_un_punto=Center view to point
3
debe_seleccionar_las_capas_de_las_que_quiera_obtener_informacion=Select the layers you want to get information from
4
formato_de_numero_incorrecto=Incorrect number format
5
no_hay_ninguna_capa_seleccionada=No layer has been selected
6
Vista=View
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/java/gui/package.html
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
<?xml version="1.0" encoding="UTF-8" ?>
5
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
<html xmlns="http://www.w3.org/1999/xhtml">
7
<head>
8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
9
<title>org.gvsig.template.extension package documentation</title>
10
</head>
11
<body>
12

  
13
	<p>TODO: Example extension gui package description.</p>
14
	
15
	<p>See the <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html#packagecomment">Javadoc Tool documentation about the package file</a></p>
16

  
17
</body>
18
</html>
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/java/gui/InputCoordinatesPanel.java
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
/* gvSIG. Geographic Information System of the Valencian Government
5
 *
6
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
7
 * of the Valencian Gobernment (CIT)
8
 * 
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 * 
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 * 
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
22
 * MA  02110-1301, USA.
23
 * 
24
 */
25

  
26
/*
27
 * AUTHORS (In addition to CIT):
28
 * 2009 {{Company}}  {{Task}}
29
 */
30
package ${package}.gui;
31

  
32
import java.awt.Color;
33
import java.awt.Component;
34
import java.awt.event.ActionEvent;
35
import java.awt.event.ActionListener;
36
import java.awt.event.MouseEvent;
37
import java.awt.geom.Point2D;
38
import java.util.prefs.Preferences;
39

  
40
import javax.swing.JDialog;
41
import javax.swing.JLabel;
42
import javax.swing.JOptionPane;
43
import javax.swing.JPanel;
44
import javax.swing.JTextField;
45

  
46
import org.cresques.cts.IProjection;
47
import org.gvsig.fmap.geom.Geometry;
48
import org.gvsig.fmap.geom.GeometryLocator;
49
import org.gvsig.fmap.geom.GeometryManager;
50
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
51
import org.gvsig.fmap.geom.Geometry.TYPES;
52
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
53
import org.gvsig.fmap.geom.exception.CreateGeometryException;
54
import org.gvsig.fmap.geom.primitive.Envelope;
55
import org.gvsig.fmap.geom.primitive.Point;
56
import org.gvsig.fmap.mapcontext.MapContext;
57
import org.gvsig.fmap.mapcontext.layers.GraphicLayer;
58
import org.gvsig.fmap.mapcontext.rendering.legend.FGraphic;
59
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
60
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
61
import org.gvsig.fmap.mapcontrol.MapControl;
62
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
63
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
64
import org.gvsig.gui.beans.AcceptCancelPanel;
65
import org.gvsig.tools.locator.LocatorException;
66
import ${package}.ExampleExtension;
67
import org.slf4j.Logger;
68
import org.slf4j.LoggerFactory;
69

  
70
import com.iver.andami.PluginServices;
71
import com.iver.andami.messages.NotificationManager;
72
import com.iver.andami.ui.mdiManager.IWindow;
73
import com.iver.andami.ui.mdiManager.WindowInfo;
74
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
75
import com.iver.cit.gvsig.project.documents.view.toolListeners.InfoListener;
76

  
77
/**
78
 * A Panel where the user can input the coordinates of the point of reference
79
 * for center the View.
80
 * 
81
 * @author <a href="mailto:devel@domain">Name Surname</a>
82
 */
83
public class InputCoordinatesPanel extends JPanel implements IWindow {
84

  
85
	/**
86
	 * TODO: generate a new serialVersionUID for your exception.
87
	 */
88
	private static final long serialVersionUID = 3748901337255426163L;
89

  
90
	/*
91
	 * Always declare your logger as private static final in each of your
92
	 * classes which do logging
93
	 */
94
	private static final Logger logger = LoggerFactory
95
			.getLogger(InputCoordinatesPanel.class);
96

  
97
	private Point2D center;
98
	private Color color = Color.red;
99
	private ColorChooserPanel colorPanel;
100
	private String firstCoordinate;
101
	private JLabel labelX = null;
102
	private JLabel labelY = null;
103
	private GraphicLayer lyr;
104
	private MapControl mapControl;
105
	private AcceptCancelPanel okCancelPanel = null;
106
	private String secondCoordinate;
107
	private JTextField textX = null;
108
	private JTextField textY = null;
109
	private WindowInfo viewInfo = null;
110

  
111
	private GeometryManager geometryManager = GeometryLocator
112
			.getGeometryManager();
113

  
114
	/**
115
	 * This is the default constructor
116
	 */
117
	public InputCoordinatesPanel(MapContext mapContext) {
118
		this.mapControl = new MapControl();
119
		mapControl.setMapContext(mapContext);
120
		lyr = mapControl.getMapContext().getGraphicsLayer();
121
		initializeCoordinates();
122
		initialize();
123
	}
124

  
125
	/**
126
	 * Returns the current draw color.
127
	 * 
128
	 * @return the draw color
129
	 */
130
	public Color getColor() {
131
		return color;
132
	}
133

  
134
	/**
135
	 * Sets the draw color.
136
	 * 
137
	 * @param color
138
	 *            to draw
139
	 */
140
	public void setColor(Color color) {
141
		this.color = color;
142
	}
143

  
144
	public WindowInfo getWindowInfo() {
145
		if (viewInfo == null) {
146
			viewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
147
			viewInfo.setTitle(PluginServices.getText(this,
148
					"Centrar_la_Vista_sobre_un_punto"));
149
			viewInfo.setWidth(this.getWidth() + 8);
150
			viewInfo.setHeight(this.getHeight());
151
		}
152
		return viewInfo;
153
	}
154

  
155
	public Object getWindowProfile() {
156
		return WindowInfo.DIALOG_PROFILE;
157
	}
158

  
159
	/**
160
	 * Close the window.
161
	 */
162
	private void closeThis() {
163
		PluginServices.getMDIManager().closeWindow(this);
164
	}
165

  
166
	/**
167
	 * Initializes the color chooser panel.
168
	 */
169
	private JPanel getColorPanel() {
170
		if (colorPanel == null) {
171
			colorPanel = new ColorChooserPanel();
172
			colorPanel.setAlpha(250);
173
			colorPanel.setColor(getColor());
174
			colorPanel.setBounds(new java.awt.Rectangle(40, 59, 123, 24));
175
		}
176
		return colorPanel;
177
	}
178

  
179
	/**
180
	 * Initializes the ok/cancel button panel.
181
	 */
182
	private AcceptCancelPanel getOkCancelPanel() {
183
		if (okCancelPanel == null) {
184
			ActionListener okAction, cancelAction;
185
			okAction = new ActionListener() {
186
				public void actionPerformed(ActionEvent e) {
187
					closePanelAndDrawPoint();
188
				}
189
			};
190
			cancelAction = new ActionListener() {
191
				public void actionPerformed(ActionEvent e) {
192
					closeThis();
193
				}
194
			};
195
			okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
196
			okCancelPanel.setBounds(new java.awt.Rectangle(40, 88, 260, 30));
197
		}
198
		return okCancelPanel;
199
	}
200

  
201
	/**
202
	 * Initializes the text field for the Point X value.
203
	 */
204
	private JTextField getTextX() {
205
		if (textX == null) {
206
			textX = new JTextField();
207
			textX.setBounds(40, 10, 260, 20);
208
			textX.addActionListener(new java.awt.event.ActionListener() {
209
				public void actionPerformed(java.awt.event.ActionEvent e) {
210
					textX.transferFocus();
211
				}
212
			});
213
		}
214
		return textX;
215
	}
216

  
217
	/**
218
	 * Initializes the text field for the Point Y value.
219
	 */
220
	private JTextField getTextY() {
221
		if (textY == null) {
222
			textY = new JTextField();
223
			textY.setBounds(40, 35, 260, 20);
224
			textY.addActionListener(new java.awt.event.ActionListener() {
225
				public void actionPerformed(java.awt.event.ActionEvent e) {
226
					textY.transferFocus();
227
				}
228
			});
229
		}
230
		return textY;
231
	}
232

  
233
	/**
234
	 * Initializes the coordinates panel.
235
	 */
236
	private void initialize() {
237
		labelY = new JLabel();
238
		labelY.setBounds(10, 35, 28, 20);
239
		labelY.setText(secondCoordinate + ":");
240
		labelX = new JLabel();
241
		labelX.setBounds(10, 10, 28, 20);
242
		labelX.setText(firstCoordinate + ":");
243
		this.setLayout(null);
244
		this.setSize(307, 100);
245
		this.add(labelX, null);
246
		this.add(getTextX(), null);
247
		this.add(labelY, null);
248
		this.add(getTextY(), null);
249
		this.add(getColorPanel());
250
		this.add(getOkCancelPanel(), null);
251
	}
252

  
253
	/**
254
	 * Sets the proper text for the first and second coordinate labels,
255
	 * depending on the kind of selected projection.
256
	 */
257
	private void initializeCoordinates() {
258
		IProjection proj = mapControl.getProjection();
259
		if (proj.isProjected()) {
260
			firstCoordinate = "X";
261
			secondCoordinate = "Y";
262
		} else {
263
			firstCoordinate = "Lon";
264
			secondCoordinate = "Lat";
265
		}
266
	}
267

  
268
	/**
269
	 * Opens the infoByPoint dialog for the selected point.
270
	 */
271
	private void openInfo() {
272
		InfoListener infoListener = new InfoListener(mapControl);
273
		MouseEvent e = new MouseEvent(
274
				(Component) (((ExampleExtension) PluginServices
275
						.getExtension(ExampleExtension.class)).getView()),
276
				MouseEvent.BUTTON1, MouseEvent.ACTION_EVENT_MASK,
277
				MouseEvent.MOUSE_CLICKED, 500, 400, 1, true);
278
		Point2D centerPixels = mapControl.getViewPort().fromMapPoint(
279
				center.getX(), center.getY());
280
		PointEvent pe = new PointEvent(centerPixels, e);
281
		try {
282
			infoListener.point(pe);
283
		} catch (BehaviorException ex) {
284
			NotificationManager.addError(ex.getLocalizedMessage(), ex);
285
		}
286
		if (mapControl.getMapContext().getLayers().getActives().length == 0) {
287
			JOptionPane
288
					.showMessageDialog(
289
							(Component) PluginServices.getMainFrame(),
290
							PluginServices.getText(this,
291
									"no_hay_ninguna_capa_seleccionada")
292
									+ " \n"
293
									+ PluginServices
294
											.getText(this,
295
													"debe_seleccionar_las_capas_de_las_que_quiera_obtener_informacion"));
296
		}
297
	}
298

  
299
	/**
300
	 * Move the view's extent so that the specified point gets centered.
301
	 * 
302
	 * @throws CreateEnvelopeException
303
	 * @throws LocatorException
304
	 */
305
	private void zoomToCoordinates() throws LocatorException,
306
			CreateEnvelopeException {
307
		Envelope oldExtent = mapControl.getViewPort().getAdjustedExtent();
308
		double oldCenterX = oldExtent.getCenter(0);
309
		double oldCenterY = oldExtent.getCenter(1);
310
		double centerX = (new Double((String) textX.getText())).doubleValue();
311
		double centerY = (new Double((String) textY.getText())).doubleValue();
312
		center = new Point2D.Double(centerX, centerY);
313
		double movX = centerX - oldCenterX;
314
		double movY = centerY - oldCenterY;
315
		double upperLeftCornerX = oldExtent.getMinimum(0) + movX;
316
		double upperLeftCornerY = oldExtent.getMinimum(1) + movY;
317
		double maxX = oldExtent.getMaximum(0);
318
		double maxY = oldExtent.getMaximum(1);
319
		Envelope extent = geometryManager.createEnvelope(upperLeftCornerX,
320
				upperLeftCornerY, maxX, maxY, SUBTYPES.GEOM2D);
321
		mapControl.getViewPort().setEnvelope(extent);
322
	}
323

  
324
	private void closePanelAndDrawPoint() {
325
		try {
326
			zoomToCoordinates();
327
			// close the input coordinates panel
328
			if (PluginServices.getMainFrame() == null) {
329
				((JDialog) (getParent().getParent().getParent().getParent()))
330
						.dispose();
331
			} else {
332
				PluginServices.getMDIManager().closeWindow(
333
						InputCoordinatesPanel.this);
334
			}
335

  
336
			logger.debug("Mostrando informaci?n sobre el punto ({}, {})",
337
					center.getX(), center.getY());
338

  
339
			Preferences prefs = Preferences.userRoot().node(
340
					"${package}");
341
			if (prefs.get("showInfo", "True").equalsIgnoreCase("True")) {
342
				openInfo();
343
			}
344
			drawPoint(((ColorChooserPanel) getColorPanel()).getColor());
345
		} catch (Exception ex) {
346
			NotificationManager.addError(ex.getLocalizedMessage(), ex);
347
			return;
348
		}
349
	}
350

  
351
	/**
352
	 * Draws the selected point on the view.
353
	 */
354
	private void drawPoint(Color color) throws CreateGeometryException {
355
		setColor(color);
356
		lyr.clearAllGraphics();
357
		ISymbol theSymbol = SymbologyFactory.createDefaultSymbolByShapeType(
358
				Geometry.TYPES.POINT, color);
359
		int idSymbol = lyr.addSymbol(theSymbol);
360
		Point geom = (Point) geometryManager.create(TYPES.POINT,
361
				SUBTYPES.GEOM2D);
362
		geom.setX(center.getX());
363
		geom.setY(center.getY());
364
		FGraphic theGraphic = new FGraphic(geom, idSymbol);
365
		lyr.addGraphic(theGraphic);
366
		mapControl.drawGraphics();
367
	}
368
}
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/java/org/gvsig/template/extension/ExampleExtension.java
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
/* gvSIG. Geographic Information System of the Valencian Government
5
 *
6
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
7
 * of the Valencian Gobernment (CIT)
8
 * 
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 * 
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 * 
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
22
 * MA  02110-1301, USA.
23
 * 
24
 */
25

  
26
/*
27
 * AUTHORS (In addition to CIT):
28
 * 2009 {{Company}}  {{Task}}
29
 */
30
package ${package};
31

  
32
import java.net.URL;
33
import java.util.Locale;
34

  
35
import org.gvsig.fmap.mapcontext.MapContext;
36
import org.gvsig.fmap.mapcontext.layers.FLayers;
37
import org.gvsig.i18n.Messages;
38
import org.gvsig.template.extension.gui.InputCoordinatesPanel;
39

  
40
import com.iver.andami.PluginServices;
41
import com.iver.andami.plugins.Extension;
42
import com.iver.cit.gvsig.About;
43
import com.iver.cit.gvsig.gui.panels.FPanelAbout;
44
import com.iver.cit.gvsig.project.documents.view.IProjectView;
45
import com.iver.cit.gvsig.project.documents.view.gui.View;
46
import com.iver.andami.ui.mdiManager.IWindow
47

  
48
/**
49
 * Example extension based on the CenterViewToPointExtension.
50
 * 
51
 * @author <a href="mailto:devel@domain">Name Surname</a>
52
 */
53
public class ExampleExtension extends Extension {
54
	private View view;
55

  
56
	public View getView() {
57
		return view;
58
	}
59

  
60
	public void initialize() {
61
		PluginServices.getIconTheme().registerDefault(
62
				"view-center-to-point",
63
				this.getClass().getClassLoader().getResource(
64
						"images/centerviewtopoint.png"));
65
	}
66

  
67
	public void postInitialize() {
68
		// TODO: change Messages to always have a default locale.
69
		if (!Messages.hasLocales()) {
70
			Messages.addLocale(Locale.ENGLISH);
71
		}
72

  
73
		/*
74
		 * Add the resource bundles of your library this way. The family
75
		 * "org.gvsig.template.extension.i18n.text" is constructed as the path
76
		 * to the resource bundle files as a package (look at the
77
		 * src/main/resources/org/gvsig/example/i18n folder) and the base name
78
		 * of those .properties files, usually "text", so you have in the
79
		 * previous folders the files:
80
		 * 
81
		 * - text.properties (this is the default one for Spanish language). -
82
		 * text_en.properties (translations for English language).
83
		 * 
84
		 * Translate your i18n texts at least to those two languages. You can
85
		 * translate to more languages by adding more text.properties files,
86
		 * following the naming scheme of the Java Locale.
87
		 */
88
		Messages.addResourceFamily(
89
				"${package}.i18n.text",
90
				ExampleExtension.class.getClassLoader(), 
91
				ExampleExtension.class.getClass().getName());
92

  
93
		// Register the about panel
94
		About about = (About) PluginServices.getExtension(About.class);
95
		FPanelAbout panelAbout = about.getAboutPanel();
96
		URL aboutURL = getClass().getResource("/about.htm");
97
		panelAbout.addAboutUrl("ExampleExtension", aboutURL);
98
	}
99

  
100
	public void execute(String actionCommand) {
101
		view = (View) PluginServices.getMDIManager().getActiveWindow();
102
		MapContext mapContext = view.getModel().getMapContext();
103
		InputCoordinatesPanel dataSelectionPanel = new InputCoordinatesPanel(
104
				mapContext);
105
		PluginServices.getMDIManager().addWindow(dataSelectionPanel);
106
	}
107

  
108
	public boolean isEnabled() {
109
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices
110
				.getMDIManager().getActiveWindow();
111
		if (f == null) {
112
			return false;
113
		}
114
		if (f.getClass() == View.class) {
115
			View vista = (View) f;
116
			IProjectView model = vista.getModel();
117
			MapContext mapa = model.getMapContext();
118
			FLayers layers = mapa.getLayers();
119
			for (int i = 0; i < layers.getLayersCount(); i++) {
120
				if (layers.getLayer(i).isAvailable())
121
					return true;
122
			}
123
		}
124
		return false;
125
	}
126

  
127
	public boolean isVisible() {
128
		IWindow f = PluginServices
129
				.getMDIManager().getActiveWindow();
130
		if (f == null) {
131
			return false;
132
		}
133
		if (f.getClass() == View.class) {
134
			View vista = (View) f;
135
			IProjectView model = vista.getModel();
136
			MapContext mapa = model.getMapContext();
137
			if (mapa.getLayers().getLayersCount() > 0) {
138
				return true;
139
			}
140
			return false;
141
		}
142
		return false;
143
	}
144
}
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/java/org/gvsig/template/extension/ExampleException.java
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
/* gvSIG. Geographic Information System of the Valencian Government
5
*
6
* Copyright (C) 2007-2008 Infrastructures and Transports Department
7
* of the Valencian Gobernment (CIT)
8
* 
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version.
13
* 
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
* GNU General Public License for more details.
18
* 
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
22
* MA  02110-1301, USA.
23
* 
24
*/
25

  
26
/*
27
* AUTHORS (In addition to CIT):
28
* 2009 {{Company}}  {{Task}}
29
*/
30
package ${package};
31

  
32
import org.gvsig.tools.exception.BaseException;
33
import org.gvsig.tools.exception.BaseRuntimeException;
34

  
35

  
36
/**
37
 * Parent Exception for the Library errors and exceptions.
38
 * 
39
 * Create new exceptions for your Library as childs of this Exception,
40
 * so your Library API throws this Exception instead of each
41
 * child one.
42
 * 
43
 * @author <a href="mailto:devel@domain">Name Surname</a>
44
 */
45
public class ExampleException extends BaseRuntimeException {
46
    
47
    /**
48
	 * TODO: generate a new serialVersionUID for your exception.
49
	 */
50
	private static final long serialVersionUID = -5202384647454194305L;
51

  
52
	/**
53
     * @see BaseException#BaseException(String, String, long)
54
     */
55
    public ExampleException(String message, String key, long code) {
56
        super(message, key, code);
57
    }
58

  
59
    /**
60
     * @see BaseException#BaseException(String, Throwable, String, long)
61
     */
62
    public ExampleException(String message, Throwable cause, String key,
63
            long code) {
64
        super(message, cause, key, code);
65
    }
66

  
67
}
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/java/org/gvsig/template/extension/package.html
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
<?xml version="1.0" encoding="UTF-8" ?>
5
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
<html xmlns="http://www.w3.org/1999/xhtml">
7
<head>
8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
9
<title>org.gvsig.template.extension package documentation</title>
10
</head>
11
<body>
12

  
13
	<p>TODO: Example extension description.</p>
14
	
15
	<p>See the <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html#packagecomment">Javadoc Tool documentation about the package file</a></p>
16

  
17
</body>
18
</html>
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/java/ExampleExtension.java
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
/* gvSIG. Geographic Information System of the Valencian Government
5
 *
6
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
7
 * of the Valencian Gobernment (CIT)
8
 * 
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 * 
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 * 
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
22
 * MA  02110-1301, USA.
23
 * 
24
 */
25

  
26
/*
27
 * AUTHORS (In addition to CIT):
28
 * 2009 {{Company}}  {{Task}}
29
 */
30
package ${package};
31

  
32
import java.net.URL;
33

  
34
import org.gvsig.fmap.mapcontext.MapContext;
35
import org.gvsig.fmap.mapcontext.layers.FLayers;
36
import ${package}.gui.InputCoordinatesPanel;
37

  
38
import com.iver.andami.PluginServices;
39
import com.iver.andami.plugins.Extension;
40
import com.iver.cit.gvsig.About;
41
import com.iver.cit.gvsig.gui.panels.FPanelAbout;
42
import com.iver.cit.gvsig.project.documents.view.IProjectView;
43
import com.iver.cit.gvsig.project.documents.view.gui.View;
44
import com.iver.andami.ui.mdiManager.IWindow;
45

  
46
/**
47
 * Example extension based on the CenterViewToPointExtension.
48
 * 
49
 * @author <a href="mailto:devel@domain">Name Surname</a>
50
 */
51
public class ExampleExtension extends Extension {
52
	private View view;
53

  
54
	public View getView() {
55
		return view;
56
	}
57

  
58
	public void initialize() {
59
		PluginServices.getIconTheme().registerDefault(
60
				"view-center-to-point",
61
				this.getClass().getClassLoader().getResource(
62
						"images/centerviewtopoint.png"));
63
	}
64

  
65
	public void postInitialize() {
66
		// Register the about panel
67
		About about = (About) PluginServices.getExtension(About.class);
68
		FPanelAbout panelAbout = about.getAboutPanel();
69
		URL aboutURL = getClass().getResource("/about.htm");
70
		panelAbout.addAboutUrl("ExampleExtension", aboutURL);
71
	}
72

  
73
	public void execute(String actionCommand) {
74
		view = (View) PluginServices.getMDIManager().getActiveWindow();
75
		MapContext mapContext = view.getModel().getMapContext();
76
		InputCoordinatesPanel dataSelectionPanel = new InputCoordinatesPanel(
77
				mapContext);
78
		PluginServices.getMDIManager().addWindow(dataSelectionPanel);
79
	}
80

  
81
	public boolean isEnabled() {
82
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices
83
				.getMDIManager().getActiveWindow();
84
		if (f == null) {
85
			return false;
86
		}
87
		if (f.getClass() == View.class) {
88
			View vista = (View) f;
89
			IProjectView model = vista.getModel();
90
			MapContext mapa = model.getMapContext();
91
			FLayers layers = mapa.getLayers();
92
			for (int i = 0; i < layers.getLayersCount(); i++) {
93
				if (layers.getLayer(i).isAvailable())
94
					return true;
95
			}
96
		}
97
		return false;
98
	}
99

  
100
	public boolean isVisible() {
101
		IWindow f = PluginServices
102
				.getMDIManager().getActiveWindow();
103
		if (f == null) {
104
			return false;
105
		}
106
		if (f.getClass() == View.class) {
107
			View vista = (View) f;
108
			IProjectView model = vista.getModel();
109
			MapContext mapa = model.getMapContext();
110
			if (mapa.getLayers().getLayersCount() > 0) {
111
				return true;
112
			}
113
			return false;
114
		}
115
		return false;
116
	}
117
}
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/java/ExampleException.java
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
/* gvSIG. Geographic Information System of the Valencian Government
5
*
6
* Copyright (C) 2007-2008 Infrastructures and Transports Department
7
* of the Valencian Gobernment (CIT)
8
* 
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version.
13
* 
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
* GNU General Public License for more details.
18
* 
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
22
* MA  02110-1301, USA.
23
* 
24
*/
25

  
26
/*
27
* AUTHORS (In addition to CIT):
28
* 2009 {{Company}}  {{Task}}
29
*/
30
package ${package};
31

  
32
import org.gvsig.tools.exception.BaseException;
33
import org.gvsig.tools.exception.BaseRuntimeException;
34

  
35

  
36
/**
37
 * Parent Exception for the Library errors and exceptions.
38
 * 
39
 * Create new exceptions for your Library as childs of this Exception,
40
 * so your Library API throws this Exception instead of each
41
 * child one.
42
 * 
43
 * @author <a href="mailto:devel@domain">Name Surname</a>
44
 */
45
public class ExampleException extends BaseRuntimeException {
46
    
47
    /**
48
	 * TODO: generate a new serialVersionUID for your exception.
49
	 */
50
	private static final long serialVersionUID = -5202384647454194305L;
51

  
52
	/**
53
     * @see BaseException#BaseException(String, String, long)
54
     */
55
    public ExampleException(String message, String key, long code) {
56
        super(message, key, code);
57
    }
58

  
59
    /**
60
     * @see BaseException#BaseException(String, Throwable, String, long)
61
     */
62
    public ExampleException(String message, Throwable cause, String key,
63
            long code) {
64
        super(message, cause, key, code);
65
    }
66

  
67
}
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/src/main/java/package.html
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
<?xml version="1.0" encoding="UTF-8" ?>
5
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
<html xmlns="http://www.w3.org/1999/xhtml">
7
<head>
8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
9
<title>org.gvsig.template.extension package documentation</title>
10
</head>
11
<body>
12

  
13
	<p>TODO: Example extension description.</p>
14
	
15
	<p>See the <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html#packagecomment">Javadoc Tool documentation about the package file</a></p>
16

  
17
</body>
18
</html>
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/archetype-resources/pom.xml
18 18
		<url>http://subversion.gvsig.org/viewvc/?root=gvSIG</url>
19 19
		<tag>HEAD</tag>
20 20
	</scm>
21
	<parent>
22
		<groupId>org.gvsig</groupId>
23
		<artifactId>gvsig-extension-base-pom</artifactId>
24
		<version>2.0-SNAPSHOT</version>
25
	</parent>
21 26
#literal()
22 27
	<properties>
23 28
		<build-dir>${basedir}/../build</build-dir>
......
41 46
			</roles>
42 47
		</developer>
43 48
	</developers>
44
	<parent>
45
		<groupId>org.gvsig</groupId>
46
		<artifactId>gvsig-extension-base-pom</artifactId>
47
		<version>2.0-SNAPSHOT</version>
48
	</parent>
49 49
	<dependencies>
50 50
		<dependency>
51 51
			<groupId>org.gvsig</groupId>
......
71 71
					<exclude>config/**</exclude>
72 72
					<exclude>about/**</exclude>
73 73
					<exclude>images/**</exclude>
74
					<exclude>locale/**</exclude>
74 75
				</excludes>
75 76
			</resource>
76 77
		</resources>
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/META-INF/maven/archetype-metadata.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2
<archetype-descriptor name="org.gvsig.library">
2
<archetype-descriptor name="org.gvsig.extension">
3 3
	<fileSets>
4 4
		<fileSet filtered="true" packaged="true" encoding="ISO-8859-1">
5 5
			<directory>src/main/java</directory>
......
8 8
				<include>**/*.java</include>
9 9
			</includes>
10 10
		</fileSet>
11
		<fileSet filtered="true" packaged="true" encoding="ISO-8859-1">
11
		<fileSet filtered="false" packaged="false" encoding="ISO-8859-1">
12 12
			<directory>src/main/resources</directory>
13 13
			<includes>
14
				<include>**/*.properties</include>
15
				<exclude>**/*.txt</exclude>
14
				<include>images/**</include>
15
				<include>locale/**</include>
16
				<include>build.number</include>
17
				<exclude>**/README.txt</exclude>
16 18
			</includes>
17 19
		</fileSet>
20
		<fileSet filtered="true" packaged="false" encoding="ISO-8859-1">
21
			<directory>src/main/resources</directory>
22
			<includes>
23
				<include>about/**</include>
24
				<include>config/**</include>
25
			</includes>
26
		</fileSet>
18 27
		<fileSet filtered="true" encoding="ISO-8859-1">
19 28
			<directory>src/main/javadoc</directory>
20 29
			<includes>
......
41 50
				<include>**/README.txt</include>
42 51
			</includes>
43 52
		</fileSet>
53
		<fileSet filtered="true" encoding="ISO-8859-1">
54
			<directory>distribution</directory>
55
			<includes>
56
				<include>distribution.xml</include>
57
			</includes>
58
		</fileSet>
44 59
	</fileSets>
45 60
	<requiredProperties>
46 61
		<!-- 
branches/v2_0_0_prep/templates/maven-archetype-extension/src/main/resources/META-INF/maven/archetype.xml
1 1
<?xml version="1.0" encoding="UTF-8"?><archetype>
2
  <id>org.gvsig.library</id>
2
  <id>org.gvsig.extension</id>
3 3
  <sources>
4 4
    <source>src/main/java/package.html</source>
5
    <source>src/main/java/ExampleImplLibrary.java</source>
6
    <source>src/main/java/org/gvsig/example/ExampleLibrary.java</source>
7
    <source>src/main/java/org/gvsig/example/ExampleLocator.java</source>
8
    <source>src/main/java/org/gvsig/example/ExampleException.java</source>
9
    <source>src/main/java/org/gvsig/example/ExampleManager.java</source>
10
    <source>src/main/java/org/gvsig/example/package.html</source>
5
    <source>src/main/java/ExampleException.java</source>
6
    <source>src/main/java/ExampleExtension.java</source>
7
    <source>src/main/java/gui/package.html</source>
8
    <source>src/main/java/gui/InputCoordinatesPanel.java</source>
11 9
  </sources>
12 10
  <testSources>
13
    <source>src/test/java/DefaultExampleManagerTest.java</source>
14
    <source>src/test/java/ExampleImplLibraryTest.java</source>
15
    <source>src/test/java/org/gvsig/example/ExampleLibraryTest.java</source>
16 11
    <source>src/test/java/README.txt</source>
17 12
  </testSources>
18 13
  <resources>
19 14
    <resource>src/main/javadoc/overview.html</resource>
20
    <resource>src/main/resources/org/gvsig/example/i18n/text.properties</resource>
21
    <resource>src/main/resources/org/gvsig/example/i18n/text_en.properties</resource>
15
    <resource>src/main/resources/locale/text.properties</resource>
16
    <resource>src/main/resources/locale/text_en.properties</resource>
17
    <resource>src/main/resources/about/about.htm</resource>
18
    <resource>src/main/resources/config/config.xml</resource>
19
    <resource>src/main/resources/images/centerviewtopoint.png</resource>    
20
    <resource>src/main/resources/images/logo_horiz_bicolor_gva.png</resource>    
22 21
    <resource>src/main/resources/README.txt</resource>
22
    <resource>src/main/resources/build.number</resource>
23
    <resource>distribution/distribution.xml</resource>
23 24
    <resource>README.txt</resource>
24 25
  </resources>
25 26
  <testResources>

Also available in: Unified diff