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

📄 ctabitem.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		gc.drawText(shortenedText, xDraw, textY, FLAGS);		gc.setFont(gcFont);				// draw a Focus rectangle		if (parent.isFocusControl()) {			Display display = getDisplay();			if (parent.simple || parent.single) {				gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));				gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));				gc.drawFocus(xDraw-1, textY-1, extent.x+2, extent.y+2);			} else {				gc.setForeground(display.getSystemColor(CTabFolder.BUTTON_BORDER));				gc.drawLine(xDraw, textY+extent.y+1, xDraw+extent.x+1, textY+extent.y+1);			}		}	}	if (parent.showClose || showClose) drawClose(gc);}void drawUnselected(GC gc) {	// Do not draw partial items	if (!isShowing()) return;		Rectangle clipping = gc.getClipping();	Rectangle bounds = getBounds();	if (!clipping.intersects(bounds)) return;		// draw border	if (parent.indexOf(this) != parent.selectedIndex - 1) {		gc.setForeground(CTabFolder.borderColor);		gc.drawLine(x + width - 1, y, x + width - 1, y + height);	}	// draw Image	int xDraw = x + LEFT_MARGIN;	Image image = getImage();	if (image != null && parent.showUnselectedImage) {		Rectangle imageBounds = image.getBounds();		// only draw image if it won't overlap with close button		int maxImageWidth = x + width - xDraw - RIGHT_MARGIN;		if (parent.showUnselectedClose && (parent.showClose || showClose)) {			maxImageWidth -= closeRect.width + INTERNAL_SPACING;		}		if (imageBounds.width < maxImageWidth) {					int imageX = xDraw;			int imageHeight = imageBounds.height;			int imageY = y + (height - imageHeight) / 2;			imageY += parent.onBottom ? -1 : 1;			int imageWidth = imageBounds.width * imageHeight / imageBounds.height;			gc.drawImage(image, 				         imageBounds.x, imageBounds.y, imageBounds.width, imageBounds.height,				         imageX, imageY, imageWidth, imageHeight);			xDraw += imageWidth + INTERNAL_SPACING;		}	}	// draw Text	int textWidth = x + width - xDraw - RIGHT_MARGIN;	if (parent.showUnselectedClose && (parent.showClose || showClose)) {		textWidth -= closeRect.width + INTERNAL_SPACING;	}	if (textWidth > 0) {		Font gcFont = gc.getFont();		gc.setFont(font == null ? parent.getFont() : font);		if (shortenedText == null || shortenedTextWidth != textWidth) {			shortenedText = shortenText(gc, getText(), textWidth);			shortenedTextWidth = textWidth;		}			Point extent = gc.textExtent(shortenedText, FLAGS);		int textY = y + (height - extent.y) / 2;		textY += parent.onBottom ? -1 : 1;		gc.setForeground(parent.getForeground());		gc.drawText(shortenedText, xDraw, textY, FLAGS);		gc.setFont(gcFont);	}	// draw close	if (parent.showUnselectedClose && (parent.showClose || showClose)) drawClose(gc);}/** * Returns a rectangle describing the receiver's size and location * relative to its parent. * * @return the receiver's bounding column rectangle * * @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 Rectangle getBounds () {	//checkWidget();	int w = width;	if (!parent.simple && !parent.single && parent.indexOf(this) == parent.selectedIndex) w += parent.curveWidth - parent.curveIndent;	return new Rectangle(x, y, w, height);}/*** Gets the control that is displayed in the content are of the tab item.** @return the control** @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 Control getControl () {	checkWidget();	return control;}/** * Get the image displayed in the tab if the tab is disabled. *  * @return the disabled image or null *  * @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> *  * @deprecated the disabled image is not used */public Image getDisabledImage(){	checkWidget();	return disabledImage;}/** * Returns the font that the receiver will use to paint textual information. * * @return the receiver's font * * @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 3.0 */public Font getFont() {	checkWidget();	if (font != null) return font;	return parent.getFont();}/** * Returns the receiver's parent, which must be a <code>CTabFolder</code>. * * @return the receiver's parent *  * @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 CTabFolder getParent () {	//checkWidget();	return parent;}/** * Returns the receiver's tool tip text, or null if it has * not been set. * * @return the receiver's tool tip text * * @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 String getToolTipText () {	checkWidget();	if (toolTipText == null && shortenedText != null) {		String text = getText();		if (!shortenedText.equals(text)) return text;	}	return toolTipText;}/*** Returns <code>true</code> if the item will be rendered in the visible area of the CTabFolder. Returns false otherwise.* *  @return <code>true</code> if the item will be rendered in the visible area of the CTabFolder. Returns false otherwise.* *  @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 3.0*/public boolean isShowing () {	checkWidget();	int index = parent.indexOf(this);	int rightEdge = parent.getRightItemEdge();	if (parent.single) {		if (index == parent.selectedIndex) {			return x <= rightEdge;		}		return false;	}	if (index < parent.firstIndex) return false;	if (parent.firstIndex == index) {		return x <= rightEdge;	}	int extra = parent.simple || index != parent.selectedIndex ? 0 : parent.curveWidth - 2*parent.curveIndent;	return x + width + extra <= rightEdge;}void onPaint(GC gc, boolean isSelected) {	if (width == 0 || height == 0) return;	if (isSelected) {		drawSelected(gc);	} else {		drawUnselected(gc);	}}int preferredHeight(GC gc) {	Image image = getImage();	int h = (image == null) ? 0 : image.getBounds().height;	String text = getText();	if (font == null) {		h = Math.max(h, gc.textExtent(text, FLAGS).y);	} else {		Font gcFont = gc.getFont();		gc.setFont(font);		h = Math.max(h, gc.textExtent(text, FLAGS).y);		gc.setFont(gcFont);	}	return h + TOP_MARGIN + BOTTOM_MARGIN;}int preferredWidth(GC gc, boolean isSelected, boolean minimum) {	// NOTE: preferred width does not include the "dead space" caused	// by the curve.	if (isDisposed()) return 0;	int w = 0;	Image image = getImage();	if (image != null && (isSelected || parent.showUnselectedImage)) {		w += image.getBounds().width;	}	String text = null;	if (minimum) {		int minChars = parent.minChars;		text = minChars == 0 ? null : getText();		if (text != null && text.length() > minChars) {			int end = minChars < ELLIPSIS.length() + 1 ? minChars : minChars - ELLIPSIS.length();			text = text.substring(0, end);			if (minChars > ELLIPSIS.length() + 1) text += ELLIPSIS;		}	} else {		text = getText();	}	if (text != null) {		if (w > 0) w += INTERNAL_SPACING;		if (font == null) {			w += gc.textExtent(text, FLAGS).x;		} else {			Font gcFont = gc.getFont();			gc.setFont(font);			w += gc.textExtent(text, FLAGS).x;			gc.setFont(gcFont);		}	}	if (parent.showClose || showClose) {		if (isSelected || parent.showUnselectedClose) {			if (w > 0) w += INTERNAL_SPACING;			w += CTabFolder.BUTTON_SIZE;		}	}	return w + LEFT_MARGIN + RIGHT_MARGIN;}/** * Sets the control that is used to fill the client area of * the tab folder when the user selects the tab item. * * @param control the new control (or null) * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>  *    <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> * </ul> * @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 setControl (Control control) {	checkWidget();	if (control != null) {		if (control.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);		if (control.getParent() != parent) SWT.error (SWT.ERROR_INVALID_PARENT);	}	if (this.control != null && !this.control.isDisposed()) {		this.control.setVisible(false);	}	this.control = control;	if (this.control != null) {		int index = parent.indexOf (this);		if (index == parent.getSelectionIndex ()){			this.control.setBounds(parent.getClientArea ());			this.control.setVisible(true);		} else {			this.control.setVisible(false);		}	}}/** * Sets the image that is displayed if the tab item is disabled. * Null will clear the image. *  * @param image the image to be displayed when the item is disabled or null * * @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> *  * @deprecated This image is not used */public void setDisabledImage (Image image) {	checkWidget();	if (image != null && image.isDisposed ()) {		SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}	this.disabledImage = image;}/** * Sets the font that the receiver will use to paint textual information * for this item to the font specified by the argument, or to the default font * for that kind of control if the argument is null. * * @param font the new font (or null) * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>  * </ul> * @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 3.0 */public void setFont (Font font){	checkWidget();	if (font != null && font.isDisposed ()) {		SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}	if (font == null && this.font == null) return;	if (font != null && font.equals(this.font)) return;	this.font = font;	if (!parent.updateTabHeight(false)) {		parent.updateItems();		parent.redraw();	}}public void setImage (Image image) {	checkWidget();	if (image != null && image.isDisposed ()) {		SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}	Image oldImage = getImage();	if (image == null && oldImage == null) return;	if (image != null && image.equals(oldImage)) return;	super.setImage(image);	if (!parent.updateTabHeight(false)) {		parent.updateItems();	}	parent.redraw();}public void setText (String string) {	checkWidget();	if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	if (string.equals(getText())) return;	super.setText(string);	shortenedText = null;	shortenedTextWidth = 0;	parent.updateItems();	parent.redraw();}/** * Sets the receiver's tool tip text to the argument, which * may be null indicating that no tool tip text should be shown. * * @param string the new tool tip text (or null) * * @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 setToolTipText (String string) {	checkWidget();	toolTipText = string;}}

⌨️ 快捷键说明

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