Revision 46168

View differences:

tags/org.gvsig.desktop-2.0.351/license.txt
1
gvSIG. Desktop Geographic Information System.
2

  
3
Copyright (C) 2007-2020 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 3
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, see <https://www.gnu.org/licenses/>. 
17

  
18
For any additional information, do not hesitate to contact us
19
at info AT gvsig.com, or visit our website www.gvsig.com.
tags/org.gvsig.desktop-2.0.351/org.gvsig.desktop.library/org.gvsig.ui/src/test/java/org/gvsig/gui/beans/defaultbuttonspanel/TestDefaultButtonsPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.defaultbuttonspanel;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47

  
48
import java.awt.BorderLayout;
49

  
50
import javax.swing.JButton;
51

  
52
import org.gvsig.gui.beans.TestUI;
53
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
54
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
55
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
56

  
57
/**
58
 * <code>TestDialogPanel</code>. Test para comprobar el funcionamiento de la
59
 * clase <code>DialogPanel</code>
60
 *
61
 * @version 15/03/2007
62
 * @author BorSanZa - Borja Sanchez Zamorano (borja.sanchez@iver.es)
63
 */
64
public class TestDefaultButtonsPanel implements ButtonsPanelListener {
65
	private TestUI frame = new TestUI("TestDefaultButtonsPanel");
66

  
67
	class NewComponentDialog extends DefaultButtonsPanel {
68
		private static final long serialVersionUID = 4452922507292538671L;
69

  
70
		public NewComponentDialog() {
71
			super(ButtonsPanel.BUTTONS_YESNO);
72
			this.setLayout(new BorderLayout());
73
			JButton b = new JButton("prueba");
74
			this.add(b, java.awt.BorderLayout.NORTH);
75
			JButton c = new JButton("prueba2");
76
			this.add(c, java.awt.BorderLayout.CENTER);
77
		}
78
	}
79

  
80
	NewComponentDialog ncd;
81

  
82
	public TestDefaultButtonsPanel() {
83
		ncd = new NewComponentDialog();
84

  
85
		frame.setSize(640, 480);
86
		frame.getContentPane().add(ncd);
87

  
88
		ncd.addButtonPressedListener(this);
89
		frame.setVisible(true);
90
	}
91

  
92
	public static void main(String[] args) {
93
		new TestDefaultButtonsPanel();
94
	}
95

  
96
	public void actionButtonPressed(ButtonsPanelEvent e) {
97
		System.out.println("Bot?n pulsado: " + e.getButton());
98
	}
99
}
0 100

  
tags/org.gvsig.desktop-2.0.351/org.gvsig.desktop.library/org.gvsig.ui/src/test/java/org/gvsig/gui/beans/comboboxconfigurablelookup/programmertests/TestJComboBoxConfigurableLookUp.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.comboboxconfigurablelookup.programmertests;
25

  
26
import java.awt.Dimension;
27

  
28
import javax.swing.JFrame;
29
import javax.swing.JOptionPane;
30

  
31
import org.gvsig.gui.beans.Messages;
32
import org.gvsig.gui.beans.comboboxconfigurablelookup.DefaultComboBoxConfigurableLookUpModel;
33
import org.gvsig.gui.beans.comboboxconfigurablelookup.JComboBoxConfigurableLookUp;
34

  
35

  
36

  
37
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
38
 *
39
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
40
 *
41
 * This program is free software; you can redistribute it and/or
42
 * modify it under the terms of the GNU General Public License
43
 * as published by the Free Software Foundation; either version 2
44
 * of the License, or (at your option) any later version.
45
 *
46
 * This program is distributed in the hope that it will be useful,
47
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
49
 * GNU General Public License for more details.
50
 *
51
 * You should have received a copy of the GNU General Public License
52
 * along with this program; if not, write to the Free Software
53
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
54
 *
55
 * For more information, contact:
56
 *
57
 *  Generalitat Valenciana
58
 *   Conselleria d'Infraestructures i Transport
59
 *   Av. Blasco Ib??ez, 50
60
 *   46010 VALENCIA
61
 *   SPAIN
62
 *
63
 *      +34 963862235
64
 *   gvsig@gva.es
65
 *      www.gvsig.gva.es
66
 *
67
 *    or
68
 *
69
 *   IVER T.I. S.A
70
 *   Salamanca 50
71
 *   46005 Valencia
72
 *   Spain
73
 *
74
 *   +34 963163400
75
 *   dac@iver.es
76
 */
77

  
78
/**
79
 * <p>Tests the class {@link JComboBoxConfigurableLookUp JComboBoxConfigurableLookUp} .</p>
80
 * 
81
 * <p>Notes:
82
 *  <ul>
83
 *   <li>MORE TESTS COULD BE ADDED!!!</li>
84
 *   <li>DON'T REMOVE TEST COMMENTED!!!</li>
85
 *  </ul>
86
 * </p>
87
 *
88
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
89
 * @version 07/02/2008
90
 */
91
public class TestJComboBoxConfigurableLookUp extends JFrame {
92
	private static final long serialVersionUID = -422198204525608333L;
93

  
94
	/**
95
	 * Test method for the <code>TestJComboBoxConfigurableLookUp</code>
96
	 * 
97
	 * @param args
98
	 */
99
	public static void main(String[] args)
100
	{
101
		int width = 300;
102
		int height = 60;
103
		
104
		try
105
		{
106
			// Objects creation
107
			JFrame jF = new JFrame();
108
	
109
			// Create a TestJComboBoxConfigurableLookUp, sets the behavior configuration and add Items
110
			
111
			// ---- TESTS ----
112
			// Test the default behavior
113
			JComboBoxConfigurableLookUp jCBSD = new JComboBoxConfigurableLookUp();
114

  
115
			// -- TESTS FLAGS FOR CONTROL --
116
			// Test the change of the flag 'onlyOneColor'
117
			// jCBSD.setOnlyOneColorOnText(true);
118
			// jCBSD.setOnlyOneColorOnText(false);
119
			
120
			// Test the change of the flag 'beepEnabled'
121
			// jCBSD.setBeepEnabled(false);
122
			// jCBSD.setBeepEnabled(true);
123

  
124
			// Test the change of the flag 'hidePopupIfThereAreNoItems'
125
			// jCBSD.setHidePopupIfThereAreNoItems(false);
126
			// jCBSD.setHidePopupIfThereAreNoItems(true);
127
			
128
			// Test the change of the flag 'toForceSelectAnItem'
129
			// jCBSD.setToForceSelectAnItem(false);
130
			// jCBSD.setToForceSelectAnItem(true);
131
			
132

  
133
			// --- TESTS ADDING A MODEL ---
134
			// -- TESTS FLAGS FOR THE MODEL --
135
			// DefaultComboBoxConfigurableLookUpModel model = new DefaultComboBoxConfigurableLookUpModel();
136
			DefaultComboBoxConfigurableLookUpModel model = new DefaultComboBoxConfigurableLookUpModel(new Object[] {"Item1", "Item2", "Item3", "Item4", "Item5"});
137
			// DefaultComboBoxConfigurableLookUpModel model = (DefaultComboBoxConfigurableLookUpModel) jCBSD.getModel();
138
				
139
			// Test the change of the flag 'itemsShownInListBox'
140
			// model.setLanguageRules("en_US");
141
			// model.setLanguageRules("fr_FR");
142
			// model.setLanguageRules("es_ES");
143
			// model.setLanguageRules(DefaultComboBoxConfigurableLookUpModel.DEFAULT_LANGUAGE_RULES_CONFIGURATION);
144
				
145
			// Test the change of the flag 'caseSensitive'
146
			// model.setCaseSensitive(false);
147
			// model.setCaseSensitive(DefaultComboBoxConfigurableLookUpModel.CASE_INSENSITIVE);
148
			// model.setCaseSensitive(true);
149
			// model.setCaseSensitive(DefaultComboBoxConfigurableLookUpModel.CASE_SENSITIVE);
150
			 
151
			// Test the change of the flag 'itemsOrder'
152
			// model.setItemsOrder(DefaultComboBoxConfigurableLookUpModel.MAINTAIN_POSITION);
153
			// model.setItemsOrder(DefaultComboBoxConfigurableLookUpModel.ALPHABETICAL_ORDERED);
154
			// model.setItemsOrder(DefaultComboBoxConfigurableLookUpModel.MAINTAIN_AGENT_POSITIONS);
155
			
156
			// Test the change of the flag 'itemsShownInListBox'
157
			// model.setShowAllItemsInListBox(DefaultComboBoxConfigurableLookUpModel.SHOW_ALL_ITEMS);
158
			// model.setShowAllItemsInListBox(true);
159
			// model.setShowAllItemsInListBox(DefaultComboBoxConfigurableLookUpModel.SHOW_ONLY_MATCHES);
160
			// model.setShowAllItemsInListBox(false);
161

  
162
			// Test the change of the flag 'completeArrowKeySelection'
163
			// jCBSD.setCompleteArrowKeySelection(true);
164
			// jCBSD.setCompleteArrowKeySelection(false);
165

  
166
			// Test the change of the flag 'displayAllItemsWithArrowButton'
167
			// jCBSD.setDisplayAllItemsWithArrowButton(false);
168
			 jCBSD.setDisplayAllItemsWithArrowButton(true);
169

  
170
			// Adds the new model
171
			jCBSD.setModel(model);
172

  
173
			// --- ADD ITEMS TO THE COMPONENT AND OTHER TESTS ---
174
			// Add some items to test if has too much delay with an average number of items
175
			jCBSD.addItem("extAddEventTheme");
176
			jCBSD.addItem("?and?");
177
			jCBSD.addItem("_fwAndami");
178
			jCBSD.addItem("extJDBC");
179

  
180
			jCBSD.addItem("extCAD");
181
			jCBSD.addItem("libuiDownCase");
182
			jCBSD.addItem("appgvSig");
183
			// jCBSD.setSelectedItem("appgvSig");
184
			// jCBSD.removeAllItems();
185
			jCBSD.addItem("RemoteServices");
186
			jCBSD.addItem("?and?");	
187
			jCBSD.addItem("?");
188
			// jCBSD.setSelectedItem("appgvSig");
189
			// jCBSD.setSelectedItem(jCBSD.getItemAt(3)); //Test setSelectedItem
190
			jCBSD.addItem("extNomenclatorIGN");
191

  
192
            // jCBSD.setSelectedItem(jCBSD.getItemAt(1)); //Test setSelectedItem
193
            // jCBSD.setSelectedIndex(1); //Test setSelectedIndex
194
			jCBSD.addItem("extWMS");
195
			jCBSD.addItem("?AND?");
196
			jCBSD.addItem("window");
197
			jCBSD.addItem("?");
198
			jCBSD.addItem("LIBUI");
199
            jCBSD.setSelectedItem("window");
200
			jCBSD.addItem("libCorePlugin");
201
			jCBSD.addItem("libCq CMS for java");
202
			jCBSD.addItem("libDriverManager");
203

  
204
            // jCBSD.setSelectedItem("libDriverManager");
205
			////				jCBSD.addItem("libFMap");
206
			////				jCBSD.addItem("libG_fwAndamiDBMS");
207
			////				jCBSD.addItem("libIverUtiles");
208
			////				jCBSD.addItem("libNomenclatorIGN");
209
			////				jCBSD.addItem("libNomenclatorIGN_GUI");
210
			////				jCBSD.addItem("libRemoteServices");
211
			//////				jCBSD.addItem("extNomenclatorIGN"); // Duplication test
212
			////				jCBSD.addItem("libUI");
213
			////				jCBSD.addItem("a");
214
			////				jCBSD.addItem("aa");
215
			////				jCBSD.addItem("aaa");
216
			////				jCBSD.addItem("aaaa");
217
			////				jCBSD.addItem("aaaaa");
218
			////				jCBSD.addItem("b");
219
			////				jCBSD.addItem("bbb");
220
			////				jCBSD.addItem("bb");
221
			////				jCBSD.addItem("c");
222
			////				jCBSD.addItem(".");
223
			////				jCBSD.addItem("ccc");
224
			////				jCBSD.addItem("cc");
225
			////				jCBSD.addItem("cccc");
226
			////				jCBSD.addItem("ddd");
227
			////				jCBSD.addItem("d");
228
			////				jCBSD.addItem("dd");
229
			////				jCBSD.addItem("dddd");
230
			////				jCBSD.addItem("e");
231
			////				jCBSD.addItem("eee");
232
			////				jCBSD.addItem("ee");
233
			////				jCBSD.addItem("eeee");
234
			//				jCBSD.addItem("ff");
235
			//				jCBSD.addItem("f");
236
			////				jCBSD.addItem("LIBZZMAYUSCULA1");
237
			////				jCBSD.addItem("ff"); // Duplication test
238
			////				jCBSD.addItem("asldf");
239
			////				jCBSD.addItem("wej");
240
			////				jCBSD.addItem("asdf");
241
			////				jCBSD.addItem("LIBMAYUSCULA2");
242
			////				jCBSD.addItem("qera");
243
			////				jCBSD.addItem("zxvcas");
244
			////				jCBSD.addItem("wea");
245
			////				jCBSD.addItem("asr");
246
			////				jCBSD.addItem("asra");
247
			////				jCBSD.addItem("LIBMAYUSCULA1");
248
			////				jCBSD.addItem("rar");
249
			////				jCBSD.addItem("afda");
250
			////				jCBSD.addItem("ljvkgk");
251
			////				jCBSD.addItem("zcv");
252
			////				jCBSD.addItem("gfhdt");
253
			////				jCBSD.addItem("dfhgd");
254
			////				jCBSD.addItem("dfh");
255
			////				jCBSD.addItem("dfhs");
256
			////				jCBSD.addItem("sfszv");
257
			////				jCBSD.addItem("qer");
258
			////				jCBSD.addItem("adfazva");
259
			////				jCBSD.addItem("xnd");
260
			////				jCBSD.addItem("vdkjgd");
261
			////				jCBSD.addItem("ddhd");
262
			////				jCBSD.addItem("dxgx");
263
			
264
			////				jCBSD.addItem("cnsf");
265
			////				jCBSD.addItem("ssfgs");
266
			////				jCBSD.addItem("sgfsbx");
267
			////				jCBSD.addItem("sfxb");
268
			////				jCBSD.addItem("chdgk");
269
			////				jCBSD.addItem("jgu");
270
			////				jCBSD.addItem("gkgj");
271
			////				jCBSD.addItem("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccddddddddddddddddddddddddddddddddddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeee");
272
			////				jCBSD.addItem("ljko?j.n");
273
			////				jCBSD.addItem("hfjf");
274
			////				jCBSD.addItem("xbxb");
275
			////				jCBSD.addItem(".,lhhi");
276
			////				jCBSD.addItem("hklx_fwAndami");
277
			////				jCBSD.addItem("cvn");
278
			////				jCBSD.addItem("dgh");
279
			////				jCBSD.addItem("cncv");
280
			////				jCBSD.addItem("sg");
281
			////				jCBSD.addItem("b,mjk");
282
			////				jCBSD.addItem("xv");
283
			////				jCBSD.addItem("sgghu");
284
			////				jCBSD.addItem("saxc");
285
			////				jCBSD.addItem("srts");
286
			////				jCBSD.addItem("sduyg");
287
			////				jCBSD.addItem("sxfsrs");
288
			////				jCBSD.addItem("rsdtf");
289
			////				jCBSD.addItem("po`llh");
290
			////				jCBSD.addItem("fghtf54j");
291
			////				jCBSD.addItem("s25ewsd");
292
			////				jCBSD.addItem("uo8khkj");
293
			////				jCBSD.addItem("sfg45");
294
			////				jCBSD.addItem("3gd");
295
			////				jCBSD.addItem("5dhd");
296
			////				jCBSD.addItem("sg4dh6");
297
			////				jCBSD.addItem("dfh5");
298
			////				jCBSD.addItem("s4hfj74");
299
			////				jCBSD.addItem("sdg534");
300
			////				jCBSD.addItem("2452etdfg");
301
			////				jCBSD.addItem("2ui068");
302
			////				jCBSD.addItem("3dsd sgr");
303
			////				jCBSD.addItem("sr sgsr");
304
			////				jCBSD.addItem("sssssssss");
305
			////				jCBSD.addItem("aaaaass");
306
			////				jCBSD.addItem("ss");
307
			////				jCBSD.addItem("sry");
308
			////				jCBSD.addItem("h?hj");
309
			////				jCBSD.addItem("gkgb");
310
			////				jCBSD.addItem("gkgu");
311
			////				jCBSD.addItem("gjugvfc");
312
			////				jCBSD.addItem("dghdd");
313
			////				jCBSD.addItem("dhdt");
314
			////				jCBSD.addItem("dhgd");
315
			////				jCBSD.addItem("ddtughd");
316
			////				jCBSD.addItem("ffuklj?d");
317
			////				jCBSD.addItem("j?olk.j");
318
			////				jCBSD.addItem("las alupoai a?ieurpay");
319
			////				jCBSD.addItem("tytresd");
320
			////				jCBSD.addItem("fgkg");
321
			////				jCBSD.addItem("lhh");
322
			////				jCBSD.addItem("hkhlhip");
323
			////				jCBSD.addItem("k?popi0??=(J");
324
			////				jCBSD.addItem("af??=)(/?/");
325
			////				jCBSD.addItem("-a,malj'=)/");
326
			////				jCBSD.addItem("2gw");
327
			////				jCBSD.addItem("5teu");
328
			////				jCBSD.addItem("4576jfff");
329
			////				jCBSD.addItem("urtyu");
330
			////				jCBSD.addItem("fi7");
331
			////				jCBSD.addItem("git7t4h");
332
			////				jCBSD.addItem("hr6frr");
333
			////				jCBSD.addItem("ehe5et");
334
			////				jCBSD.addItem("eue5klhj");
335
			////				jCBSD.addItem("yoiyoy");
336
			////				jCBSD.addItem("yoyi");
337
			////				jCBSD.addItem("sgcsc");
338
			////				jCBSD.addItem("sgmff74");
339
			////				jCBSD.addItem("dd43d d6dhlhju");
340
			////				jCBSD.addItem("gkjngr");
341
			////				jCBSD.addItem("dbddht");
342
			////				jCBSD.addItem("sbd");
343
			////				jCBSD.addItem("dcbd5opihjj");
344
			////				jCBSD.addItem("pujtth");
345
			////				jCBSD.addItem("ZZZZZ");
346
			////				jCBSD.addItem("ytht");
347
			////				jCBSD.addItem("tjgt");
348
			////				jCBSD.addItem("rrf");
349
			////				jCBSD.addItem("BLIUE? ");
350
			////				jCBSD.addItem("?AND?");
351
			////				jCBSD.addItem("axaaa4iktiu");
352
			////				jCBSD.addItem("tttyir");
353
			////				jCBSD.addItem("ruyrrruu4");
354
			////				jCBSD.addItem("rryewrsw");
355
			////				jCBSD.addItem("wertw");
356
			////				jCBSD.addItem("wer26e");
357
			////				jCBSD.addItem("eceye");
358
			////				jCBSD.addItem("etye7yyy-er");
359
			////				jCBSD.addItem("eyert7e7e7");
360
			////				jCBSD.addItem("_abcdefghijklmn?opqrstuvwxyz");
361
			////				jCBSD.addItem("_0123456789");
362
			////				jCBSD.addItem("sstsnmmsutt");
363
			////				jCBSD.addItem("dcytdtyd");
364
			////				jCBSD.addItem("dcdtdty");
365
			////				jCBSD.addItem("dctycd");
366
			////				jCBSD.addItem("cstyd");
367
			////				jCBSD.addItem("dbddcytdsssc");
368
			////				jCBSD.addItem("cdydt");
369
			////				jCBSD.addItem("scscydu");
370
			////				jCBSD.addItem("axct");
371
			////				jCBSD.addItem("joobfvd");
372
			////				jCBSD.addItem("jomj");
373
			////				jCBSD.addItem("omjo");
374
			////				jCBSD.addItem("mol");
375
			////				jCBSD.addItem("agdhfj");
376
			////				jCBSD.addItem("fjfhjuh,ooom");
377
			////				jCBSD.addItem("affjfa");
378
			////				jCBSD.addItem("afjfjyfga");
379
			////				jCBSD.addItem("NOMENCLATOR");
380
			////				jCBSD.addItem("asg");
381
			////				jCBSD.addItem("afaea");
382
			////				jCBSD.addItem("gvSIG");
383
			////				jCBSD.addItem("yoiey");
384
			////				jCBSD.addItem("35");
385
			////				jCBSD.addItem("ewgw2dh");
386
			////				jCBSD.addItem("titgr");
387
			////				jCBSD.addItem("o9yky");
388
			////				jCBSD.addItem("kyio8gbr");
389
			////				jCBSD.addItem("eve5yed574rir");
390
			////				jCBSD.addItem("578tygmtio");
391
			////				jCBSD.addItem("t43262ryteye");
392
			////				jCBSD.addItem("wvwx");
393
			////				jCBSD.addItem("zssscwwwwww");
394
			////				jCBSD.addItem("sgvr");
395
			////				jCBSD.addItem("...");
396
			//				jCBSD.addItem("?LTIMO ITEM EN A?ADIRSE");
397
			
398
			// --- END ADD ITEMS TO THE COMPONENT AND OTHER TESTS ---
399
			
400
			// Test of no item default selection 
401
			// jCBSD.setSelectedIndex(-1);
402
			
403
			// Other tests
404
			// jCBSD.setSelectedIndex(0);
405
			// System.out.println("Selected: " + jCBSD.getSelectedItem());
406
			// jCBSD.setSelectedIndex(3);
407
			// System.out.println("Item at 3: " + jCBSD.getItemAt(3));
408
			// jCBSD.setSelectedItem("?AND?");
409

  
410
			// System.out.println("Index of LIBUI: " + ((DefaultComboBoxConfigurableLookUpModel)jCBSD.getModel()).getIndexOf("LIBUI"));
411
			// jCBSD.addItem("A?ADIDO");
412
			// jCBSD.removeItemAt(0);
413
			// jCBSD.removeAllItems();
414
			// ((DefaultComboBoxConfigurableLookUpModel)jCBSD.getModel()).removeAllElements();
415
			// System.out.println("Number of elements (list box): " + jCBSD.getItemCount());
416

  
417
			// Tests the method ''setPrototypeDisplayValue''
418
			// jCBSD.addItem("ABCDEFGHIJKLMN?OPQRSTUVWXYZ-ABCDEFGHIJKLMN?OPQRSTUVWXYZ-ABCDEFGHIJKLMN?OPQRSTUVWXYZ");
419
			// jCBSD.setSelectedItem("ABCDEFGHIJKLMN?OPQRSTUVWXYZ-ABCDEFGHIJKLMN?OPQRSTUVWXYZ-ABCDEFGHIJKLMN?OPQRSTUVWXYZ");
420
			// jCBSD.setPrototypeDisplayValue("ABCDEFGHIJKLMN?OPQRSTUVWXYZ");
421
			
422
			// Configure the JFrame
423
			jF.setTitle("Test JComboBoxConfigurableLookUp");
424
			jF.setSize(new Dimension(width, height));	    
425
		    jF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
426
		    jF.getContentPane().add(jCBSD);
427
		    jF.setVisible(true);
428

  
429
		    // More tests
430
			// jCBSD.setSelectedIndex(0); // Failures before the component could be showed
431
			// System.out.println("Selected: " + jCBSD.getSelectedItem());
432
			// jCBSD.setSelectedIndex(3); // Failures before the component could be showed
433
			// System.out.println("Item at 3: " + jCBSD.getItemAt(3));
434
			// jCBSD.setSelectedItem("?AND?"); // Failures before the component could be showed
435
		    
436
		    // Test a Look up Agent
437
		    // model.setLookUpAgent(new SampleAgent());
438
		    
439
		    // Test changing the renderer
440
		    // jCBSD.setRenderer(new SampleBasicComboBoxRenderer());
441
		    
442
			// More tests
443
			// jCBSD.removeAllItems();
444
			// jCBSD.addItem("extCAD");
445
			// jCBSD.addItem("libuiDownCase");
446
			// jCBSD.addItem("appgvSig");
447
			// jCBSD.removeAllItems();
448
			// jCBSD.addItem("extCAD");
449
			// jCBSD.addItem("libuiDownCase");
450
			// jCBSD.addItem("appgvSig");
451
			// jCBSD.setSelectedItem("libuiDownCase");
452
		    
453
		    // Test change the editor
454
		    // jCBSD.setEditor(new SampleComboBoxEditor());
455
		}
456
		catch(Exception e)
457
		{
458
			e.printStackTrace();
459
			JOptionPane.showMessageDialog(null, Messages.getText("testJComboBoxConfigurableLookUpErrorMessage"), Messages.getText("error"), JOptionPane.ERROR_MESSAGE);
460
		}
461
	}
462
}
0 463

  
tags/org.gvsig.desktop-2.0.351/org.gvsig.desktop.library/org.gvsig.ui/src/test/java/org/gvsig/gui/beans/comboboxconfigurablelookup/programmertests/SampleAgent.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.comboboxconfigurablelookup.programmertests;
25

  
26
import java.util.ArrayList;
27
import java.util.List;
28
import java.util.Vector;
29

  
30
import org.gvsig.gui.beans.comboboxconfigurablelookup.ILookUp;
31
import org.gvsig.gui.beans.comboboxconfigurablelookup.StringComparator;
32

  
33
/**
34
 * <p>Sample of personalized look up algorithm for the model of a <code>JComboBoxConfigurableLookUp</code> object.</p>
35
 * 
36
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
37
 * @version 08/02/2008
38
 */
39
public class SampleAgent implements ILookUp {
40
	/**
41
	 * <p>Creates a new instance of the class <code>StartsWithLookUpAgent</code>.</p>
42
	 */
43
	public SampleAgent() {
44
	}
45
	
46
	/*
47
	 * (non-Javadoc)
48
	 * @see org.gvsig.gui.beans.comboboxconfigurablelookup.ILookUp#doLookUpConsideringCaseSensitive(java.lang.String, java.util.Vector, org.gvsig.gui.beans.comboboxconfigurablelookup.StringComparator)
49
	 */
50
	public List<Object> doLookUpConsideringCaseSensitive(String text, Vector<Object> sortOrderedItems, StringComparator comp) {
51
		if (sortOrderedItems == null)
52
			return null;
53

  
54
		List<Object> list = new ArrayList<Object>();
55
		
56
		for (int i = 0; i < (sortOrderedItems.size()); i++) {
57
			if (i % 2 == 0)
58
				list.add(sortOrderedItems.get(i));
59
		}
60

  
61
		return list;
62
	}
63

  
64
	/*
65
	 * (non-Javadoc)
66
	 * @see org.gvsig.gui.beans.comboboxconfigurablelookup.ILookUp#doLookUpIgnoringCaseSensitive(java.lang.String, java.util.Vector, org.gvsig.gui.beans.comboboxconfigurablelookup.StringComparator)
67
	 */
68
	public List<Object> doLookUpIgnoringCaseSensitive(String text, Vector<Object> sortOrderedItems, StringComparator comp) {
69
		if (sortOrderedItems == null)
70
			return null;
71

  
72
		List<Object> list = new ArrayList<Object>();
73
		
74
		for (int i = 0; i < (sortOrderedItems.size()); i++) {
75
			if (i % 2 == 0)
76
				list.add(sortOrderedItems.get(i));
77
		}
78

  
79
		return list;
80
	}
81
}
0 82

  
tags/org.gvsig.desktop-2.0.351/org.gvsig.desktop.library/org.gvsig.ui/src/test/java/org/gvsig/gui/beans/comboboxconfigurablelookup/programmertests/SampleComboBoxEditor.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.comboboxconfigurablelookup.programmertests;
25

  
26
import java.awt.Component;
27
import java.awt.event.ActionListener;
28
import java.awt.event.FocusEvent;
29
import java.awt.event.FocusListener;
30
import java.lang.reflect.Method;
31

  
32
import javax.swing.ComboBoxEditor;
33
import javax.swing.JTextField;
34
import javax.swing.border.Border;
35
import javax.swing.plaf.basic.BasicComboBoxEditor;
36

  
37
import org.gvsig.gui.beans.editabletextcomponent.JEditableTextField;
38

  
39
/**
40
 * <p>The default editor for editable combo boxes. The editor is implemented as a JTextField.</p>
41
 *
42
 * @version 12/02/08
43
 * @author Arnaud Weber
44
 * @author Mark Davidson
45
 * @author Pablo Piqueras Bartolom?
46
 */
47
public class SampleComboBoxEditor implements ComboBoxEditor, FocusListener {
48
    protected JTextField editor;
49
    private Object oldValue;
50

  
51
    public SampleComboBoxEditor() {
52
        editor = new BorderlessTextField("",9);
53
        editor.setBorder(null);
54
    }
55

  
56
    public Component getEditorComponent() {
57
        return editor;
58
    }
59

  
60
    /** 
61
     * Sets the item that should be edited. 
62
     *
63
     * @param anObject the displayed value of the editor
64
     */
65
    public void setItem(Object anObject) {
66
        if ( anObject != null )  {
67
            editor.setText(anObject.toString());
68
            
69
            oldValue = anObject;
70
        } else {
71
            editor.setText("");
72
        }
73
    }
74

  
75
    public Object getItem() {
76
        Object newValue = editor.getText();
77
        
78
        if (oldValue != null && !(oldValue instanceof String))  {
79
            // The original value is not a string. Should return the value in it's
80
            // original type.
81
            if (newValue.equals(oldValue.toString()))  {
82
                return oldValue;
83
            } else {
84
                // Must take the value from the editor and get the value and cast it to the new type.
85
                Class cls = oldValue.getClass();
86
                try {
87
                    Method method = cls.getMethod("valueOf", new Class[]{String.class});
88
                    newValue = method.invoke(oldValue, new Object[] { editor.getText()});
89
                } catch (Exception ex) {
90
                    // Fail silently and return the newValue (a String object)
91
                }
92
            }
93
        }
94
        return newValue;
95
    }
96

  
97
    public void selectAll() {
98
        editor.selectAll();
99
        editor.requestFocus();
100
    }
101

  
102
    // This used to do something but now it doesn't.  It couldn't be
103
    // removed because it would be an API change to do so.
104
    public void focusGained(FocusEvent e) {}
105
    
106
    // This used to do something but now it doesn't.  It couldn't be
107
    // removed because it would be an API change to do so.
108
    public void focusLost(FocusEvent e) {}
109

  
110
    public void addActionListener(ActionListener l) {
111
        editor.addActionListener(l);
112
    }
113

  
114
    public void removeActionListener(ActionListener l) {
115
        editor.removeActionListener(l);
116
    }
117

  
118
    /** 
119
     * Inner text field editable as a component of a ComboBox editor.
120
     * 
121
     * @see JEditableTextField
122
     * 
123
     * @version 12/02/08
124
     * @author Arnaud Weber
125
     * @author Mark Davidson
126
     * @author Pablo Piqueras Bartolom?
127
     */
128
    private class BorderlessTextField extends JEditableTextField {
129
		private static final long serialVersionUID = -3333236529430569318L;
130

  
131
		public BorderlessTextField(String value,int n) {
132
            super(value,n);
133
        }
134

  
135
        // workaround for 4530952
136
        public void setText(String s) {
137
            if (getText().equals(s)) {
138
                return;
139
            }
140
            super.setText(s);
141
        }
142

  
143
        public void setBorder(Border b) {}
144
    }
145
    
146
    /**
147
     * A subclass of BasicComboBoxEditor that implements UIResource.
148
     * BasicComboBoxEditor doesn't implement UIResource
149
     * directly so that applications can safely override the
150
     * cellRenderer property with BasicListCellRenderer subclasses.
151
     * <p>
152
     * <strong>Warning:</strong>
153
     * Serialized objects of this class will not be compatible with
154
     * future Swing releases. The current serialization support is
155
     * appropriate for short term storage or RMI between applications running
156
     * the same version of Swing.  As of 1.4, support for long term storage
157
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
158
     * has been added to the <code>java.beans</code> package.
159
     * Please see {@link java.beans.XMLEncoder}.
160
     */
161
    public static class UIResource extends BasicComboBoxEditor
162
    implements javax.swing.plaf.UIResource {
163
    }
164
}
0 165

  
tags/org.gvsig.desktop-2.0.351/org.gvsig.desktop.library/org.gvsig.ui/src/test/java/org/gvsig/gui/beans/comboboxconfigurablelookup/programmertests/SampleBasicComboBoxRenderer.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.comboboxconfigurablelookup.programmertests;
25

  
26
import java.awt.Color;
27
import java.awt.Component;
28

  
29
import javax.swing.JList;
30
import javax.swing.plaf.basic.BasicComboBoxRenderer;
31

  
32
/**
33
 * <p>Sample of personalized combo box cell renderer.</p>
34
 * 
35
 * @version 08/02/2008
36
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) 
37
 */
38
public class SampleBasicComboBoxRenderer extends BasicComboBoxRenderer {
39
	private static final long serialVersionUID = -9044759678425798655L;
40

  
41
	/**
42
	 * <p>Creates a new instance of the <code>SampleBasicComboBoxRenderer</code> class.</p>
43
	 */
44
	public SampleBasicComboBoxRenderer() {
45
		super();
46
	}
47

  
48
	/*
49
	 * (non-Javadoc)
50
	 * @see javax.swing.plaf.basic.BasicComboBoxRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
51
	 */
52
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
53
		Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
54
		
55
		if (isSelected)
56
			component.setBackground(Color.GRAY);
57
		else
58
			component.setBackground(new Color(((17 * index) % 256), ((31 * index) % 256), ((7 * index) % 256)));
59
		
60
		return component;
61
	}
62
}
0 63

  
tags/org.gvsig.desktop-2.0.351/org.gvsig.desktop.library/org.gvsig.ui/src/test/java/org/gvsig/gui/beans/comboboxconfigurablelookup/usertests/JFrameUserTestOfJComboBoxConfigurableLookUp.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.comboboxconfigurablelookup.usertests;
25

  
26
import java.io.Serializable;
27

  
28
import javax.swing.JFrame;
29

  
30
import org.gvsig.gui.beans.Messages;
31
import org.gvsig.gui.beans.comboboxconfigurablelookup.JComboBoxConfigurableLookUp;
32

  
33

  
34
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
35
*
36
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
37
*
38
* This program is free software; you can redistribute it and/or
39
* modify it under the terms of the GNU General Public License
40
* as published by the Free Software Foundation; either version 2
41
* of the License, or (at your option) any later version.
42
*
43
* This program is distributed in the hope that it will be useful,
44
* but WITHOUT ANY WARRANTY; without even the implied warranty of
45
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46
* GNU General Public License for more details.
47
*
48
* You should have received a copy of the GNU General Public License
49
* along with this program; if not, write to the Free Software
50
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
51
*
52
* For more information, contact:
53
*
54
*  Generalitat Valenciana
55
*   Conselleria d'Infraestructures i Transport
56
*   Av. Blasco Ib??ez, 50
57
*   46010 VALENCIA
58
*   SPAIN
59
*
60
*      +34 963862235
61
*   gvsig@gva.es
62
*      www.gvsig.gva.es
63
*
64
*    or
65
*
66
*   IVER T.I. S.A
67
*   Salamanca 50
68
*   46005 Valencia
69
*   Spain
70
*
71
*   +34 963163400
72
*   dac@iver.es
73
*/
74

  
75
/**
76
 * <p>Creates and launches an application for testing {@link JComboBoxConfigurableLookUp JComboBoxConfigurableLookUp}.</p>
77
 * 
78
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
79
 * @version 07/02/2008
80
 */
81
public class JFrameUserTestOfJComboBoxConfigurableLookUp implements Serializable{
82
	private static final long serialVersionUID = 5760643373469048220L;
83

  
84
	private JPanelUserTestOfJComboBoxConfigurableLookUp mainPanel = null;
85
	private JFrame frame;
86

  
87
	/**
88
	 * <p>Default constructor.</p>
89
	 */
90
	public JFrameUserTestOfJComboBoxConfigurableLookUp() {
91
		createFrame();
92
	}
93

  
94
	/**
95
	 * <p>Creates the main <code>JFrame</code> for execute the application, and adds to it the <code>JPanel</code> test application.</p> 
96
	 */
97
	private void createFrame() {
98
		// Create: Configuration Frame
99
		frame = new JFrame();
100
		frame.setResizable(false);
101
		frame.setTitle(Messages.getText("jComboBoxConfigurableLookUpByTheUser_frameTitle"));
102
		frame.getContentPane().add(getJPanelUserTestOfJComboBoxConfigurableLookUp());
103
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
104
		frame.pack();
105

  
106
		// Centers the frame in the middle of the screen
107
		frame.setLocationRelativeTo(null);
108
	}
109
	
110
	/**
111
	 * <p>Initializes <code>mainPanel</code>.</p>
112
	 * 
113
	 * @return JPanelUserTestOfJComboBoxConfigurableLookUp
114
	 */
115
	private JPanelUserTestOfJComboBoxConfigurableLookUp getJPanelUserTestOfJComboBoxConfigurableLookUp() {
116
		if (mainPanel == null) {
117
			mainPanel = new JPanelUserTestOfJComboBoxConfigurableLookUp();
118
		}
119
		
120
		return mainPanel;
121
	}
122

  
123
	/**
124
	 * <p>Method for launch the application.</p>
125
	 * 
126
	 * @param args
127
	 */
128
	public static void main(String[] args) {
129
		JFrameUserTestOfJComboBoxConfigurableLookUp app = new JFrameUserTestOfJComboBoxConfigurableLookUp();
130
		app.setVisible(true);
131
	}
132

  
133
	/**
134
	 * <p>Sets visible the frame.</p>
135
	 * 
136
	 * @param visible True or false
137
	 */
138
	public void setVisible(boolean visible) {
139
		frame.setVisible(visible);
140
	}	
141
}
0 142

  
tags/org.gvsig.desktop-2.0.351/org.gvsig.desktop.library/org.gvsig.ui/src/test/java/org/gvsig/gui/beans/comboboxconfigurablelookup/usertests/JPanelUserTestOfJComboBoxConfigurableLookUp.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.comboboxconfigurablelookup.usertests;
25

  
26
import java.awt.Color;
27
import java.awt.Dimension;
28
import java.awt.FlowLayout;
29
import java.awt.Font;
30
import java.awt.GridLayout;
31
import java.awt.event.MouseAdapter;
32
import java.awt.event.MouseEvent;
33
import java.awt.event.WindowAdapter;
34
import java.awt.event.WindowEvent;
35
import java.io.BufferedReader;
36
import java.io.File;
37
import java.io.FileReader;
38
import java.io.IOException;
39
import java.io.OutputStream;
40
import java.io.PrintStream;
41
import java.io.Serializable;
42
import java.lang.reflect.InvocationTargetException;
43
import java.lang.reflect.Method;
44
import java.util.HashMap;
45
import java.util.Map;
46
import java.util.StringTokenizer;
47
import java.util.Vector;
48

  
49
import javax.swing.BorderFactory;
50
import javax.swing.JButton;
51
import javax.swing.JCheckBox;
52
import javax.swing.JComboBox;
53
import javax.swing.JFrame;
54
import javax.swing.JLabel;
55
import javax.swing.JOptionPane;
56
import javax.swing.JPanel;
57
import javax.swing.JScrollPane;
58
import javax.swing.JTabbedPane;
59
import javax.swing.JTextArea;
60
import javax.swing.JTextField;
61
import javax.swing.border.TitledBorder;
62
import javax.swing.event.ListDataEvent;
63
import javax.swing.event.ListDataListener;
64
import javax.swing.event.PopupMenuEvent;
65
import javax.swing.event.PopupMenuListener;
66

  
67
import org.gvsig.gui.beans.Messages;
68
import org.gvsig.gui.beans.comboboxconfigurablelookup.DefaultComboBoxConfigurableLookUpModel;
69
import org.gvsig.gui.beans.comboboxconfigurablelookup.JComboBoxConfigurableLookUp;
70
import org.gvsig.gui.beans.comboboxconfigurablelookup.programmertests.SampleBasicComboBoxRenderer;
71

  
72

  
73
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
74
*
75
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
76
*
77
* This program is free software; you can redistribute it and/or
78
* modify it under the terms of the GNU General Public License
79
* as published by the Free Software Foundation; either version 2
80
* of the License, or (at your option) any later version.
81
*
82
* This program is distributed in the hope that it will be useful,
83
* but WITHOUT ANY WARRANTY; without even the implied warranty of
84
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
85
* GNU General Public License for more details.
86
*
87
* You should have received a copy of the GNU General Public License
88
* along with this program; if not, write to the Free Software
89
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
90
*
91
* For more information, contact:
92
*
93
*  Generalitat Valenciana
94
*   Conselleria d'Infraestructures i Transport
95
*   Av. Blasco Ib??ez, 50
96
*   46010 VALENCIA
97
*   SPAIN
98
*
99
*      +34 963862235
100
*   gvsig@gva.es
101
*      www.gvsig.gva.es
102
*
103
*    or
104
*
105
*   IVER T.I. S.A
106
*   Salamanca 50
107
*   46005 Valencia
108
*   Spain
109
*
110
*   +34 963163400
111
*   dac@iver.es
112
*/
113

  
114
/** 
115
 * <p>Application for testing <code>JComboBoxLookUpConfigurable</code> objects.</p>
116
 * 
117
 * <p>This class is a JPanel and has other classes nested.</p>
118
 * 
119
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
120
 * @version 07/02/2008
121
 */
122
public class JPanelUserTestOfJComboBoxConfigurableLookUp extends JPanel implements Serializable {
123
	private static final long serialVersionUID = -8900802197326194647L;
124

  
125
	private final int panelWidth = 735;
126
	private final int panelHeight = 580;
127
	private final int testWidth = 260;
128
	private ConfigurationJPanel configurationPanel = null;
129
	private OtherTestsJPanel otherTestsPanel = null;
130
	private JavaFileMethodsLoader javaFileMethodsLoader;
131
	private int testNumber;
132
	private String path;
133
	private boolean isConfiguring;
134
	
135
	private static final short DEFAULT_CELL_RENDERER = 0;
136
	private static final short SAMPLE_BG_COLOR_CELL_RENDERER = 1;
137
	
138
	/**
139
	 * <p>Default constructor.</p>
140
	 */
141
	public JPanelUserTestOfJComboBoxConfigurableLookUp() {
142
		super();
143
		this.initialize();
144
	}
145

  
146
	/**
147
	 * <p>Initializes the application pane.</p>
148
	 */
149
	private void initialize() {
150
		path = "src/org/gvsig/gui/beans/comboboxconfigurablelookup/JComboBoxConfigurableLookUp.java";
151
		isConfiguring = false;
152
		this.setPreferredSize(new Dimension(panelWidth, panelHeight));
153
		this.setSize(new Dimension(panelWidth, panelHeight));
154
		FlowLayout flowLayout = new FlowLayout();
155
		flowLayout.setAlignment(FlowLayout.LEFT);
156
		this.setLayout(flowLayout);
157
		this.add(this.getConfigurationPanel());
158
		this.add(this.getOtherTestsPanel());	
159
		this.loadPublicMethods();
160
		this.redirectDebugAndErrorMessages();
161
		testNumber = 1;
162
	}	
163

  
164
	/**
165
	 * <p>Loads public methods of the <code>JComboBoxConfigurableLookUp</code> from its file class and adds the constructors to the
166
	 *   inner <code>ConfigurationPanel</code> and the other methods to the <code>OtherTestsPanel</code>.</p>
167
	 */
168
	private void loadPublicMethods() {
169
		String methodHead;
170
		String reservedWord = new String("public ");
171
		int reservedWordLength = reservedWord.length();
172
		
173
		for (int i = 0; i < javaFileMethodsLoader.size(); i++)
174
		{
175
			methodHead = javaFileMethodsLoader.getMethodHead(i);
176
			if (methodHead.startsWith(reservedWord))
177
			{
178
				if (methodHead.startsWith(reservedWord + javaFileMethodsLoader.getClassName()))
179
					getConfigurationPanel().addConstructorItem(methodHead.substring(reservedWordLength, methodHead.length()));
180
				else
181
					getOtherTestsPanel().addMethodItem(methodHead.substring(reservedWordLength, methodHead.length()));
182
			}
183
		}
184
	}
185
	
186
	/**
187
	 * <p>Redirects the default output and error stream to the inner log <code>JTextArea</code>.</p>
188
	 */
189
	private void redirectDebugAndErrorMessages() {
190
		// Now create a new TextAreaOutputStream to write to our JTextArea control and wrap a
191
		// PrintStream around it to support the println/printf methods.
192
		PrintStream out = new PrintStream( new TextAreaOutputStream( getOtherTestsPanel().getJTextAreaLog() ) );
193

  
194
		// Redirect standard output stream to the TextAreaOutputStream
195
		System.setOut( out );
196

  
197
		// Redirect standard error stream to the TextAreaOutputStream
198
		System.setErr( out );
199
	}
200
	
201
	/**
202
	 * <p>This method initializes <code>configurationPanel</code>.</p>
203
	 * 	
204
	 * @return javax.swing.JComboBoxItemsSeekerConfigurableTestingByTheUserConfigurationPanel	
205
	 */
206
	private ConfigurationJPanel getConfigurationPanel() {
207
		if (configurationPanel == null) {			
208
			configurationPanel = new ConfigurationJPanel();
209
			configurationPanel.getJButtonNew().addMouseListener(new MouseAdapter() {
210
				/*
211
				 * (non-Javadoc)
212
				 * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
213
				 */
214
				public void mouseClicked(MouseEvent arg0) {
215
					addNewTestObject();
216
				}
217
			});
218
		}
219

  
220
		return configurationPanel;
221
	}
222
	
223
	/**
224
	 * <p>This method initializes <code>otherTestsPanel</code>.<p>
225
	 * 	
226
	 * @return javax.swing.JComboBoxItemsSeekerConfigurableTestingByTheUserOtherTestsPanel	
227
	 */
228
	private OtherTestsJPanel getOtherTestsPanel() {
229
		if (this.otherTestsPanel == null)
230
			this.otherTestsPanel = new OtherTestsJPanel(path);
231

  
232
		return this.otherTestsPanel;
233
	}
234
	
235
	/**
236
	 * <p>This method creates a JFrame with a new object for testing.</p>
237
	 * <p>This method also defines the closing methods and the name of the <code>JFrame</code>, and add the <code>JFrame</code> to the <code>OtherTestPanel</code>; that panel.
238
	 *    will use it for do methods.</p>
239
	 */
240
	private void addNewTestObject() {
241
		JComboBoxConfigurableLookUp object = this.createComponent();
242
		object.setPreferredSize(new Dimension(testWidth, object.getPreferredSize().height));
243
		String keyAndTitle = Messages.getText("test") + " " + String.valueOf(testNumber++);
244
		
245
		JFrame jFrame = new JFrame(keyAndTitle);
246
		jFrame.getContentPane().add(object);
247
		jFrame.pack();
248
		jFrame.setVisible(true);
249
		
250
		// Centers the JFrame in the middle of the screen
251
		jFrame.setLocationRelativeTo(null);
252
		
253
		// Defines the methods that will have to do the JFrame when it would have to be closed
254
		jFrame.addWindowListener(new WindowAdapter(){
255

  
256
			/*
257
			 * (non-Javadoc)
258
			 * @see java.awt.event.WindowAdapter#windowClosed(java.awt.event.WindowEvent)
259
			 */
260
			public void windowClosed(WindowEvent e) {
261
				// It's executen when the application closes the JFrame
262
				getOtherTestsPanel().removeTestObject(((JFrame)e.getSource()).getTitle());
263
				getOtherTestsPanel().getJTextAreaLog().append('(' + ((JFrame)e.getSource()).getTitle() + ", " + Messages.getText("elimination") + ")\n");
264
			}
265
			
266
			/*
267
			 * (non-Javadoc)
268
			 * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent)
269
			 */
270
			public void windowClosing(WindowEvent e) {
271
				// It's executen when the user closes the JFrame
272
				getOtherTestsPanel().removeTestObject(((JFrame)e.getSource()).getTitle());
273
				getOtherTestsPanel().getJTextAreaLog().append('(' + ((JFrame)e.getSource()).getTitle() + ", " + Messages.getText("elimination") + ")\n");
274
			}
275
		});
276

  
277
		this.getOtherTestsPanel().addTestObject(keyAndTitle, jFrame);
278
	}
279
	
280

  
281
	/**
282
	 * <p>Obtains the configuration value for create the new object and creates it.</p>
283
	 * 
284
	 * @return JComboBoxConfigurableLookUp The new object created
285
	 */
286
	private JComboBoxConfigurableLookUp createComponent() {
287
		JComboBoxConfigurableLookUp comboBox = null;
288
		String argument = "";
289

  
290
		// ESTA PARTE CREA EL OBJETO, AVISA DE QUE EN CASO NECESARIO PONDR? UN PAR?METRO PREESTABLECIDO, Y ALMACENA EL TEXTO ACERCA
291
		//  DEL PAR?METRO QUE PONDR? LUEGO EN EL LOG
292
		switch(getConfigurationPanel().getSelectedComboBoxConstructor()) {
293
			case 0:
294
				comboBox = new JComboBoxConfigurableLookUp();
295
				break;
296
			case 1:
297
				JOptionPane.showMessageDialog(null, Messages.getText("will_use_a_default_model"), Messages.getText("warning"), JOptionPane.WARNING_MESSAGE);
298
				DefaultComboBoxConfigurableLookUpModel model = new DefaultComboBoxConfigurableLookUpModel(new Object[] {"Item1", "Item2", "Item3", "Item4", "Item5"});
299
				comboBox = new JComboBoxConfigurableLookUp(model);
300
				argument = "model; ";
301
				break;
302
			case 2:
303
				JOptionPane.showMessageDialog(null, Messages.getText("will_use_a_default_array_of_items"), Messages.getText("warning"), JOptionPane.WARNING_MESSAGE);
304
				comboBox = new JComboBoxConfigurableLookUp(new Object[] {"Item1", "Item2", "Item3", "Item4", "Item5"});
305
				argument = "array; ";
306
				break;
307
			case 3:
308
				JOptionPane.showMessageDialog(null, Messages.getText("will_use_a_default_vector_of_items"), Messages.getText("warning"), JOptionPane.WARNING_MESSAGE);
309
				Vector<Object> vector = new Vector<Object>();
310
				vector.add("Item1");
311
				vector.add("Item2");
312
				vector.add("Item3");
313
				vector.add("Item4");
314
				vector.add("Item5");
315
				comboBox = new JComboBoxConfigurableLookUp(vector);
316
				argument = "vector; ";
317
				break;
318
			default:
319
				comboBox = new JComboBoxConfigurableLookUp();
320
		}
321

  
322
		DefaultComboBoxConfigurableLookUpModel model = (DefaultComboBoxConfigurableLookUpModel)comboBox.getModel();
323
		String itemsOrderText = null;
324
		String languageRule = null;
325
		String cellRenderer = getConfigurationPanel().getSelectedComboBoxCellRenderer();
326

  
327
		
328
		if (isConfiguring) {
329
			comboBox.setOnlyOneColorOnText(getConfigurationPanel().isSelectedJCheckBoxOnlyOneColor());
330
			comboBox.setBeepEnabled(getConfigurationPanel().isSelectedJCheckBoxBeepEnabled());
331
			comboBox.setHidePopupIfThereAreNoItems(getConfigurationPanel().isSelectedJCheckBoxHidePopupIfThereAreNoItems());
332
			comboBox.setToForceSelectAnItem(getConfigurationPanel().isSelectedJCheckBoxToForceSelectAnItem());
333
			comboBox.setCompleteArrowKeySelection(getConfigurationPanel().isSelectedJCheckBoxCompleteArrowKeySelection());
334
			comboBox.setDisplayAllItemsWithArrowButton(getConfigurationPanel().isSelectedJCheckBoxDisplayAllItemsWithArrowButton());
335
			
336
			if (getConfigurationPanel().getSelectedComboBoxCellRendererIndex() == SAMPLE_BG_COLOR_CELL_RENDERER)
337
				comboBox.setRenderer(new SampleBasicComboBoxRenderer());
338

  
339
			// Configuration of the model
340
			model.setItemsOrder(getConfigurationPanel().getSelectedComboBoxItemsOrder());
341
			model.setShowAllItemsInListBox(getConfigurationPanel().isSelectedJCheckBoxShowAllItemsInListBox());
342
			model.setLocaleRules(getConfigurationPanel().getSelectedComboBoxLanguageRuleText());
343
			model.setCaseSensitive(getConfigurationPanel().isSelectedJCheckBoxCaseSensitive());
344
			
345
			itemsOrderText = getConfigurationPanel().getSelectedComboBoxItemsOrderText();
346
			languageRule = getConfigurationPanel().getSelectedComboBoxLanguageRuleText();
347
			
348
			// Write the log
349
			getOtherTestsPanel().getJTextAreaLog().append('(' + Messages.getText("test") + " " + String.valueOf(testNumber) + ", " +
350
					Messages.getText("creaction") + ": " + argument + Messages.getText("configuration") + ": " + getConfigurationPanel().isSelectedJCheckBoxOnlyOneColor() + ", " + 
351
					getConfigurationPanel().isSelectedJCheckBoxBeepEnabled() + ", " + getConfigurationPanel().isSelectedJCheckBoxHidePopupIfThereAreNoItems() + ", " +
352
					getConfigurationPanel().isSelectedJCheckBoxToForceSelectAnItem() + ", " +
353
					getConfigurationPanel().isSelectedJCheckBoxCompleteArrowKeySelection() + ", " +
354
					getConfigurationPanel().isSelectedJCheckBoxDisplayAllItemsWithArrowButton() + ", " +
355
					cellRenderer + ", " +
356
					itemsOrderText + ", " +
357
					getConfigurationPanel().isSelectedJCheckBoxShowAllItemsInListBox() + ", " + languageRule + ", " +
358
					getConfigurationPanel().isSelectedJCheckBoxCaseSensitive() + ")\n");
359
		}
360
		else {
361
			switch(model.getItemsOrder()) {
362
				case DefaultComboBoxConfigurableLookUpModel.MAINTAIN_POSITION:
363
					itemsOrderText = Messages.getText("maintain_position");
364
					break;
365
				case DefaultComboBoxConfigurableLookUpModel.ALPHABETICAL_ORDERED:
366
					itemsOrderText = Messages.getText("alphabetical_ordered");
367
					break;
368
				case DefaultComboBoxConfigurableLookUpModel.MAINTAIN_AGENT_POSITIONS:
369
					itemsOrderText = Messages.getText("agent_positions");
370
					break;
371
			}
372
			
373
			// Write the log
374
			getOtherTestsPanel().getJTextAreaLog().append('(' + Messages.getText("test") + " " + String.valueOf(testNumber) + ", " +
375
					Messages.getText("creaction") + ": " + argument + Messages.getText("configuration") + ": " + comboBox.isOnlyOneColorOnText() + ", " +
376
					 comboBox.isBeepEnabled() + ", " + comboBox.isHidePopupIfThereAreNoItems() + ", " + comboBox.isToForceSelectAnItem() + ", " +
377
					 comboBox.isCompleteArrowKeySelection() + ", " + comboBox.isDisplayAllItemsWithArrowButton() + ", " + cellRenderer + ", " +
378
					 itemsOrderText + ", " + model.isShowAllItemsInListBox() + ", " + model.getLocaleRules() + ", " + model.isCaseSensitive() + ")\n");
379
		}
380

  
381
		return comboBox;
382
	}
383

  
384
	/**
385
	 * <p>A JPanel for the configuration and create a new JComboBoxConfigurableLookUp for testing.</p>
386
	 *  
387
	 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
388
	 */
389
	private class ConfigurationJPanel extends JPanel implements Serializable {
390
		private static final long serialVersionUID = 6327342028864667372L;
391

  
392
		private final int configurationPanelWidth = 310;
393
		private final int configurationPanelHeight = 570;
394
		private final int subPanelWidth = 280;
395
		private final int subPanelHeight = 28;
396
		private final int buttonWidth = 90;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff