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

📄 gridlayouttab.java

📁 很好的学习swt的 sample 很好的学习swt的 sample
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.eclipse.swt.examples.layoutexample;/* * Copyright (c) 2000, 2002 IBM Corp.  All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */import org.eclipse.swt.*;import org.eclipse.swt.custom.*;import org.eclipse.swt.events.*;import org.eclipse.swt.layout.*;import org.eclipse.swt.widgets.*;import org.eclipse.swt.graphics.*;class GridLayoutTab extends Tab {	/* Controls for setting layout parameters */	Text numColumns;	Button makeColumnsEqualWidth;	Combo marginHeight, marginWidth, horizontalSpacing, verticalSpacing;	/* The example layout instance */	GridLayout gridLayout;	/* TableEditors and related controls*/	TableEditor comboEditor, widthEditor, heightEditor;	TableEditor vAlignEditor, hAlignEditor, hIndentEditor;	TableEditor hSpanEditor, vSpanEditor, hGrabEditor, vGrabEditor;	CCombo combo, vAlign, hAlign, hGrab, vGrab;	Text widthText, heightText, hIndent, hSpan, vSpan;		/* Constants */	final int COMBO_COL = 1;	final int WIDTH_COL = 2;	final int HEIGHT_COL = 3;	final int HALIGN_COL = 4;	final int VALIGN_COL = 5;	final int HINDENT_COL = 6;	final int HSPAN_COL = 7;	final int VSPAN_COL = 8;	final int HGRAB_COL = 9;	final int VGRAB_COL = 10;		final int TOTAL_COLS = 11;			/**	 * Creates the Tab within a given instance of LayoutExample.	 */	GridLayoutTab(LayoutExample instance) {		super(instance);	}		/**	 * Creates the widgets in the "child" group.	 */	void createChildWidgets () {		/* Create the TraverseListener */		final TraverseListener traverseListener = new TraverseListener () {			public void keyTraversed (TraverseEvent e) {				if (e.detail == SWT.TRAVERSE_RETURN || e.detail == SWT.TRAVERSE_TAB_NEXT)					resetEditors ();				if (e.detail == SWT.TRAVERSE_ESCAPE)					disposeEditors ();			};		};				/* Add common controls */		super.createChildWidgets ();					/* Add TableEditors */				comboEditor = new TableEditor (table);		widthEditor = new TableEditor (table);		heightEditor = new TableEditor (table);		vAlignEditor = new TableEditor (table);		hAlignEditor = new TableEditor (table);		hIndentEditor = new TableEditor (table);		hSpanEditor = new TableEditor (table);		vSpanEditor = new TableEditor (table);		hGrabEditor = new TableEditor (table);		vGrabEditor = new TableEditor (table);		table.addMouseListener (new MouseAdapter () {			public void mouseDown(MouseEvent e) {				resetEditors();				index = table.getSelectionIndex ();				Point pt = new Point (e.x, e.y);                newItem = table.getItem (pt);                if (newItem == null) return;                TableItem oldItem = comboEditor.getItem ();                if (newItem == oldItem || newItem != lastSelected) {					lastSelected = newItem;					return;				}				table.showSelection ();								combo = new CCombo (table, SWT.READ_ONLY);				createComboEditor (combo, comboEditor);								widthText = new Text (table, SWT.SINGLE);				widthText.setText (((String [])data.elementAt (index)) [WIDTH_COL]);				createTextEditor (widthText, widthEditor, WIDTH_COL);								heightText = new Text (table, SWT.SINGLE);				heightText.setText (((String [])data.elementAt (index)) [HEIGHT_COL]);				createTextEditor (heightText, heightEditor, HEIGHT_COL);				String [] alignValues = new String [] {"BEGINNING","CENTER","END","FILL"};				hAlign = new CCombo (table, SWT.NONE);				hAlign.setItems (alignValues);				hAlign.setText (newItem.getText (HALIGN_COL));				hAlignEditor.horizontalAlignment = SWT.LEFT;				hAlignEditor.grabHorizontal = true;				hAlignEditor.minimumWidth = 50;				hAlignEditor.setEditor (hAlign, newItem, HALIGN_COL);				hAlign.addTraverseListener (traverseListener);								vAlign = new CCombo (table, SWT.NONE);				vAlign.setItems (alignValues);				vAlign.setText (newItem.getText (VALIGN_COL));				vAlignEditor.horizontalAlignment = SWT.LEFT;				vAlignEditor.grabHorizontal = true;				vAlignEditor.minimumWidth = 50;				vAlignEditor.setEditor (vAlign, newItem, VALIGN_COL);				vAlign.addTraverseListener (traverseListener);								hIndent = new Text (table, SWT.SINGLE);				hIndent.setText (((String [])data.elementAt (index)) [HINDENT_COL]);				createTextEditor (hIndent, hIndentEditor, HINDENT_COL);								hSpan = new Text (table, SWT.SINGLE);				hSpan.setText (((String [])data.elementAt (index)) [HSPAN_COL]);				createTextEditor (hSpan, hSpanEditor, HSPAN_COL);								vSpan = new Text (table, SWT.SINGLE);				vSpan.setText (((String [])data.elementAt (index)) [VSPAN_COL]);				createTextEditor (vSpan, vSpanEditor, VSPAN_COL);								String [] boolValues = new String [] {"false","true"};				hGrab = new CCombo (table, SWT.NONE);				hGrab.setItems (boolValues);				hGrab.setText (newItem.getText (HGRAB_COL));				hGrabEditor.horizontalAlignment = SWT.LEFT;				hGrabEditor.grabHorizontal = true;				hGrabEditor.minimumWidth = 50;				hGrabEditor.setEditor (hGrab, newItem, HGRAB_COL);				hGrab.addTraverseListener (traverseListener);;								vGrab = new CCombo (table, SWT.NONE);				vGrab.setItems (boolValues);				vGrab.setText (newItem.getText (VGRAB_COL));				vGrabEditor.horizontalAlignment = SWT.LEFT;				vGrabEditor.grabHorizontal = true;				vGrabEditor.minimumWidth = 50;				vGrabEditor.setEditor (vGrab, newItem, VGRAB_COL);				vGrab.addTraverseListener (traverseListener);                                for (int i=0; i<table.getColumnCount (); i++) {                	Rectangle rect = newItem.getBounds (i);                    if (rect.contains (pt)) {                    	switch (i) {							case COMBO_COL :								combo.setFocus ();									break;							case WIDTH_COL :									widthText.setFocus ();								break;							case HEIGHT_COL :								heightText.setFocus ();								break;							case HALIGN_COL :								hAlign.setFocus ();								break;							case VALIGN_COL :								vAlign.setFocus ();								break;							case HINDENT_COL :								hIndent.setFocus ();								break;							case HSPAN_COL :								hSpan.setFocus ();								break;							case VSPAN_COL :								vSpan.setFocus ();								break;							case HGRAB_COL :								hGrab.setFocus ();								break;							case VGRAB_COL :								vGrab.setFocus ();								break;							default :								resetEditors ();								break;						}                    }                } 			}		});				/* Add listener to add an element to the table */		add.addSelectionListener(new SelectionAdapter () {			public void widgetSelected(SelectionEvent e) {				TableItem item = new TableItem (table, 0);				String [] insert = new String [] { 					String.valueOf (table.indexOf (item)), "Button",					"-1","-1","BEGINNING","CENTER",					"0","1","1","false","false"};				item.setText (insert);				data.addElement (insert);				resetEditors ();			}		});	}	/**	 * Creates the control widgets.	 */	void createControlWidgets () {		/* Rearrange the layout of the control group */		size.setLayoutData (new GridData ());				/* Controls the margins and spacing of the GridLayout */		String [] marginValues = new String [] {"0","3","5","10"};		Group marginGroup = new Group (controlGroup, SWT.NONE);		marginGroup.setText (LayoutExample.getResourceString ("Margins_Spacing"));		GridData data = new GridData (GridData.FILL_HORIZONTAL);		data.verticalSpan = 2;		marginGroup.setLayoutData (data);		GridLayout layout = new GridLayout ();		layout.numColumns = 2;		marginGroup.setLayout (layout);		new Label (marginGroup, SWT.NONE).setText ("marginHeight");		marginHeight = new Combo (marginGroup, SWT.NONE);		marginHeight.setItems (marginValues);		marginHeight.select (2);		data = new GridData (GridData.FILL_HORIZONTAL);		data.widthHint = 60;		marginHeight.setLayoutData (data);		marginHeight.addSelectionListener (selectionListener);		marginHeight.addTraverseListener (traverseListener);		new Label (marginGroup, SWT.NONE).setText ("marginWidth");		marginWidth = new Combo (marginGroup, SWT.NONE);		marginWidth.setItems (marginValues);		marginWidth.select (2);		data = new GridData (GridData.FILL_HORIZONTAL);		data.widthHint = 60;		marginWidth.setLayoutData (data);		marginWidth.addSelectionListener (selectionListener);		marginWidth.addTraverseListener (traverseListener);		new Label (marginGroup, SWT.NONE).setText ("horizontalSpacing");		horizontalSpacing = new Combo (marginGroup, SWT.NONE);		horizontalSpacing.setItems (marginValues);		horizontalSpacing.select (2);		data = new GridData (GridData.FILL_HORIZONTAL);		data.widthHint = 60;		horizontalSpacing.setLayoutData (data);		horizontalSpacing.addSelectionListener (selectionListener);		horizontalSpacing.addTraverseListener (traverseListener);		new Label (marginGroup, SWT.NONE).setText ("verticalSpacing");		verticalSpacing = new Combo (marginGroup, SWT.NONE);		verticalSpacing.setItems (marginValues);		verticalSpacing.select (2);		data = new GridData (GridData.FILL_HORIZONTAL);		data.widthHint = 60;		verticalSpacing.setLayoutData (data);		verticalSpacing.addSelectionListener (selectionListener);		verticalSpacing.addTraverseListener (traverseListener);                /* Controls the columns in the GridLayout */		Group columnGroup = new Group (controlGroup, SWT.NONE);		columnGroup.setText (LayoutExample.getResourceString ("Columns"));		layout = new GridLayout ();		layout.numColumns = 2;		columnGroup.setLayout (layout);		data = new GridData (GridData.VERTICAL_ALIGN_FILL);		columnGroup.setLayoutData (data);		numColumns = new Text (columnGroup, SWT.BORDER);		numColumns.setText ("1");		numColumns.addSelectionListener (selectionListener);		numColumns.addTraverseListener (traverseListener);       	data = new GridData (GridData.FILL_HORIZONTAL);       	data.widthHint = 15;       	numColumns.setLayoutData (data);       	new Label (columnGroup, SWT.NONE).setText ("numColumns");		makeColumnsEqualWidth = new Button (columnGroup, SWT.CHECK);		makeColumnsEqualWidth.setText ("makeColumnsEqualWidth");		makeColumnsEqualWidth.addSelectionListener (selectionListener);		data = new GridData (GridData.FILL_HORIZONTAL);		data.horizontalSpan = 2;		data.horizontalIndent = 14;		makeColumnsEqualWidth.setLayoutData (data);		/* Add common controls */		super.createControlWidgets ();		controlGroup.pack();	}	

⌨️ 快捷键说明

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