📄 stackermaker.java
字号:
package com.zcsoft.stock;
import java.awt.*;
import java.awt.geom.AffineTransform;
import com.zcsoft.stock.*;
import javax.swing.*;
import com.zcsoft.image.*;
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 StackerMaker extends AllocatorMaker
{
// private ImageMaker liftMaker;
private ImageMaker downViewContainer;
private ImageMaker faceViewContainer;
private DirectionPainter upwardIcon;
private DirectionPainter downwardIcon;
/** 记录是否存于正视图下 */
private boolean underPlatView = true;
/** 俯视图下的堆垛机图片 */
private java.net.URL downViewImageURL;
/** 正视图下的堆垛机图片 */
private java.net.URL faceViewImageURL;
/** 载货台图像路径 */
private java.net.URL liftImageURL;
/** 载货台运行轨迹 */
private Path verticalPath;
/** 当堆剁机所在行等于该参数值时,需要倒置绘制堆垛机 */
private int reversePaintLine = - 1;
/** 绘制正视图时,是否以小图标形式绘制 */
private boolean underMinimumMode;
public StackerMaker()
{
}
/** 绘制图形
*
* @param g2
* @param width
* @param height */
protected void paint(Graphics2D g2, int width, int height)
{
if (this.underMinimumMode)
{
String name = this.getName();
if (name != null)
{
int y = g2.getFontMetrics().getAscent();
g2.drawString(name, 0, y);
y += 2;
g2.drawLine(0, y, g2.getFontMetrics().stringWidth(name) - 1, y);
}
return;
}
Stacker device = (Stacker)this.getDevice();
//绘制列和层文字信息,格式为:列号-层号
String locationMsg = String.valueOf(device.getColumn())
+ '-'
+ String.valueOf(1 + device.getLayer());
int centerX = ( width - g2.getFontMetrics().stringWidth(locationMsg) ) >> 1;
g2.drawString(locationMsg, centerX, height);
//x轴方向沿所在矩形区域的中线倒换
if (isToReverse())
{
//~(width & 0x1) == width % 2 - 1
g2.transform(new AffineTransform(-1, 0, 0, 1, width + ~(width & 0x1), 0));
}
super.paint(g2, width, height);
if(underPlatView == false)
{
Image liftImage = getCachedImage(this.liftImageURL);
if (liftImage != null)
{
Composite old = g2.getComposite();
g2.setComposite(composite);
Point location = this.verticalPath.getPoint(device.getLayer());
g2.translate(location.x, location.y);
g2.drawImage(liftImage, 0, 0, null);
if (this.isContainerVisible())
{
super.paintContainer(g2);
}
g2.translate(-location.x, -location.y);
g2.setComposite(old);
}
if (device.getDirection() == null)
{
super.drawDirection(g2, device);
}
if (device.getVerticalDirection() != null)
{
this.drawVerticalDirection(g2, device);
}
}
}
/** Override super method. Only paint downview container when stacker is under down view mode*/
protected void paintContainer(Graphics2D g2)
{
// if (this.underPlatView)
// {
// this.getContainer().paint(g2);
// }
}
/**
* 绘制水平运行方向图标
* 只有在正视图下才绘制水平方向图标
* @param g2
* @param device
*/
protected void drawDirection(Graphics2D g2, Allocator device)
{
// if (this.underPlatView == false)
// {
// super.drawDirection(g2, device);
// }
}
/**
* 绘制载货台的运行方向提示图标
* @param g2
* @param device
*/
protected void drawVerticalDirection(Graphics2D g2, Stacker device)
{
DirectionPainter dp;
if (Boolean.TRUE.equals(device.getVerticalDirection()))
{
dp = upwardIcon;
}
else
{
dp = downwardIcon;
}
if (dp != null)
{
dp.drawDirection(g2, 0, 0, device.getVerticalSpeed());
}
}
/**
* 判断绘制的图形是否需要水平倒置
* @return
*/
boolean isToReverse()
{
return reversePaintLine == ((Stacker)this.device).getLine();
}
public java.net.URL getImageURL()
{
return this.underPlatView?this.downViewImageURL:this.faceViewImageURL;
}
public ImageMaker getContainer()
{
return this.underPlatView?this.downViewContainer:this.faceViewContainer;
}
/**
* 获取上下文操作菜单
* @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 setLiftMaker(ImageMaker liftMaker)
// {
// this.liftMaker = liftMaker;
// }
public void setFaceViewContainer(ImageMaker faceViewContainer)
{
this.faceViewContainer = faceViewContainer;
}
public void setDownwardIcon(DirectionPainter downwardIcon)
{
this.downwardIcon = downwardIcon;
}
public void setUpwardIcon(DirectionPainter upwardIcon)
{
this.upwardIcon = upwardIcon;
}
public void setUnderPlatView(boolean underPlatView)
{
this.underPlatView = underPlatView;
}
public void setFaceViewImageURL(java.net.URL url)
{
this.faceViewImageURL = url;
}
public java.net.URL getFaceViewImageURL()
{
return faceViewImageURL;
}
public void setReversePaintLine(int lineNo)
{
this.reversePaintLine = lineNo;
}
public void setDownViewImageURL(java.net.URL downViewImageURL)
{
this.downViewImageURL = downViewImageURL;
}
public void setLiftImageURL(java.net.URL liftImageURL)
{
this.liftImageURL = liftImageURL;
}
public void setVerticalPath(Path p)
{
this.verticalPath = p;
// if ( p != null && this.getDevice() != null && this.liftMaker != null)
// {
// this.liftMaker.setLocation(p.getPoint(((Stacker)this.getDevice()).getLayer()));
// }
}
public void setDownViewContainer(ImageMaker c)
{
this.downViewContainer = c;
}
public Path getVerticalPath()
{
return verticalPath;
}
public DirectionPainter getUpwardIcon()
{
return upwardIcon;
}
public boolean isUnderPlatView()
{
return underPlatView;
}
// public ImageMaker getLiftMaker()
// {
// return liftMaker;
// }
public int getReversePaintLine()
{
return reversePaintLine;
}
public java.net.URL getLiftImageURL()
{
return liftImageURL;
}
public ImageMaker getFaceViewContainer()
{
return faceViewContainer;
}
public DirectionPainter getDownwardIcon()
{
return downwardIcon;
}
public java.net.URL getDownViewImageURL()
{
return downViewImageURL;
}
public ImageMaker getDownViewContainer()
{
return downViewContainer;
}
/**
* 正视图下,双击完成最小化和最大化绘制方式之间的转换
* @param location
*/
public void doubleClick(Point location)
{
if (this.underPlatView)
{
return;
}
this.underMinimumMode = !this.underMinimumMode;
Rectangle oldBounds = this.getRange();
if (this.underMinimumMode)
{
String name = this.getName();
if (name != null)
{
FontMetrics fm = this.getOwner().getFontMetrics(this.getOwner().getFont());
this.setSize(fm.stringWidth(name), fm.getHeight());
}
}
else//retreive to normal size
{
Image im = this.getImage();
if (im == null)
{
this.loadImage();
im = this.getImage();
}
if (im != null)
{
this.setSize(im.getWidth(null), im.getHeight(null));
}
}
this.getOwner().repaint(oldBounds.union(this.range));
}
/** 属性发生改变后,通知绘制器
* 当分配车所属排改变后,更改设备的位置,然后通知属性location发生改变
* @param evt */
public void propertyChange(PropertyChangeEvent evt)
{
if (evt.getPropertyName().equals("column") && this.getHorizonalPath() != null)
{
Integer nw = (Integer)evt.getNewValue();
Point oldValue = this.getLocation();
this.setLocation(this.getHorizonalPath().getPoint(nw.intValue()));
Point newValue = this.getLocation();
super.propertyChange(new PropertyChangeEvent(evt.getSource(), "location", oldValue, newValue));
}
else if(evt.getPropertyName().equals("line") == false)
{
super.propertyChange(evt);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -