Revision 22084

View differences:

trunk/extensions/extSymbology/src-test/org/gvsig/symbology/gui/layerproperties/LabelingPanelTestCase.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.symbology.gui.layerproperties;
42

  
43
import junit.framework.TestCase;
44

  
45
import com.iver.cit.gvsig.fmap.MapContext;
46
import com.iver.cit.gvsig.fmap.layers.FLayer;
47
import com.iver.cit.gvsig.project.documents.view.legend.gui.ILabelingStrategyPanel;
48

  
49
/**
50
 * 
51
 * LabelingPanelTestCase.java
52
 *
53
 * 
54
 * @author jaume dominguez faus - jaume.dominguez@iver.es Jun 13, 2008
55
 *
56
 */
57
public abstract class LabelingPanelTestCase extends TestCase {
58
	protected Class<? extends ILabelingStrategyPanel> panelClazz;
59

  
60
	public LabelingPanelTestCase(Class<? extends ILabelingStrategyPanel> panelClazz) {
61
		this.panelClazz = panelClazz;
62
	}
63
	
64
	public ILabelingStrategyPanel newInstance() {
65
		try {
66
			ILabelingStrategyPanel p = panelClazz.newInstance();
67
			initPanel(p);
68
			return p;
69
		} catch (Exception e) {
70
			fail("Failed installing panel to test "+panelClazz.getName());
71
			return null;
72
		} 
73
	}
74
	
75
	/**
76
	 * this method is intended to completely set up the panels. Remember that
77
	 * you are testing GUI components. So, you must not initialize any labeling strategy
78
	 * here. just use it if you did design your panel to have plugable further panels, such
79
	 * are labeling method within the general labeling strategy panel.
80
	 * 
81
	 * to test the strategies itself you should refer to the 
82
	 * org.gvsig.symbology.fmap.labeling.TestLabelingStrategy test!!
83
	 * 
84
	 * @param p
85
	 */
86
	protected abstract void initPanel(ILabelingStrategyPanel p);
87
	
88
	public abstract FLayer getTestLayer();
89

  
90
	public abstract MapContext getTestMapContext() ;
91
	
92
	
93
}
trunk/extensions/extSymbology/src-test/org/gvsig/symbology/gui/layerproperties/TestILabelingStrategyPanel.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.symbology.gui.layerproperties;
42

  
43
import java.awt.Dimension;
44
import java.awt.image.BufferedImage;
45
import java.util.ArrayList;
46
import java.util.Hashtable;
47

  
48
import junit.framework.TestCase;
49
import junit.framework.TestSuite;
50

  
51
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
52
import com.iver.cit.gvsig.fmap.MapContext;
53
import com.iver.cit.gvsig.fmap.ViewPort;
54
import com.iver.cit.gvsig.fmap.core.ILabelable;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56
import com.iver.cit.gvsig.fmap.operations.Cancel;
57
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy;
58
import com.iver.cit.gvsig.project.documents.view.legend.gui.ILabelingStrategyPanel;
59

  
60
public class TestILabelingStrategyPanel extends TestCase {
61
	private static Hashtable<
62
		Class<? extends ILabelingStrategy>, 
63
		LabelingPanelTestCase> classesToTest;
64
	private static boolean init;
65
	
66
	
67
	public static void addPanelTest(LabelingPanelTestCase labelPanelTestClass) {
68
		if (classesToTest == null) {
69
			classesToTest = new Hashtable<
70
									Class<? extends ILabelingStrategy>, 
71
									LabelingPanelTestCase
72
								>();
73
			Class<? extends ILabelingStrategy> c = labelPanelTestClass.
74
				newInstance().
75
				getLabelingStrategyClass();
76
			if (!classesToTest.containsKey(c))
77
				classesToTest.put(c, labelPanelTestClass);
78
		}
79
		
80
	}
81

  
82
	public static ILabelingStrategyPanel[] getNewLabelingStrategyInstances() {
83
		if (init) suite();
84
		init = false;
85
		ArrayList<ILabelingStrategyPanel> stratPanels = new ArrayList<ILabelingStrategyPanel>();
86
		for (LabelingPanelTestCase p : classesToTest.values()) {
87
			stratPanels.add( p.newInstance() );
88
		}
89
		return stratPanels.toArray(new ILabelingStrategyPanel[0]);
90
	}
91

  
92
	public static String shortClassName(Class<?> c) {
93
		return c.getName().substring(
94
				c.getName().lastIndexOf('.')+1,
95
				c.getName().length());
96
	}
97
	
98
	public static TestSuite suite() {
99
		TestSuite suite = new TestSuite("Integration test for labeling strategy configuration panels");
100
		suite.addTestSuite(TestILabelingStrategyPanel.class);
101
		addPanelTest(new GeneralLabelingStrategyPanelTestCase());
102
		return suite;
103
	}
104
	
105

  
106
	public void testGetLabelingStrategyName() {
107
		System.out
108
				.println("TestILabelingStrategyPanel.testGetLabelingStrategyName()"+": Not yet implemented!");
109
	}
110
	
111
	/**
112
	 * Tests the default settings of a labeling strategy panel.
113
	 * (Detects if the labeling strategy crashes when no user
114
	 * interaction has been made)
115
	 */
116
	public void testGetDefaultSettingsLabelingStrategy() {
117
		ILabelingStrategyPanel[] p = getNewLabelingStrategyInstances();
118
		
119
		for (int i = 0; i < p.length; i++) {
120
			LabelingPanelTestCase testCase = classesToTest.
121
								get(p[i].getLabelingStrategyClass());
122
			FLayer testLayer = testCase.getTestLayer();
123
			p[i].setModel(testLayer, null); // the null is the key of this test
124
			
125
			ILabelingStrategy strat = p[i].getLabelingStrategy();
126
			try {
127
				tryStrategy(testCase, testLayer, strat);
128
			} catch (Error e) {
129
				fail(e.getMessage());
130
			}
131
		}
132
	}
133

  
134
	private static void tryStrategy(LabelingPanelTestCase testCase, FLayer testLayer, ILabelingStrategy strat) {
135
		if (testLayer == null) 
136
			throw new Error("test layer is null! please check "+
137
					"case "+shortClassName(testCase.getClass())+
138
					".getTestLayer() method)");
139

  
140
		if (testLayer instanceof ILabelable) {
141
			try {
142
				// necessery rendering contexts previous settings
143
				ILabelable labelable = (ILabelable) testLayer;
144
				labelable.setLabelingStrategy(strat);
145
				MapContext mc = testCase.getTestMapContext();
146
				ViewPort viewPort = mc.getViewPort();
147
				viewPort.setExtent(testLayer.getFullExtent());
148
				viewPort.setImageSize(new Dimension(400, 400));
149
				BufferedImage bi = new BufferedImage(
150
						viewPort.getImageWidth(),
151
						viewPort.getImageHeight(),
152
						BufferedImage.TYPE_4BYTE_ABGR
153
				);
154
				
155
				// the actual test
156
				labelable.drawLabels(
157
						bi, 
158
						bi.createGraphics(),
159
						viewPort,
160
						new Cancel(),
161
						mc.getScaleView(),
162
						MapContext.getScreenDPI());
163
			} catch (ReadDriverException e) {
164
				throw new Error(e);
165
			} catch (Exception e) {
166
				fail("The rendering of the strategy failed. At this point, it can be due either to " +
167
					 "the panel malfunction, or to the LabelingStrategy itself. If the ILabelingStrategy "+
168
					 "'"+shortClassName(strat.getClass())+"' passed all the tests in FMap (TestILabelingStrategy), " +
169
					 "then the problem is in the panel, otherwise ensure that '"+shortClassName(strat.getClass())+"' " +
170
					 "passes such tests before testing its config panel ("+ shortClassName(testCase.panelClazz)+") to " +
171
					 "be sure that the problem is in the panel.");
172
			}
173
		} else {
174
			throw new Error("test layer is not labelable! " +
175
					"(this is a misconcept bug in the test " +
176
					"case "+shortClassName(testCase.getClass())+
177
					"'.getTestLayer() method)");
178
		}
179
	}
180

  
181
	public void testSetModel() {
182
		System.out.println("TestILabelingStrategyPanel.testSetModel()"+": Not yet implemented!");
183
	}
184
	
185
	public void testGetLabelingStrategyClass() {
186
		System.out
187
				.println("TestILabelingStrategyPanel.testGetLabelingStrategyClass()"+": Not yet implemented!");
188
	}
189
}
trunk/extensions/extSymbology/src-test/org/gvsig/symbology/gui/layerproperties/GeneralLabelingStrategyPanelTestCase.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.symbology.gui.layerproperties;
42

  
43
import java.io.File;
44

  
45
import org.gvsig.symbology.AllTests;
46

  
47
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
48
import com.iver.cit.gvsig.fmap.MapContext;
49
import com.iver.cit.gvsig.fmap.featureiterators.FeatureIteratorTest;
50
import com.iver.cit.gvsig.fmap.layers.FLayer;
51
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
52
import com.iver.cit.gvsig.project.documents.view.legend.gui.ILabelingStrategyPanel;
53

  
54
public class GeneralLabelingStrategyPanelTestCase extends LabelingPanelTestCase {
55
	
56
	public GeneralLabelingStrategyPanelTestCase() {
57
		super(GeneralLabeling.class);
58
	}
59
	
60
	@Override
61
	public FLayer getTestLayer() {
62
		AllTests.setUpDrivers();
63
		try {
64
			return LayerFactory.createLayer("test layer",
65
					FeatureIteratorTest.SHP_DRIVER_NAME,
66
					new File("src-test/test-data/layer-sample-files/cons_punt.shp"),
67
					com.iver.cit.gvsig.fmap.AllTests.TEST_DEFAULT_MERCATOR_PROJECTION);
68
		} catch (LoadLayerException e) {
69
			return null;
70
		}
71
	}
72
	
73
	@Override
74
	public MapContext getTestMapContext() {
75
		return com.iver.cit.gvsig.fmap.AllTests.newMapContext(
76
				com.iver.cit.gvsig.fmap.AllTests.TEST_DEFAULT_MERCATOR_PROJECTION);
77
	}
78
	
79
	@Override
80
	protected void initPanel(ILabelingStrategyPanel p) {
81
		GeneralLabeling.addLabelingMethod(DefaultLabeling.class);
82
	}
83
}
trunk/extensions/extSymbology/src-test/org/gvsig/symbology/gui/layerproperties/TestLabelFieldCellEditor.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.symbology.gui.layerproperties;
42

  
43
import java.awt.BorderLayout;
44
import java.util.ArrayList;
45
import java.util.List;
46
import java.util.Vector;
47

  
48
import javax.swing.JFrame;
49
import javax.swing.JPanel;
50

  
51
import org.gvsig.gui.beans.comboboxconfigurablelookup.DefaultComboBoxConfigurableLookUpModel;
52
import org.gvsig.gui.beans.comboboxconfigurablelookup.ILookUp;
53
import org.gvsig.gui.beans.comboboxconfigurablelookup.JComboBoxConfigurableLookUp;
54
import org.gvsig.gui.beans.comboboxconfigurablelookup.StringComparator;
55
import org.gvsig.symbology.fmap.labeling.parse.LabelExpressionParserConstants;
56

  
57
public class TestLabelFieldCellEditor /*extends TestCase*/ {
58

  
59

  
60

  
61

  
62
	public static void main(String[] args) {
63
		JFrame j = new JFrame("test field cell editor");
64
		JPanel content = new JPanel(new BorderLayout(10, 10));
65

  
66
		JComboBoxConfigurableLookUp combo = new JComboBoxConfigurableLookUp();
67
		final DefaultComboBoxConfigurableLookUpModel m = (DefaultComboBoxConfigurableLookUpModel)combo.getModel();
68

  
69
		ILookUp agent = new ILookUp() {
70
			ArrayList<Object> allElements = new ArrayList<Object>();
71
			{
72
				for (int i = 0; i < LabelExpressionParserConstants.tokenImage.length; i++) {
73
					allElements.add(LabelExpressionParserConstants.tokenImage[i].replaceAll("\"",	""));
74
				}
75
			}
76
			public List<Object> doLookUpConsideringCaseSensitive(String text,
77
					Vector<Object> sortOrderedItems, StringComparator comp) {
78
				Vector<Object> suggested = new Vector<Object>();
79

  
80
				String t_aux;
81
				m.setEventsEnabled(false);
82
				m.removeAllElements();
83

  
84
//				LabelExpressionParser p = new LabelExpressionParser(new StringReader(text));
85
				try {
86
					if (text.compareTo("Hola") != 0) {
87
						throw new Exception();
88
					}
89

  
90
					t_aux = text;
91
//					p.FieldExpression();
92
//					m.disableEvents();
93
//					m.removeAllElements();
94
//					m.addElement(text);
95
//					m.enableEvents();
96
//					} catch (ParseException e) {
97
//					for (int i = 0; i < e.expectedTokenSequences.length; i++) {
98
//					suggested.add(LabelExpressionParserConstants.tokenImage[e.expectedTokenSequences[i][0]].replaceAll("\"",	""));
99
//					}
100
				}
101
				catch (Exception e) {
102
					t_aux = "";
103
					///System.out.println(e.getMessage());
104
//					return (List) suggested;
105
				}
106
//				System.out.println("gaste tots els elements");
107

  
108
				for (Object string : allElements) {
109
					m.addElement(t_aux + " " + string);
110
					suggested.add(t_aux + " " + string);
111
				}
112
//				return suggested;
113

  
114
				m.setEventsEnabled(true);
115
				return suggested;
116
			}
117

  
118
			public List<Object> doLookUpIgnoringCaseSensitive(String text,
119
					Vector<Object> sortOrderedItems, StringComparator comp) {
120

  
121
				return null;
122
			}
123

  
124
		};
125
		m.setCaseSensitive(true);
126
		m.setLookUpAgent(agent);
127
		for (int i = 0; i < LabelExpressionParserConstants.tokenImage.length; i++) {
128
			m.addElement(LabelExpressionParserConstants.tokenImage[i]);
129
		}
130

  
131
		content.add(combo, BorderLayout.CENTER);
132
		j.setContentPane(content);
133
		j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
134
		j.pack();
135
		j.setVisible(true);
136

  
137

  
138
	}
139
}

Also available in: Unified diff