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

📄 tab.java

📁 SUN公司eclipse3.2.2经典例子
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			typeName = returnType.getName();		}		String typeNameString = typeName;		int index = typeName.lastIndexOf('.');		if (index != -1 && index+1 < typeName.length()) typeNameString = typeName.substring(index+1);		String info = ControlExample.getResourceString("Info_" + typeNameString + (isArray ? "A" : ""));		if (isArray) {			typeNameString += "[]";		}		return ControlExample.getResourceString("Parameter_Info", new Object[] {typeNameString, info});	}	void getValue() {		String methodName = "get" + nameCombo.getText();		getText.setText("");		Widget[] widgets = getExampleWidgets();		for (int i = 0; i < widgets.length; i++) {			try {				java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, null);				Object result = method.invoke(widgets[i], null);				if (result == null) {					getText.append("null");				} else if (result.getClass().isArray()) {					int length = java.lang.reflect.Array.getLength(result);					if (length == 0) {						getText.append(result.getClass().getComponentType() + "[0]");					}					for (int j = 0; j < length; j++) {						getText.append(java.lang.reflect.Array.get(result,j).toString() + "\n");					}				} else {					getText.append(result.toString());				}			} catch (Exception e) {				getText.append(e.toString());			}			if (i + 1 < widgets.length) {				getText.append("\n\n");			}		}	}	Class getReturnType(String methodRoot) {		Class returnType = null;		String methodName = "get" + methodRoot;		Widget[] widgets = getExampleWidgets();		try {			java.lang.reflect.Method method = widgets[0].getClass().getMethod(methodName, null);			returnType = method.getReturnType();		} catch (Exception e) {		}		return returnType;	}		void setValue() {		/* The parameter type must be the same as the get method's return type */		String methodRoot = nameCombo.getText();		Class returnType = getReturnType(methodRoot);		String methodName = setMethodName(methodRoot);		String value = setText.getText();		Widget[] widgets = getExampleWidgets();		for (int i = 0; i < widgets.length; i++) {			try {				java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, new Class[] {returnType});				String typeName = returnType.getName();				Object[] parameter = null;				if (typeName.equals("int")) {					parameter = new Object[] {new Integer(value)};				} else if (typeName.equals("long")) {					parameter = new Object[] {new Long(value)};				} else if (typeName.equals("char")) {					parameter = new Object[] {value.length() == 1 ? new Character(value.charAt(0)) : new Character('\0')};				} else if (typeName.equals("boolean")) {					parameter = new Object[] {new Boolean(value)};				} else if (typeName.equals("java.lang.String")) {					parameter = new Object[] {value};				} else if (typeName.equals("org.eclipse.swt.graphics.Point")) {					String xy[] = split(value, ',');					parameter = new Object[] {new Point(new Integer(xy[0]).intValue(),new Integer(xy[1]).intValue())};				} else if (typeName.equals("[I")) {					String strings[] = split(value, ',');					int[] ints = new int[strings.length];					for (int j = 0; j < strings.length; j++) {						ints[j] = new Integer(strings[j]).intValue();					}					parameter = new Object[] {ints};				} else if (typeName.equals("[Ljava.lang.String;")) {					parameter = new Object[] {split(value, ',')};				} else {					parameter = parameterForType(typeName, value, widgets[i]);				}				method.invoke(widgets[i], parameter);			} catch (Exception e) {				getText.setText(e.toString());			}		}	}	Object[] parameterForType(String typeName, String value, Widget widget) {		return new Object[] {value};	}	void createOrientationGroup () {		/* Create Orientation group*/		orientationGroup = new Group (controlGroup, SWT.NONE);		orientationGroup.setLayout (new GridLayout());		orientationGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));		orientationGroup.setText (ControlExample.getResourceString("Orientation"));		defaultOrietationButton = new Button (orientationGroup, SWT.RADIO);		defaultOrietationButton.setText (ControlExample.getResourceString("Default"));		defaultOrietationButton.setSelection (true);		ltrButton = new Button (orientationGroup, SWT.RADIO);		ltrButton.setText ("SWT.LEFT_TO_RIGHT");		rtlButton = new Button (orientationGroup, SWT.RADIO);		rtlButton.setText ("SWT.RIGHT_TO_LEFT");	}		/**	 * Creates the "Size" group.  The "Size" group contains	 * controls that allow the user to change the size of	 * the example widgets.	 */	void createSizeGroup () {		/* Create the group */		sizeGroup = new Group (controlGroup, SWT.NONE);		sizeGroup.setLayout (new GridLayout());		sizeGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));		sizeGroup.setText (ControlExample.getResourceString("Size"));			/* Create the controls */			/*		 * The preferred size of a widget is the size returned		 * by widget.computeSize (SWT.DEFAULT, SWT.DEFAULT).		 * This size is defined on a widget by widget basis.		 * Many widgets will attempt to display their contents.		 */		preferredButton = new Button (sizeGroup, SWT.RADIO);		preferredButton.setText (ControlExample.getResourceString("Preferred"));		tooSmallButton = new Button (sizeGroup, SWT.RADIO);		tooSmallButton.setText (TOO_SMALL_SIZE + " X " + TOO_SMALL_SIZE);		smallButton = new Button(sizeGroup, SWT.RADIO);		smallButton.setText (SMALL_SIZE + " X " + SMALL_SIZE);		largeButton = new Button (sizeGroup, SWT.RADIO);		largeButton.setText (LARGE_SIZE + " X " + LARGE_SIZE);		fillHButton = new Button (sizeGroup, SWT.CHECK);		fillHButton.setText (ControlExample.getResourceString("Fill_X"));		fillVButton = new Button (sizeGroup, SWT.CHECK);		fillVButton.setText (ControlExample.getResourceString("Fill_Y"));				/* Add the listeners */		SelectionAdapter selectionListener = new SelectionAdapter () {			public void widgetSelected (SelectionEvent event) {				setExampleWidgetSize ();			}		};		preferredButton.addSelectionListener(selectionListener);		tooSmallButton.addSelectionListener(selectionListener);		smallButton.addSelectionListener(selectionListener);		largeButton.addSelectionListener(selectionListener);		fillHButton.addSelectionListener(selectionListener);		fillVButton.addSelectionListener(selectionListener);			/* Set the default state */		preferredButton.setSelection (true);	}		/**	 * Creates the "Style" group.  The "Style" group contains	 * controls that allow the user to change the style of	 * the example widgets.  Changing a widget "Style" causes	 * the widget to be destroyed and recreated.	 */	void createStyleGroup () {		styleGroup = new Group (controlGroup, SWT.NONE);		styleGroup.setLayout (new GridLayout ());		styleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));		styleGroup.setText (ControlExample.getResourceString("Styles"));	}		/**	 * Creates the tab folder page.	 *	 * @param tabFolder org.eclipse.swt.widgets.TabFolder	 * @return the new page for the tab folder	 */	Composite createTabFolderPage (TabFolder tabFolder) {		/* Cache the shell and display. */		shell = tabFolder.getShell ();		display = shell.getDisplay ();				/* Create a two column page. */		tabFolderPage = new Composite (tabFolder, SWT.NONE);		tabFolderPage.setLayout (new GridLayout (2, false));			/* Create the "Example" and "Control" groups. */		createExampleGroup ();		createControlGroup ();				/* Create the "Listeners" group under the "Control" group. */		createListenersGroup ();				/* Create and initialize the example and control widgets. */		createExampleWidgets ();		hookExampleWidgetListeners ();		createControlWidgets ();		createBackgroundModeGroup ();		setExampleWidgetState ();				return tabFolderPage;	}		void setExampleWidgetPopupMenu() {		Control[] controls = getExampleControls();		for (int i = 0; i < controls.length; i++) {			final Control control = controls [i];			control.addListener(SWT.MenuDetect, new Listener() {				public void handleEvent(Event event) {		        	Menu menu = control.getMenu();		        	if (menu != null && samplePopup) {		        		menu.dispose();		        		menu = null;		        	}		        	if (menu == null && popupMenuButton.getSelection()) {			        	menu = new Menu(shell, SWT.POP_UP);			        	MenuItem item = new MenuItem(menu, SWT.PUSH);			        	item.setText("Sample popup menu item");			        	specialPopupMenuItems(menu, event);			        	control.setMenu(menu);		        		samplePopup = true;		        	}				}			});		}	}	protected void specialPopupMenuItems(final Menu menu, final Event event) {	}	/**	 * Disposes the "Example" widgets.	 */	void disposeExampleWidgets () {		Widget [] widgets = getExampleWidgets ();		for (int i=0; i<widgets.length; i++) {			widgets [i].dispose ();		}	}		Image colorImage (Color color) {		Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);		GC gc = new GC(image);		gc.setBackground(color);		Rectangle bounds = image.getBounds();		gc.fillRectangle(0, 0, bounds.width, bounds.height);		gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));		gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);		gc.dispose();		return image;	}		Image fontImage (Font font) {		Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);		GC gc = new GC(image);		Rectangle bounds = image.getBounds();		gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));		gc.fillRectangle(0, 0, bounds.width, bounds.height);		gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));		gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);		FontData data[] = font.getFontData();		int style = data[0].getStyle();		switch (style) {		case SWT.NORMAL:			gc.drawLine(3, 3, 3, 8);			gc.drawLine(4, 3, 7, 8);			gc.drawLine(8, 3, 8, 8);			break;		case SWT.BOLD:			gc.drawLine(3, 2, 3, 9);			gc.drawLine(4, 2, 4, 9);			gc.drawLine(5, 2, 7, 2);			gc.drawLine(5, 3, 8, 3);			gc.drawLine(5, 5, 7, 5);			gc.drawLine(5, 6, 7, 6);			gc.drawLine(5, 8, 8, 8);			gc.drawLine(5, 9, 7, 9);			gc.drawLine(7, 4, 8, 4);			gc.drawLine(7, 7, 8, 7);			break;		case SWT.ITALIC:			gc.drawLine(6, 2, 8, 2);			gc.drawLine(7, 3, 4, 8);			gc.drawLine(3, 9, 5, 9);			break;		case SWT.BOLD | SWT.ITALIC:			gc.drawLine(5, 2, 8, 2);			gc.drawLine(5, 3, 8, 3);			gc.drawLine(6, 4, 4, 7);			gc.drawLine(7, 4, 5, 7);			gc.drawLine(3, 8, 6, 8);			gc.drawLine(3, 9, 6, 9);			break;		}		gc.dispose();		return image;	}		/**	 * Gets the list of custom event names.	 * 	 * @return an array containing custom event names	 */	String [] getCustomEventNames () {		return new String [0];	}		/**	 * Gets the default style for a widget	 *	 * @return the default style bit	 */	int getDefaultStyle () {		if (ltrButton != null && ltrButton.getSelection()) {			return SWT.LEFT_TO_RIGHT;		}		if (rtlButton != null && rtlButton.getSelection()) {			return SWT.RIGHT_TO_LEFT;		}		return SWT.NONE;	}		/**	 * Gets the "Example" widgets.	 *	 * @return an array containing the example widgets	 */	Widget [] getExampleWidgets () {		return new Widget [0];	}		/**	 * Gets the "Example" controls.	 * This is the subset of "Example" widgets that are controls.	 *	 * @return an array containing the example controls	 */	Control [] getExampleControls () {		Widget [] widgets = getExampleWidgets ();		Control [] controls = new Control [0];		for (int i = 0; i < widgets.length; i++) {			if (widgets[i] instanceof Control) {				Control[] newControls = new Control[controls.length + 1];				System.arraycopy(controls, 0, newControls, 0, controls.length);				controls = newControls;				controls[controls.length - 1] = (Control)widgets[i];			}		}		return controls;	}		/**	 * Gets the "Example" widget children's items, if any.	 *	 * @return an array containing the example widget children's items	 */

⌨️ 快捷键说明

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