📄 stockpane.java
字号:
static Path createPath(Element e)
{
if (e == null)
{
return null;
}
Element txtChild = e.getChild(Element.TAG_TEXT);
String samplePoints;
if (txtChild == null)
{
samplePoints = "";
}
else
{
samplePoints = txtChild.getTagValue();
}
StringTokenizer sampleToken = new StringTokenizer(samplePoints, ";");
Point[] pts;
Integer count = IntegerValue(e.getAttributeValue("count"));
if (count != null)
{
pts = new Point[count.intValue()];
fillPointBySpace(pts, sampleToken
, floatArray(e.getAttributeValue("spaceX"))
, floatArray(e.getAttributeValue("spaceY")));
}
else
{
pts = new Point[sampleToken.countTokens()];
fillPointBySpace(pts, sampleToken, null, null);
}
return new Path(pts);
}
static void fillPointBySpace(Point[] pts, StringTokenizer initialPoints, float[] spaceX, float[] spaceY)
{
double lastX = 0, lastY = 0;
int i;
for ( i = 0; initialPoints.hasMoreTokens() && i < pts.length; i++ )
{
pts[i] = pointValue(initialPoints.nextToken(), null);
lastX = pts[i].getX();
lastY = pts[i].getY();
}
if (pts.length == i)
{
return ;
}
int start = i;
for ( ; i < pts.length; i++ )
{
if (spaceX != null && spaceX.length > 0)
{
lastX += spaceX[(i - start)%spaceX.length];
}
if (spaceY != null && spaceY.length > 0)
{
lastY += spaceY[(i - start)%spaceY.length];
}
pts[i] = new Point((int)lastX, (int)lastY);
}
}
public static Integer IntegerValue(String v)
{
if (v != null)
{
v = v.trim();
}
return v != null && v.length() > 0?Integer.decode(v):null;
}
public static java.awt.Dimension sizeValue(String v)
{
if (v == null)
{
return null;
}
Point p = pointValue(v, new Point());
return new Dimension(p.x, p.y);
}
public static java.awt.Point pointValue(String v, java.awt.Point p)
{
if (v == null)
{
return null;
}
if (p == null)
{
p = new Point();
}
int last;
int cntNumber = 0;
char c;
int i;
for (i = 0, last = -1; i <= v.length(); i++)
{
c = i < v.length()?v.charAt(i):0;
if ((c < '0' || c > '9' ) && c != '-')
{
if (i > (last + 1))
{
int No = Integer.decode(v.substring(last + 1, i)).intValue();
if (cntNumber == 0)
{
p.x = No;
}
else
{
p.y = No;
break;
}
cntNumber ++;
}
last = i;
}
}
return p;
}
/**
* 将以","分开的数值序列字符串转换成数组
* @param arrayStr 以","分开的数值序列
* @return 如果arrayStr == null,则返回null
*/
public static float[] floatArray(String arrayStr)
{
float[] array;
if (arrayStr == null)
{
array = null;
}
else
{
StringTokenizer st = new StringTokenizer(arrayStr, ", ");
array = new float[st.countTokens()];
for ( int i = 0; st.hasMoreTokens(); i++ )
{
array[i] = Float.parseFloat(st.nextToken());
}
}
return array;
}
public void setBackgroundImage(Image im)
{
Image old = this.backgroundImage;
this.backgroundImage = im;
Dimension prefSize = this.getPreferredSize();
if (im != old
&& (prefSize == null || prefSize.width < 50 || prefSize.height <= 50))
{
this.setPreferredSize(new Dimension(im.getWidth(this), im.getHeight(this)));
}
}
/** 重写超类方法,使得背景可以绘制图片
*
* @param g
*/
protected void paintComponent(Graphics g)
{
Image im = this.backgroundImage;
if (im != null)
{
if ( g.hitClip(0, 0, getWidth(), getHeight()) )
{
Rectangle clip = g.getClipBounds();
clip = clip.intersection(new Rectangle(0, 0, im.getWidth(this), im.getHeight(this)));
g.drawImage(im, clip.x, clip.y, clip.x + clip.width, clip.y + clip.height
, clip.x, clip.y, clip.x + clip.width, clip.y + clip.height, this);
}
}
super.paintComponent(g);
}
//仅作测试用
public String getToolTipText(MouseEvent e)
{
String txt = super.getToolTipText(e);
if (txt == null && debug)
{
txt = e.getX() + ", " + e.getY();
}
return txt;
}
// /**
// * 测试
// * @param args
// */
// public static void main(String[] args)
// {
// try
// {
// Container contentPane = new JPanel();
// contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// StockPane sp = new StockPane();
// ArrayList stackerMakers = new ArrayList(1);
// DeviceMaker[] devices =
// sp.configureFromElement(RootElementGenerator.fromXml(
// new java.io.File("E:\\commAPI\\defaultRoot\\立体仓库配置.xml"))
// , stackerMakers);
// ShapePane faceViewPane = new ShapePane();
// int x = 0;
// int h = 0;
// for (int i = 0; i < stackerMakers.size(); i++)
// {
// StackerMaker sm = (StackerMaker)stackerMakers.get(i);
// StackerMaker faceMaker = new StackerMaker();
// faceMaker.setDevice(sm.getDevice());
// faceMaker.setUnderPlatView(false);
// faceMaker.setVerticalPath(sm.getVerticalPath());
// faceMaker.setHorizonalPath(faceMaker.getHorizonalPath());
// faceMaker.setForwardIcon(sm.getForwardIcon());
// faceMaker.setBackwardIcon(sm.getBackwardIcon());
// faceMaker.setDownwardIcon(sm.getDownwardIcon());
// faceMaker.setUpwardIcon(sm.getUpwardIcon());
// faceMaker.setFaceViewContainer(sm.getFaceViewContainer());
// faceMaker.setFaceViewImageURL(sm.getFaceViewImageURL());
// faceMaker.setLiftImageURL(sm.getLiftImageURL());
// faceMaker.setLiftMaker(sm.getLiftMaker());
// faceMaker.setReversePaintLine(sm.getReversePaintLine());
// faceMaker.setXTranslatable(sm.isXTranslatable());
// x += 30;
// faceMaker.setLocation(x, 0);
//
// Rectangle r = faceMaker.getRange();
// x += r.width;
// h = Math.max(h, r.height);
//
// faceViewPane.addShapeMaker(faceMaker);
// }
// faceViewPane.setPreferredSize(new Dimension(x + 30, h + 10));
//
// JFrame frame = new JFrame("StockPane class test");
// contentPane.add(new JScrollPane(sp));
// contentPane.add(faceViewPane);
// frame.setContentPane(contentPane);
// frame.pack();
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.show();
// }
// catch (Exception ex)
// {
// ex.printStackTrace();
// }
// }
static Image getCachedImage(String name)
{
java.net.URL url = getImageURL(name);
// System.out.println("image " + name + "'URL is " + url);
if (url != null)
{
Image im = ImageMaker.getCachedImage(url);
}
return null;
}
static java.net.URL getImageURL(String name)
{
if (name != null)
{
return StockPane.class.getResource("/images/" + name + (name.indexOf('.') == -1?".jpg":""));
}
return null;
}
public void setDebug(boolean debug)
{
this.debug = debug;
// this.setMouseMotionEnabled(debug);
}
public boolean isDebug()
{
return debug;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -