2010-06-26 3 views
4

나는 smartgwt를 사용하여 이미지를 축소하고 축소하는 코드를 작성했습니다. 하지만 문제가 포함 캔버스 그것을 해결하는 방법을 스크롤 막대의 표시 할 수 없다는 것입니다 그scrollabe Img smartgwt

public class ImageViewer implements EntryPoint { 

static int counter = 0; 
int widths[] = new int[5]; 
int hights[] = new int[5]; 
int originalW=0; 
int originalH=0; 

public void onModuleLoad() { 
    // -------tool bar --------------- 
    ToolStrip toolbar = new ToolStrip(); 
    toolbar.setWidth("100%"); 
    toolbar.addFill(); 

    ToolStripButton max = new ToolStripButton(" + "); 
    ToolStripButton min = new ToolStripButton(" - "); 
    ToolStripButton auto = new ToolStripButton(" auto "); 

    ToolStripButton print = new ToolStripButton(" print "); 
    ToolStripButton save = new ToolStripButton(" save "); 

    toolbar.addButton(max); 
    toolbar.addButton(min); 
    toolbar.addButton(auto); 

    toolbar.addSeparator(); 

    toolbar.addButton(print); 
    toolbar.addButton(save); 
    // ------------------------------- 
    HLayout hLayout = new HLayout(); 
    VLayout vLayout = new VLayout(); 


    SectionStack sectionStack = new SectionStack(); 
    sectionStack.setWidth("100%"); 
    sectionStack.setHeight("100%"); 
    sectionStack.setVisibilityMode(VisibilityMode.MULTIPLE); 
    sectionStack.setAnimateSections(true); 
    sectionStack.setOverflow(Overflow.HIDDEN); 

    SectionStackSection summarySection = new SectionStackSection(); 
    summarySection.setTitle("Image Viewer"); 
    summarySection.setExpanded(true); 
    summarySection.setItems(hLayout); 

    sectionStack.setSections(summarySection); 

    TreeGrid treeGrid = new TreeGrid(); 
    treeGrid.setWidth("20%"); 
    treeGrid.setShowConnectors(true); 
    treeGrid.setShowResizeBar(true); 


    final Canvas imgCanvas = new Canvas(); 
    imgCanvas.setShowEdges(true); 

    final Img img = new Img("http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"); 
    img.setParentElement(imgCanvas); 
    img.draw(); 
    img.setImageType(ImageStyle.CENTER); 
    originalW = img.getWidth(); 
    originalH = img.getHeight(); 
    widths[0] = originalW; 
    hights[0] = originalH; 

    widths[1] = widths[0]*2; 
    hights[1] = hights[0]*2; 

    widths[2] = widths[1]*2; 
    hights[2] = hights[1]*2; 

    widths[3] = widths[2]*2; 
    hights[3] = hights[2]*2; 

    widths[4] = widths[3]*2; 
    hights[4] = hights[3]*2; 



    hLayout.setMembers(treeGrid, vLayout); 
    vLayout.setMembers(toolbar,imgCanvas); 

    RootPanel.get("imgPanel").add(sectionStack); 


    //-------------- handelers -------------------- 

    max.addClickHandler(new ClickHandler() { 

     @Override 
     public void onClick(ClickEvent event) { 
      img.setImageType(ImageStyle.STRETCH); 
      if (counter <4){ 
       counter++; 
       img.animateRect(0, 0, widths[counter] , hights[counter]); 
      } 
     } 
    }); 

    min.addClickHandler(new ClickHandler() { 

     @Override 
     public void onClick(ClickEvent event) { 
      img.setImageType(ImageStyle.STRETCH); 
      if (counter > 0){ 
       counter--; 
       img.animateRect(0, 0, widths[counter], hights[counter]); 
      }    
     } 
    }); 

    auto.addClickHandler(new ClickHandler() { 

     @Override 
     public void onClick(ClickEvent event) { 
      img.setImageType(ImageStyle.CENTER); 
      img.animateRect(0, 0, originalW, originalH); 
      imgCanvas.adjustForContent(true); 

     } 
    }); 
    //--------------------------------------------- 
} 

}

답변

2

imgCanvas.setOverflow (Overflow.AUTO). ImgCanvas는 Img가 imgCanvas의 지정된 크기보다 큰 경우 필요에 따라 스크롤 막대를 표시합니다.