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

📄 coolbartab.java

📁 SUN公司eclipse3.2.2经典例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.swt.examples.controlexample; import org.eclipse.swt.*;import org.eclipse.swt.graphics.*;import org.eclipse.swt.widgets.*;import org.eclipse.swt.layout.*;import org.eclipse.swt.events.*;class CoolBarTab extends Tab {	/* Example widgets and group that contains them */	CoolBar coolBar;	CoolItem pushItem, dropDownItem, radioItem, checkItem, textItem;	Group coolBarGroup;		/* Style widgets added to the "Style" group */	Button horizontalButton, verticalButton;	Button dropDownButton, flatButton;	/* Other widgets added to the "Other" group */	Button lockedButton;		Point[] sizes;	int[] wrapIndices;	int[] order;		/**	 * Creates the Tab within a given instance of ControlExample.	 */	CoolBarTab(ControlExample instance) {		super(instance);	}		/**	 * Creates the "Other" group.	 */	void createOtherGroup () {		super.createOtherGroup ();			/* Create display controls specific to this example */		lockedButton = new Button (otherGroup, SWT.CHECK);		lockedButton.setText (ControlExample.getResourceString("Locked"));			/* Add the listeners */		lockedButton.addSelectionListener (new SelectionAdapter () {			public void widgetSelected (SelectionEvent event) {				setWidgetLocked ();			}		});	}		/**	 * Creates the "Example" group.	 */	void createExampleGroup () {		super.createExampleGroup ();		coolBarGroup = new Group (exampleGroup, SWT.NONE);		coolBarGroup.setLayout (new GridLayout ());		coolBarGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));		coolBarGroup.setText ("CoolBar");	}		/**	 * Creates the "Example" widgets.	 */	void createExampleWidgets () {		int style = getDefaultStyle(), itemStyle = 0;		/* Compute the widget, item, and item toolBar styles */		int toolBarStyle = SWT.FLAT;		boolean vertical = false;		if (horizontalButton.getSelection ()) {			style |= SWT.HORIZONTAL;			toolBarStyle |= SWT.HORIZONTAL;		}		if (verticalButton.getSelection ()) {			style |= SWT.VERTICAL;			toolBarStyle |= SWT.VERTICAL;			vertical = true;		}		if (borderButton.getSelection()) style |= SWT.BORDER;		if (flatButton.getSelection()) style |= SWT.FLAT;		if (dropDownButton.getSelection()) itemStyle |= SWT.DROP_DOWN;			/*		* Create the example widgets.		*/		coolBar = new CoolBar (coolBarGroup, style);				/* Create the push button toolbar cool item */		ToolBar toolBar = new ToolBar (coolBar, toolBarStyle);		ToolItem item = new ToolItem (toolBar, SWT.PUSH);		item.setImage (instance.images[ControlExample.ciClosedFolder]);		item.setToolTipText ("SWT.PUSH");		item = new ToolItem (toolBar, SWT.PUSH);		item.setImage (instance.images[ControlExample.ciOpenFolder]);		item.setToolTipText ("SWT.PUSH");		item = new ToolItem (toolBar, SWT.PUSH);		item.setImage (instance.images[ControlExample.ciTarget]);		item.setToolTipText ("SWT.PUSH");		item = new ToolItem (toolBar, SWT.SEPARATOR);		item = new ToolItem (toolBar, SWT.PUSH);		item.setImage (instance.images[ControlExample.ciClosedFolder]);		item.setToolTipText ("SWT.PUSH");		item = new ToolItem (toolBar, SWT.PUSH);		item.setImage (instance.images[ControlExample.ciOpenFolder]);		item.setToolTipText ("SWT.PUSH");				pushItem = new CoolItem (coolBar, itemStyle);		pushItem.setControl (toolBar);		pushItem.addSelectionListener (new CoolItemSelectionListener());						/* Create the dropdown toolbar cool item */		toolBar = new ToolBar (coolBar, toolBarStyle);		item = new ToolItem (toolBar, SWT.DROP_DOWN);		item.setImage (instance.images[ControlExample.ciOpenFolder]);		item.setToolTipText ("SWT.DROP_DOWN");		item.addSelectionListener (new DropDownSelectionListener());		item = new ToolItem (toolBar, SWT.DROP_DOWN);		item.setImage (instance.images[ControlExample.ciClosedFolder]);		item.setToolTipText ("SWT.DROP_DOWN");		item.addSelectionListener (new DropDownSelectionListener());		dropDownItem = new CoolItem (coolBar, itemStyle);		dropDownItem.setControl (toolBar);		dropDownItem.addSelectionListener (new CoolItemSelectionListener());		/* Create the radio button toolbar cool item */		toolBar = new ToolBar (coolBar, toolBarStyle);		item = new ToolItem (toolBar, SWT.RADIO);		item.setImage (instance.images[ControlExample.ciClosedFolder]);		item.setToolTipText ("SWT.RADIO");		item = new ToolItem (toolBar, SWT.RADIO);		item.setImage (instance.images[ControlExample.ciClosedFolder]);		item.setToolTipText ("SWT.RADIO");		item = new ToolItem (toolBar, SWT.RADIO);		item.setImage (instance.images[ControlExample.ciClosedFolder]);		item.setToolTipText ("SWT.RADIO");		radioItem = new CoolItem (coolBar, itemStyle);		radioItem.setControl (toolBar);		radioItem.addSelectionListener (new CoolItemSelectionListener());				/* Create the check button toolbar cool item */		toolBar = new ToolBar (coolBar, toolBarStyle);		item = new ToolItem (toolBar, SWT.CHECK);		item.setImage (instance.images[ControlExample.ciClosedFolder]);		item.setToolTipText ("SWT.CHECK");		item = new ToolItem (toolBar, SWT.CHECK);		item.setImage (instance.images[ControlExample.ciTarget]);		item.setToolTipText ("SWT.CHECK");		item = new ToolItem (toolBar, SWT.CHECK);		item.setImage (instance.images[ControlExample.ciOpenFolder]);		item.setToolTipText ("SWT.CHECK");		item = new ToolItem (toolBar, SWT.CHECK);		item.setImage (instance.images[ControlExample.ciTarget]);		item.setToolTipText ("SWT.CHECK");		checkItem = new CoolItem (coolBar, itemStyle);		checkItem.setControl (toolBar);		checkItem.addSelectionListener (new CoolItemSelectionListener());				/* Create the text cool item */		if (!vertical) {			Text text = new Text (coolBar, SWT.BORDER | SWT.SINGLE);			textItem = new CoolItem (coolBar, itemStyle);			textItem.setControl (text);			textItem.addSelectionListener (new CoolItemSelectionListener());			Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);			textSize = textItem.computeSize(textSize.x, textSize.y);			textItem.setMinimumSize(textSize);			textItem.setPreferredSize(textSize);			textItem.setSize(textSize);		}		/* Set the sizes after adding all cool items */		CoolItem[] coolItems = coolBar.getItems();		for (int i = 0; i < coolItems.length; i++) {			CoolItem coolItem = coolItems[i];			Control control = coolItem.getControl();			Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);			Point coolSize = coolItem.computeSize(size.x, size.y);			if (control instanceof ToolBar) {				ToolBar bar = (ToolBar)control;				if (bar.getItemCount() > 0) {					if (vertical) {						size.y = bar.getItem(0).getBounds().height;					} else {						size.x = bar.getItem(0).getWidth();					}				}			}			coolItem.setMinimumSize(size);			coolItem.setPreferredSize(coolSize);			coolItem.setSize(coolSize);		}				/* If we have saved state, restore it */		if (order != null && order.length == coolBar.getItemCount()) {			coolBar.setItemLayout(order, wrapIndices, sizes);		} else {			coolBar.setWrapIndices(new int[] {1, 3});		}				/* Add a listener to resize the group box to match the coolbar */		coolBar.addListener(SWT.Resize, new Listener() {			public void handleEvent(Event event) {				exampleGroup.layout();			}		});	}		/**	 * Creates the "Style" group.	 */	void createStyleGroup() {		super.createStyleGroup();			/* Create the extra widgets */		horizontalButton = new Button (styleGroup, SWT.RADIO);		horizontalButton.setText ("SWT.HORIZONTAL");		verticalButton = new Button (styleGroup, SWT.RADIO);		verticalButton.setText ("SWT.VERTICAL");		borderButton = new Button (styleGroup, SWT.CHECK);		borderButton.setText ("SWT.BORDER");		flatButton = new Button (styleGroup, SWT.CHECK);		flatButton.setText ("SWT.FLAT");		Group itemGroup = new Group(styleGroup, SWT.NONE);		itemGroup.setLayout (new GridLayout ());		itemGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));		itemGroup.setText(ControlExample.getResourceString("Item_Styles"));		dropDownButton = new Button (itemGroup, SWT.CHECK);		dropDownButton.setText ("SWT.DROP_DOWN");	}		/**	 * Disposes the "Example" widgets.	 */	void disposeExampleWidgets () {		/* store the state of the toolbar if applicable */

⌨️ 快捷键说明

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