<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 36, comments - 30, trackbacks - 0, articles - 3

    流程設計器開發七(轉移拐點部分)

    Posted on 2008-01-10 09:46 笑看人生 閱讀(1397) 評論(2)  編輯  收藏 所屬分類: Java插件開發

    這一節主要介紹如何在轉移上增加拐點,要實現這功能,首先要修改轉移的模型,增加一個列表屬性,維護轉移上所有的拐點,轉移模型為實現拐點功能而增加的代碼如下:

     

    public static final String BENDPOINT_PROP = "Transition.BendPoint";
    private List bendPoints = new ArrayList();//存放轉移上的所有拐點的坐標
    //向轉移上增加拐點(拐點在轉移上是有順序的)
    //index 拐點的順序
    //point 觀點的坐標
    public void addBendPoint(int index,Point point){
                  
    if(point == null){
                         
    throw new IllegalArgumentException();
                  }

                  bendPoints.add(index,point);
    //通知轉移控制器,轉移的拐點屬性變化了,讓它刷新視圖
                  firePropertyChange(BENDPOINT_PROP, null, point);
           }

    //從轉移上刪除指定位置的拐點
    public void removeBendPoint(int index){
                  
    if(index<0){
                         
    throw new IllegalArgumentException();
                  }

                  bendPoints.remove(index);
    //通知轉移控制器,轉移的拐點屬性變化了,讓它刷新視圖
     
                  firePropertyChange(BENDPOINT_PROP, 
    nullnull);
           }

    //得到轉移上的拐點列表
    public List getBendPoints() {
                  
    return new ArrayList(bendPoints);
           }

    要讓轉移控制器能接受增加拐點的請求,應該在轉移的控制器上安裝相應的策略,代碼如下:
    //add or remove or move the BendPoint
                  installEditPolicy(EditPolicy.CONNECTION_BENDPOINTS_ROLE,new TransitionBendpointEditPolicy());
    在這里安裝了TransitionBendpointEditPolicy策略,這個策略使的轉移控制器能接受增加,刪除和移動拐點的請求,這個類的代碼如下:
    package com.example.workflow.policy;
     
    import org.eclipse.draw2d.geometry.Point;
    import org.eclipse.gef.commands.Command;
    import org.eclipse.gef.editpolicies.BendpointEditPolicy;
    import org.eclipse.gef.requests.BendpointRequest;
     
    import com.example.workflow.commands.AbstractBendpointCommand;
    import com.example.workflow.commands.CreateBendpointCommand;
    import com.example.workflow.commands.DeleteBendpointCommand;
    import com.example.workflow.commands.MoveBendpointCommand;
    import com.example.workflow.model.Transition;
     
    /**
     * EditPolicy for the BendPoint used by this edit part. 
     
    */

    public class TransitionBendpointEditPolicy extends BendpointEditPolicy{
           
           
    /**新建拐點 */
           
    protected Command getCreateBendpointCommand(BendpointRequest request) {
                  Point point 
    = request.getLocation();             //得到拐點的坐標
                  int index = request.getIndex(); //得到拐點的順序
                  Transition tran = (Transition)getHost().getModel();//得到要增加拐點的轉移
    //創建一個增加拐點的命令,給這命令設置相應的參數
                  AbstractBendpointCommand cmd = new CreateBendpointCommand();
                  cmd.setIndex(index);
                  cmd.setPoint(point);
                  cmd.setTran(tran);
                  
    return cmd;
           }

    /**刪除拐點 */
           
    protected Command getDeleteBendpointCommand(BendpointRequest request) {             
                  
    int index = request.getIndex();//得到拐點的順序        
                  Transition tran = (Transition)getHost().getModel();//得到要刪除拐點的轉移
    //創建一個刪除拐點的命令,給這命令設置相應的參數
                  AbstractBendpointCommand cmd = new DeleteBendpointCommand();             
                  cmd.setIndex(index);            
                  cmd.setTran(tran);
                  
    return cmd;
           }

    /**移動拐點 */
           
    protected Command getMoveBendpointCommand(BendpointRequest request) {              
                  
    int index = request.getIndex();//得到拐點的順序
                  Point point = request.getLocation();      //得到拐點的坐標
                  Transition tran = (Transition)getHost().getModel();//得到要移動拐點的轉移
    //創建一個移動拐點的命令,給這命令設置相應的參數
                  AbstractBendpointCommand cmd = new MoveBendpointCommand();             
                  cmd.setIndex(index);
                  cmd.setPoint(point);
                  cmd.setTran(tran);
                  
    return cmd;
           }

     
    }

    在上面的策略類中,我們覆蓋了父類的三個方法,在這三個方法中,我們分別新建了CreateBendpointCommand,DeleteBendpointCommand,MoveBendpointCommand命令,由于這三個類有一些公共屬性和方法,因此我們進行了抽象,把公共屬性和方法抽象到父類中,這幾個命令的代碼如下:
    父類:

    package com.example.workflow.commands;
    import org.eclipse.draw2d.geometry.Point;
    import org.eclipse.gef.commands.Command;
    import com.example.workflow.model.Transition;
    public class AbstractBendpointCommand extends Command{
           
           
    protected int index;//拐點的次序
           protected Transition tran;//轉移對象
           protected Point point;//拐點的絕對位置
           
    //命令的重做方法
           public void redo(){
                  execute();
           }

           
           
    public void setPoint(Point point) {
                  
    this.point = point;
           }

           
    public void setIndex(int index) {
                  
    this.index = index;
           }

           
    public void setTran(Transition tran) {
                  
    this.tran = tran;
           }

           
           
    }

    新建拐點命令
    package com.example.workflow.commands;
     
    /**createabendpointforthetransition*/
    publicclass CreateBendpointCommand 
    extends AbstractBendpointCommand
    //如果轉移對象或者拐點的坐標為空,不能執行這個命令
        publicboolean canExecute() {      
           
    return (tran != null&& (point != null);
        }

    //命令的執行方法,在轉移維護的拐點列表中增加拐點信息,拐點位置作為索引,拐點坐標作//為值
        publicvoid execute() {
           tran.addBendPoint(index, point);       
        }

    //命令的撤銷,從在轉移維護的拐點列表中刪除指定位置的拐點
        publicvoid undo() {
           tran.removeBendPoint(index);
        }

    //標志執行命令的名稱
        public String getLabel() {      
           
    return"create bendpoint";
        }
       
        
    }

    刪除拐點的命令
    package com.example.workflow.commands;
     
    import org.eclipse.draw2d.geometry.Point;
     
    /**deleteabendpointforthetransition*/
    publicclass DeleteBendpointCommand 
    extends AbstractBendpointCommand{
        
    //如果轉移對象為空,不能執行這個命令
        publicboolean canExecute() {      
           
    return (tran != null);
        }

    //首先取出要刪除拐點的坐標,以備撤銷操作時使用,然后再從列表中刪除指定位置的拐點
        publicvoid execute() {
           point 
    = (Point)tran.getBendPoints().get(index);
           tran.removeBendPoint(index);
        }

    //撤銷操作,在列表的指定位置,增加剛才刪除的拐點
        publicvoid undo() {
           tran.addBendPoint(index, point);
        }
       
        
    //標志執行命令的名稱
        public String getLabel() {      
           
    return"delete bendpoint";
        }
       
    }

    移動拐點的命令
    package com.example.workflow.commands;
     
    import org.eclipse.draw2d.geometry.Point;
     
    /**deleteabendpointforthetransition*/
    publicclass MoveBendpointCommand 
    extends AbstractBendpointCommand{
        
    //移動之前拐點的坐標
        private Point oldPoint = null;
    //如果轉移對象或者拐點的坐標為空,不能執行這個命令
        publicboolean canExecute() {      
           
    return (tran != null&& (point != null);
        }

    //首先得到移動之前的拐點的坐標,以備撤銷操作使用
    //然后再刪除這個拐點
    //最后再增加新的拐點
        publicvoid execute() {
           oldPoint 
    = (Point)tran.getBendPoints().get(index);
           tran.removeBendPoint(index);
           tran.addBendPoint(index, point);
        }

    //撤銷操作,首先刪除新的拐點,然后再增加上原來拐點
        publicvoid undo() {
           tran.removeBendPoint(index);
           tran.addBendPoint(index, oldPoint);
        }
       
        
    //標志執行命令的名稱
        public String getLabel() {      
           
    return"move bendpoint";
        }
       
    }

    以前我們新建轉移時,都不用刷新轉移的Figure,現在在轉移上增加了拐點,要想顯示出拐點的效果,就必須覆蓋轉移控制器的refreshVisuals方法,代碼如下:
    //因為在轉移模型的addBendPoint和removeBendPoint方法中,都通知轉移控制器
    //轉移的BENDPOINT_PROP屬性發生變化,所以在這兒我們當
    //變化屬性的名稱是BENDPOINT_PROP,我們刷新視圖
    public void propertyChange(PropertyChangeEvent evt) {
           String prop 
    = evt.getPropertyName();   
           
    if(Transition.BENDPOINT_PROP.equals(prop)){
               refreshVisuals();
           }

        }

    //刷新轉移對應的視圖,首先得到轉移模型中的拐點列表,然后把每個拐點的坐標
    //構造成AbsoluteBendpoint對象,放在一個新的列表中,然后設置轉移圖形的
    //路由
        protected void refreshVisuals() 
           List constraint 
    = new ArrayList();
           List list 
    = getCastedModel().getBendPoints();
           
    for(int i=0;i<list.size();i++){        
               constraint.add(
    new AbsoluteBendpoint((Point)list.get(i)));
           }

           getConnectionFigure().setRoutingConstraint(constraint);
        }

    要想使轉移視圖展示出拐點,我們還必須修改createFigure方法,修改如下:
    protected IFigure createFigure() {
           PolylineConnection connection 
    = (PolylineConnection) super.createFigure();
           connection.setTargetDecoration(
    new PolygonDecoration()); // arrow at target endpoint    
           connection.setConnectionRouter(new BendpointConnectionRouter());//為了顯示拐點,設置轉移的路由
           return connection;
        }

    這樣,我們運行程序,就能看到轉移上增加拐點的效果了

    至此,拐點有關的內容,我們就介紹完了,下面我們介紹如何在為編輯器增加大綱視圖。

    Feedback

    # re: 流程設計器開發七(轉移拐點部分)  回復  更多評論   

    2008-01-10 15:11 by Strive
    老大,確實牛,正是我要的,哈哈,頂.

    # re: 流程設計器開發七(轉移拐點部分)  回復  更多評論   

    2008-05-14 19:20 by Octo-Lions
    你好,請問怎么保存轉移的拐點呢?謝謝
    主站蜘蛛池模板: 国产成人免费ā片在线观看老同学| 免费在线中文日本| 亚洲av日韩av天堂影片精品| 久9热免费精品视频在线观看| 亚洲福利电影一区二区?| 91精品成人免费国产| 亚洲高清资源在线观看| 全免费a级毛片免费看不卡| 亚洲春色另类小说| 国产精品免费一级在线观看| 国产一区二区免费| 亚洲精品无码aⅴ中文字幕蜜桃| 97人伦色伦成人免费视频 | 日韩精品视频在线观看免费| 精品国产亚洲一区二区三区| 久久精品国产免费| 亚洲欧洲专线一区| 亚洲国产精品乱码一区二区| 污视频在线观看免费| 大桥未久亚洲无av码在线| 俄罗斯极品美女毛片免费播放| 香蕉免费一区二区三区| 精品久久久久亚洲| 亚洲宅男天堂a在线| 在线观看国产区亚洲一区成人| 久久久久久99av无码免费网站| 色www永久免费网站| 亚洲AV成人无码久久WWW| 亚洲综合激情六月婷婷在线观看 | 日日操夜夜操免费视频| 一级毛片不卡片免费观看| 成人午夜免费视频| 国产亚洲av片在线观看播放| 成人永久免费高清| 嫖丰满老熟妇AAAA片免费看| 性色午夜视频免费男人的天堂| 一本大道一卡二大卡三卡免费| 日韩亚洲AV无码一区二区不卡| 亚洲一区二区视频在线观看| 在线观看免费亚洲| 最新猫咪www免费人成|