📄 devicecarrier.java
字号:
//package vlab; 在DesignPanel上显示的模块的实现类import java.awt.*;import java.beans.*;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.net.URL;import java.net.URLClassLoader;import java.util.HashMap;import java.util.Iterator;import java.util.Vector;/** * Title: work-flow * Description: * Copyright: Copyright (c) 2002 * Company: CSU * @author smallbeetle * @version 1.0 */public class DeviceCarrier implements Serializable { private String name; private String title; private String classURL; private String selectedMethod; private int x; private int y; private int width; private int height; private boolean selected; private transient HashMap leads ; private transient Object instance; private transient Method procMethod; private transient Object methodOut; private transient Object[] methodIn; public int connectorNum = 0; public int connectorHasDraw = 1; public DeviceCarrier() { x = 0; y = 0; width = 100; height = 30; selected = true; javax.swing.Box b = javax.swing.Box.createVerticalBox(); }private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); } //draw itself in g; public void draw(Graphics g){ //显示模块框图 g.setColor(Color.black) ; g.drawRect(x, y, width, height); g.setColor(Color.orange); g.fillRect(x+1,y+1,width-1,height-1); g.setColor(Color.black) ; FontMetrics fm = g.getFontMetrics() ; int w = fm.stringWidth(title); String sTitle = title; int iEnd = sTitle.length() ; //将模块说明显示在模块框图中 while ( w > width - 5 ){ iEnd --; sTitle = sTitle.substring(0, iEnd) ; w = fm.stringWidth(sTitle) ; } g.drawString(sTitle, x+(int)((width - w)/2), y+ 20) ; //当模块被选择后在模块上显示标识 if (selected){ g.fillRect(x-2, y-2, 5, 5); g.fillRect(x+width-2, y-2, 5, 5); g.fillRect(x+width-2, y+height-2, 5, 5); g.fillRect(x-2, y+height-2, 5, 5); } } public Object getPropertyValue(String propertyName) throws IntrospectionException, InvocationTargetException, IllegalAccessException{ Class selfClass = instance.getClass() ; // get instance's class Class stopClass = selfClass.getSuperclass(); BeanInfo beanInfo = Introspector.getBeanInfo(selfClass, stopClass); PropertyDescriptor properties[] = beanInfo.getPropertyDescriptors() ; try{ if (procMethod != null && methodIn != null && propertyName.startsWith("MI ")){ int i = Integer.parseInt(propertyName.substring(3)); return methodIn[i]; } for (int i = 0; i < properties.length; i++){ if (properties[i].getName().equals( propertyName)){ Method getter = properties[i].getReadMethod(); if (getter!=null){ Object o = getter.invoke(instance, null); return o; }else{ return null; } } } } catch (Exception e){ throw new IllegalArgumentException("[ "+ name+ " ] is error, Please contact the bean designer or check input argument "); } return null; } public void setPropertyValue(String propertyName, Object o) throws IntrospectionException, InvocationTargetException, IllegalAccessException, InterruptedException{ Class selfClass = instance.getClass() ; // get instance's class Class stopClass = selfClass.getSuperclass(); BeanInfo beanInfo = Introspector.getBeanInfo(selfClass, stopClass); PropertyDescriptor properties[] = beanInfo.getPropertyDescriptors() ; try{ if (procMethod != null && propertyName.startsWith("MI ")){ int i = Integer.parseInt(propertyName.substring(3)); methodIn[i] = o; return; } for (int i = 0; i < properties.length; i++){ if (properties[i].getName().equals( propertyName)){ Method setter = properties[i].getWriteMethod(); setter.invoke(instance, new Object[]{o} ); return; } } } catch ( InvocationTargetException e){ throw new InvocationTargetException(e, e.getTargetException().getMessage()); } catch ( IllegalAccessException e){ throw e; } } public String getClassURL() { return classURL; } public void setX(int newX) { x = newX; } public int getX() { return x; } public void setY(int newY) { y = newY; } public int getY() { return y; } public void setWidth(int newWidth) { width = newWidth; } public int getWidth() { return width; } public void setHeight(int newHeight) { height = newHeight; } public int getHeight() { return height; } public String getName() { return name; } public Object getInstance() { return instance; } public Object getMethodOut() { return methodOut; } public String getTitle() { return title; } public void setTitle(String newTitle) { title = newTitle; } public String getSelectedMethod() { return selectedMethod; } public void setSelectedMethod(String newSelectedMethod) { this.selectedMethod = newSelectedMethod; } public void setName(String newName) { name = newName.substring(newName.lastIndexOf("/")+1); title = newName.substring(newName.lastIndexOf("/")+1); } public void setSelected(boolean newSelected) { selected = newSelected; } public boolean isSelected() { return selected; } public Method getProcMethod(){ return procMethod; } public Object[] getMethodIn(){ return methodIn; } public Object Clone(){ Object o = null; try{ o = super.clone(); }catch(CloneNotSupportedException e){ e.printStackTrace(); } return o; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -