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

📄 designpanel.java

📁 这是自定义工作流的图形定义部分
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      type = node.type == ClassNode.CLASS ? node.type : -1 ;    }    if (type != -1 ){      setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));      mouseStatus = "hand_cursor";    }else{      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));    }  }  public void mouseExited(MouseEvent e){    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  }  public void keyTyped(KeyEvent e) {  }  public void keyPressed(KeyEvent e) {  }  public void keyReleased(KeyEvent e) {//    mainWindow.setStatus(e.getKeyCode()+ "  :  "+ KeyEvent.VK_DELETE  );    if (!getEditable()) return;    if (e.getKeyCode() == KeyEvent.VK_DELETE) {  //delete the current object      this.delete(); //     this.propertyEdit.setEditTable();      this.drawCanvas.repaint();    }  }  private void addConnector(MouseEvent e){    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));    Point[] handler = tConnector.getHandler() ;    if (handler[0].y-e.getPoint().y>height  &&  yFlag){        handler[0].y=handler[0].y-height;        tConnector.setHandler(handler);        yFlag = false;    }    handler[3] = new Point(e.getPoint());    handler[1] = new Point(handler[0].x, (int)((handler[0].y + handler[3].y)/2));    handler[2] = new Point(handler[3].x, (int)((handler[0].y + handler[3].y)/2));    this.hotLeadArea = null;    Set entries = carriers.entrySet();    Iterator iterator = entries.iterator() ;    DeviceCarrier car1;    Map.Entry entry;    while (iterator.hasNext()){      entry = (Map.Entry)iterator.next();      car1 =(DeviceCarrier)entry.getValue();      Point[] pa = tConnector.getHandler();          //check the input lead has input parameter or not          boolean bNotConnect = false;          Set set2 = connectors.entrySet() ;          Iterator it2 = set2.iterator() ;          DeviceConnector dc2;          Map.Entry entry2;          while(it2.hasNext()){            entry2 = (Map.Entry)it2.next();            dc2 = (DeviceConnector)entry2.getValue();            if (car1.getName() == dc2.getOutDeviceCarrierName() && dc2.getInDeviceCarrierName().equals(mouseSelectedCarrier.getName())){               bNotConnect = true;               break;            }          }          int x =car1.getX();          int y =car1.getY();          Point temp = new Point(e.getPoint());          width = car1.getWidth();          height = car1.getHeight();          if(!bNotConnect&& Intersect.isIntersect(temp,new Rectangle(x,y,width,height))){            this.hotLeadArea = new Point(car1.getX() -2, car1.getY()-2);            this.tConnector.setOutDeviceCarrierName(car1.getName()) ;          }        }}//delete a device or a connector  public void delete(){    Vector v = new Vector();    if (this.selectedCarrier != null ) {      String name = this.selectedCarrier.getName();      Iterator iterator = connectors.entrySet().iterator();      DeviceConnector connector;      while(iterator.hasNext()){        Map.Entry entry = (Map.Entry)iterator.next();        connector =(DeviceConnector)entry.getValue();        if (connector.getInDeviceCarrierName().equals(name)||connector.getOutDeviceCarrierName().equals(name)){          v.add(connector.getName()) ;        }      }      Iterator it2 = v.iterator() ;      while(it2.hasNext()){        DeviceConnector conn = (DeviceConnector) connectors.get(it2.next().toString());        DeviceCarrier outDevice =(DeviceCarrier) this.carriers.get(conn.getOutDeviceCarrierName());        DeviceCarrier inDevice = (DeviceCarrier) this.carriers.get(conn.getInDeviceCarrierName());        outDevice.connectorNum--;        inDevice.connectorNum--;        connectors.remove(it2.next().toString());      }      carriers.remove(name);      this.selectedCarrier = null;    }    if (this.selectedConnecor != null){      String name = this.selectedConnecor.getName();      DeviceCarrier outDevice =(DeviceCarrier) this.carriers.get(this.selectedConnecor.getOutDeviceCarrierName());      DeviceCarrier inDevice = (DeviceCarrier) this.carriers.get(this.selectedConnecor.getInDeviceCarrierName());      outDevice.connectorNum--;      inDevice.connectorNum--;      connectors.remove(name) ;      this.selectedConnecor = null;    }    drawCanvas.repaint();  }//check the selected device has any connector or not  public boolean hasConnector(String carName){    Iterator iterator = connectors.entrySet().iterator();    DeviceConnector connector;    while(iterator.hasNext()){      Map.Entry entry = (Map.Entry)iterator.next();      connector =(DeviceConnector)entry.getValue();      if (connector.getOutDeviceCarrierName().equals(carName)||connector.getInDeviceCarrierName().equals(carName)){         return false;      }    }    return true;  } //@carName : carrier name //@paraName: parameter name//get the inconnector of the special device(carName)  public DeviceConnector getInConnector(String carName, String paraName){    Iterator iterator = connectors.entrySet().iterator();    DeviceConnector connector;    while(iterator.hasNext()){      Map.Entry entry = (Map.Entry)iterator.next();      connector =(DeviceConnector)entry.getValue();      if (connector.getOutDeviceCarrierName().equals(carName)&&connector.getOutParameterName().equals(paraName)){         return connector;      }    }    return null;  }  public DeviceConnector[] getOutConnectors(String carName, String paraName){    Vector v = new Vector();    Iterator iterator = connectors.entrySet().iterator();    DeviceConnector connector;    DeviceConnector[] connectors;    while(iterator.hasNext()){      Map.Entry entry = (Map.Entry)iterator.next();      connector =(DeviceConnector)entry.getValue();      if (connector.getInDeviceCarrierName().equals(carName)&&connector.getInParameterName().equals(paraName)){         v.add(connector) ;      }    }    Iterator it = v.iterator() ;    connectors = new DeviceConnector[v.size()];    int i = 0;    while(it.hasNext() ){      connectors[i] = (DeviceConnector)it.next();      i++;    }    return connectors;  }  private void jbInit(MainWindow pMainWindow) throws Exception {    this.mainWindow = pMainWindow;    this.setLayout(new BorderLayout()) ;    this.add(jSplitPane1, BorderLayout.CENTER);    JPanel panel = new JPanel(paneLayout);    designScrollPane = new JScrollPane(panel);    designScrollPane.setBorder(null);    panel.setBorder(null) ;    panel.add(drawCanvas, canvasConstraints ) ;//    drawCanvas.setOpaque(true) ;//    drawCanvas.setBorder(null) ;    jSplitPane1.setOneTouchExpandable(true);    jSplitPane1.add(registeredClassPane, JSplitPane.LEFT);    jSplitPane1.add(jSplitPane2, JSplitPane.RIGHT );    jSplitPane2.setOrientation(JSplitPane.HORIZONTAL_SPLIT);    jSplitPane2.add(designScrollPane, JSplitPane.LEFT);    jSplitPane2.setDividerLocation(600);//    jSplitPane2.add(propertyEdit, JSplitPane.RIGHT);    drawCanvas.addMouseListener(this);    drawCanvas.addKeyListener(this);    drawCanvas.addMouseMotionListener(this);    drawCanvas.requestFocus();    canvasG = drawCanvas.getGraphics();    carriers = new HashMap();    connectors = new HashMap();//    this.propertyEdit.setEditTable();  }//  public boolean isFocusTraversable() {//    return true;//  }//set the device or connector containing the special point "p" selected  private void setSelected(Point p, boolean flag){    DeviceCarrier carrier;    DeviceConnector connector;    if (this.selectedCarrier != null ) this.selectedCarrier.setSelected(false);    if (this.selectedConnecor != null ) this.selectedConnecor.setSelected(false);    Set entries = carriers.entrySet();    Iterator iterator = entries.iterator();    this.selectedCarrier = null;    this.selectedConnecor = null;    while (iterator.hasNext()){      Map.Entry entry = (Map.Entry)iterator.next();      carrier =(DeviceCarrier)entry.getValue();      Rectangle r = new Rectangle(carrier.getX(), carrier.getY(), carrier.getWidth() , carrier.getHeight());      if (r.contains(p)){        carrier.setSelected(flag) ;        this.selectedCarrier = carrier;        return;      }    }    entries = connectors.entrySet();    iterator = entries.iterator() ;    while (iterator.hasNext()){      Map.Entry entry = (Map.Entry)iterator.next();      connector =(DeviceConnector)entry.getValue();      if (connector.in(p)){       connector.setSelected(true);       this.selectedConnecor = connector;       return;      }    }  }  private void addCarrier(String classURL, Point location){/*取得所选结点下的首个方法名*/    String methodName = registeredClassPane.getMethodName(classURL);/*if the selected component is deviceCarrier ,set the property of selectedCarrier false to make it syncronized*/    if (this.selectedCarrier != null || this.selectedConnecor != null) this.selectedCarrier.setSelected(false) ;/*the new DeviceCarrier will be layouted.*/    DeviceCarrier carrier = new DeviceCarrier();    String name = classURL.substring(classURL.lastIndexOf("/")+1);   //取得所选择地模块的类名    name = newName(name); //when user use the same device for more times, we must give the device a new name    carrier.setName(name);    carrier.setX(location.x) ;    carrier.setY(location.y) ;    carriers.put(carrier.getName(), carrier);   //将选中的模块加入    this.selectedCarrier = carrier;    drawCanvas.repaint();  } //设计模块中最主要的部分  private class DrawCanvas extends JButton{    public DrawCanvas() {      super();/** Sets focus on the receiving component if isRequestFocusEnabled     *  returns true and the component doesn't already have focus. **/      this.requestFocus() ;      this.setBackground(Color.white) ;    }    public void adjustConnector(){      Set  entries = connectors.entrySet();      DeviceConnector connector;      Iterator iterator = entries.iterator() ;      while (iterator.hasNext()){        Map.Entry entry = (Map.Entry)iterator.next();        connector =(DeviceConnector)entry.getValue();        DeviceCarrier outDevice =(DeviceCarrier) carriers.get(connector.getOutDeviceCarrierName());        DeviceCarrier inDevice = (DeviceCarrier) carriers.get(connector.getInDeviceCarrierName());        Point[] tempoint = connector.getHandler();        tempoint[0].x = inDevice.getX()+inDevice.getWidth()/(inDevice.connectorNum+1)*inDevice.connectorHasDraw;        inDevice.connectorHasDraw++;        tempoint[1].x = tempoint[0].x;        tempoint[3].x = outDevice.getX()+outDevice.getWidth()/(outDevice.connectorNum+1)*outDevice.connectorHasDraw;        outDevice.connectorHasDraw++;        tempoint[2].x = tempoint[3].x;      }    }    public void paint(Graphics g){      Graphics2D g2d = (Graphics2D)g;      g2d.setColor(Color.white) ;      g2d.fillRect(0, 0, this.getWidth() , this.getHeight() ) ;      DeviceCarrier carrier;      DeviceConnector connector;      adjustConnector();      Set  entries = connectors.entrySet();      Iterator iterator = entries.iterator() ;      while (iterator.hasNext()){        Map.Entry entry = (Map.Entry)iterator.next();        connector =(DeviceConnector)entry.getValue();        connector.draw(g);      }/*A collection that contains no duplicate elements. More formally,sets contain no pair of elements e1 and e2   such that e1.equals(e2), and at most one null element. As implied by its name, this interface   models the mathematical set abstraction.*/      entries = carriers.entrySet();      iterator = entries.iterator();/*The Stroke interface allows a Graphics2D object to obtain a Shape that is the decorated outline,  or stylistic representation of the outline, of the specified Shape.*/      Stroke oldStroke =  g2d.getStroke() ;      while (iterator.hasNext()){/*A map entry (key-value pair). The Map.entrySet method returns a collection-view  of the map, whose elements are of this class. The only way to obtain a reference  to a map entry is from the iterator of this collection-view.*/        Map.Entry entry = (Map.Entry)iterator.next();        carrier =(DeviceCarrier)entry.getValue();        carrier.connectorHasDraw=1;        carrier.draw(g);      }//对进行连接两个模块的连接线进行重汇      if (tConnector != null){        tConnector.draw(g);      }//当tconnector和接口产生结合点(显现绿点)时,进行重汇      if (hotLeadArea != null){        g.setColor(Color.red) ;//        g.fillOval(hotLeadArea.x -3 , hotLeadArea.y, 7, 7);        g.drawRect(hotLeadArea.x, hotLeadArea.y,width+4,height+4);        g.setColor(Color.black) ;      }    }  }}

⌨️ 快捷键说明

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