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

📄 sashform.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	if (controls.length == 0) return;		int sashwidth = sashes.length > 0 ? SASH_WIDTH + sashes [0].getBorderWidth() * 2 : SASH_WIDTH;	// get the ratios	long[] ratios = new long[controls.length];	long total = 0;	for (int i = 0; i < controls.length; i++) {		Long ratio = (Long)controls[i].getData(LAYOUT_RATIO);		if (ratio != null) {			ratios[i] = ratio.longValue();		} else {			ratios[i] = ((200 << 16) + 999) / 1000;		}		total += ratios[i];	}		if (orientation == SWT.HORIZONTAL) {		total += (((long)(sashes.length * sashwidth) << 16) + area.width - 1) / area.width;	} else {		total += (((long)(sashes.length * sashwidth) << 16) + area.height - 1) / area.height;	}	if (orientation == SWT.HORIZONTAL) {		int width = (int)(ratios[0] * area.width / total);		int x = area.x;		controls[0].setBounds(x, area.y, width, area.height);		x += width;		for (int i = 1; i < controls.length - 1; i++) {			sashes[i - 1].setBounds(x, area.y, sashwidth, area.height);			x += sashwidth;			width = (int)(ratios[i] * area.width / total);			controls[i].setBounds(x, area.y, width, area.height);			x += width;		}		if (controls.length > 1) {			sashes[sashes.length - 1].setBounds(x, area.y, sashwidth, area.height);			x += sashwidth;			width = area.width - x;			controls[controls.length - 1].setBounds(x, area.y, width, area.height);		}	} else {		int height = (int)(ratios[0] * area.height / total);		int y = area.y;		controls[0].setBounds(area.x, y, area.width, height);		y += height;		for (int i = 1; i < controls.length - 1; i++) {			sashes[i - 1].setBounds(area.x, y, area.width, sashwidth);			y += sashwidth;			height = (int)(ratios[i] * area.height / total);			controls[i].setBounds(area.x, y, area.width, height);			y += height;		}		if (controls.length > 1) {			sashes[sashes.length - 1].setBounds(area.x, y, area.width, sashwidth);			y += sashwidth;			height = area.height - y;			controls[controls.length - 1].setBounds(area.x, y, area.width, height);		}	}}void onDragSash(Event event) {	if (event.detail == SWT.DRAG) {		// constrain feedback		Rectangle area = getClientArea();		if (orientation == SWT.HORIZONTAL) {			event.x = Math.min(Math.max(DRAG_MINIMUM, event.x), area.width - DRAG_MINIMUM);		} else {			event.y = Math.min(Math.max(DRAG_MINIMUM, event.y), area.height - DRAG_MINIMUM);		}		return;	}	Sash sash = (Sash)event.widget;	int sashIndex = -1;	for (int i= 0; i < sashes.length; i++) {		if (sashes[i] == sash) {			sashIndex = i;			break;		}	}	if (sashIndex == -1) return;	Control c1 = controls[sashIndex];	Control c2 = controls[sashIndex + 1];	Rectangle b1 = c1.getBounds();	Rectangle b2 = c2.getBounds();		Rectangle sashBounds = sash.getBounds();	Rectangle area = getClientArea();	if (orientation == SWT.HORIZONTAL) {		int shift = event.x - sashBounds.x;		b1.width += shift;		b2.x += shift;		b2.width -= shift;		if (b1.width < DRAG_MINIMUM || b2.width < DRAG_MINIMUM) {			return;		}		c1.setData(LAYOUT_RATIO, new Long((((long)b1.width << 16) + area.width - 1) / area.width));		c2.setData(LAYOUT_RATIO, new Long((((long)b2.width << 16) + area.width - 1) / area.width));			} else {		int shift = event.y - sashBounds.y;		b1.height += shift;		b2.y += shift;		b2.height -= shift;		if (b1.height < DRAG_MINIMUM || b2.height < DRAG_MINIMUM) {			return;		}		c1.setData(LAYOUT_RATIO, new Long((((long)b1.height << 16) + area.height - 1) / area.height));		c2.setData(LAYOUT_RATIO, new Long((((long)b2.height << 16) + area.height - 1) / area.height));	}		c1.setBounds(b1);	sash.setBounds(event.x, event.y, event.width, event.height);	c2.setBounds(b2);}/** * If orientation is SWT.HORIZONTAL, lay the controls in the SashForm  * out side by side.  If orientation is SWT.VERTICAL, lay the  * controls in the SashForm out top to bottom. *  * @param orientation SWT.HORIZONTAL or SWT.VERTICAL *  * @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 value of orientation is not SWT.HORIZONTAL or SWT.VERTICAL * </ul> */public void setOrientation(int orientation) {	checkWidget();	if (this.orientation == orientation) return;	if (orientation != SWT.HORIZONTAL && orientation != SWT.VERTICAL) {		SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}	this.orientation = orientation;		int sashStyle = (orientation == SWT.HORIZONTAL) ? SWT.VERTICAL : SWT.HORIZONTAL;	if ((getStyle() & SWT.BORDER) != 0) sashStyle |= SWT.BORDER;	for (int i = 0; i < sashes.length; i++) {		sashes[i].dispose();		sashes[i] = new Sash(this, sashStyle);		sashes[i].setBackground(background);		sashes[i].setForeground(foreground);		sashes[i].addListener(SWT.Selection, sashListener);	}	layout();}public void setBackground (Color color) {	super.setBackground(color);	background = color;	for (int i = 0; i < sashes.length; i++) {		sashes[i].setBackground(background);	}}public void setForeground (Color color) {	super.setForeground(color);	foreground = color;	for (int i = 0; i < sashes.length; i++) {		sashes[i].setForeground(foreground);	}}public void setLayout (Layout layout) {	checkWidget();}/** * Specify the control that should take up the entire client area of the SashForm.   * If one control has been maximized, and this method is called with a different control,  * the previous control will be minimized and the new control will be maximized.. * if the value of control is null, the SashForm will minimize all controls and return to * the default layout where all controls are laid out separated by sashes. *  * @param control the control to be maximized 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 setMaximizedControl(Control control){	checkWidget();	if (control == null) {		if (maxControl != null) {			this.maxControl = null;			layout();			for (int i= 0; i < sashes.length; i++){				sashes[i].setVisible(true);			}		}		return;	}		for (int i= 0; i < sashes.length; i++){		sashes[i].setVisible(false);	}	maxControl = control;	layout();}/** * Specify the relative weight of each child in the SashForm.  This will determine * what percent of the total width (if SashForm has Horizontal orientation) or  * total height (if SashForm has Vertical orientation) each control will occupy. * The weights must be positive values and there must be an entry for each * non-sash child of the SashForm. *  * @param weights the relative weight of each child *  * @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 weights value is null or of incorrect length (must match the number of children)</li> * </ul> */public void setWeights(int[] weights) {	checkWidget();	Control[] cArray = getControls(false);	if (weights == null || weights.length != cArray.length) {		SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}		int total = 0;	for (int i = 0; i < weights.length; i++) {		if (weights[i] < 0) {			SWT.error(SWT.ERROR_INVALID_ARGUMENT);		}		total += weights[i];	}	if (total == 0) {		SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}	for (int i = 0; i < cArray.length; i++) {		cArray[i].setData(LAYOUT_RATIO, new Long((((long)weights[i] << 16) + total - 1) / total));	}	layout();}}

⌨️ 快捷键说明

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