<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

    這一節(jié)主要介紹如何在轉(zhuǎn)移上增加拐點(diǎn),要實(shí)現(xiàn)這功能,首先要修改轉(zhuǎn)移的模型,增加一個(gè)列表屬性,維護(hù)轉(zhuǎn)移上所有的拐點(diǎn),轉(zhuǎn)移模型為實(shí)現(xiàn)拐點(diǎn)功能而增加的代碼如下:

     

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

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

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

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

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

    要讓轉(zhuǎn)移控制器能接受增加拐點(diǎn)的請(qǐng)求,應(yīng)該在轉(zhuǎn)移的控制器上安裝相應(yīng)的策略,代碼如下:
    //add or remove or move the BendPoint
                  installEditPolicy(EditPolicy.CONNECTION_BENDPOINTS_ROLE,new TransitionBendpointEditPolicy());
    在這里安裝了TransitionBendpointEditPolicy策略,這個(gè)策略使的轉(zhuǎn)移控制器能接受增加,刪除和移動(dòng)拐點(diǎn)的請(qǐng)求,這個(gè)類的代碼如下:
    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{
           
           
    /**新建拐點(diǎn) */
           
    protected Command getCreateBendpointCommand(BendpointRequest request) {
                  Point point 
    = request.getLocation();             //得到拐點(diǎn)的坐標(biāo)
                  int index = request.getIndex(); //得到拐點(diǎn)的順序
                  Transition tran = (Transition)getHost().getModel();//得到要增加拐點(diǎn)的轉(zhuǎn)移
    //創(chuàng)建一個(gè)增加拐點(diǎn)的命令,給這命令設(shè)置相應(yīng)的參數(shù)
                  AbstractBendpointCommand cmd = new CreateBendpointCommand();
                  cmd.setIndex(index);
                  cmd.setPoint(point);
                  cmd.setTran(tran);
                  
    return cmd;
           }

    /**刪除拐點(diǎn) */
           
    protected Command getDeleteBendpointCommand(BendpointRequest request) {             
                  
    int index = request.getIndex();//得到拐點(diǎn)的順序        
                  Transition tran = (Transition)getHost().getModel();//得到要?jiǎng)h除拐點(diǎn)的轉(zhuǎn)移
    //創(chuàng)建一個(gè)刪除拐點(diǎn)的命令,給這命令設(shè)置相應(yīng)的參數(shù)
                  AbstractBendpointCommand cmd = new DeleteBendpointCommand();             
                  cmd.setIndex(index);            
                  cmd.setTran(tran);
                  
    return cmd;
           }

    /**移動(dòng)拐點(diǎn) */
           
    protected Command getMoveBendpointCommand(BendpointRequest request) {              
                  
    int index = request.getIndex();//得到拐點(diǎn)的順序
                  Point point = request.getLocation();      //得到拐點(diǎn)的坐標(biāo)
                  Transition tran = (Transition)getHost().getModel();//得到要移動(dòng)拐點(diǎn)的轉(zhuǎn)移
    //創(chuàng)建一個(gè)移動(dòng)拐點(diǎn)的命令,給這命令設(shè)置相應(yīng)的參數(shù)
                  AbstractBendpointCommand cmd = new MoveBendpointCommand();             
                  cmd.setIndex(index);
                  cmd.setPoint(point);
                  cmd.setTran(tran);
                  
    return cmd;
           }

     
    }

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

    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;//拐點(diǎn)的次序
           protected Transition tran;//轉(zhuǎn)移對(duì)象
           protected Point point;//拐點(diǎn)的絕對(duì)位置
           
    //命令的重做方法
           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;
           }

           
           
    }

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

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

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

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

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

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

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

    移動(dòng)拐點(diǎn)的命令
    package com.example.workflow.commands;
     
    import org.eclipse.draw2d.geometry.Point;
     
    /**deleteabendpointforthetransition*/
    publicclass MoveBendpointCommand 
    extends AbstractBendpointCommand{
        
    //移動(dòng)之前拐點(diǎn)的坐標(biāo)
        private Point oldPoint = null;
    //如果轉(zhuǎn)移對(duì)象或者拐點(diǎn)的坐標(biāo)為空,不能執(zhí)行這個(gè)命令
        publicboolean canExecute() {      
           
    return (tran != null&& (point != null);
        }

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

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

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

        }

    //刷新轉(zhuǎn)移對(duì)應(yīng)的視圖,首先得到轉(zhuǎn)移模型中的拐點(diǎn)列表,然后把每個(gè)拐點(diǎn)的坐標(biāo)
    //構(gòu)造成AbsoluteBendpoint對(duì)象,放在一個(gè)新的列表中,然后設(shè)置轉(zhuǎn)移圖形的
    //路由
        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);
        }

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

    這樣,我們運(yùn)行程序,就能看到轉(zhuǎn)移上增加拐點(diǎn)的效果了

    至此,拐點(diǎn)有關(guān)的內(nèi)容,我們就介紹完了,下面我們介紹如何在為編輯器增加大綱視圖。

    Feedback

    # re: 流程設(shè)計(jì)器開發(fā)七(轉(zhuǎn)移拐點(diǎn)部分)  回復(fù)  更多評(píng)論   

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

    # re: 流程設(shè)計(jì)器開發(fā)七(轉(zhuǎn)移拐點(diǎn)部分)  回復(fù)  更多評(píng)論   

    2008-05-14 19:20 by Octo-Lions
    你好,請(qǐng)問怎么保存轉(zhuǎn)移的拐點(diǎn)呢?謝謝
    主站蜘蛛池模板: 亚洲色大成网站www尤物| 亚洲男女性高爱潮网站| 国产亚洲婷婷香蕉久久精品 | 亚洲色欲色欲www在线播放 | 51午夜精品免费视频| 亚洲欧美日韩中文字幕一区二区三区| 久久久久久亚洲精品| 亚洲人成网站18禁止久久影院| 亚洲资源在线观看| 亚洲综合欧美色五月俺也去| 国产精品亚洲精品日韩电影| 亚洲视频国产精品| 亚洲今日精彩视频| 亚洲国产区男人本色在线观看| 黄床大片30分钟免费看| 国产亚洲视频在线播放大全| 中文字幕免费在线播放| 日韩不卡免费视频| 四虎永久成人免费| 日本一区二区三区日本免费| 337p日本欧洲亚洲大胆裸体艺术| 免费一级毛片在线播放| 国产av无码专区亚洲国产精品| 亚洲А∨精品天堂在线| 亚洲Aⅴ无码专区在线观看q| 亚洲精品国产日韩| 国产乱妇高清无乱码免费| 国产大片91精品免费观看不卡| 在线视频免费观看高清| 成人免费在线观看网站| 亚洲国产日韩在线视频| 中国china体内裑精亚洲日本| 国产97视频人人做人人爱免费| 四虎1515hh永久久免费| 亚洲人成电影网站国产精品| 国产成人亚洲影院在线观看| 亚洲伊人精品综合在合线| 一区二区三区在线免费观看视频| 我的小后妈韩剧在线看免费高清版 | 久久精品国产亚洲Aⅴ蜜臀色欲| 337p日本欧洲亚洲大胆裸体艺术|