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

📄 devicemaker.java

📁 用于串口通讯测试的工具软件。完全使用java语言编写。
💻 JAVA
字号:
/***********************************************************************
 * Module:  DeviceMaker.java
 * Author:  Administrator
 * Purpose: Defines the Class DeviceMaker
 ***********************************************************************/

package com.zcsoft.stock;

import com.zcsoft.image.*;
import java.beans.*;
import java.awt.*;
import javax.swing.*;

/** <p>Title: 设备绘制器 </p>
  * <p>Description: 用图形方式表示设备和当前设备状态和位置
  *  </p>
  * <p>Copyright: Copyright (c) 2003</p>
  * <p>Company: Zhicheng Software&Service Co. Ltd.</p>
  *
  * @author 蒋智湘
  * @version 1.0 */
public abstract class DeviceMaker extends ImageMaker
		implements PropertyChangeListener//, Cloneable
{
	/** 设备数据 */
	protected Device device;
	/** 错误图标 */
	public static Icon ERROR_ICON = UIManager.getIcon("OptionPane.errorIcon");

	public DeviceMaker()
	{
		super(null);
	}

	/** @param im 设备的图形表示 */
	public DeviceMaker(java.net.URL im)
	{
		super(im);
	}

	/** @param origin 设备所在坐标系原点在其绘制容器所在坐标系上的坐标 */
	public DeviceMaker(Point origin)
	{
		this(origin.x, origin.y);
	}

	/** @param origin 设备所在坐标系原点在其绘制容器所在坐标系上的坐标 */
	public DeviceMaker(int originX, int originY)
	{
		super(null);
		this.setLocation(originX, originY);
	}

	/** @param origin 设备所在坐标系原点在其绘制容器所在坐标系上的坐标
	  * @param im 设备的图形表示 */
	public DeviceMaker(Point origin, java.net.URL im)
	{
		super(im);
		this.setLocation(origin.x, origin.y);
	}

	protected void paintErrorMsg(Graphics2D g2)
	{
		if(ERROR_ICON != null)
		{
			double sx = Math.min(1, ((double)this.range.width)/ERROR_ICON.getIconWidth())
					, sy = Math.min(1, ((double)this.range.height)/ERROR_ICON.getIconHeight());
			g2.scale(sx, sy);
			ERROR_ICON.paintIcon(this.getOwner(), g2, 0, 0);
			g2.scale(1/sx, 1/sy);
		}
	}

	/** 重写超类方法
	  *
	  * @return 设备上是否有东西 */
	public boolean isVisible()
	{
		return this.device != null && super.isVisible();
	}

	/**
	 * 用设备ID作为其工具提示
	 * @param p
	 * @return
	 */
	public String getToolTipText(Point p)
	{
		String err = this.device != null?this.device.getErrorMsg():null;
		return err != null?err:String.valueOf(this.device.getID());
	}


	/** 获取对应的设备数据对象
	  *
	  * @return */
	public Device getDevice()
	{
		return device;
	}

	/** 设置绘制的设备的数据对象
	  *
	  * @param d
	  */
	public void setDevice(Device d)
	{
		this.setDevice(d, this);
	}


	/** 设置绘制的设备的数据对象
	  *
	  * @param d
	  * @param pcl
	  */
	public void setDevice(Device d, PropertyChangeListener pcl)
	{
		if(this.device == null || !d.equals(this.device))
		{
			if (this.device != null && pcl != null)
			{
				this.device.removePropertyChangeListener(pcl);
			}
			this.device = d;
			if (pcl != null)
			{
				d.addPropertyChangeListener(pcl);
			}
			this.setName(String.valueOf(d.getID()));
		}
		//复制对应的属性值
		this.device.copyFieldFrom(d);
	}


	/** 属性发生改变后,通知绘制器
	  *
	  * @param evt */
	public void propertyChange(PropertyChangeEvent evt)
	{
		JComponent owner = this.getOwner();
		if (owner != null)
		{
			Rectangle bounds = this.range;
//			System.out.println(evt.getSource() + evt.getPropertyName()
//									 + "," + evt.getOldValue()
//									 + "," + evt.getNewValue() );
			if (evt.getPropertyName().equals("location"))
			{
				Point old = (Point)evt.getOldValue();
				bounds = bounds.union(new Rectangle(old.x, old.y, bounds.width, bounds.height));
			}
			RepaintManager.currentManager(owner).addDirtyRegion(owner, bounds.x, bounds.y
																				, bounds.width, bounds.height);
		}
	}
}

⌨️ 快捷键说明

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