📄 cbanner.java
字号:
Point leftSize = new Point(0, 0); if (left != null) { Point trim = left.computeSize(width, SWT.DEFAULT); trim.x = trim.x - width; leftSize = left.computeSize(width - trim.x, SWT.DEFAULT); } int x = 0; int y = 0; int oldStart = curveStart; Rectangle leftRect = null; Rectangle rightRect = null; Rectangle bottomRect = null; if (bottom != null) { bottomRect = new Rectangle(x, y+size.y-bottomSize.y, bottomSize.x, bottomSize.y); } if (showCurve) y += BORDER_TOP + BORDER_STRIPE; if(left != null) { leftRect = new Rectangle(x, y, leftSize.x, leftSize.y); curveStart = x + leftSize.x - curve_indent; x += leftSize.x + curve_width - 2*curve_indent; } if (right != null) { rightRect = new Rectangle(x, y, rightSize.x, rightSize.y); } if (curveStart < oldStart) { redraw(curveStart - CURVE_TAIL, 0, oldStart + curve_width - curveStart + CURVE_TAIL + 5, size.y, false); } if (curveStart > oldStart) { redraw(oldStart - CURVE_TAIL, 0, curveStart + curve_width - oldStart + CURVE_TAIL + 5, size.y, false); } curveRect = new Rectangle(curveStart, 0, curve_width, size.y); update(); if (bottomRect != null) bottom.setBounds(bottomRect); if (rightRect != null) right.setBounds(rightRect); if (leftRect != null) left.setBounds(leftRect);}void onDispose() { if (resizeCursor != null) resizeCursor.dispose(); resizeCursor = null; left = null; right = null;}void onMouseDown (int x, int y) { if (curveRect.contains(x, y)) { dragging = true; rightDragDisplacement = curveStart - x + curve_width - curve_indent; }}void onMouseExit() { if (!dragging) setCursor(null);}void onMouseMove(int x, int y) { if (dragging) { Point size = getSize(); if (!(0 < x && x < size.x)) return; rightWidth = size.x - x - rightDragDisplacement; rightWidth = Math.max(MIN_RIGHT, rightWidth); layout(); return; } if (curveRect.contains(x, y)) { setCursor(resizeCursor); } else { setCursor(null); }}void onMouseUp () { dragging = false;}void onPaint(GC gc) {// Useful for debugging paint problems// {// Point size = getSize(); // gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GREEN));// gc.fillRectangle(-10, -10, size.x+20, size.y+20);// } Point size = getSize(); Color border1 = getDisplay().getSystemColor(BORDER1); if (bottom != null && (left != null || right != null)) { gc.setForeground(border1); int y = bottom.getBounds().y - BORDER_BOTTOM - BORDER_STRIPE; gc.drawLine(0, y, size.x, y); } if (left == null || right == null) return; int[] line1 = new int[curve.length+6]; int index = 0; int x = curveStart; int y = 0; line1[index++] = x + 1; line1[index++] = size.y - BORDER_STRIPE; for (int i = 0; i < curve.length/2; i++) { line1[index++]=x+curve[2*i]; line1[index++]=y+curve[2*i+1]; } line1[index++] = x + curve_width; line1[index++] = 0; line1[index++] = size.x; line1[index++] = 0; Color background = getBackground(); if (getDisplay().getDepth() >= 15) { // Anti- aliasing int[] line2 = new int[line1.length]; index = 0; for (int i = 0; i < line1.length/2; i++) { line2[index] = line1[index++] - 1; line2[index] = line1[index++]; } int[] line3 = new int[line1.length]; index = 0; for (int i = 0; i < line1.length/2; i++) { line3[index] = line1[index++] + 1; line3[index] = line1[index++]; } RGB from = border1.getRGB(); RGB to = background.getRGB(); int red = from.red + 3*(to.red - from.red)/4; int green = from.green + 3*(to.green - from.green)/4; int blue = from.blue + 3*(to.blue - from.blue)/4; Color color = new Color(getDisplay(), red, green, blue); gc.setForeground(color); gc.drawPolyline(line2); gc.drawPolyline(line3); color.dispose(); // draw tail fading to background int x1 = Math.max(0, curveStart - CURVE_TAIL); gc.setForeground(background); gc.setBackground(border1); gc.fillGradientRectangle(x1, size.y - BORDER_STRIPE, curveStart-x1+1, 1, false); } else { // draw solid tail int x1 = Math.max(0, curveStart - CURVE_TAIL); gc.setForeground(border1); gc.drawLine(x1, size.y - BORDER_STRIPE, curveStart+1, size.y - BORDER_STRIPE); } // draw border gc.setForeground(border1); gc.drawPolyline(line1);}void onResize() { updateCurve(getSize().y); layout();}/*** Set the control that appears on the bottom side of the banner.* The bottom control is optional. Setting the bottom control to null will remove it from * the banner - however, the creator of the control must dispose of the control.* * @param control the control to be displayed on the bottom 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>* <li>ERROR_INVALID_ARGUMENT - if the bottom control was not created as a child of the receiver</li>* </ul>* * @since 3.0*/public void setBottom(Control control) { checkWidget(); if (control != null && control.getParent() != this) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } if (bottom != null && !bottom.isDisposed()) { Point size = bottom.getSize(); bottom.setLocation(OFFSCREEN - size.x, OFFSCREEN - size.y); } bottom = control; layout();}/** * Sets the layout which is associated with the receiver to be * the argument which may be null. * <p> * Note : CBanner does not use a layout class to size and position its children. * </p> * * @param layout the receiver's new layout 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 setLayout (Layout layout) { checkWidget(); return;}/*** Set the control that appears on the left side of the banner.* The left control is optional. Setting the left control to null will remove it from * the banner - however, the creator of the control must dispose of the control.* * @param control the control to be displayed on the left 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>* <li>ERROR_INVALID_ARGUMENT - if the left control was not created as a child of the receiver</li>* </ul>* * @since 3.0*/public void setLeft(Control control) { checkWidget(); if (control != null && control.getParent() != this) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } if (left != null && !left.isDisposed()) { Point size = left.getSize(); left.setLocation(OFFSCREEN - size.x, OFFSCREEN - size.y); } left = control; layout();}/*** Set the control that appears on the right side of the banner.* The right control is optional. Setting the right control to null will remove it from * the banner - however, the creator of the control must dispose of the control.* * @param control the control to be displayed on the right 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>* <li>ERROR_INVALID_ARGUMENT - if the right control was not created as a child of the receiver</li>* </ul>* * @since 3.0*/public void setRight(Control control) { checkWidget(); if (control != null && control.getParent() != this) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } if (right != null && !right.isDisposed()) { Point size = right.getSize(); right.setLocation(OFFSCREEN - size.x, OFFSCREEN - size.y); } right = control; layout();}/** * Set the width of the control control that appears on the right side of the banner. * * @param width the width of the control on the right * * @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 setRightWidth(int width) { checkWidget(); if (width < SWT.DEFAULT) SWT.error(SWT.ERROR_INVALID_ARGUMENT); rightWidth = width; layout(true);}/** * Sets the shape that the CBanner will use to render itself. * * @param simple <code>true</code> if the CBanner should render itself in a simple, traditional style * * @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 setSimple(boolean simple) { checkWidget(); if (this.simple != simple) { this.simple = simple; if (simple) { curve_width = 5; curve_indent = -2; } else { curve_width = 50; curve_indent = 5; } updateCurve(getSize().y); layout(); redraw(); }}void updateCurve(int height) { int h = height - BORDER_STRIPE; if (simple) { curve = new int[] {0,h, 1,h, 2,h-1, 3,h-2, 3,2, 4,1, 5,0,}; } else { curve = bezier(0, h+1, BEZIER_LEFT, h+1, curve_width-BEZIER_RIGHT, 0, curve_width, 0, curve_width); }}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -