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

📄 deviceconnector.java

📁 这是自定义工作流的图形定义部分
💻 JAVA
字号:
//package vlab; 在DesignPanel上显示的DeviceCarrier之间的连接线import java.awt.image.*;import java.awt.*;import java.io.*;import java.lang.*;import java.lang.Cloneable;/** * Title:        work-flow * Description: * Copyright:    Copyright (c) 2002 * Company:      CSU * @author       smallbeetle * @version 1.0 */public class DeviceConnector implements Serializable, Cloneable{  static int total = 0;  private String name;  private String inDeviceCarrierName=null;  private String outDeviceCarrierName=null;  private String outParameterName;  private String inParameterName;  private java.awt.Point[] handler = new java.awt.Point[4]; //控制调节每个connector上的四个拖拽点  private boolean selected;  private transient Object value;  public  String connectorStatus = "";  public DeviceConnector() {    for (int i = 0; i < handler.length; i++){      handler[i] = new Point(0, 0);    }    selected = true;  }  public Point getHandler(Point p){    Rectangle rect;    for (int i = 1; i <= 2; i++){      rect = new Rectangle(handler[i].x -2  , handler[i].y -2 , 5, 5) ;      if (rect.contains(p)){        return handler[i];      }    }    return null;  }  //why?  public boolean in(Point p){    for (int i = 0; i < handler.length-1; i++){      if (Intersect.isIntersect(p, handler[i], handler[i+1])){        return true;      }    }    return false;  }  public static Point[] adjustConnector(DeviceConnector conn){     Point[] handler2 = null;     DeviceCarrier inDevice2 = null;;     DeviceCarrier outDevice2 = null;     outDevice2 = (DeviceCarrier) DesignPanel.carriers.get(conn.getOutDeviceCarrierName());     inDevice2 = (DeviceCarrier) DesignPanel.carriers.get(conn.getInDeviceCarrierName());     handler2 = conn.getHandler();     if (outDevice2!=null && inDevice2!=outDevice2){        int inDeviceHeight = inDevice2.getHeight();        int outDeviceHeight = outDevice2.getHeight();        Rectangle tempRec1 = new Rectangle(inDevice2.getX(),inDevice2.getY(),inDevice2.getWidth(),inDeviceHeight);        Rectangle tempRec2 = new Rectangle(outDevice2.getX(),outDevice2.getY(),outDevice2.getWidth(),outDevice2.getHeight());        while ((tempRec1.contains(handler2[0]) && tempRec1.contains(handler2[1]))||(tempRec2.contains(handler2[2]) && tempRec2.contains(handler2[3]))){            if (DesignPanel.mouseOrient.equals("south")){                int lowPoint = 0;                if (outDevice2.getY()<inDevice2.getY()) lowPoint = outDevice2.getY()-outDeviceHeight;                 else lowPoint = inDevice2.getY()-inDeviceHeight;                handler2[0].y = inDevice2.getY();                handler2[1].y = lowPoint;                handler2[2].y = handler2[1].y;                handler2[3].y = outDevice2.getY();             }            else{                int highPoint = 0;                if (outDevice2.getY()>inDevice2.getY()) highPoint = outDevice2.getY()+outDeviceHeight*2;                 else highPoint = inDevice2.getY()+inDeviceHeight*2;                handler2[0].y = inDevice2.getY()+inDevice2.getHeight();                handler2[1].y = highPoint;                handler2[2].y = handler2[1].y;                handler2[3].y = outDevice2.getY()+outDevice2.getHeight();             }        }     }     return handler2;  }  //draw itself in g;  public void draw(Graphics g){    g.setColor(Color.black);    for (int i = 0; i < handler.length-1; i ++){      DeviceCarrier inDevice =(DeviceCarrier)  DesignPanel.carriers.get(this.getInDeviceCarrierName());      DeviceCarrier outDevice =(DeviceCarrier)  DesignPanel.carriers.get(this.getOutDeviceCarrierName());      if (i==0 && inDevice!=null){ //画线时进行分类,曲线上行,曲线下行          int currentHeight = inDevice.getHeight();          if (handler[0].y<inDevice.getY()+currentHeight/2 && handler[1].y>inDevice.getY()+currentHeight/2){             handler[0].y=inDevice.getY()+currentHeight;          }          if (handler[0].y>inDevice.getY()+currentHeight/2 && handler[1].y<inDevice.getY()+currentHeight/2){             handler[0].y=inDevice.getY();          } //当曲线的转折点在模块之内时,进行处理      }      if (i==2 && outDevice!=null) {   //画线时进行分类,曲线上行,曲线下行          if (handler[3].y<outDevice.getY()+outDevice.getHeight()/2 && handler[2].y>outDevice.getY()+outDevice.getHeight()/2){            handler[3].y=outDevice.getY()+outDevice.getHeight();          }          if (handler[3].y>outDevice.getY()+outDevice.getHeight()/2 && handler[2].y<outDevice.getY()+outDevice.getHeight()/2){            handler[3].y=outDevice.getY();          }      }      handler = adjustConnector(this);      if (i==3||i==0) {          if (outDevice!=null && inDevice!=outDevice){              if (handler[3].y<outDevice.getY() ) handler[3].y = outDevice.getY();              if (handler[3].y>outDevice.getY() ) handler[3].y = outDevice.getY()+outDevice.getHeight();          }              if (handler[0].y<inDevice.getY() ) handler[0].y = inDevice.getY();              if (handler[0].y>inDevice.getY() ) handler[0].y = inDevice.getY()+inDevice.getHeight();      }      g.drawLine(handler[i].x, handler[i].y, handler[i+1].x, handler[i+1].y);    }    //draw the arrow    if (handler[2].y>handler[3].y) {        g.drawLine(handler[handler.length-1].x-2, handler[handler.length-1].y+5,               handler[handler.length-1].x, handler[handler.length-1].y);        g.drawLine(handler[handler.length-1].x+2, handler[handler.length-1].y+5,               handler[handler.length-1].x , handler[handler.length-1].y );    }else{        g.drawLine(handler[handler.length-1].x-2, handler[handler.length-1].y-5,               handler[handler.length-1].x, handler[handler.length-1].y);        g.drawLine(handler[handler.length-1].x+2, handler[handler.length-1].y-5,               handler[handler.length-1].x , handler[handler.length-1].y );    }    //if selected, draw the handlers;    if (selected){      for (int i = 0; i < handler.length; i++){        g.fillRect(handler[i].x-2, handler[i].y-2, 5, 5);      }    }  }  private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {    ois.defaultReadObject();  }  private void writeObject(ObjectOutputStream oos) throws IOException {    oos.defaultWriteObject();  }  public void setName(String newName) {    name = newName;  }  public String getName() {    return name;  }  public void setInDeviceCarrierName(String newInDeviceCarrierName) {    inDeviceCarrierName = newInDeviceCarrierName;  }  public String getInDeviceCarrierName() {    return inDeviceCarrierName;  }  public void setOutDeviceCarrierName(String newOutDeviceCarrierName) {    outDeviceCarrierName = newOutDeviceCarrierName;  }  public String getOutDeviceCarrierName() {    return outDeviceCarrierName;  }  public void setOutParameterName(String newOutParameterName) {    outParameterName = newOutParameterName;  }  public String getOutParameterName() {    return outParameterName;  }  public void setInParameterName(String newInParameterName) {    inParameterName = newInParameterName;  }  public String getInParameterName() {    return inParameterName;  }  public void setHandler(java.awt.Point[] newHandler) {    for (int i = 0; i < handler.length; i++){      handler[i].x = newHandler[i].x ;      handler[i].y = newHandler[i].y ;    }  }  public java.awt.Point[] getHandler() {    return handler;  }  public void setSelected(boolean newSelected) {    selected = newSelected;  }  public boolean isSelected() {    return selected;  }  public Object getValue(){    return value;  }  public void setValue(Object newValue){    this.value = newValue;  }  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 + -