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

📄 shapemaker.java

📁 用于串口通讯测试的工具软件。完全使用java语言编写。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		for (int i = 0; i < p.length; i++)
			ps[i]=(DoublePoint)p[i].clone();
		return ps;
	}

	/**
	 * 设置图形的颜色。
	 * @param newShapeColor 图形颜色,如果为null值,则忽略。
	 */
	public final void setShapeColor(java.awt.Color newShapeColor)
	{
		if(newShapeColor==null)
			return;
		 shapeColor = newShapeColor;
	}

	/**
	 * 获取指定控制点的鼠标形状。
	 * @return 如果pointIndx无效,则返回null。
	 */
	public Cursor getCuror(int pointIndx)
	{
		if(!check(pointIndx,this.getPoints()))
			return null;
		return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
	}

	/**
	 * 当图形移动时鼠标的形状
	 */
	public Cursor getMovingCursor()
	{
		 return Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
	}
	/**
	 *  获取图形的颜色
	 */
	public final java.awt.Color getShapeColor()
	{
		return shapeColor;
	}

	/**
	 * 显示上下文菜单。默认情况下,没有任何实现
	 * @param 鼠标点击点。坐标相对于绘制容器所在坐标系
	 */
	public javax.swing.JPopupMenu getContextMenu(Point p)
	{
		return null;
	}

	/**
	 * 设置图形所在矩形区域。
	 * @param x 区域左上顶点X坐标
	 * @param y 区域左上顶点Y坐标
	 * @param w 区域宽度
	 * @param h 区域高度
	 *
	 * @since 2.1
	 */
	public void setBounds(double x, double y, double w, double h)
	{
		if(w<0||h<0)
		{
			System.out.println("w<0||h<0");
			return ;
		}
		range.setFrameFromDiagonal(x, y, x + w, y + h);
	}

	/**
	 * 设置图形所在矩形区域。
	 * @param newRange 不为null的矩形区域
	 * @see @setRange(int, int, int, int)
	 */
	public void setRange(java.awt.Rectangle newRange)
	{
		setBounds(newRange.getX(), newRange.getY(), newRange.getWidth(), newRange.getHeight());
	}

	/**
	 * 获取图形所在矩形区域
	 */
	public java.awt.Rectangle getRange()
	{
		return (java.awt.Rectangle)range.clone();//已防止错误修改而采用克隆技术
	}

	/**
	 * 获取指定控制点的描述信息
	 */
	public Object getPointInfo(int indx)
	{
		DoublePoint ps[]=this.getPoints();
		if(!check(indx,ps))
			return null;
		return getScaledValue(ps[indx].getX(),2,true)+
			", "+getScaledValue(ps[indx].getY(),2,true);
	}

	/**
	 * 对给定的双精度小数的精度调整为2,进行四舍五入换算
	 * 如果调整后的值的小数部分为0,且cutZero为true,则转化为整数。
	 */
	public static final String getScaledValue(double original,int scale,boolean cutZero)
	{
		return com.zcsoft.util.ZCToolKits.getScaledValue(original,scale,cutZero);
	}

	/**
	 * 判断指定索引是否合法
	 */
	private boolean check(int indx,DoublePoint ps[])
	{
		return indx>=0 && indx < (ps==null?0:ps.length);
	}

	/**
	 * 设置图形的名称
	 */
	public void setName(String newName)
	{
		name = newName;
	}

	/**
	 * 获取图形的名称
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * 获取该图形的字符串描述
	 */
	public String toString()
	{
		return getClass().getName()+" contructed by "+(points==null?"no":(""+points.length))+" point(s).";
	}

	/**
	 * 在非控制点的工具提示
	 *
	 * @return null
	 *
	 * @since 2.0
	 */
	public String getToolTipText(Point p)
	{
		return null;
	}

	/**
	 * 设置图形是否可以移动
	 *
	 * @since 2.0
	 */
	public void setMovable(boolean newMovable)
	{
		movable = newMovable;
	}

	/**
	 * 判断图形是否可以移动
	 *
	 * @since 2.0
	 */
	public boolean isMovable()
	{
		return movable;
	}

	/**
	 * 设置绘制该图形的组件容器
	 *
	 *
	 * @since 2.0
	 */
	public void setOwner(ShapePane newOwner)
	{
		owner = newOwner;
	}

	/**
	 * 获取绘制该图形的组件容器
	 *
	 * @since 2.0
	 */
	public ShapePane getOwner()
	{
		return owner;
	}

	/**
	 * 处理鼠标左键单击或回车事件
	 * 只有在图形被选中时才会调用该方法。
	 *
	 * @param p 左键单击时鼠标所在点。如果为回车键激发该方法,
	 *  则p为null
	 *
	 * @since 2.0
	 */
	public void click(Point p){}

	/**
	 * 处理鼠标左键双击事件
	 * 只有在图形被选中时才会调用该方法。
	 *
	 * @param p 左键单击时鼠标所在点。如果为回车键+ALT修饰键激发该方法,
	 *  则p为null
	 *
	 * @since 2.0
	 */
	public void doubleClick(Point p){}

	/**
	 * 设置背景颜色
	 *
	 * @since 2.0
	 */
	public void setBackgroud(java.awt.Color newBackgroud)
	{
		backgroud = newBackgroud;
	}

	/**
	 * 获取设置的背景颜色
	 *
	 * @return 背景颜色。如果用户没有显示设定,则在绘制时,
	 *      将返回绘制面板的背景色。
	 *
	 * @since 2.0
	 */
	public java.awt.Color getBackgroud()
	{
		return backgroud != null ? backgroud:this.getOwner().getBackground();
	}

	/**
	 * 设置绘制矩形区域左上角坐标
	 * @param loc 左上角坐标
	 * @since 2.2
	 */
	public void setLocation(Point loc)
	{
		this.setLocation(loc.x, loc.y);
	}

	/**
	 * 设置绘制矩形区域左上角坐标
	 * @param x X坐标
	 * @param y Y坐标
	 * @since 2.2
	 */
	public void setLocation(int x, int y)
	{
		this.range.setLocation(x, y);
	}

	/**
	 * 获取图形的位置
	 * @return 所在区域的左上角顶点
	 * @since 2.2
	 */
	public Point getLocation()
	{
		return this.range.getLocation();
	}

	/**
	 * 判断图形绘制器所在区域是否同指定矩形区域相交。
	 * @param rect 指定的矩形区域
	 * @return true相交,false不相交
	 * @since 2.2
	 */
	public boolean intersects(Rectangle2D rect)
	{
		return hasNotSetBounds() || this.range.intersects(rect);
	}

	/**
	 * 判断图形绘制器所在区域是否同指定矩形区域相交。
	 * @param x 指定的矩形区域左上角X坐标
	 * @param x 指定的矩形区域左上角Y坐标
	 * @param x 指定的矩形区域的宽度
	 * @param x 指定的矩形区域的高度
	 * @return true相交,false不相交
	 * @since 2.2
	 */
	public boolean intersects(double x, double y, double w, double h)
	{
		return hasNotSetBounds() || this.range.intersects(x, y, w, h);
	}

	/**
	 * 判断绘制器的尺寸是否还未设定
	 * @return
	 */
	public boolean hasNotSetBounds()
	{//this.range.width == 0 表示大小需要在绘制一次后才能确定
		return this.range.width == 0;
	}


	public int getX()
	{
		return this.range.x;
	}

	public int getY()
	{
		return this.range.y;
	}

	public int getWidth()
	{
		return this.range.width;
	}

	public int getHeight()
	{
		return this.range.height;
	}

	public void setSize(java.awt.Dimension size)
	{
		this.range.setSize(size);
	}

	public java.awt.Dimension getSize()
	{
		return this.range.getSize();
	}

	public void setSize(int w, int h)
	{
		this.range.setSize(w, h);
	}


	/**
	 *
	 * @param visible 是否可见
	 * @since 2.2
	 */
	public void setVisible(boolean visible)
	{
		this.visible = visible;
	}

	/**
	 *
	 * @return 是否可见
	 * @since 2.2
	 */
	public boolean isVisible()
	{
		return visible;
	}

}

⌨️ 快捷键说明

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