myviewform.java
来自「SANCHO」· Java 代码 · 共 697 行 · 第 1/2 页
JAVA
697 行
* Typically this is a Close button or a composite with a Menu and Close button.
*
* @return the control in the top right corner of the pane or null
*/
public Control getTopRight() {
//checkWidget();
return topRight;
}
public void layout(boolean changed) {
checkWidget();
Rectangle rect = getClientArea();
Point leftSize = new Point(0, 0);
if (topLeft != null && !topLeft.isDisposed()) {
leftSize = topLeft.computeSize(SWT.DEFAULT, SWT.DEFAULT);
}
Point centerSize = new Point(0, 0);
if (topCenter != null && !topCenter.isDisposed()) {
centerSize = topCenter.computeSize(SWT.DEFAULT, SWT.DEFAULT);
}
Point rightSize = new Point(0, 0);
if (topRight != null && !topRight.isDisposed()) {
rightSize = topRight.computeSize(SWT.DEFAULT, SWT.DEFAULT);
}
int minTopWidth = leftSize.x + centerSize.x + rightSize.x + 2 * marginWidth;
int count = -1;
if (leftSize.x > 0)
count++;
if (centerSize.x > 0)
count++;
if (rightSize.x > 0)
count++;
if (count > 0)
minTopWidth += count * horizontalSpacing;
int x = rect.x + rect.width - marginWidth;
int y = rect.y + marginHeight;
boolean top = false;
if (separateTopCenter || minTopWidth > rect.width) {
int topHeight = Math.max(rightSize.y, leftSize.y);
if (topRight != null && !topRight.isDisposed()) {
top = true;
x -= rightSize.x;
topRight.setBounds(x, y, rightSize.x, topHeight);
x -= horizontalSpacing;
}
if (topLeft != null && !topLeft.isDisposed()) {
top = true;
leftSize = topLeft.computeSize(x - rect.x - marginWidth, SWT.DEFAULT);
topLeft.setBounds(rect.x + marginWidth, y, leftSize.x, topHeight);
}
if (top)
y += topHeight + verticalSpacing;
if (topCenter != null && !topCenter.isDisposed()) {
top = true;
centerSize = topCenter.computeSize(rect.width - 2 * marginWidth, SWT.DEFAULT);
topCenter.setBounds(rect.x + rect.width - marginWidth - centerSize.x, y, centerSize.x, centerSize.y);
y += centerSize.y + verticalSpacing;
}
} else {
int topHeight = Math.max(rightSize.y, Math.max(centerSize.y, leftSize.y));
if (topRight != null && !topRight.isDisposed()) {
top = true;
x -= rightSize.x;
topRight.setBounds(x, y, rightSize.x, topHeight);
x -= horizontalSpacing;
}
if (topCenter != null && !topCenter.isDisposed()) {
top = true;
x -= centerSize.x;
topCenter.setBounds(x, y, centerSize.x, topHeight);
x -= horizontalSpacing;
}
if (topLeft != null && !topLeft.isDisposed()) {
top = true;
leftSize = topLeft.computeSize(x - rect.x - marginWidth, topHeight);
topLeft.setBounds(rect.x + marginWidth, y, leftSize.x, topHeight);
}
if (top)
y += topHeight + verticalSpacing;
}
if (content != null && !content.isDisposed()) {
content.setBounds(rect.x + marginWidth, y, rect.width - 2 * marginWidth, rect.y + rect.height - y
- marginHeight);
}
}
void onDispose() {
if (borderColor1 != null) {
borderColor1.dispose();
}
borderColor1 = null;
if (borderColor2 != null) {
borderColor2.dispose();
}
borderColor2 = null;
if (borderColor3 != null) {
borderColor3.dispose();
}
borderColor3 = null;
topLeft = null;
topCenter = null;
topRight = null;
content = null;
oldArea = null;
}
void onPaint(GC gc) {
Color gcForeground = gc.getForeground();
Point size = getSize();
if (showBorder) {
if ((getStyle() & SWT.FLAT) != 0) {
gc.setForeground(borderColor1);
gc.drawRectangle(0, 0, size.x - 1, size.y - 1);
} else {
gc.setForeground(borderColor1);
gc.drawRectangle(0, 0, size.x - 3, size.y - 3);
gc.setForeground(borderColor2);
gc.drawLine(1, size.y - 2, size.x - 1, size.y - 2);
gc.drawLine(size.x - 2, 1, size.x - 2, size.y - 1);
gc.setForeground(borderColor3);
gc.drawLine(2, size.y - 1, size.x - 2, size.y - 1);
gc.drawLine(size.x - 1, 2, size.x - 1, size.y - 2);
}
}
gc.setForeground(gcForeground);
}
void onResize() {
layout();
Rectangle area = super.getClientArea();
if (oldArea == null || oldArea.width == 0 || oldArea.height == 0) {
redraw();
} else {
int width = 0;
if (oldArea.width < area.width) {
width = area.width - oldArea.width + borderRight;
} else if (oldArea.width > area.width) {
width = borderRight;
}
redraw(area.x + area.width - width, area.y, width, area.height, false);
int height = 0;
if (oldArea.height < area.height) {
height = area.height - oldArea.height + borderBottom;
}
if (oldArea.height > area.height) {
height = borderBottom;
}
redraw(area.x, area.y + area.height - height, area.width, height, false);
}
oldArea = area;
}
/**
* Sets the content.
* Setting the content to null will remove it from
* the pane - however, the creator of the content must dispose of the content.
*
* @param content the control to be displayed in the content area 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 control is not a child of this ViewForm</li>
* </ul>
*/
public void setContent(Control content) {
checkWidget();
if (content != null && content.getParent() != this) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
if (this.content != null && !this.content.isDisposed()) {
this.content.setBounds(OFFSCREEN, OFFSCREEN, 0, 0);
}
this.content = content;
layout();
}
public void setFont(Font f) {
super.setFont(f);
if (topLeft != null && !topLeft.isDisposed())
topLeft.setFont(f);
if (topCenter != null && !topCenter.isDisposed())
topCenter.setFont(f);
if (topRight != null && !topRight.isDisposed())
topRight.setFont(f);
layout();
}
/**
* Sets the layout which is associated with the receiver to be
* the argument which may be null.
* <p>
* Note : ViewForm 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 in the top center of the pane.
* Typically this is a toolbar.
* The topCenter is optional. Setting the topCenter to null will remove it from
* the pane - however, the creator of the topCenter must dispose of the topCenter.
*
* @param topCenter the control to be displayed in the top center 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 control is not a child of this ViewForm</li>
* </ul>
*/
public void setTopCenter(Control topCenter) {
checkWidget();
if (topCenter != null && topCenter.getParent() != this) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
if (this.topCenter != null && !this.topCenter.isDisposed()) {
this.topCenter.setBounds(OFFSCREEN, OFFSCREEN, 0, 0);
}
this.topCenter = topCenter;
layout();
}
/**
* Set the control that appears in the top left corner of the pane.
* Typically this is a label such as CLabel.
* The topLeft is optional. Setting the top left control to null will remove it from
* the pane - however, the creator of the control must dispose of the control.
*
* @param c the control to be displayed in the top left corner 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 control is not a child of this ViewForm</li>
* </ul>
*/
public void setTopLeft(Control c) {
checkWidget();
if (c != null && c.getParent() != this) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
if (this.topLeft != null && !this.topLeft.isDisposed()) {
this.topLeft.setBounds(OFFSCREEN, OFFSCREEN, 0, 0);
}
this.topLeft = c;
layout();
}
/**
* Set the control that appears in the top right corner of the pane.
* Typically this is a Close button or a composite with a Menu and Close button.
* The topRight is optional. Setting the top right control to null will remove it from
* the pane - however, the creator of the control must dispose of the control.
*
* @param c the control to be displayed in the top right corner 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 control is not a child of this ViewForm</li>
* </ul>
*/
public void setTopRight(Control c) {
checkWidget();
if (c != null && c.getParent() != this) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
if (this.topRight != null && !this.topRight.isDisposed()) {
this.topRight.setBounds(OFFSCREEN, OFFSCREEN, 0, 0);
}
this.topRight = c;
layout();
}
/**
* Specify whether the border should be displayed or not.
*
* @param show true if the border should be displayed
*
* @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 setBorderVisible(boolean show) {
checkWidget();
if (showBorder == show)
return;
showBorder = show;
if (showBorder) {
if ((getStyle() & SWT.FLAT) != 0) {
borderLeft = borderTop = borderRight = borderBottom = 1;
} else {
borderLeft = borderTop = 1;
borderRight = borderBottom = 3;
}
} else {
borderBottom = borderTop = borderLeft = borderRight = 0;
}
layout();
redraw();
}
/**
* If true, the topCenter will always appear on a separate line by itself, otherwise the
* topCenter will appear in the top row if there is room and will be moved to the second row if
* required.
*
* @param show true if the topCenter will always appear on a separate line by itself
*
* @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 setTopCenterSeparate(boolean show) {
checkWidget();
separateTopCenter = show;
layout();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?