⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controlrect.java

📁 java实现的版画图程序
💻 JAVA
字号:
/*
 * Created on 2003-11-10
 */
package drawfigure;

/**
 * @author peter
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
import java.awt.*;
import java.awt.geom.*;

public class ControlRect implements Cloneable {
	final public static int UNDEFINE_POSITION = 0;
	final public static int LEFT_TOP_POSITION = 1;
	final public static int TOP_POSITION = 2;
	final public static int RIGHT_TOP_POSITION = 3;
	final public static int RIGHT_POSITION = 4;
	final public static int RIGHT_BOTTOM_POSITION = 5;
	final public static int BOTTOM_POSITION = 6;
	final public static int LEFT_BOTTOM_POSITION = 7;
	final public static int LEFT_POSITION = 8;
	final public static int OTHER_POSITION = 9;

	private int position = UNDEFINE_POSITION;
	private double sidewidth = 4;
	private Color color = Color.GREEN; //Color.BLACK;
	private Point2D center = null;

	private boolean isSelected=false;
	
	public ControlRect(double centerX, double centerY) {
		center = new Point2D.Double(centerX, centerY);
	}
	public ControlRect(double x, double y, int posi) {
		this(x, y);
		this.position = posi;
	}
	public ControlRect(Point2D p) {
		center = p;
	}
	public ControlRect(Point2D p, int posi) {
		this(p);
		position = posi;
	}
	public Object clone() {
		ControlRect ctrl = (ControlRect) this.clone();
		return ctrl;
	}
	
	public boolean pointInside(Point2D p) {
			double r = sidewidth / 2;
			boolean result =
				(p.getX() < center.getX() + r
					&& p.getX() > center.getX() - r
					&& p.getY() < center.getY() + r
					&& p.getY() > center.getY() - r);
			if(result) System.out.println(p+"/"+center+"["+result+"]@ControlRect");
			return result;
		}

	public Cursor getCursor() {
		Cursor cursor = null;
		switch (this.position) {
			case LEFT_TOP_POSITION :
				cursor = new Cursor(Cursor.NW_RESIZE_CURSOR);
				break;
			case TOP_POSITION :
				cursor = new Cursor(Cursor.N_RESIZE_CURSOR);
				break;
			case RIGHT_TOP_POSITION :
				cursor = new Cursor(Cursor.NE_RESIZE_CURSOR);
				break;
			case RIGHT_POSITION :
				cursor = new Cursor(Cursor.E_RESIZE_CURSOR);
				break;
			case RIGHT_BOTTOM_POSITION :
				cursor = new Cursor(Cursor.SE_RESIZE_CURSOR);
				break;
			case BOTTOM_POSITION :
				cursor = new Cursor(Cursor.S_RESIZE_CURSOR);
				break;
			case LEFT_BOTTOM_POSITION :
				cursor = new Cursor(Cursor.SW_RESIZE_CURSOR);
				break;
			case LEFT_POSITION :
				cursor = new Cursor(Cursor.W_RESIZE_CURSOR);
				break;
			default :
				cursor = new Cursor(Cursor.DEFAULT_CURSOR);
		}
		return cursor;
	}

	public void paint(Graphics g) {
		Graphics2D g2=(Graphics2D)g;
		Color oldColor = g2.getColor();
		g2.setColor(this.color);
		double r = sidewidth / 2;
		//g.drawRect(center.x - r, center.y - r, sidewidth, sidewidth);
		g2.draw(new Rectangle.Double(center.getX() - r, center.getY() - r, sidewidth, sidewidth));
		g2.setColor(oldColor);
	}

	/**
	 * 
	 * @param posi
	 * @return 相反的位置代号
	 */
	public static int getOppositePosition(int posi){
		switch(posi){
			case LEFT_TOP_POSITION :
				return RIGHT_BOTTOM_POSITION;
			case TOP_POSITION :
				return BOTTOM_POSITION;
			case RIGHT_TOP_POSITION :
				return LEFT_BOTTOM_POSITION;
			case RIGHT_POSITION :
				return LEFT_POSITION;
			case RIGHT_BOTTOM_POSITION :
				return LEFT_TOP_POSITION;
			case BOTTOM_POSITION :
				return TOP_POSITION;
			case LEFT_BOTTOM_POSITION :
				return RIGHT_TOP_POSITION;
			case LEFT_POSITION :			
			    return RIGHT_POSITION;
		}
		return -1;
	}
	/**
	 * 
	 * @return 相反的位置代号
	 */
	public int getOppositePosition(){
		return getOppositePosition(this.getPosition());
	}
	//--访问器-------------

	public int getPosition(){
		return position;
	}
	public void setPosition(int posi){
		this.position=posi;
	}
	public double getSidewidth(){
		return sidewidth;
	}
	public void setSidewidth(float f){
		this.sidewidth=f;
	}
	public Color getColor(){
		return this.color;
	}
	public void setColor(Color c){
		this.color=c;
	}
	public Point2D getCenter(){
		return this.center;
	}	
	public void setCenter(Point2D p){
		this.center=p;
	}
	public boolean isSelected(){
	  	return this.isSelected;
	}
	public void selected(){
	  	this.isSelected=true;
	}
	public void unSelected(){
	  	this.isSelected=false;
	}
}

⌨️ 快捷键说明

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