@Test public void testRenderScrollBarsVisibleUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(sc); Fixture.markInitialized(hScroll); Fixture.markInitialized(vScroll); hScroll.setVisible(false); vScroll.setVisible(false); Fixture.preserveWidgets(); lca.renderChanges(sc); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(hScroll, "visibility")); assertNull(message.findSetOperation(vScroll, "visibility")); }
@Test public void testRenderScrollBarsVisible_Vertical() throws IOException { vScroll.setVisible(true); lca.renderChanges(sc); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(hScroll, "visibility")); assertEquals(JsonValue.TRUE, message.findSetProperty(vScroll, "visibility")); }
private void resizeScrollBar() { int imageWidth = patchedBothImage.getImageData().width + 50; int imageHeight = patchedBothImage.getImageData().height + patchedHeightImage.getImageData().height + patchedWidthImage.getImageData().height + 50; Rectangle rect = canvas.getBounds(); if (backgroundImage != null && !backgroundImage.isDisposed()) { backgroundImage.dispose(); } if (rect.width < imageWidth && rect.height < imageHeight) { backgroundImage = createTransparentBackground(imageWidth, imageHeight); vBar.setVisible(true); hBar.setVisible(true); } else if (rect.width < imageWidth && rect.height > imageHeight) { backgroundImage = createTransparentBackground(imageWidth, rect.height); vBar.setVisible(false); hBar.setVisible(true); } else if (rect.width > imageWidth && rect.height < imageHeight) { backgroundImage = createTransparentBackground(rect.width, imageHeight); vBar.setVisible(true); hBar.setVisible(false); } if (backgroundImage.isDisposed()) { backgroundImage = createTransparentBackground(rect.width, rect.height); vBar.setVisible(false); hBar.setVisible(false); } hBar.setMaximum(imageWidth); vBar.setMaximum(imageHeight); hBar.setThumb(Math.min(imageWidth, rect.width)); vBar.setThumb(Math.min(imageHeight, rect.height)); int hPage = imageWidth - rect.width; int vPage = imageHeight - rect.height; int hSelection = hBar.getSelection(); int vSelection = vBar.getSelection(); if (hSelection >= hPage) { if (hPage <= 0) { hSelection = 0; } origin.x = -hSelection; } if (vSelection >= vPage) { if (vPage <= 0) { vSelection = 0; } origin.y = -vSelection; } }
private void updateScrollBars() { ScrollBar hBar = getHorizontalBar(); ScrollBar vBar = getVerticalBar(); if (image == null || image.isDisposed()) { hBar.setVisible(false); vBar.setVisible(false); return; } // 표시해야할 이미지의 크기 Rectangle imageBounds = image != null ? image.getBounds() : new Rectangle(0, 0, 0, 0); // 표시에 사용할 수 있는 클라이언트 영역 Rectangle clientArea = getClientArea(); // 스크롤바 표시 여부 계산, 표시해야할 그림이 클라이언트 영역보다 넓으면 표시 hBar.setVisible(imageBounds.width > clientArea.width); vBar.setVisible(imageBounds.height > clientArea.height); hBar.setMaximum(imageBounds.width); vBar.setMaximum(imageBounds.height); clientArea = getClientArea(); // 현재 표시중인 영역이 표시해야할 전체 영역에 대한 비율을 계산 double hRatio = clientArea.width / (double) imageBounds.width; double vRatio = clientArea.height / (double) imageBounds.height; // 스크롤바의 썸 크기 업데이트 hBar.setThumb((int) (hRatio * imageBounds.width)); vBar.setThumb((int) (vRatio * imageBounds.height)); // 스크롤바 빈영역 클릭시 10% 정도씩 이동하도록 지정 hBar.setPageIncrement((int) (imageBounds.width * 0.1)); vBar.setPageIncrement((int) (imageBounds.height * 0.1)); }
/** This only works on linux */ private void syncTreeTableScrollBars() { final ScrollBar treeBar = treeComposite.getTree().getHorizontalBar(); final ScrollBar totalBar = totalComposite.getTable().getHorizontalBar(); treeBar.setVisible(false); treeBar.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { scrollTable(); } @Override public void widgetSelected(SelectionEvent e) { scrollTable(); } private void scrollTable() { int selection = treeBar.getSelection(); totalBar.setSelection(selection); } }); totalBar.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { scrollTree(); } @Override public void widgetSelected(SelectionEvent e) { scrollTree(); } private void scrollTree() { int selection = totalBar.getSelection(); treeBar.setSelection(selection); } }); }
protected void layout(Composite composite, boolean flushCache) { if (inLayout) { return; } ScrolledComposite sc = (ScrolledComposite) composite; if (sc.content == null) { return; } ScrollBar hBar = sc.getHorizontalBar(); ScrollBar vBar = sc.getVerticalBar(); if (hBar != null) { if (hBar.getSize().y >= sc.getSize().y) { return; } } if (vBar != null) { if (vBar.getSize().x >= sc.getSize().x) { return; } } inLayout = true; Rectangle contentRect = sc.content.getBounds(); if (!sc.alwaysShowScroll) { boolean hVisible = sc.needHScroll(contentRect, false); boolean vVisible = sc.needVScroll(contentRect, hVisible); if (!hVisible && vVisible) { hVisible = sc.needHScroll(contentRect, vVisible); } if (hBar != null) { hBar.setVisible(hVisible); } if (vBar != null) { vBar.setVisible(vVisible); } } Rectangle hostRect = sc.getClientArea(); if (sc.expandHorizontal) { contentRect.width = Math.max(sc.minWidth, hostRect.width); } if (sc.expandVertical) { contentRect.height = Math.max(sc.minHeight, hostRect.height); } if (hBar != null) { hBar.setMaximum(contentRect.width); hBar.setThumb(Math.min(contentRect.width, hostRect.width)); int hPage = contentRect.width - hostRect.width; int hSelection = hBar.getSelection(); if (hSelection >= hPage) { if (hPage <= 0) { hSelection = 0; hBar.setSelection(0); } contentRect.x = -hSelection; } } if (vBar != null) { vBar.setMaximum(contentRect.height); vBar.setThumb(Math.min(contentRect.height, hostRect.height)); int vPage = contentRect.height - hostRect.height; int vSelection = vBar.getSelection(); if (vSelection >= vPage) { if (vPage <= 0) { vSelection = 0; vBar.setSelection(0); } contentRect.y = -vSelection; } } sc.content.setBounds(contentRect); inLayout = false; }