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

📄 allocatormaker.java

📁 用于串口通讯测试的工具软件。完全使用java语言编写。
💻 JAVA
字号:
package com.zcsoft.stock;

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

/** <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 class AllocatorMaker extends DeviceMaker
{
	/** FilterComposite(new int[]{32, 32, 32, 0}) */
	public static final Composite DEFAULT_COMPOSITE = new com.zcsoft.image.FilterComposite(new int[]{32, 32, 32, 0});
	/**  默认的图形组合方式FilterComposite(new int[]{32, 32, 32, 0}) */
	protected Composite composite = DEFAULT_COMPOSITE;
	/** 设备运行轨迹 */
	private Path horizonalPath;
	/** 分配车上托盘图像 */
	protected ImageMaker container;
	private DirectionPainter forwardIcon;
	private DirectionPainter backwardIcon;

	public AllocatorMaker()
	{
		this.setXTranslatable(true);
		this.setYTranslatable(true);
	}

	/** 绘制图形。
	  *
	  * @param g2
	  * @param width
	  * @param height */
	protected void paint(Graphics2D g2, int width, int height)
	{
		Allocator device = (Allocator)this.getDevice();
		if (device.isOnline())
		{
			Color old = g2.getColor();
			g2.setColor(Color.green);
			g2.fillRect(0, 0, 20, 20);
			g2.setColor(old);
		}
		if (device.getErrorMsg() != null)
		{
			paintErrorMsg(g2);
		}
		Composite old = null;
		if (composite != null)
		{
			old = g2.getComposite();
			g2.setComposite(composite);
		}
		super.paint(g2, width, height);
		if (old != null)
		{
			g2.setComposite(old);
		}
		if (this.isContainerVisible())
		{
			paintContainer(g2);
		}
		if (device.getDirection() != null)
		{
			drawDirection(g2, device);
		}
	}

	protected void paintContainer(Graphics2D g2)
	{
		this.getContainer().paint(g2);
	}

	/**
	 * 绘制运行方向图标
	 * @param g2
	 * @param device
	 */
	protected void drawDirection(Graphics2D g2, Allocator device)
	{
		DirectionPainter dp;
		if (Boolean.TRUE.equals(device.getDirection()))
		{
			dp = forwardIcon;
		}
		else
		{
			dp = backwardIcon;
		}
		if (dp != null)
		{
			dp.drawDirection(g2, 0, 0, device.getSpeed());
		}
	}

	/** @param container 分配车上的托盘图像绘制器 */
	public void setContainer(ImageMaker container)
	{
		this.container = container;
	}


	public ImageMaker getContainer()
	{
		return container;
	}


	/** @return 是否显示托盘 */
	public boolean isContainerVisible()
	{
		return this.device != null && !((Allocator)this.device).isEmpty();
	}
//
//	/**
//	 * 获取上下文操作菜单
//	 * @param p
//	 * @return
//	 */
//	public JPopupMenu getContextMenu(Point p)
//	{
//		JPopupMenu pop = new JPopupMenu();
//		Action a = (Action)UIManager.get(this.getName()+".stopAtion");
//		if (a != null)
//		{
//			pop.add(a);
//		}
//		a = (Action)UIManager.get(this.getName()+".backAtion");
//		if (a != null)
//		{
//			pop.add(a);
//		}
//		return pop;
//	}

//
//	public void doubleClick(Point p)
//	{
//		int x = this.getX();
//		Point[] samples = this.path.pts;
//		if (this.sampleIndex == samples.length - 1)
//		{
//			this.sampleIndex = 0;
//		}
//		else
//		{
//			for (int i = 0; i < samples.length; i++)
//			{
//				if (samples[i].getX() > x)
//				{
//					this.sampleIndex = i;
//					break;
//				}
//			}
//		}
//		this.setSampleIndex(this.sampleIndex);
//		super.getOwner().repaint();
//	}

	/** 设置设备运行轨迹
	  *
	  * @param p */
	public void setHorizonalPath(Path p)
	{
		this.horizonalPath = p;
		if ( p != null && this.getDevice() != null)
		{
			this.setLocation(p.getPoint(((Allocator)this.getDevice()).getLine()));
		}
	}

	/** 获取设备运行轨迹 */
	public Path getHorizonalPath()
	{
		return horizonalPath;
	}

	public void setBackwardIcon(DirectionPainter backwardIcon)
	{
		this.backwardIcon = backwardIcon;
	}
	public void setForwardIcon(DirectionPainter forwardIcon)
	{
		this.forwardIcon = forwardIcon;
	}
	public DirectionPainter getForwardIcon()
	{
		return forwardIcon;
	}
	public DirectionPainter getBackwardIcon()
	{
		return backwardIcon;
	}

	/** 属性发生改变后,通知绘制器
	  * 当分配车所属排改变后,更改设备的位置,然后通知属性location发生改变
	  * @param evt */
	public void propertyChange(PropertyChangeEvent evt)
	{
		if (evt.getPropertyName().equals("line") && this.horizonalPath != null)
		{
			Integer nw = (Integer)evt.getNewValue();
			Point oldValue = this.getLocation();
			this.setLocation(this.horizonalPath.getPoint(nw.intValue()));
			Point newValue = this.getLocation();
			super.propertyChange(new PropertyChangeEvent(evt.getSource(), "location", oldValue, newValue));
		}
		else
		{
			super.propertyChange(evt);
		}
	}

}

⌨️ 快捷键说明

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