Broke out textual parsing into another method to ease subclassing.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3025 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: FieldEditor.java,v 1.10 2004/04/05 23:44:28 eric Exp $
|
// $Id: FieldEditor.java,v 1.11 2004/06/15 03:25:19 ray Exp $
|
||||||
|
|
||||||
package com.threerings.admin.client;
|
package com.threerings.admin.client;
|
||||||
|
|
||||||
@@ -94,62 +94,59 @@ public class FieldEditor extends JPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface
|
/**
|
||||||
public void actionPerformed (ActionEvent event)
|
* Parse the value.
|
||||||
|
*/
|
||||||
|
protected Object parseValue (String text)
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
Object value = null;
|
|
||||||
|
|
||||||
// parse the new value
|
// parse the new value
|
||||||
if (_field.getType().equals(Integer.class) ||
|
if (_field.getType().equals(Integer.class) ||
|
||||||
_field.getType().equals(Integer.TYPE)) {
|
_field.getType().equals(Integer.TYPE)) {
|
||||||
try {
|
return new Integer(text);
|
||||||
value = new Integer(_value.getText());
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
updateBorder(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (_field.getType().equals(Long.class) ||
|
} else if (_field.getType().equals(Long.class) ||
|
||||||
_field.getType().equals(Long.TYPE)) {
|
_field.getType().equals(Long.TYPE)) {
|
||||||
try {
|
return new Long(text);
|
||||||
value = new Long(_value.getText());
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
updateBorder(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (_field.getType().equals(Float.class) ||
|
} else if (_field.getType().equals(Float.class) ||
|
||||||
_field.getType().equals(Float.TYPE)) {
|
_field.getType().equals(Float.TYPE)) {
|
||||||
try {
|
return new Float(text);
|
||||||
value = new Float(_value.getText());
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
updateBorder(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (_field.getType().equals(Double.class) ||
|
} else if (_field.getType().equals(Double.class) ||
|
||||||
_field.getType().equals(Double.TYPE)) {
|
_field.getType().equals(Double.TYPE)) {
|
||||||
try {
|
return new Double(text);
|
||||||
value = new Double(_value.getText());
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
updateBorder(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (_field.getType().equals(String.class)) {
|
} else if (_field.getType().equals(String.class)) {
|
||||||
value = _value.getText();
|
return text;
|
||||||
|
|
||||||
} else if (_field.getType().equals(STRING_ARRAY_PROTO.getClass())) {
|
} else if (_field.getType().equals(STRING_ARRAY_PROTO.getClass())) {
|
||||||
value = StringUtil.parseStringArray(_value.getText());
|
return StringUtil.parseStringArray(_value.getText());
|
||||||
|
|
||||||
} else if (_field.getType().equals(INT_ARRAY_PROTO.getClass())) {
|
} else if (_field.getType().equals(INT_ARRAY_PROTO.getClass())) {
|
||||||
value = StringUtil.parseIntArray(_value.getText());
|
return StringUtil.parseIntArray(_value.getText());
|
||||||
|
|
||||||
} else if (_field.getType().equals(FLOAT_ARRAY_PROTO.getClass())) {
|
} else if (_field.getType().equals(FLOAT_ARRAY_PROTO.getClass())) {
|
||||||
value = StringUtil.parseFloatArray(_value.getText());
|
return StringUtil.parseFloatArray(_value.getText());
|
||||||
|
|
||||||
} else if (_field.getType().equals(Boolean.TYPE)) {
|
} else if (_field.getType().equals(Boolean.TYPE)) {
|
||||||
value = new Boolean(_value.getText().equalsIgnoreCase("true"));
|
return new Boolean(_value.getText().equalsIgnoreCase("true"));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.warning("Unknown field type '" + _field.getName() + "': " +
|
Log.warning("Unknown field type '" + _field.getName() + "': " +
|
||||||
_field.getType().getName() + ".");
|
_field.getType().getName() + ".");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface
|
||||||
|
public void actionPerformed (ActionEvent event)
|
||||||
|
{
|
||||||
|
Object value = null;
|
||||||
|
try {
|
||||||
|
value = parseValue(_value.getText());
|
||||||
|
} catch (Exception e) {
|
||||||
|
updateBorder(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// submit an attribute changed event with the new value
|
// submit an attribute changed event with the new value
|
||||||
|
|||||||
Reference in New Issue
Block a user