Revision 11315

View differences:

trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/defaultbuttonspanel/TestDefaultButtonsPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
package org.gvsig.gui.beans.defaultbuttonspanel;
20

  
21
import java.awt.BorderLayout;
22

  
23
import javax.swing.JButton;
24
import javax.swing.JFrame;
25
import javax.swing.UIManager;
26

  
27
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
28
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
29
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
30
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
31
/**
32
 * <code>TestDialogPanel</code>. Test para comprobar el funcionamiento de la
33
 * clase <code>DialogPanel</code>
34
 * 
35
 * @version 15/03/2007
36
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
37
 */
38
public class TestDefaultButtonsPanel implements ButtonsPanelListener {
39
	private JFrame frame = new JFrame();
40

  
41
	class NewComponentDialog extends DefaultButtonsPanel {
42
		private static final long serialVersionUID = 4452922507292538671L;
43

  
44
		public NewComponentDialog() {
45
			super(ButtonsPanel.BUTTONS_YESNO);
46
			this.setLayout(new BorderLayout());
47
			JButton b = new JButton("prueba");
48
			this.add(b, java.awt.BorderLayout.NORTH);
49
			JButton c = new JButton("prueba2");
50
			this.add(c, java.awt.BorderLayout.CENTER);
51
		}
52
	}
53

  
54
	NewComponentDialog ncd;
55

  
56
	public TestDefaultButtonsPanel() {
57
		ncd = new NewComponentDialog();
58

  
59
		frame.setSize(640, 480);
60
		frame.getContentPane().add(ncd);
61
		frame.show();
62

  
63
		ncd.addButtonPressedListener(this);
64
		frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
65
	}
66

  
67
	public static void main(String[] args) {
68
		try {
69
			UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
70
		} catch (Exception e) {
71
			System.err.println("No se puede cambiar al LookAndFeel");
72
		}
73

  
74
		new TestDefaultButtonsPanel();
75
	}
76

  
77
	public void actionButtonPressed(ButtonsPanelEvent e) {
78
		System.out.println("Bot?n pulsado: " + e.getButton());
79
	}
80
}
0 81

  
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/propertiesdialog/TestPropertiesDialog.java
5 5
import javax.swing.JFrame;
6 6
import javax.swing.UIManager;
7 7

  
8
public class TestPropertiesDialog {
8
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
9
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
10
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
11
import org.gvsig.gui.beans.propertiesdialog.PropertiesDialog.PropertyStruct;
12

  
13
public class TestPropertiesDialog implements ButtonsPanelListener {
9 14
	JFrame frame = null;
10 15
	PropertiesDialog pd = null;
11 16
	
......
21 26

  
22 27
		frame = new JFrame();
23 28
		pd = new PropertiesDialog();
29
		pd.addButtonPressedListener(this);
24 30
		pd.addValue("Protocolo", "protocolo", "texto", null);
25 31
		pd.addValue("Integer", "var1", new Integer(50), null);
26 32
		pd.addValue("Slider", "slider1", new Integer(50), type); // Slider
27
		pd.addValue("Slider", "slider2", new Integer(20), type); // Slider
28
		pd.addValue("Slider", "slider3", new Integer(80), type); // Slider
29
		pd.addValue("Protocolo", "protocolo2", "texto", null);
30
		pd.addValue("Slider", "slider4", new Integer(20), type); // Slider
31
		pd.addValue("Slider", "slider5", new Integer(80), type); // Slider
33
		pd.addValue("Activo", "check1", new Boolean(true), null); // Slider
32 34

  
33 35
		frame.getContentPane().add(pd);
34 36
		frame.show();
......
46 48
		
47 49
		new TestPropertiesDialog();
48 50
	}
51

  
52
	public void actionButtonPressed(ButtonsPanelEvent e) {
53
		if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
54
			ArrayList values = pd.getValues();
55
			System.out.println("-----");
56
			for (int i=0; i<values.size(); i++) {
57
				System.out.println(((PropertyStruct)values.get(i)).key + " (old): " + ((PropertyStruct)values.get(i)).oldValue.toString());
58
				System.out.println(((PropertyStruct)values.get(i)).key + " (new): " + ((PropertyStruct)values.get(i)).newValue.toString());
59
			}
60
		}
61
		
62
	}
49 63
}
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/propertiesdialog/PropertiesDialog.java
25 25
import java.util.Enumeration;
26 26
import java.util.Hashtable;
27 27

  
28
import javax.swing.JCheckBox;
28 29
import javax.swing.JLabel;
29 30
import javax.swing.JPanel;
30 31
import javax.swing.JScrollPane;
......
45 46
	private static final long serialVersionUID = 372118344763661890L;
46 47
	JScrollPane jScrollPane = null;
47 48
	JPanel jPanelContent = null;
48
	Hashtable datalist = new Hashtable();
49
	ArrayList datalist = new ArrayList();
49 50
	
50 51
	static final public int TYPE_DEFAULT = 1; 
51 52
	static final public int TYPE_SLIDER = 2; 
......
70 71
	
71 72
	public void resizeLabels() {
72 73
		int max = 0;
73
		for (Enumeration e = datalist.elements(); e.hasMoreElements();) {
74
			ArrayList list = (ArrayList) e.nextElement();
75
			JLabel label = (JLabel) list.get(2);
74
		for (int i=0; i<datalist.size(); i++) {
75
			JLabel label = ((PropertyStruct) datalist.get(i)).jLabel;
76 76
			int aux = (int) label.getWidth();
77 77
			if (max < aux)
78 78
				max = aux;
79 79
		}
80 80
		if (max == 0) max = 32676;
81
		for (Enumeration e = datalist.elements(); e.hasMoreElements();) {
82
			ArrayList list = (ArrayList) e.nextElement();
83
			JLabel label = (JLabel) list.get(2);
81
		for (int i=0; i<datalist.size(); i++) {
82
			JLabel label = ((PropertyStruct) datalist.get(i)).jLabel;
84 83
			label.setMaximumSize(new Dimension(max, 80));
85 84
			label.setMinimumSize(new Dimension(max, 80));
86 85
			label.setPreferredSize(new Dimension(max, 80));
......
98 97
		JLabel label = new JLabel(textLabel + ": ");
99 98
		jPaneltmp.add(label);
100 99
		Component component = null;
100
		
101
		// Tratamiento de Strings, como un JTextField
101 102
		if (value instanceof String) {
102 103
			component = new JTextField(value.toString());
103 104
			((JTextField) component).setMaximumSize(new Dimension(200, 25));
104 105
		}
106
		
107
		// Tratamiento de Integer
105 108
		if (value instanceof Integer) {
106 109
			boolean created = false;
107 110
			if (extras != null) {
......
126 129
			}
127 130
		}
128 131
		
132
		// Tratamiento de Boolean
133
		if (value instanceof Boolean) {
134
			component = new JCheckBox();
135
			((JCheckBox) component).setSelected(((Boolean) value).booleanValue());
136
		}
129 137
		
130 138
		jPaneltmp.add(component);
131 139
		jPanelContent.add(jPaneltmp);
132 140
		label.setLabelFor(component);
133 141
		label.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
134 142
		
135
		ArrayList values = new ArrayList();
136
		values.add(value);
137
		values.add(extras);
138
		values.add(label);
139
		values.add(component);
140
		datalist.put(key, values);
143
		PropertyStruct propertyStruct = new PropertyStruct();
144
		propertyStruct.key = key;
145
		propertyStruct.oldValue = value;
146
		propertyStruct.extras = extras;
147
		propertyStruct.jLabel = label;
148
		propertyStruct.component = component;
149

  
150
		datalist.add(propertyStruct);
141 151
	}
142 152

  
153
	public ArrayList getValues() {
154
		for (int i=0; i<datalist.size(); i++) {
155
			PropertyStruct propertyStruct = ((PropertyStruct) datalist.get(i));
143 156

  
157
			if (propertyStruct.component instanceof JTextField) {
158
				propertyStruct.newValue = ((JTextField) propertyStruct.component).getText();
159
				continue;
160
			}
161
			if (propertyStruct.component instanceof JSpinner) {
162
				propertyStruct.newValue = ((JSpinner) propertyStruct.component).getValue();
163
				continue;
164
			}
165
			if (propertyStruct.component instanceof JSlider) {
166
				propertyStruct.newValue = new Integer(((JSlider) propertyStruct.component).getValue());
167
				continue;
168
			}
169
			if (propertyStruct.component instanceof JCheckBox) {
170
				propertyStruct.newValue = new Boolean(((JCheckBox) propertyStruct.component).getSelectedObjects()!=null);
171
				continue;
172
			}
173
		}
174
		return datalist;
175
	}
176
	
177
	public class PropertyStruct {
178
		public String key;
179
		public Object oldValue;
180
		public Object newValue;
181
		public ArrayList extras;
182
		public JLabel jLabel;
183
		public Component component;
184
	}
185

  
144 186
}

Also available in: Unified diff