posts - 59, comments - 244, trackbacks - 0, articles - 0
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          jbpm流程設(shè)計(jì)器開發(fā)(2)

          Posted on 2010-08-25 15:24 penngo 閱讀(4265) 評(píng)論(1)  編輯  收藏 所屬分類: JBPM
          jbpm流程設(shè)計(jì)器開發(fā)(1)

          本篇主要實(shí)現(xiàn)了多個(gè)流程節(jié)點(diǎn)的繪制。

          部分功能代碼
          FlowNode.xml主要配置流程節(jié)點(diǎn)的屬性。

          <?xml version="1.0" encoding="GBK" standalone="yes"?>
          <flowNode>
              
          <node height="40" width="40" type="straight" shape="shape=ellipse;perimeter=ellipsePerimeter;" 

          icon
          ="images/straight.gif" label="直線"/>
              
          <node height="40" width="40" type="start" shape="shape=ellipse;perimeter=ellipsePerimeter;" icon="images/start.gif" 

          label
          ="開始"/>
              
          <node height="40" width="40" type="end" shape="shape=doubleEllipse;perimeter=ellipsePerimeter;" icon="images/end.gif" 

          label
          ="結(jié)束"/>
              
          <node height="40" width="80" type="state" shape="rounded=1;" icon="images/state.gif" label="狀態(tài)"/>
              
          <node height="40" width="80" type="task" shape="rounded=1;" icon="images/task.gif" label="任務(wù)"/>
              
          <node height="40" width="40" type="decision" shape="shape=rhombus;perimeter=rhombusPerimeter;" 

          icon
          ="images/decision.gif" label="判斷"/>
              
          <node height="40" width="40" type="fork" shape="shape=rhombus;perimeter=rhombusPerimeter;" icon="images/fork.gif" 

          label
          ="分支"/>
              
          <node height="40" width="40" type="join" shape="shape=rhombus;perimeter=rhombusPerimeter;" icon="images/join.gif" 

          label
          ="合并"/>
          </flowNode>

          LeftPanel.java主要顯示流程節(jié)點(diǎn)列表
          package com.workflow.designer.view;
          import java.awt.Color;
          import java.awt.Component;
          import java.awt.Desktop;
          import java.awt.event.MouseAdapter;
          import java.awt.event.MouseEvent;
          import java.io.File;

          import javax.swing.DefaultListModel;
          import javax.swing.Icon;
          import javax.swing.ImageIcon;
          import javax.swing.JLabel;
          import javax.swing.JList;
          import javax.swing.JPanel;
          import javax.swing.ListCellRenderer;
          import javax.swing.filechooser.FileSystemView;
          import javax.xml.bind.JAXBContext;
          import javax.xml.bind.Unmarshaller;

          import com.mxgraph.view.mxGraph;
          import com.workflow.designer.model.FlowNode;
          import com.workflow.designer.model.Node;
          import com.workflow.designer.util.Logger;

          public class LeftPanel extends JList{
              
          //private JList list = null;
              private GraphImpl graph = null;
              
          private DefaultListModel listModel = null;
              
          public LeftPanel(){
                  init();
              }

              
              
          public DefaultListModel getListModel() {
                  
          return listModel;
              }


              
          public void setListModel(DefaultListModel listModel) {
                  
          this.listModel = listModel;
              }


              
          private void init() {
                  listModel 
          = new DefaultListModel();
                  
                  
          try{
                      
          //JList數(shù)據(jù)初始化
                  JAXBContext jc = JAXBContext.newInstance("com.workflow.designer.model");
                  Unmarshaller u 
          = jc.createUnmarshaller();
                  FlowNode fn 
          = (FlowNode) u
                  .unmarshal(FlowNode.
          class.getClassLoader().getResourceAsStream("com/workflow/designer/model/FlowNode.xml"));
                  
          for(Node n:fn.getNode()){
                      listModel.addElement(n);
                  }

                  }

                  
          catch(Exception e){
                      e.printStackTrace();
                  }

                  
          this.setModel(listModel);
                  
          this.setCellRenderer(new MyCellRenderer());
                  
          this.addMouseListener(new MouseAdapter() {
                      
          public void mouseClicked(MouseEvent e) {
                          
          super.mouseClicked(e);
                      }

                  
                      
          public void mousePressed(MouseEvent e) {

                          
          super.mousePressed(e);
                      }

                  }
          );
              
              }

              
              
          class MyCellRenderer extends JLabel implements ListCellRenderer {
                  
          public Component getListCellRendererComponent(JList list, 
                          Object value, 
                          
          int index, 
                          
          boolean isSelected, 
                          
          boolean cellHasFocus) 
                  
          {
                      
          if (value instanceof Node) {
                          Node n 
          = (Node) value;
                          Icon icon 
          = new ImageIcon(getClass().getClassLoader().getResource(n.getIcon()));
                          setIcon(icon);
                      }

                      String s 
          = value.toString();
                      setText(s);
                      
          this.setToolTipText(s);
                      
                      
          if (isSelected) {
                          setBackground(list.getSelectionBackground());
                          setForeground(list.getSelectionForeground());
                      }
           else {
                          setBackground(Color.WHITE);
                          setForeground(list.getForeground());
                      }

                      
                      setEnabled(list.isEnabled());
                      setOpaque(
          true);
                      
          return this;
                  }

              }

              
              
          public void setGraph(GraphImpl gi) {
                  
          this.graph = gi;
              }

              
              
          public static void main(String arg[]) {
                  
          new LeftPanel();
              }

          }

          GraphView.java獲取LeftPanel中被選中的節(jié)點(diǎn),并在面板上繪制該節(jié)點(diǎn)
          package com.workflow.designer.view;

          import java.awt.Point;
          import java.awt.event.MouseEvent;

          import com.mxgraph.model.mxCell;
          import com.mxgraph.view.mxGraph;
          import com.workflow.designer.model.Node;
          import com.workflow.designer.util.Logger;

          public class GraphView extends GraphImpl{
              
          private mxGraph graph = this.getGraph();
              
          private Object parent = graph.getDefaultParent();
              
          private LeftPanel lp = null;
               
          public GraphView(LeftPanel lp){
                   
          this.lp = lp;
               }


               
          public void inser(Point p, Node n){
                   
          this.getGraph().getModel().beginUpdate();
                      
          try
                      
          {
                          
          //調(diào)用jgraph插入節(jié)點(diǎn)
                         Object v1 = graph.insertVertex(parent, null, n.getLabel(), p.getX() - 5, p.getY() - 5

          n.getWidth(),
                               n.getHeight(), n.getShape());
                         ((mxCell)v1).setConnectable(
          false);
                      }

                      
          finally
                      
          {
                         graph.getModel().endUpdate();
                      }

               }

               
               
          public void mouseClicked(MouseEvent e){
                  
          //獲取被選中節(jié)點(diǎn)
                   Object obj = lp.getSelectedValue();
                   
          if(obj instanceof Node){
                       Node n 
          = (Node)obj;
                       Point p 
          = e.getPoint();
                       
          if(!n.getType().equals("straight")){
                          
          //鼠標(biāo)點(diǎn)擊時(shí),在jgraph面板上插入節(jié)點(diǎn)
                           inser(p, n);
                           lp.clearSelection();
                       }

                   }

               }


              
          public void mousePressed(MouseEvent e){
                  
              }


              
          public void mouseReleased(MouseEvent e){
                  
              }


              
          public void mouseEntered(MouseEvent e){
                  
          //只有在線條節(jié)點(diǎn)被選中時(shí),才能繪制連接線
                  Object obj = lp.getSelectedValue();
                   
          if(obj instanceof Node){
                       Node n 
          = (Node)obj;
                       Object parent 
          = graph.getDefaultParent();
                       Object childs[] 
          = graph.getChildCells(parent);
                       
          if(n.getType().equals("straight")){
                          
          for(Object cell:childs){
                              ((mxCell)cell).setConnectable(
          true); //設(shè)置可連線
                          }

                       }

                       
          else{
                           
          for(Object cell:childs){
                              ((mxCell)cell).setConnectable(
          false);
                          }

                       }

                  }

              }


              
          public void mouseExited(MouseEvent e){
              }

          }


          繪制的流程圖


          現(xiàn)在已經(jīng)基本實(shí)現(xiàn)流程的繪制了,下一篇將會(huì)介紹流程定義文件保存打開。
          源碼:源碼
          打包jar:jgraphxflow.jar


          評(píng)論

          # re: jbpm流程設(shè)計(jì)器開發(fā)(2)  回復(fù)  更多評(píng)論   

          2010-08-25 18:06 by pengo
          忘記說,附件的jar都是JDK1.6編譯的。還未具體研究過jbpm4.4的流程定義文件,下一篇還要過比較久才能寫得出來(lái)。
          主站蜘蛛池模板: 翁源县| 怀宁县| 鱼台县| 深圳市| 循化| 阜阳市| 忻州市| 武汉市| 沙河市| 白城市| 郓城县| 三河市| 新平| 保德县| 大丰市| 赤峰市| 读书| 龙井市| 神农架林区| 精河县| 凤城市| 鄂托克旗| 无极县| 泸西县| 临沭县| 牙克石市| 类乌齐县| 垦利县| 旅游| 常山县| 昂仁县| 浙江省| 盘锦市| 玉山县| 纳雍县| 苗栗市| 凤台县| 阳信县| 旌德县| 平乐县| 江油市|