利用GEF制作表格系统(视图设计)

视图设计

表格视图设计

在编辑器中调色板中,选择表格,拖入编辑器,系统默认显示一个方框的思路,来规划表格的显示图形。由于表格中有很多子元素,所以设置显示图形时,必须考虑子元素的显示位置和子元素的布局管理。

public class TableFigure extends Figure{

      private TableNode model;

      private Figure childPanel;

     

      public TableFigure(TableNode node){

             super();

            

             this.model=node;

            

             init();

            

      }

      public void init(){

             childPanel=new Figure(){

            protected void paintFigure(Graphics g){

                   super.paintFigure(g);

                  

            }

            public Dimension getPreferredSize(int wHint,int hHint){

                   Dimension dimension = super.getPreferredSize(wHint, hHint);

 

                int w = Math.max(dimension.width, 200);

                int h = Math.max(dimension.height, 200);

 

                return new Dimension(w, h);

            }

        };

        if(model.getBgColor() != null){

            childPanel.setBackgroundColor(model.getBgColor());

        }

       

        ToolbarLayout stepLayout = new ToolbarLayout();

 

        stepLayout.setVertical(true);

 

        this.setBorder(new MarginBorder(1, 1, 1, 1));

        this.setLayoutManager(stepLayout);

       

        //设置表格

       

        GridLayout grid=model.getGrid();

        if(grid==null){

            grid=new GridLayout();

        }

       

        childPanel.setLayoutManager(grid);

        this.add(childPanel);

        this.setOpaque(true);

      }

       public void paintFigure(Graphics graphics) {

              super.paintFigure(graphics);

              if(model.isBorder()){

                    Rectangle rect=getBounds();

                   

                    graphics.setForegroundColor(new Color(null, 0, 0, 255));

                      graphics.drawRectangle(new Rectangle(rect.x,rect.y,rect.width-1,rect.height-1));

              }

             

              

      }

      public Figure getContainerFigure() {

        

        return this.childPanel;

    }

      public void setModel(TableNode node){

             this.model=node;

             this.repaint();

            

      }

 

}

 

单元格视图

单元格视图相对比较简单,就显示一个方框。

 

public class CellFigure extends Figure{

      private CellNode model;

      private Figure childPanel;

     

      public CellFigure(CellNode node){

             super();

            

             this.model=node;

            

             init();

            

      }

      public void init(){

             childPanel=new Figure(){

            protected void paintFigure(Graphics g){

                   super.paintFigure(g);

                  

            }

        };

        if(model.getBgColor() != null){

            childPanel.setBackgroundColor(model.getBgColor());

        }

       

        ToolbarLayout stepLayout = new ToolbarLayout();

        //stepLayout.setSpacing(4);

        stepLayout.setVertical(true);

        //this.setBorder(new MarginBorder(8, 8, 8, 8));

        this.setBorder(new MarginBorder(1, 1, 1, 1));

        this.setLayoutManager(stepLayout);

       

        //设置表格

       

        GridLayout grid=new GridLayout();

       

        childPanel.setLayoutManager(grid);

   

        this.add(childPanel);

        this.setOpaque(true);

      }

      public void setModel(CellNode node){

             this.model=node;

             this.repaint();

            

      }

 

}

其它视图

画布采用XYLayout布局,直接在控制器中设置就可以了。

行、列做为逻辑层,不需要设计视图。

 

至此,视图已经设计完成了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值