Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / test / java / org / gvsig / gui / beans / swing / jComboBoxWithImageIconItems / TestJComboBoxWithImageIconItems.java @ 40561

History | View | Annotate | Download (9.21 KB)

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.swing.jComboBoxWithImageIconItems;
25

    
26
import java.awt.Dimension;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.util.Vector;
30

    
31
import javax.swing.JFrame;
32

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

    
74
/**
75
 * Tests JPanelWithJComboBoxImageItems
76
 * 
77
 * This code has been extracted and modified from the Java Sun Microsystems's example: 'CustomComboBoxDemo.java'
78
 *   in http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
79
 * 
80
 * @author Sun Microsystems
81
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
82
 */
83
public class TestJComboBoxWithImageIconItems {
84
    /**
85
     * Main test method
86
     * 
87
     * @param args Arguments
88
     */
89
    public static void main(String[] args) {
90
            /**
91
             * Schedule a job for the event-dispatching thread:
92
             * creating and showing this application's GUI.
93
             */
94
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
95
                /*
96
                 * (non-Javadoc)
97
                 * @see java.lang.Runnable#run()
98
                 */
99
            public void run() {
100
                createAndShowGUI();
101
            }
102
        });
103
    }
104

    
105
    /**
106
     * Create the GUI and show it.  For thread safety,
107
     * this method should be invoked from the
108
     * event-dispatching thread.
109
     */
110
    private static void createAndShowGUI() {
111
        //Create and set up the window.
112
        JFrame frame = new JFrame("Test TestJComboBoxWithImageIconItems");
113
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
114

    
115
        //Create and set up the content pane.
116
        JComboBoxWithImageIconItems component = new JComboBoxWithImageIconItems(); 
117
        component.setOpaque(true); //content panes must be opaque
118
        frame.setContentPane(component);
119
        component.addActionListener(new ActionListener() {
120
                /*
121
                 *  (non-Javadoc)
122
                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
123
                 */
124
                        public void actionPerformed(ActionEvent e) {                
125
                                JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
126
                                ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
127
                                if (iiii != null) {
128
                                        String value = (String)iiii.getItemValue();
129
                                        if (value != null)
130
                                                System.out.println("Seleccionado item con null: " + value);
131
                                        else
132
                                                System.out.println("Seleccionado item con con valor null");
133
                                }
134
                        }
135
                
136
        });
137
        
138
        /**** METHOD TESTS ****/
139

    
140
        /**** Don't Remove any test! ****/
141
        /**** Some tests could be commented but not removed! ****/
142

    
143
        // Test 'setJComboBoxRendererPreferredSize' method
144
        component.setJComboBoxRendererPreferredSize(new Dimension(150, 80));
145

    
146
        // Test 'getJComboBoxRendererPreferredSize' method
147
        System.out.println("JComboBox Renderer Preferred Size: " + component.getJComboBoxRendererPreferredSize());
148

    
149
        // Data samples
150
        ImageIconItemInfo backward = new ImageIconItemInfo("images/backward.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "images/backward.png"), "Retroceder", null);
151
        ImageIconItemInfo fastbackward = new ImageIconItemInfo("images/fastbackward.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "images/fastbackward.png"), "Retroceso r?pido", null);
152
        ImageIconItemInfo forward = new ImageIconItemInfo("images/forward.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "images/forward.png"), "Avanzar", "Avanzar");
153
        ImageIconItemInfo fastforward = new ImageIconItemInfo("images/fastforward.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "images/fastforward.png"), "Avance r?pido", null);
154
        
155
        ImageIconItemInfo error1 = new ImageIconItemInfo("Error1.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "Error1.png"),"Error 1", "Error 1");
156
        ImageIconItemInfo error2 = new ImageIconItemInfo("Error2.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "Error2.png"),"Error 2", null);
157
        ImageIconItemInfo error3 = new ImageIconItemInfo("Error3.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "Error3.png"),"Error 3", "Error 3");
158
        ImageIconItemInfo error4 = new ImageIconItemInfo("Error4.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "Error4.png"),"Error 4", null);
159
        ImageIconItemInfo error5 = new ImageIconItemInfo("Error5.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "Error5.png"),"Error 5", "Error 5");
160
        ImageIconItemInfo error6 = new ImageIconItemInfo("Error6.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "Error6.png"),"Error 6", null);
161
        ImageIconItemInfo error7 = new ImageIconItemInfo("Error7.png", ImageIconItemInfoUtils.createImageIcon(TestJComboBoxWithImageIconItems.class, "Error7.png"),"Error 5", null);
162
        
163
        // Test 'addImageIcon' method
164
        component.addImageIconItem(backward);
165
        component.addImageIconItem(error1);
166
        
167
        // Test 'removeImageIcon' method
168
        component.removeImageIconItem(backward);
169
        component.removeImageIconItem(error2);
170
        component.removeImageIconItem(error1);
171

    
172
        // Test 'getMaximumRowCount' method
173
        System.out.println("N?mero de filas por defecto: " + component.getMaximumRowCount());
174

    
175
        // Test 'setMaximumRowCount' method
176
        component.setMaximumRowCount(4);
177

    
178
        // Test 'getMaximumJComboBoxRowCount' method
179
        System.out.println("N?mero de filas despues de modificarlo el atributo: " + component.getMaximumRowCount());
180

    
181
        // Tests 'addImageIcons(String [])' method
182
        ImageIconItemInfo[] icons = {backward, forward, forward, // Duplicated 'forward.png'
183
                        error3, fastbackward, fastforward};
184
        component.addImageIconItems(icons);
185

    
186
        // Tests 'removeAllImageIcons' method
187
        component.removeAllImageIconItems();
188

    
189
        // Tests 'removeImageIcons(String [])' method
190
        component.addImageIconItems(icons);
191
        ImageIconItemInfo[] icons2 = {error3, error4, forward};
192
        component.removeImageIconItems(icons2);
193

    
194
        // Tests 'addImageIcons(Vector)' method
195
        Vector icons3 = new Vector();
196
        icons3.add(forward); // Allow repeated items
197
        icons3.add(error5);
198
        icons3.add(backward); // Allow repeated items
199
        icons3.add(error6);
200
        component.addImageIconItems(icons3);
201

    
202
        // Tests 'setShowImageIconAndTextProperty' method
203
        component.setShowImageIconAndTextProperty(true);
204
        component.setShowImageIconAndTextProperty(false);
205

    
206
        // Tests 'removeImageIcons(Vector)' method
207
        Vector icons4 = new Vector();
208
        icons4.add(forward); // Remove a repeted item (only one time)
209
        icons4.add(error6);
210
        icons4.add(error7); // Tries to remove an item but its tool tip text it's incorrect and then it can't remove this item
211
        component.removeImageIconItems(icons4);
212

    
213
        /**** END METHOD TESTS ****/
214

    
215
        //Display the window.
216
        frame.pack();
217
        frame.setVisible(true);
218
    }
219
}