Revision 11565 trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/propertiespanel/PropertiesComponent.java
PropertiesComponent.java | ||
---|---|---|
76 | 76 |
this.setViewportView(jPanelContent); |
77 | 77 |
} |
78 | 78 |
|
79 |
int y = 0; |
|
79 | 80 |
/** |
80 |
* A?ade una clave/valor al panel de propiedades.<br> |
|
81 |
* <br> |
|
82 |
* El componente seleccionado dependera del instanceof del valor y las |
|
83 |
* opciones extras que se pongan. Por ejemplo: para el instanceof de un String |
|
84 |
* siempre se usara un JTextField, en cambio, para un Integer, se podran usar |
|
85 |
* 3 tipos, el JSlider, JComboBox y JSpinner. Estos tipos se especifican en el |
|
86 |
* array extras, poniendolo siempre en la posicion 0. En la posici?n 1 y 2 de |
|
87 |
* un JSlider se puede especificar el m?nimo y el m?ximo del Slider. |
|
88 |
* |
|
89 |
* @param textLabel |
|
90 |
* @param key |
|
91 |
* @param value |
|
92 |
* @param extras |
|
81 |
* A?ade un PropertyStruct al componente |
|
82 |
* @param property |
|
93 | 83 |
*/ |
94 |
int y = 0; |
|
95 |
|
|
96 | 84 |
public void addPropertyStruct(PropertyStruct property) { |
97 |
JLabel label = new JLabel(property.textLabel + ": ");
|
|
85 |
JLabel label = new JLabel(property.getTextLabel() + ": ");
|
|
98 | 86 |
|
99 | 87 |
jPanelContent.add(label, new GridBagConstraints(0, y, 1, 1, 0.0, 0.0, |
100 | 88 |
GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
... | ... | |
103 | 91 |
Component component = null; |
104 | 92 |
|
105 | 93 |
// Tratamiento de Strings, como un JTextField |
106 |
if (property.oldValue instanceof String) {
|
|
107 |
component = new JTextField(property.oldValue.toString());
|
|
94 |
if (property.getOldValue() instanceof String) {
|
|
95 |
component = new JTextField(property.getOldValue().toString());
|
|
108 | 96 |
((JTextField) component).setMaximumSize(new Dimension(200, 25)); |
109 | 97 |
} |
110 | 98 |
|
111 | 99 |
// Tratamiento de Integer |
112 |
if (property.oldValue instanceof Integer) {
|
|
100 |
if (property.getOldValue() instanceof Integer) {
|
|
113 | 101 |
boolean created = false; |
114 |
if (property.extras != null) {
|
|
115 |
switch (((Integer) property.extras[0]).intValue()) {
|
|
102 |
if (property.getExtras() != null) {
|
|
103 |
switch (((Integer) property.getExtras()[0]).intValue()) {
|
|
116 | 104 |
case TYPE_SLIDER: |
117 | 105 |
component = new JSlider(); |
118 |
if (property.extras.length >= 2)
|
|
119 |
((JSlider) component).setMinimum(((Integer) property.extras[1]).intValue());
|
|
120 |
if (property.extras.length >= 3)
|
|
121 |
((JSlider) component).setMaximum(((Integer) property.extras[2]).intValue());
|
|
122 |
((JSlider) component).setValue(((Integer) property.oldValue).intValue());
|
|
106 |
if (property.getExtras().length >= 2)
|
|
107 |
((JSlider) component).setMinimum(((Integer) property.getExtras()[1]).intValue());
|
|
108 |
if (property.getExtras().length >= 3)
|
|
109 |
((JSlider) component).setMaximum(((Integer) property.getExtras()[2]).intValue());
|
|
110 |
((JSlider) component).setValue(((Integer) property.getOldValue()).intValue());
|
|
123 | 111 |
((JSlider)component).setMajorTickSpacing(10); |
124 | 112 |
((JSlider)component).setMinorTickSpacing(5); |
125 | 113 |
((JSlider)component).setPaintTicks(true); |
... | ... | |
128 | 116 |
break; |
129 | 117 |
case TYPE_COMBO: |
130 | 118 |
component = new JComboBox(); |
131 |
ArrayList aux = (ArrayList) property.extras[1];
|
|
119 |
ArrayList aux = (ArrayList) property.getExtras()[1];
|
|
132 | 120 |
for (int i=0; i<aux.size(); i++) |
133 | 121 |
((JComboBox) component).addItem(aux.get(i).toString()); |
134 |
((JComboBox) component).setSelectedIndex(((Integer) property.oldValue).intValue());
|
|
122 |
((JComboBox) component).setSelectedIndex(((Integer) property.getOldValue()).intValue());
|
|
135 | 123 |
created = true; |
136 | 124 |
break; |
137 | 125 |
} |
138 | 126 |
} |
139 | 127 |
if (!created) { |
140 | 128 |
component = new JSpinner(); |
141 |
((JSpinner) component).setValue(property.oldValue);
|
|
129 |
((JSpinner) component).setValue(property.getOldValue());
|
|
142 | 130 |
} |
143 | 131 |
} |
144 | 132 |
|
145 | 133 |
// Tratamiento de Boolean |
146 |
if (property.oldValue instanceof Boolean) {
|
|
134 |
if (property.getOldValue() instanceof Boolean) {
|
|
147 | 135 |
component = new JCheckBox(); |
148 |
((JCheckBox) component).setSelected(((Boolean) property.oldValue).booleanValue());
|
|
136 |
((JCheckBox) component).setSelected(((Boolean) property.getOldValue()).booleanValue());
|
|
149 | 137 |
} |
150 | 138 |
|
151 | 139 |
jPanelContent.add(component, new GridBagConstraints(1, y, 1, 1, 0.0, 0.0, |
... | ... | |
156 | 144 |
label.setLabelFor(component); |
157 | 145 |
label.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
158 | 146 |
|
159 |
property.jLabel = label;
|
|
160 |
property.component = component;
|
|
147 |
property.setJLabel(label);
|
|
148 |
property.setComponent(component);
|
|
161 | 149 |
datalist.add(property); |
162 | 150 |
} |
163 | 151 |
|
152 |
/** |
|
153 |
* A?ade una clave/valor al panel de propiedades.<br> |
|
154 |
* <br> |
|
155 |
* El componente seleccionado dependera del instanceof del valor y las |
|
156 |
* opciones extras que se pongan. Por ejemplo: para el instanceof de un String |
|
157 |
* siempre se usara un JTextField, en cambio, para un Integer, se podran usar |
|
158 |
* 3 tipos, el JSlider, JComboBox y JSpinner. Estos tipos se especifican en el |
|
159 |
* array extras, poniendolo siempre en la posicion 0. En la posici?n 1 y 2 de |
|
160 |
* un JSlider se puede especificar el m?nimo y el m?ximo del Slider. |
|
161 |
* |
|
162 |
* @param textLabel |
|
163 |
* @param key |
|
164 |
* @param value |
|
165 |
* @param extras |
|
166 |
*/ |
|
167 |
|
|
164 | 168 |
public void addValue(String textLabel, String key, Object value, Object[] extras) { |
165 |
PropertyStruct propertyStruct = new PropertyStruct(); |
|
166 |
propertyStruct.textLabel = textLabel; |
|
167 |
propertyStruct.key = key; |
|
168 |
propertyStruct.oldValue = value; |
|
169 |
propertyStruct.extras = extras; |
|
169 |
PropertyStruct propertyStruct = new PropertyStruct(textLabel, key, value, extras); |
|
170 | 170 |
addPropertyStruct(propertyStruct); |
171 | 171 |
} |
172 | 172 |
|
... | ... | |
184 | 184 |
for (int i=0; i<datalist.size(); i++) { |
185 | 185 |
PropertyStruct propertyStruct = ((PropertyStruct) datalist.get(i)); |
186 | 186 |
|
187 |
if (propertyStruct.component instanceof JTextField) {
|
|
188 |
propertyStruct.newValue = ((JTextField) propertyStruct.component).getText();
|
|
187 |
if (propertyStruct.getComponent() instanceof JTextField) {
|
|
188 |
propertyStruct.setNewValue(((JTextField) propertyStruct.getComponent()).getText());
|
|
189 | 189 |
continue; |
190 | 190 |
} |
191 |
if (propertyStruct.component instanceof JSpinner) {
|
|
192 |
propertyStruct.newValue = ((JSpinner) propertyStruct.component).getValue();
|
|
191 |
if (propertyStruct.getComponent() instanceof JSpinner) {
|
|
192 |
propertyStruct.setNewValue(((JSpinner) propertyStruct.getComponent()).getValue());
|
|
193 | 193 |
continue; |
194 | 194 |
} |
195 |
if (propertyStruct.component instanceof JSlider) {
|
|
196 |
propertyStruct.newValue = new Integer(((JSlider) propertyStruct.component).getValue());
|
|
195 |
if (propertyStruct.getComponent() instanceof JSlider) {
|
|
196 |
propertyStruct.setNewValue(new Integer(((JSlider) propertyStruct.getComponent()).getValue()));
|
|
197 | 197 |
continue; |
198 | 198 |
} |
199 |
if (propertyStruct.component instanceof JCheckBox) {
|
|
200 |
propertyStruct.newValue = new Boolean(((JCheckBox) propertyStruct.component).getSelectedObjects()!=null);
|
|
199 |
if (propertyStruct.getComponent() instanceof JCheckBox) {
|
|
200 |
propertyStruct.setNewValue(new Boolean(((JCheckBox) propertyStruct.getComponent()).getSelectedObjects()!=null));
|
|
201 | 201 |
continue; |
202 | 202 |
} |
203 |
if (propertyStruct.component instanceof JComboBox) {
|
|
204 |
propertyStruct.newValue = new Integer(((JComboBox) propertyStruct.component).getSelectedIndex());
|
|
203 |
if (propertyStruct.getComponent() instanceof JComboBox) {
|
|
204 |
propertyStruct.setNewValue(new Integer(((JComboBox) propertyStruct.getComponent()).getSelectedIndex()));
|
|
205 | 205 |
continue; |
206 | 206 |
} |
207 | 207 |
} |
Also available in: Unified diff