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

pointsupport.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 Point type.
* @author David Vivash
* @version 1.0, 08/02/01
*/
public class PointSupport extends ClassSupport implements KeyListener
{

	private Point point;
	private JTextField xPosField;
	private JTextField yPosField;


	public PointSupport(Property property) {
		super(property);

		//Make sure everything is correctly typed
		if ((property.getValue() == null) || (property.getType() != Point.class)
								|| (property.getValue().getClass() != Point.class))
			property.setValue(new Point(0,0));

		GridBagLayout gridbag = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();

		setLayout(gridbag);
		c.fill = GridBagConstraints.HORIZONTAL;
		Insets pad = new Insets(0,4,0,0);
		Insets noPad = new Insets(0,0,0,0);


		c.ipadx = 8; c.ipady = 8;
		c.anchor = GridBagConstraints.EAST;

		c.gridx = 0; c.weightx = 0; c.insets = pad;

		JLabel label = new JLabel("X");
		gridbag.setConstraints(label, c);
		add(label);
			
		point = (Point)property.getValue();
		if (point == null) {
			point = new Point(0, 0);
			property.setValue(point);		
		}
		

		xPosField = new JTextField(""+point.getX());
		yPosField = new JTextField(""+point.getY());

		c.gridx = 1; c.weightx = 1.0; c.insets = noPad;
		gridbag.setConstraints(xPosField , c);
		add(xPosField);
	
		c.gridx = 2; c.weightx = 0; c.insets = pad;

		JLabel label2 = new JLabel("Y");
		gridbag.setConstraints(label2, c);
		add(label2);

		c.gridx = 3; c.weightx = 1.0; c.insets = noPad;
		gridbag.setConstraints(yPosField , c);
		add(yPosField);

		validate();

		xPosField.addKeyListener(this);
		yPosField.addKeyListener(this);
	}

	public static Class getSupportedClass() { return Point.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 xText = xPosField.getText();
			String yText = yPosField.getText();
			double xVal=0, yVal=0;

			if (!(xText.equals("") || xText.equals("-")))
				xVal = Double.parseDouble(xText);
				
			if (!(yText.equals("") || yText.equals("-")))
				yVal = Double.parseDouble(yText);

			property.setValue(new Point((int)xVal, (int)yVal));
			ProjectHandler.getInstance().projectChanged();
						
		} catch (NumberFormatException exception) {
			Point point = (Point)property.getValue();
			xPosField.setText(""+point.getX());
			yPosField.setText(""+point.getY());
		}
	}

}

⌨️ 快捷键说明

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