changeaction.java

来自「PIY(Program It Yourself)是一个基于Java的应用程序开发」· Java 代码 · 共 53 行

JAVA
53
字号
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 + =
减小字号Ctrl + -
显示快捷键?