📄 ctabfolder.java
字号:
* * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * * @exception SWTError <ul> * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> * </ul> * * @see CTabFolderListener * @see #removeCTabFolderListener(CTabFolderListener) * * @deprecated use addCTabFolder2Listener(CTabFolder2Listener) */public void addCTabFolderListener(CTabFolderListener listener) { checkWidget(); if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); // add to array CTabFolderListener[] newTabListeners = new CTabFolderListener[tabListeners.length + 1]; System.arraycopy(tabListeners, 0, newTabListeners, 0, tabListeners.length); tabListeners = newTabListeners; tabListeners[tabListeners.length - 1] = listener; // display close button to be backwards compatible if (!showClose) { showClose = true; updateItems(); redraw(); }}/** * Adds the listener to receive events. * <p> * * @param listener the listener * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * * @exception SWTError <ul> * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> * </ul> */public void addSelectionListener(SelectionListener listener) { checkWidget(); if (listener == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } TypedListener typedListener = new TypedListener(listener); addListener(SWT.Selection, typedListener); addListener(SWT.DefaultSelection, typedListener);}void antialias (int[] shape, RGB lineRGB, RGB innerRGB, RGB outerRGB, GC gc){ // Don't perform anti-aliasing on Mac because the platform // already does it. The simple style also does not require anti-aliasing. if (simple || "carbon".equals(SWT.getPlatform())) return; //$NON-NLS-1$ // Don't perform anti-aliasing on low resolution displays if (getDisplay().getDepth() < 15) return; if (outerRGB != null) { int index = 0; boolean left = true; int oldY = onBottom ? 0 : getSize().y; int[] outer = new int[shape.length]; for (int i = 0; i < shape.length/2; i++) { if (left && (index + 3 < shape.length)) { left = onBottom ? oldY <= shape[index+3] : oldY >= shape[index+3]; oldY = shape[index+1]; } outer[index] = shape[index++] + (left ? -1 : +1); outer[index] = shape[index++]; } RGB from = lineRGB; RGB to = outerRGB; int red = from.red + 2*(to.red - from.red)/3; int green = from.green + 2*(to.green - from.green)/3; int blue = from.blue + 2*(to.blue - from.blue)/3; Color color = new Color(getDisplay(), red, green, blue); gc.setForeground(color); gc.drawPolyline(outer); color.dispose(); } if (innerRGB != null) { int[] inner = new int[shape.length]; int index = 0; boolean left = true; int oldY = onBottom ? 0 : getSize().y; for (int i = 0; i < shape.length/2; i++) { if (left && (index + 3 < shape.length)) { left = onBottom ? oldY <= shape[index+3] : oldY >= shape[index+3]; oldY = shape[index+1]; } inner[index] = shape[index++] + (left ? +1 : -1); inner[index] = shape[index++]; } RGB from = lineRGB; RGB to = innerRGB; int red = from.red + 2*(to.red - from.red)/3; int green = from.green + 2*(to.green - from.green)/3; int blue = from.blue + 2*(to.blue - from.blue)/3; Color color = new Color(getDisplay(), red, green, blue); gc.setForeground(color); gc.drawPolyline(inner); color.dispose(); }}public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget(); // preferred width of tab area to show all tabs int tabW = 0; GC gc = new GC(this); for (int i = 0; i < items.length; i++) { if (single) { tabW = Math.max(tabW, items[i].preferredWidth(gc, true, false)); } else { tabW += items[i].preferredWidth(gc, i == selectedIndex, false); } } gc.dispose(); tabW += 3; if (showMax) tabW += BUTTON_SIZE; if (showMin) tabW += BUTTON_SIZE; if (single) tabW += 3*BUTTON_SIZE/2; //chevron if (topRight != null) tabW += topRight.computeSize(SWT.DEFAULT, tabHeight).x; if (!single && !simple) tabW += curveWidth - 2*curveIndent; int controlW = 0; int controlH = 0; // preferred size of controls in tab items for (int i = 0; i < items.length; i++) { Control control = items[i].getControl(); if (control != null && !control.isDisposed()){ Point size = control.computeSize (wHint, hHint); controlW = Math.max (controlW, size.x); controlH = Math.max (controlH, size.y); } } int minWidth = Math.max(tabW, controlW); int minHeight = (minimized) ? 0 : controlH; if (minWidth == 0) minWidth = DEFAULT_WIDTH; if (minHeight == 0) minHeight = DEFAULT_HEIGHT; if (wHint != SWT.DEFAULT) minWidth = wHint; if (hHint != SWT.DEFAULT) minHeight = hHint; Rectangle trim = computeTrim(0, 0, minWidth, minHeight); return new Point (trim.width, trim.height);}public Rectangle computeTrim (int x, int y, int width, int height) { checkWidget(); int trimX = x - marginWidth - highlight_margin - borderLeft; int trimWidth = width + borderLeft + borderRight + 2*marginWidth + 2*highlight_margin; if (minimized) { int trimY = onBottom ? y - borderTop : y - highlight_header - tabHeight - borderTop; int trimHeight = borderTop + borderBottom + tabHeight + highlight_header; return new Rectangle (trimX, trimY, trimWidth, trimHeight); } else { int trimY = onBottom ? y - marginHeight - highlight_margin - borderTop: y - marginHeight - highlight_header - tabHeight - borderTop; int trimHeight = height + borderTop + borderBottom + 2*marginHeight + tabHeight + highlight_header + highlight_margin; return new Rectangle (trimX, trimY, trimWidth, trimHeight); }}void createItem (CTabItem item, int index) { if (0 > index || index > getItemCount ()){ SWT.error (SWT.ERROR_INVALID_RANGE); } // grow by one and rearrange the array. CTabItem[] newItems = new CTabItem [items.length + 1]; System.arraycopy(items, 0, newItems, 0, index); newItems[index] = item; System.arraycopy(items, index, newItems, index + 1, items.length - index); items = newItems; item.parent = this; if (selectedIndex >= index) { selectedIndex ++; } if (items.length == 1) { firstIndex = 0; if (!updateTabHeight(false)) updateItems(); redraw(); } else { updateItems(); // redraw tabs if new item visible if (item.isShowing()) redraw(); }}void destroyItem (CTabItem item) { if (inDispose) return; int index = indexOf(item); if (index == -1) return; insertionIndex = -2; if (items.length == 1) { items = new CTabItem[0]; selectedIndex = -1; firstIndex = 0; Control control = item.getControl(); if (control != null && !control.isDisposed()) { control.setVisible(false); } if (fixedTabHeight == SWT.DEFAULT) tabHeight = 0; if (onBottom) { yClient = borderTop + highlight_margin + marginHeight; } else { yClient = borderTop + tabHeight + highlight_header + marginHeight; } hideToolTip(); redraw(); return; } // shrink by one and rearrange the array. CTabItem[] newItems = new CTabItem [items.length - 1]; System.arraycopy(items, 0, newItems, 0, index); System.arraycopy(items, index + 1, newItems, index, items.length - index - 1); items = newItems; if (firstIndex == items.length) { --firstIndex; } // move the selection if this item is selected if (selectedIndex == index) { Control control = item.getControl(); selectedIndex = -1; setSelection(Math.max(0, index - 1), true); if (control != null && !control.isDisposed()) { control.setVisible(false); } } else if (selectedIndex > index) { selectedIndex --; } updateItems(); redraw();}void drawBackground(GC gc, int[] shape, boolean selected) { Color defaultBackground = selected ? selectionBackground : getBackground(); Image image = selected ? selectionBgImage : bgImage; Color[] colors = selected ? selectionGradientColors : gradientColors; int[] percents = selected ? selectionGradientPercents : gradientPercents; boolean vertical = selected ? selectionGradientVertical : gradientVertical; Point size = getSize(); int width = size.x; int height = tabHeight + highlight_header; int x = 0; if (borderLeft > 0) { x += 1; width -= 2; } int y = onBottom ? size.y - borderBottom - height : borderTop; drawBackground(gc, shape, x, y, width, height, defaultBackground, image, colors, percents, vertical);}void drawBackground(GC gc, int[] shape, int x, int y, int width, int height, Color defaultBackground, Image image, Color[] colors, int[] percents, boolean vertical) { Region clipping = new Region(); gc.getClipping(clipping); Region region = new Region(); region.add(shape); region.intersect(clipping); gc.setClipping(region); if (image != null) { // draw the background image in shape gc.setBackground(defaultBackground); gc.fillRectangle(x, y, width, height); Rectangle imageRect = image.getBounds(); gc.drawImage(image, imageRect.x, imageRect.y, imageRect.width, imageRect.height, x, y, width, height); } else if (colors != null) { // draw gradient if (colors.length == 1) { Color background = colors[0] != null ? colors[0] : defaultBackground; gc.setBackground(background); gc.fillRectangle(x, y, width, height); } else { if (vertical) { if (onBottom) { int pos = 0; if (percents[percents.length - 1] < 100) { pos = percents[percents.length - 1] * height / 100; gc.setBackground(defaultBackground); gc.fillRectangle(x, y, width, pos); } Color lastColor = colors[colors.length-1]; if (lastColor == null) lastColor = defaultBackground; for (int i = percents.length-1; i >= 0; i--) { gc.setForeground(lastColor); lastColor = colors[i]; if (lastColor == null) lastColor = defaultBackground; gc.setBackground(lastColor); int gradientHeight = percents[i] * height / 100; gc.fillGradientRectangle(x, y+pos, width, gradientHeight, true); pos += gradientHeight; } } else { Color lastColor = colors[0]; if (lastColor == null) lastColor = defaultBackground; int pos = 0; for (int i = 0; i < percents.length; i++) { gc.setForeground(lastColor); lastColor = colors[i + 1]; if (lastColor == null) lastColor = defaultBackground; gc.setBackground(lastColor); int gradientHeight = percents[i] * height / 100; gc.fillGradientRectangle(x, y+pos, width, gradientHeight, true); pos += gradientHeight; } if (pos < height) { gc.setBackground(defaultBackground); gc.fillRectangle(x, pos, width, height-pos+1); } } } else { //horizontal gradient y = 0; height = getSize().y; Color lastColor = colors[0]; if (lastColor == null) lastColor = defaultBackground; int pos = 0; for (int i = 0; i < percents.length; ++i) { gc.setForeground(lastColor); lastColor = colors[i + 1]; if (lastColor == null) lastColor = defaultBackground; gc.setBackground(lastColor); int gradientWidth = (percents[i] * width / 100) - pos; gc.fillGradientRectangle(x+pos, y, gradientWidth, height, false); pos += gradientWidth; } if (pos < width) { gc.setBackground(defaultBackground); gc.fillRectangle(x+pos, y, width-pos, height); } } } } else { // draw a solid background using default background in shape if ((getStyle() & SWT.NO_BACKGROUND) != 0 || !defaultBackground.equals(getBackground())) { gc.setBackground(defaultBackground); gc.fillRectangle(x, y, width, height); } } gc.setClipping(clipping); clipping.dispose(); region.dispose();}void drawBody(Event event) { GC gc = event.gc; Point size = getSize(); // fill in body if (!minimized){ int width = size.x - borderLeft - borderRight - 2*highlight_margin; int height = size.y - borderTop - borderBottom - tabHeight - highlight_header - highlight_margin; // Draw highlight margin if (highlight_margin > 0) { int[] shape = null; if (onBottom) { int x1 = borderLeft; int y1 = borderTop; int x2 = size.x - borderRight; int y2 = size.y - borderBottom - tabHeight - highlight_header; shape = new int[] {x1,y1, x2,y1, x2,y2, x2-highlight_margin,y2, x2-highlight_margin, y1+highlight_margin, x1+highlight_margin,y1+highlight_margin, x1+highlight_margin,y2, x1,y2}; } else { int x1 = borderLeft; int y1 = borderTop + tabHeight + highlight_header; int x2 = size.x - borderRight; int y2 = size.y - borderBottom; shape = new int[] {x1,y1, x1+highlight_margin,y1, x1+highlight_margin,y2-highlight_margin, x2-highlight_margin,y2-highlight_margin, x2-highlight_margin,y1, x2,y1, x2,y2, x1,y2}; } // If horizontal gradient, show gradient across the whole area if (selectedIndex != -1 && selectionGradientColors != null && selectionGradientColors.length > 1 && !selectionGradientVertical) { drawBackground(gc, shape, true); } else if (selectedIndex == -1 && gradientColors != null && gradientColors.length > 1 && !gradientVertical) { drawBackground(gc, shape, false); } else { gc.setBackground(selectedIndex == -1 ? getBackground() : selectionBackground); gc.fillPolygon(shape); } } //Draw client area if ((getStyle() & SWT.NO_BACKGROUND) != 0) { gc.setBackground(getBackground()); gc.fillRectangle(xClient - marginWidth, yClient - marginHeight, width, height); } } else { if ((getStyle() & SWT.NO_BACKGROUND) != 0) { int height = borderTop + tabHeight + highlight_header + borderBottom; if (size.y > height) { gc.setBackground(getParent().getBackground()); gc.fillRectangle(0, height, size.x, size.y - height); } } } //draw 1 pixel border around outside if (borderLeft > 0) { gc.setForeground(borderColor); int x1 = borderLeft - 1; int x2 = size.x - borderRight; int y1 = onBottom ? borderTop - 1 : borderTop + tabHeight; int y2 = onBottom ? size.y - tabHeight - borderBottom - 1 : size.y - borderBottom; gc.drawLine(x1, y1, x1, y2); // left gc.drawLine(x2, y1, x2, y2); // right if (onBottom) { gc.drawLine(x1, y1, x2, y1); // top
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -