radioproperty.java

来自「JAVA 数学程序库 提供常规的数值计算程序包」· Java 代码 · 共 66 行

JAVA
66
字号
package jmathlib.core.graphics.properties;

import java.util.Set;
import java.util.Collections;
import java.util.HashSet;
import jmathlib.core.graphics.*;

public class RadioProperty extends Property
{
	protected Set    valueSet;
	protected String value;

	public RadioProperty(PropertySet parent, String name, String[] values, String defaultValue)
	{
		super(parent, name);
		valueSet = Collections.synchronizedSet(new HashSet());
        
		for (int i=0; i<values.length; i++)
			valueSet.add(values[i]);
		
        if (valueSet.contains(defaultValue))
			value = defaultValue;
		else
			value = values[0];
	}

	public Object get()
	{
		return getValue();
	}

	public void set(Object newValue) throws PropertyException
	{
		if (newValue instanceof String)
			setValueInternal((String)newValue);
		else
			throw new PropertyException("invalid property value - " + newValue.toString());
	}

	public String getValue()
	{
		return value;
	}

	public boolean is(String val)
	{
		return value.equals(val);
	}

	private void setValueInternal(String newValue) throws PropertyException
	{
		if (valueSet.contains(newValue))
		{
			value = newValue;
			valueChanged();
		}
		else
			throw new PropertyException("invalid property value - " + newValue);
	}

	public String toString()
	{
		return value;
	}
}

⌨️ 快捷键说明

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