Revision 507
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.field/src/main/java/org/gvsig/tools/swing/serv/field/component/JNumberDynFieldComponent.java | ||
---|---|---|
36 | 36 |
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener; |
37 | 37 |
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent; |
38 | 38 |
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField; |
39 |
import org.gvsig.tools.swing.serv.field.component.date.JNullValueMuttableTextFieldComponent; |
|
40 |
import org.gvsig.tools.swing.serv.field.component.date.NullValueMuttableModel; |
|
39 | 41 |
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent; |
40 | 42 |
|
41 | 43 |
/** |
... | ... | |
51 | 53 |
private static Object NULL_VALUE = null; |
52 | 54 |
private static final String BTN_EMPTY_IMG_PATH = "editdelete.png"; |
53 | 55 |
|
54 |
private JNullValueMuttableTextField pane; |
|
56 |
private JNullValueMuttableTextFieldComponent pane;
|
|
55 | 57 |
|
56 | 58 |
/** |
57 | 59 |
* @param parent |
... | ... | |
79 | 81 |
* @see org.gvsig.tools.swing.api.dynobject.JComponent#getComponent() |
80 | 82 |
*/ |
81 | 83 |
public JComponent asJComponent() { |
82 |
return this.getModel();
|
|
84 |
return this.pane;
|
|
83 | 85 |
} |
84 | 86 |
|
85 | 87 |
protected ImageIcon getBtnEmptyImageIcon() { |
86 |
return new ImageIcon(org.gvsig.tools.swing.serv.field.component.date.JDateDynFieldComponent.class.getResource(BTN_EMPTY_IMG_PATH));
|
|
88 |
return new ImageIcon(org.gvsig.tools.swing.serv.field.component.JNumberDynFieldComponent.class.getResource(BTN_EMPTY_IMG_PATH));
|
|
87 | 89 |
} |
88 | 90 |
|
89 |
private JNullValueMuttableTextField getModel() { |
|
90 |
return this.pane; |
|
91 |
} |
|
92 |
|
|
91 |
|
|
93 | 92 |
/* |
94 | 93 |
* (non-Javadoc) |
95 | 94 |
* |
... | ... | |
102 | 101 |
return getModel().getTextFieldValue(); |
103 | 102 |
} |
104 | 103 |
|
104 |
private NullValueMuttableModel getModel() { |
|
105 |
return this.pane.getModel(); |
|
106 |
} |
|
107 |
|
|
105 | 108 |
public void handleValueChanged(JDynFieldComponent field) { |
106 | 109 |
this.fireValueChangedEvent(); |
107 | 110 |
} |
... | ... | |
121 | 124 |
@Override |
122 | 125 |
protected void initUI() { |
123 | 126 |
this.pane = |
124 |
new JNullValueMuttableTextField(this.getDynField(), this
|
|
127 |
new JNullValueMuttableTextFieldComponent(this, this
|
|
125 | 128 |
.getInitialValue(), Locale.getDefault(), getBtnEmptyImageIcon()); |
126 | 129 |
this.pane.addValueChangedListener(this); |
127 | 130 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.field/src/main/java/org/gvsig/tools/swing/serv/field/component/JTextFieldComponent.java | ||
---|---|---|
33 | 33 |
*/ |
34 | 34 |
package org.gvsig.tools.swing.serv.field.component; |
35 | 35 |
|
36 |
import java.awt.Component; |
|
36 |
import java.awt.BorderLayout; |
|
37 |
import java.awt.GridBagConstraints; |
|
38 |
import java.awt.GridBagLayout; |
|
39 |
import java.awt.Insets; |
|
37 | 40 |
import java.awt.event.KeyEvent; |
38 | 41 |
import java.awt.event.KeyListener; |
39 | 42 |
|
40 | 43 |
import javax.swing.BorderFactory; |
44 |
import javax.swing.BoxLayout; |
|
41 | 45 |
import javax.swing.JComponent; |
42 | 46 |
import javax.swing.JLabel; |
47 |
import javax.swing.JPanel; |
|
43 | 48 |
import javax.swing.JTextArea; |
44 | 49 |
import javax.swing.text.JTextComponent; |
45 | 50 |
|
46 |
import org.gvsig.tools.dynobject.DynField; |
|
47 | 51 |
import org.gvsig.tools.service.ServiceException; |
52 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
48 | 53 |
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent; |
49 | 54 |
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField; |
50 | 55 |
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent; |
... | ... | |
76 | 81 |
@Override |
77 | 82 |
protected void afterUI() { |
78 | 83 |
// TODO Auto-generated method stub |
84 |
JComponent comp = asJComponent(); |
|
85 |
comp.setBorder(BorderFactory.createTitledBorder("")); |
|
86 |
if (isReadOnly()) { |
|
87 |
comp.setOpaque(false); |
|
88 |
} else { |
|
89 |
comp.setFont(comp.getFont().deriveFont(12f)); |
|
90 |
} |
|
79 | 91 |
|
80 | 92 |
} |
93 |
|
|
81 | 94 |
|
82 | 95 |
public JComponent asJComponent() { |
83 |
if (pane != null) { |
|
84 |
return pane; |
|
85 |
} |
|
86 |
if (label != null) { |
|
87 |
this.pane = createPane(label); |
|
88 |
} else |
|
89 |
if (jtext != null) { |
|
90 |
this.pane = createPane(jtext); |
|
91 |
// if (label != null) |
|
92 |
// return this.label; |
|
93 |
// else if (jtext != null) |
|
94 |
// return this.jtext; |
|
95 |
} |
|
96 | 96 |
|
97 |
return pane; |
|
97 |
if (isReadOnly()) { |
|
98 |
return this.label; |
|
99 |
} |
|
100 |
// JPanel pane = new JPanel(new GridBagLayout()); |
|
101 |
// GridBagConstraints constr = new GridBagConstraints(); |
|
102 |
// constr.anchor = GridBagConstraints.PAGE_START; |
|
103 |
// constr.insets = new Insets(5, 5, 5, 5); |
|
104 |
// constr.fill = GridBagConstraints.BOTH; |
|
105 |
// pane.add(jtext, constr); |
|
106 |
return jtext; |
|
107 |
|
|
98 | 108 |
} |
109 |
|
|
110 |
private JTextArea createTextArea(String text){ |
|
111 |
JTextArea ta = ToolsSwingLocator.getUsabilitySwingManager().createJTextArea(text, -1); |
|
112 |
ta.setEditable(!isReadOnly()); |
|
113 |
return ta; |
|
114 |
} |
|
99 | 115 |
|
100 |
private JComponent createPane(Component comp) { |
|
101 |
// JPanel pane = new JPanel(new GridBagLayout()); |
|
102 |
// GridBagConstraints constr = new GridBagConstraints(); |
|
103 |
// constr.insets = new Insets(3, 3, 3, 3); |
|
104 |
// constr.gridwidth = 1; |
|
105 |
// constr.fill = GridBagConstraints.REMAINDER; |
|
106 |
// pane.add(comp,constr); |
|
107 |
JTextArea tf = new JTextArea(); |
|
108 |
tf.setBorder(BorderFactory.createEtchedBorder()); |
|
109 |
tf.setText(getLabel()); |
|
110 |
if (this.getDynField().isReadOnly()) { |
|
111 |
tf.setEditable(false); |
|
112 |
tf.setOpaque(false); |
|
113 |
} else { |
|
114 |
tf.setFont(tf.getFont().deriveFont(12f)); |
|
115 |
tf.setRows(2); |
|
116 |
} |
|
116 |
private JComponent createPane(JComponent comp) { |
|
117 |
JPanel pane = new JPanel(new GridBagLayout()); |
|
118 |
GridBagConstraints constr = new GridBagConstraints(); |
|
119 |
constr.insets = new Insets(3, 3, 3, 3); |
|
120 |
constr.gridx = 0; |
|
121 |
constr.gridy = 0; |
|
122 |
|
|
123 |
constr.fill = GridBagConstraints.HORIZONTAL; |
|
124 |
|
|
125 |
pane.add(comp,constr); |
|
126 |
|
|
127 |
constr.gridx = 1; |
|
128 |
constr.gridy = 0; |
|
129 |
constr.fill = GridBagConstraints.NONE; |
|
130 |
pane.add(new JLabel("")); |
|
117 | 131 |
// JTextField tff = new JTextField(); |
118 | 132 |
// tff.setEditable(false); |
119 | 133 |
// tff.add(tf); |
120 | 134 |
// tf.setVisible(false); |
121 |
this.jtext = tf; |
|
122 |
return tf; |
|
135 |
return pane; |
|
123 | 136 |
} |
124 | 137 |
|
125 | 138 |
private String getLabel() { |
126 | 139 |
Object value = this.getInitialValue(); |
127 |
return (value == null) ? "" : value.toString(); |
|
140 |
return (value == null) ? "" : value.toString().trim();
|
|
128 | 141 |
} |
129 | 142 |
|
130 | 143 |
public Object getValue() { |
... | ... | |
136 | 149 |
if (jtext != null) { |
137 | 150 |
text = jtext.getText(); |
138 | 151 |
} |
152 |
if (text!=null){ |
|
153 |
text = text.trim(); |
|
154 |
} |
|
139 | 155 |
if (text.equals("")){ |
140 |
if (this.getDynField().isMandatory()){ |
|
141 |
text = (String)this.getDynField().getDefaultValue(); |
|
142 |
} else { |
|
143 |
text = null; |
|
144 |
} |
|
156 |
// if (this.getDynField().isMandatory()){ |
|
157 |
// text = (String)this.getDynField().getDefaultValue(); |
|
158 |
// } else { |
|
159 |
// text = null; |
|
160 |
// } |
|
161 |
return null; |
|
145 | 162 |
} |
163 |
|
|
146 | 164 |
return text; |
147 | 165 |
} |
148 | 166 |
|
... | ... | |
157 | 175 |
*/ |
158 | 176 |
@Override |
159 | 177 |
protected void initUI() { |
160 |
DynField field = this.getDynField(); |
|
161 |
if (field.isReadOnly()) { |
|
162 |
label = new JLabel(this.getLabel()); |
|
163 |
// label.setBorder(BorderFactory.createEmptyBorder(2, 10, 4, 4)); |
|
164 |
} else { |
|
165 |
// this.panel = new JPanel(new BorderLayout()); |
|
166 |
JTextArea textArea = new JTextArea(this.getLabel()); |
|
167 |
textArea.setFont(textArea.getFont().deriveFont(12f)); |
|
168 |
textArea.setWrapStyleWord(true); |
|
169 |
textArea.setLineWrap(true); |
|
170 |
// textArea.setBorder(BorderFactory.createEmptyBorder(4, 10, 4, 4)); |
|
171 |
jtext = textArea; |
|
172 |
// jtext.setBorder(BorderFactory.createLineBorder(Color.GRAY)); |
|
173 |
} |
|
178 |
// DynField field = this.getDynField(); |
|
179 |
// if (field.isReadOnly()) { |
|
180 |
// label = new JLabel(this.getLabel()); |
|
181 |
// // label.setBorder(BorderFactory.createEmptyBorder(2, 10, 4, 4)); |
|
182 |
// } else { |
|
183 |
// // this.panel = new JPanel(new BorderLayout()); |
|
184 |
// JTextArea textArea = new JTextArea(this.getLabel()); |
|
185 |
// textArea.setFont(textArea.getFont().deriveFont(12f)); |
|
186 |
// textArea.setWrapStyleWord(true); |
|
187 |
// textArea.setLineWrap(true); |
|
188 |
// // textArea.setBorder(BorderFactory.createEmptyBorder(4, 10, 4, 4)); |
|
189 |
// jtext = textArea; |
|
190 |
// // jtext.setBorder(BorderFactory.createLineBorder(Color.GRAY)); |
|
191 |
// } |
|
192 |
|
|
193 |
//Component not initialized yet |
|
194 |
|
|
195 |
if (isReadOnly()) { |
|
196 |
if (this.label==null){ |
|
197 |
this.label = new JLabel(getLabel()); |
|
198 |
// this.pane = createPane(label); |
|
199 |
} |
|
200 |
} else |
|
201 |
if (jtext == null) { |
|
202 |
this.jtext = createTextArea(getLabel()); |
|
203 |
// this.pane = createPane(jtext); |
|
204 |
} |
|
205 |
|
|
206 |
// return pane; |
|
174 | 207 |
} |
175 | 208 |
|
176 | 209 |
@Override |
... | ... | |
232 | 265 |
} |
233 | 266 |
|
234 | 267 |
protected void setNonNullValue(Object value) { |
268 |
String text = value.toString().trim(); |
|
235 | 269 |
if (label != null) { |
236 |
label.setText(value.toString());
|
|
270 |
label.setText(text);
|
|
237 | 271 |
} else { |
238 | 272 |
if (jtext != null) { |
239 |
jtext.setText(value.toString());
|
|
273 |
jtext.setText(text);
|
|
240 | 274 |
} |
241 | 275 |
} |
242 | 276 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.field/src/main/java/org/gvsig/tools/swing/serv/field/component/JFileDynfieldComponent.java | ||
---|---|---|
49 | 49 |
import org.gvsig.tools.service.ServiceException; |
50 | 50 |
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent; |
51 | 51 |
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField; |
52 |
import org.gvsig.tools.swing.components.file.JFileChooser;
|
|
52 |
import org.gvsig.tools.swing.serv.field.component.file.JFileChooser;
|
|
53 | 53 |
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent; |
54 | 54 |
|
55 | 55 |
/** |
... | ... | |
79 | 79 |
|
80 | 80 |
@Override |
81 | 81 |
protected void afterUI() { |
82 |
// TODO Auto-generated method stub |
|
82 |
|
|
83 | 83 |
|
84 | 84 |
} |
85 | 85 |
|
... | ... | |
99 | 99 |
return panel; |
100 | 100 |
} |
101 | 101 |
|
102 |
public Object getValue() { |
|
103 |
return file; |
|
104 |
} |
|
105 |
|
|
106 | 102 |
@Override |
107 | 103 |
protected void initData() { |
108 | 104 |
previousText = ""; |
... | ... | |
150 | 146 |
tfFile.setText(file.getAbsolutePath()); |
151 | 147 |
else |
152 | 148 |
tfFile.setText(""); |
149 |
if ((!isReadOnly())&&(!this.jBtnChangeFile.isVisible())){ |
|
150 |
this.jBtnChangeFile.setVisible(true); |
|
151 |
} |
|
153 | 152 |
} |
154 | 153 |
|
155 | 154 |
public void requestFocus() { |
... | ... | |
169 | 168 |
@Override |
170 | 169 |
protected void setReadOnly() { |
171 | 170 |
tfFile.setEditable(false); |
171 |
this.jBtnChangeFile.setVisible(false); |
|
172 | 172 |
} |
173 | 173 |
|
174 | 174 |
protected void setNullValue() { |
... | ... | |
222 | 222 |
return checkPath(path); |
223 | 223 |
} |
224 | 224 |
|
225 |
public Object getValue() { |
|
226 |
return this.file; |
|
227 |
} |
|
228 |
|
|
229 |
public String toString() { |
|
230 |
if (this.file == null){ |
|
231 |
return null; |
|
232 |
} |
|
233 |
return this.file.getAbsolutePath(); |
|
234 |
} |
|
225 | 235 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.field/src/main/java/org/gvsig/tools/swing/serv/field/component/JDefaultDynFieldComponent.java | ||
---|---|---|
40 | 40 |
public class JDefaultDynFieldComponent extends AbstractJDynFieldComponent |
41 | 41 |
implements JDynFieldComponent { |
42 | 42 |
|
43 |
// private JPanel panel; |
|
44 | 43 |
protected JLabel label; |
45 | 44 |
|
46 | 45 |
/** |
... | ... | |
78 | 77 |
return (value == null) ? "" : value.toString(); |
79 | 78 |
} |
80 | 79 |
|
81 |
/* |
|
82 |
* (non-Javadoc) |
|
83 |
* |
|
84 |
* @see |
|
85 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#getValue |
|
86 |
* () |
|
87 |
*/ |
|
88 |
@Override |
|
89 |
public Object getValue() { |
|
90 |
return label.getText(); |
|
91 |
} |
|
92 | 80 |
|
93 |
// /** |
|
94 |
// * Creates the component ui. |
|
95 |
// */ |
|
96 |
// private void initUI() { |
|
97 |
// // this.panel = new JPanel(); |
|
98 |
// // this.panel.setLayout(new BorderLayout()); |
|
99 |
// // this.panel.add(label, BorderLayout.CENTER); |
|
100 |
// } |
|
101 |
|
|
102 | 81 |
/* |
103 | 82 |
* (non-Javadoc) |
104 | 83 |
* |
... | ... | |
120 | 99 |
label = new JLabel(this.getLabel()); |
121 | 100 |
} |
122 | 101 |
|
123 |
/* |
|
124 |
* (non-Javadoc) |
|
125 |
* |
|
126 |
* @see |
|
127 |
* |
|
128 |
* |
|
129 |
* |
|
130 |
* |
|
131 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#isMandatory |
|
132 |
* () |
|
133 |
*/ |
|
134 | 102 |
@Override |
135 | 103 |
public boolean isMandatory() { |
136 | 104 |
return this.getDynField().isMandatory(); |
137 | 105 |
} |
138 | 106 |
|
139 |
/* |
|
140 |
* (non-Javadoc) |
|
141 |
* |
|
142 |
* @see |
|
143 |
* |
|
144 |
* |
|
145 |
* |
|
146 |
* |
|
147 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#requestFocus |
|
148 |
* () |
|
149 |
*/ |
|
150 | 107 |
public void requestFocus() { |
151 | 108 |
label.requestFocus(); |
152 | 109 |
} |
153 | 110 |
|
154 |
/* |
|
155 |
* (non-Javadoc) |
|
156 |
* |
|
157 |
* @see |
|
158 |
* |
|
159 |
* |
|
160 |
* |
|
161 |
* |
|
162 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#setEnabled |
|
163 |
* (boolean) |
|
164 |
*/ |
|
165 | 111 |
public void setEnabled(boolean isEnabled) { |
166 | 112 |
label.setEnabled(isEnabled); |
167 | 113 |
} |
... | ... | |
194 | 140 |
protected void setNullValue() { |
195 | 141 |
label.setText(""); |
196 | 142 |
} |
143 |
|
|
197 | 144 |
|
198 |
/* |
|
199 |
* (non-Javadoc) |
|
200 |
* |
|
201 |
* @see org.gvsig.tools.swing.spi.AbstractJDynFieldComponent#setReadOnly() |
|
202 |
*/ |
|
203 |
@Override |
|
204 | 145 |
protected void setReadOnly() { |
205 | 146 |
// Do nothing. Label is already ReadOnly |
206 | 147 |
} |
148 |
|
|
149 |
@Override |
|
150 |
public Object getValue() { |
|
151 |
return label.getText(); |
|
152 |
} |
|
207 | 153 |
} |
Also available in: Unified diff