欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

fixedproperty.java

PIY(Program It Yourself)是一个基于Java的应用程序开发环境
JAVA
字号:
package piy;

import java.io.Serializable;

/**
* Represents a property type which is fixed.  The editor for this type allows the user to
* use a standard piy editor, or to bind the value to another component.  If the 
* <code>setProperty</code> method is used, the next call to <code>getActualValue</code> returns
* the value of the property.  If the <code>setValue</code> method is used, the next call to
* <code>getActualValue</code> returns the internally stored value.
* @author David Vivash
* @version 1.0, 25/03/01
*/
public class FixedProperty implements Serializable {
	private Object value = null;
	private Class type = null;
	private boolean dynamic = false;
	private Property property = null;

	private boolean internal = true; //the value is internal
	private boolean converted = false;

	public FixedProperty(Object value, Class type) {
		this.value = value;
		setType(type);
	}
	
	public Class getType() { 
		if (converted) {
			if (type == Integer.class)		return int.class;
			if (type == Boolean.class)		return boolean.class;	
			if (type == Byte.class)			return byte.class;	
			if (type == Character.class)	return char.class;	
			if (type == Short.class)		return short.class;	
			if (type == Long.class)			return long.class;	
			if (type == Float.class)		return float.class;	
			if (type == Double.class)		return double.class;	
			if (type == Void.class)			return void.class;	
		}		
		return type; 		
	}

	private void setType(Class type) {
		this.type = type; 

		if (type == null) return; //null pointers are just scary. Run away.

		if (type.isPrimitive()) {
			if (type == int.class)		this.type = Integer.class;
			if (type == boolean.class)	this.type = Boolean.class;
			if (type == byte.class)		this.type = Byte.class;
			if (type == char.class)		this.type = Character.class;
			if (type == short.class)	this.type = Short.class;
			if (type == long.class)		this.type = Long.class;
			if (type == float.class)	this.type = Float.class;
			if (type == double.class)	this.type = Double.class;
			if (type == void.class)		this.type = Void.class;
			converted = true;
		} else {
			value = null; //to maintain the integrity of the value's type
			converted = false;
		}	
	}

	/**
	* Gets the <i>actual</i> value stored in this object.  
	* @return either the internally stored value, or the value of the stored property
	*/
	public Object getActualValue() {
		if (internal) return value;
		else return property == null ? null : property.getValue();
	}
	
	public void setProperty(Property value) {
		if (value != null) {
			if (type == null) setType(value.getType());
			if (value.getType() == getType()) property = value;
		}

		internal = false;
	}
	
	public void setValue(Object value) {
		if (value != null)
			this.value = value;
		
		internal = true;
	}
	
	public Object getValue() { return value; }
	public Property getProperty() { return property; }
	
	public void setInternal(boolean internal) { this.internal = internal; }
	public boolean getInternal() { return internal; }

	public void setDynamicOnly(boolean dynamic) { this.dynamic = dynamic; }
	public boolean getDynamicOnly() { return dynamic; }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -