changeaction.java
字号:
package piy.action;
import piy.*;
import java.lang.reflect.*;
import java.io.Serializable;
/**
* PIYAction to change a property in a component to a different value.
* @author David Vivash
* @version 1.0, 22/03/01
*/
public class ChangeAction implements PIYAction, Serializable {
private Property toChange = null; //the property to be changed
private Object value = null; //what to change the property to
public Object execute() {
if ((toChange != null) && (value != null)) {
try{
Method toInvoke = toChange.getHolder().getClass().getMethod("set" + toChange.getName(),
new Class[] { toChange.getType() });
if (value instanceof FixedProperty) //dynamically bound
toInvoke.invoke(toChange.getHolder(), new Object[] { ((FixedProperty)value).getActualValue() });
} catch (Exception e) {
System.err.println("Unable to to execute the Change PIYAction.");
}
}
return null;
}
public Class getReturnType() {
return null;
}
public Property getChange() { return toChange; }
public void setChange(Property change) { toChange = change; }
public Object getTo() { return value; }
public void setTo(Object value) { this.value = value; }
/**
* Tell PIY what property the To property is dependent on.
* @return the property which To relies on
*/
public Property getToBinding() {
return new Property(this, "Change", toChange == null ? null : toChange.getType());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -