⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swtscrolledcomposite.java

📁 一个基于PlaceLab的室内和室外的智能导航系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	Rectangle hostRect = getBounds();	int border = getBorderWidth();	hostRect.width -= 2*border;	ScrollBar vBar = getVerticalBar();	if (vVisible && vBar != null) hostRect.width -= vBar.getSize().x;		if (!expandHorizontal && contentRect.width > hostRect.width) return true;	if (expandHorizontal && minWidth > hostRect.width) return true;	return false;}private boolean needVScroll(Rectangle contentRect, boolean hVisible) {	ScrollBar vBar = getVerticalBar();	if (vBar == null) return false;		Rectangle hostRect = getBounds();	int border = getBorderWidth();	hostRect.height -= 2*border;	ScrollBar hBar = getHorizontalBar();	if (hVisible && hBar != null) hostRect.height -= hBar.getSize().y;		if (!expandHorizontal && contentRect.height > hostRect.height) return true;	if (expandHorizontal && minHeight > hostRect.height) return true;	return false;}private void resize() {	if (inResize) return;	inResize = true;	layout();	inResize = false;}/** * Return the point in the content that currenly appears in the top left  * corner of the scrolled composite. *  * @return the point in the content that currenly appears in the top left  * corner of the scrolled composite.  If no content has been set, this returns * (0, 0). *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> *  * @since 2.0 */public Point getOrigin() {	checkWidget();	if (content == null) return new Point(0, 0);	Point location = content.getLocation();	return new Point(-location.x, -location.y);}/** * Scrolls the content so that the specified point in the content is in the top  * left corner.  If no content has been set, nothing will occur.   *  * Negative values will be ignored.  Values greater than the maximum scroll  * distance will result in scrolling to the end of the scrollbar. * * @param origin the point on the content to appear in the top left corner  *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> *    <li>ERROR_INVALID_ARGUMENT - value of origin is outside of content * </ul> * @since 2.0 */public void setOrigin(Point origin) {	setOrigin(origin.x, origin.y);}/** * Scrolls the content so that the specified point in the content is in the top  * left corner.  If no content has been set, nothing will occur.   *  * Negative values will be ignored.  Values greater than the maximum scroll  * distance will result in scrolling to the end of the scrollbar. * * @param x the x coordinate of the content to appear in the top left corner  *  * @param y the y coordinate of the content to appear in the top left corner  *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> *  * @since 2.0 */public void setOrigin(int x, int y) {	checkWidget();	if (content == null) return;	ScrollBar hBar = getHorizontalBar ();	if (hBar != null) {		hBar.setSelection(x);		x = -hBar.getSelection ();	} else {		x = 0;	}	ScrollBar vBar = getVerticalBar ();	if (vBar != null) {		vBar.setSelection(y);		y = -vBar.getSelection ();	} else {		y = 0;	}	content.setLocation(x, y);}/** * Set the Always Show Scrollbars flag.  True if the scrollbars are  * always shown even if they are not required.  False if the scrollbars are only  * visible when some part of the composite needs to be scrolled to be seen. * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the  * horizontal and vertical directions. *  * @param show true to show the scrollbars even when not required, false to show scrollbars only when required *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setAlwaysShowScrollBars(boolean show) {	checkWidget();	if (show == alwaysShowScroll) return;	alwaysShowScroll = show;	ScrollBar hBar = getHorizontalBar ();	if (hBar != null && alwaysShowScroll) hBar.setVisible(true);	ScrollBar vBar = getVerticalBar ();	if (vBar != null && alwaysShowScroll) vBar.setVisible(true);	layout();}/** * Set the content that will be scrolled. *  * @param content the control to be displayed in the content area *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setContent(Control content) {	checkWidget();	if (this.content != null && !this.content.isDisposed()) {		this.content.removeListener(SWT.Resize, contentListener);		this.content.setBounds(new Rectangle(-200, -200, 0, 0));		}		this.content = content;	ScrollBar vBar = getVerticalBar ();	ScrollBar hBar = getHorizontalBar ();	if (this.content != null) {		if (vBar != null) {			vBar.setMaximum (0);			vBar.setThumb (0);			vBar.setSelection(0);		}		if (hBar != null) {			hBar.setMaximum (0);			hBar.setThumb (0);			hBar.setSelection(0);		}		content.setLocation(0, 0);		layout();		this.content.addListener(SWT.Resize, contentListener);	} else {		if (hBar != null) hBar.setVisible(alwaysShowScroll);		if (vBar != null) vBar.setVisible(alwaysShowScroll);	}}/** * Configure the ScrolledComposite to resize the content object to be as wide as the  * ScrolledComposite when the width of the ScrolledComposite is greater than the * minimum width specified in setMinWidth.  If the ScrolledComposite is less than the * minimum width, the content will not resized and instead the horizontal scroll bar will be * used to view the entire width. * If expand is false, this behaviour is turned off.  By default, this behaviour is turned off. *  * @param expand true to expand the content control to fill available horizontal space *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setExpandHorizontal(boolean expand) {	checkWidget();	if (expand == expandHorizontal) return;	expandHorizontal = expand;	layout();}/** * Configure the ScrolledComposite to resize the content object to be as tall as the  * ScrolledComposite when the height of the ScrolledComposite is greater than the * minimum height specified in setMinHeight.  If the ScrolledComposite is less than the * minimum height, the content will not resized and instead the vertical scroll bar will be * used to view the entire height. * If expand is false, this behaviour is turned off.  By default, this behaviour is turned off. *  * @param expand true to expand the content control to fill available vertical space *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setExpandVertical(boolean expand) {	checkWidget();	if (expand == expandVertical) return;	expandVertical = expand;	layout();}public void setLayout (Layout layout) {	// do not allow a layout to be set on this class because layout is being handled by the resize listener	checkWidget();	return;}/** * Specify the minimum height at which the ScrolledComposite will begin scrolling the * content with the vertical scroll bar.  This value is only relevant if   * setExpandVertical(true) has been set. *  * @param height the minimum height or 0 for default height *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setMinHeight(int height) {	setMinSize(minWidth, height);}/** * Specify the minimum width and height at which the ScrolledComposite will begin scrolling the * content with the horizontal scroll bar.  This value is only relevant if   * setExpandHorizontal(true) and setExpandVertical(true) have been set. *  * @param size the minimum size or null for the default size *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setMinSize(Point size) {	if (size == null) {		setMinSize(0, 0);	} else {		setMinSize(size.x, size.y);	}}/** * Specify the minimum width and height at which the ScrolledComposite will begin scrolling the * content with the horizontal scroll bar.  This value is only relevant if   * setExpandHorizontal(true) and setExpandVertical(true) have been set. *  * @param width the minimum width or 0 for default width * @param height the minimum height or 0 for default height *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setMinSize(int width, int height) {	checkWidget();	if (width == minWidth && height == minHeight) return;	minWidth = Math.max(0, width);	minHeight = Math.max(0, height);	layout();}/** * Specify the minimum width at which the ScrolledComposite will begin scrolling the * content with the horizontal scroll bar.  This value is only relevant if   * setExpandHorizontal(true) has been set. *  * @param width the minimum width or 0 for default width *  * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setMinWidth(int width) {	setMinSize(width, minHeight);}private void vScroll() {	if (content == null) return;	Point location = content.getLocation ();	ScrollBar vBar = getVerticalBar ();	int vSelection = vBar.getSelection ();	content.setLocation (location.x, -vSelection);}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -