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

intsupport.java

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

import java.awt.event.*;
import java.awt.*;
import piy.*;
import javax.swing.*;
import java.awt.Dimension;

/**
* Support for properties of String type.
* @author David Vivash
* @version 1.0, 08/02/01
*/
public class IntSupport extends ClassSupport implements KeyListener
{
	private int value = 0;
	private JTextField textField;

	public IntSupport(Property property) {
		super(property);
	
		//Make sure everything is correctly typed
		if ((property.getValue() == null) || (property.getType() != int.class)
								|| (property.getValue().getClass() != Integer.class))
			property.setValue(new Integer(0));

		//Make sure the variable with this as a property type is primitive		
		if (property.getHolder().getClass() == Variable.class)
			((Variable)property.getHolder()).setType(int.class);


		Integer val = ((Integer)property.getValue());
		value = (val == null) ? 0 : val.intValue();

		setLayout(new BorderLayout());
		add(textField = new JTextField(""+value), BorderLayout.CENTER);
		textField.addKeyListener(this);

	}

	public static Class getSupportedClass() { return int.class; }

	public Dimension getMinimumSize() { return new Dimension(10, 20); }
	public Dimension getPreferredSize() { return new Dimension(100, 20); }
	public Dimension getMaximumSize() { return new Dimension(10000, 20); }

	//--------- KeyListener methods ------------
	public void keyPressed(KeyEvent e) {	/* ignore */ }
	public void keyTyped(KeyEvent e) { 		/* ignore */ }

	public void keyReleased(KeyEvent e) {	
		try {
			String text = textField.getText();

			if (text.equals("") || text.equals("-"))
				property.setValue(new Integer(0));
			else
				property.setValue(new Integer(text));

			ProjectHandler.getInstance().projectChanged();
							
		} catch (NumberFormatException exception) {
			value = ((Integer)property.getValue()).intValue();
			property.setValue(new Integer(value));
			textField.setText(""+value);
		}
	}

}

⌨️ 快捷键说明

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