Java Code Examples for org.eclipse.swt.SWT#Traverse

The following examples show how to use org.eclipse.swt.SWT#Traverse . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AggregateEditorComposite.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusOut :
			focusLost( new FocusEvent( event ) );
			break;

		case SWT.Traverse :
			switch ( event.detail )
			{
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
					// Indicates getting focus control rather than
					// cursor control
					event.doit = true;
					isPressingKey = true;
			}
			break;

	}
}
 
Example 2
Source File: DateChooserComboCellEditor.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
protected Control createControl(Composite parent) {
	combo = new DateChooserCombo(parent, getStyle());
	combo.setFont(parent.getFont());

	Listener listener = new Listener() {
		public void handleEvent(Event event) {
			switch ( event.type ) {
				case SWT.Traverse :
					if ( event.detail == SWT.TRAVERSE_ESCAPE
							 || event.detail == SWT.TRAVERSE_RETURN ) {
						event.doit = false;
					}
					break;

				case SWT.FocusOut :
					DateChooserComboCellEditor.this.focusLost();
					break;
			}				
		}
	};
	combo.addListener(SWT.Traverse, listener);
	combo.addListener(SWT.FocusOut, listener);

	return combo;
}
 
Example 3
Source File: CTree.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void handleEvent(Event event) {
	switch (event.type) {
	case SWT.FocusIn:
	case SWT.FocusOut:
		handleFocus(event.type);
		break;
	case SWT.MouseDoubleClick:
	case SWT.MouseDown:
	case SWT.MouseMove:
	case SWT.MouseUp:
		handleMouseEvents(event);
		break;
	case SWT.Traverse:
		handleTraverse(event);
		break;
	}
}
 
Example 4
Source File: DatePicker.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void setSelectionFromFocusButton(Event event) {
    int fb = getFocusDayButton();
    if (fb >= 0 && fb < dayButtons.length) {
        VButton button = dayButtons[fb];
        int stateMask = event.stateMask;
        setSelectionFromButton(button, stateMask);
        boolean defaultSelection = false;
        if (event.type == SWT.KeyDown && event.stateMask == 0) {
            if (event.keyCode == SWT.KEYPAD_CR
                    || event.character == SWT.CR) {
                defaultSelection = true;
            }
        } else if (event.type == SWT.Traverse && event.stateMask == 0) {
            if (event.keyCode == SWT.TRAVERSE_RETURN) {
                defaultSelection = true;
            }
        }
        cdt.fireSelectionChanged(defaultSelection);
    }
}
 
Example 5
Source File: FillChooserComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 */
private void placeComponents( )
{
	// THE LAYOUT OF THIS COMPOSITE (FILLS EVERYTHING INSIDE IT)
	FillLayout flMain = new FillLayout( );
	flMain.marginHeight = 0;
	flMain.marginWidth = 0;
	setLayout( flMain );

	// THE LAYOUT OF THE OUTER COMPOSITE (THAT GROWS VERTICALLY BUT ANCHORS
	// ITS CONTENT NORTH)
	cmpContentOuter = new Composite( this, SWT.NONE );
	GridLayout glContentOuter = new GridLayout( );
	glContentOuter.verticalSpacing = 0;
	glContentOuter.horizontalSpacing = 0;
	glContentOuter.marginHeight = 0;
	glContentOuter.marginWidth = 0;
	glContentOuter.numColumns = 1;
	cmpContentOuter.setLayout( glContentOuter );

	// THE LAYOUT OF THE INNER COMPOSITE (ANCHORED NORTH AND ENCAPSULATES
	// THE CANVAS + BUTTON)
	cmpContentInner = new Composite( cmpContentOuter, SWT.BORDER );
	GridLayout glContentInner = new GridLayout( );
	glContentInner.verticalSpacing = 0;
	glContentInner.horizontalSpacing = 0;
	glContentInner.marginHeight = 0;
	glContentInner.marginWidth = 0;
	glContentInner.numColumns = 2;
	cmpContentInner.setLayout( glContentInner );
	GridData gdContentInner = new GridData( GridData.FILL_HORIZONTAL );
	cmpContentInner.setLayoutData( gdContentInner );

	// THE CANVAS
	cnvSelection = new FillCanvas( cmpContentInner,
			SWT.NONE,
			this.bAutoEnabled,
			wizardContext == null ? null
					: wizardContext.getImageServiceProvider( ) );
	cnvSelection.setTextIndent( 8 );
	GridData gdCNVSelection = new GridData( GridData.FILL_BOTH );
	gdCNVSelection.heightHint = iSize;
	cnvSelection.setLayoutData( gdCNVSelection );

	initFill( );

	// THE BUTTON
	btnDown = new Button( cmpContentInner, SWT.ARROW | SWT.DOWN );
	GridData gdBDown = new GridData( GridData.FILL );
	gdBDown.verticalAlignment = GridData.BEGINNING;
	gdBDown.widthHint = iSize - 2;
	gdBDown.heightHint = iSize;
	btnDown.setLayoutData( gdBDown );
	btnDown.addSelectionListener( this );

	addDisposeListener( this );

	Listener listener = new Listener( ) {

		public void handleEvent( Event event )
		{
			handleEventCanvas( event );
		}
	};

	int[] textEvents = {
			SWT.KeyDown,
			SWT.MouseDown,
			SWT.Traverse,
			SWT.FocusIn,
			SWT.FocusOut
	};
	for ( int i = 0; i < textEvents.length; i++ )
	{
		cnvSelection.addListener( textEvents[i], listener );
	}

}
 
Example 6
Source File: VControl.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private boolean include(boolean key, int type) {
	if(type == SWT.Selection) {
		return false;
	}
	if(key && (type == SWT.KeyDown || type == SWT.KeyUp || type == SWT.Traverse)) {
		return true;
	}
	if(!key && !(type == SWT.KeyDown || type == SWT.KeyUp || type == SWT.Traverse)) {
		return true;
	}
	return false;
}
 
Example 7
Source File: FindBarActions.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void consumeEvent(Event event)
{
	switch (event.type)
	{
		case SWT.KeyDown:
			event.doit = false;
			break;
		case SWT.Traverse:
			event.detail = SWT.TRAVERSE_NONE;
			event.doit = true;
			break;
		default:
	}
	event.type = SWT.NONE;
}
 
Example 8
Source File: StyleCombo.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
void createPopup( Object[] items, int selectionIndex )
{
	// create shell and list
	popup = new Shell( getShell( ), SWT.NO_TRIM | SWT.ON_TOP );

	table = new Table( popup, SWT.SINGLE
			| SWT.V_SCROLL
			| SWT.FULL_SELECTION );
	new TableColumn( table, SWT.LEFT );
	if ( font != null )
		table.setFont( font );
	if ( foreground != null )
		table.setForeground( foreground );
	if ( background != null )
		table.setBackground( background );

	label.setBackground( table.getBackground( ) );
	label.setForeground( table.getForeground( ) );
	label.setFont( table.getFont( ) );

	int[] popupEvents = {
			SWT.Close, SWT.Paint, SWT.Deactivate
	};
	for ( int i = 0; i < popupEvents.length; i++ )
		popup.addListener( popupEvents[i], listener );
	int[] tableEvents = {
			SWT.MouseUp,
			SWT.Selection,
			SWT.Traverse,
			SWT.KeyDown,
			SWT.KeyUp,
			SWT.FocusIn,
			SWT.FocusOut,
			SWT.Dispose
	};
	for ( int i = 0; i < tableEvents.length; i++ )
		table.addListener( tableEvents[i], listener );
}
 
Example 9
Source File: DataItemCombo.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
void createPopup( String[] items, int selectionIndex )
{
	// create shell and list
	popup = new Shell( getShell( ), SWT.NO_TRIM | SWT.ON_TOP );
	int style = getStyle( );
	int listStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ( ( style & SWT.FLAT ) != 0 )
		listStyle |= SWT.FLAT;
	if ( ( style & SWT.RIGHT_TO_LEFT ) != 0 )
		listStyle |= SWT.RIGHT_TO_LEFT;
	if ( ( style & SWT.LEFT_TO_RIGHT ) != 0 )
		listStyle |= SWT.LEFT_TO_RIGHT;
	list = new List( popup, listStyle );
	if ( font != null )
		list.setFont( font );
	if ( foreground != null )
		list.setForeground( foreground );
	if ( background != null )
		list.setBackground( background );

	int[] popupEvents = {
			SWT.Close, SWT.Paint, SWT.Deactivate
	};
	for ( int i = 0; i < popupEvents.length; i++ )
		popup.addListener( popupEvents[i], listener );
	int[] listEvents = {
			SWT.MouseUp,
			SWT.Selection,
			SWT.Traverse,
			SWT.KeyDown,
			SWT.KeyUp,
			SWT.FocusIn,
			SWT.Dispose
	};
	for ( int i = 0; i < listEvents.length; i++ )
		list.addListener( listEvents[i], listener );

	if ( items != null )
		list.setItems( items );
	if ( selectionIndex != -1 )
		list.setSelection( selectionIndex );
}
 
Example 10
Source File: FillChooserComposite.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusOut :
			if ( event.widget instanceof ColorSelectionCanvas )
			{
				( (ColorSelectionCanvas) event.widget ).redraw( );
			}
			if ( isPopupControl( event.widget ) )
			{
				Control cTmp = isPressingKey ? getDisplay( ).getFocusControl( )
						: getDisplay( ).getCursorControl( );
				// Set default value back
				isPressingKey = false;
				if ( cTmp != null )
				{
					// Condition added to handle behavior under Linux
					if ( isPopupControl( cTmp )
							|| SWT.getPlatform( ).indexOf( "win32" ) == 0//$NON-NLS-1$
							&& ( cTmp.equals( cnvSelection ) || cTmp.equals( btnDown ) ) )
					{
						return;
					}

					if ( cTmp.equals( cnvSelection )
							|| cTmp.equals( btnDown ) )
					{
						bJustFocusLost = true;
					}
				}

				cmpDropDown.getShell( ).close( );
			}
			break;

		case SWT.KeyDown :
			if ( cmpDropDown != null
					&& !cmpDropDown.getShell( ).isDisposed( ) )
			{
				if ( event.keyCode == SWT.ARROW_UP )
				{
					cmpDropDown.getShell( ).close( );
				}
				else if ( event.keyCode == SWT.CR
						|| event.keyCode == SWT.KEYPAD_CR )
				{
					if ( srTransparency != null )
					{
						this.iTransparency = srTransparency.getSelection( );
					}
					if ( fCurrent instanceof ColorDefinition
							&& bTransparencyChanged )
					{
						( (ColorDefinition) fCurrent ).setTransparency( this.iTransparency );
					}
					this.setFill( fCurrent );
					cmpDropDown.getShell( ).close( );
				}
			}
			break;

		case SWT.Traverse :
			switch ( event.detail )
			{
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
					// Indicates getting focus control rather than cursor
					// control
					isPressingKey = true;
					event.doit = true;
			}
			break;
	}

}
 
Example 11
Source File: FillChooserComposite.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
void handleEventCanvas( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusIn :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.FocusOut :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.KeyDown :
		{
			if ( event.keyCode == SWT.KEYPAD_CR
					|| event.keyCode == SWT.CR
					|| event.keyCode == ' ' )
			{
				event.doit = true;
				toggleDropDown( );
			}
			break;
		}
		case SWT.MouseDown :
			if ( !bEnabled )
			{
				return;
			}
			// fireHandleEvent( MOUSE_CLICKED_EVENT );
			toggleDropDown( );
			break;
		case SWT.Traverse :
		{
			switch ( event.detail )
			{
				case SWT.TRAVERSE_ESCAPE :
					getShell( ).close( );
					break;
				case SWT.TRAVERSE_RETURN :
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
				case SWT.TRAVERSE_ARROW_PREVIOUS :
				case SWT.TRAVERSE_ARROW_NEXT :
					event.doit = true;
					cnvSelection.redraw( );
			}
			break;
		}
	}
}
 
Example 12
Source File: TableCombo.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// set style
	int style = getStyle();
	int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		tableStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		tableStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		tableStyle |= SWT.LEFT_TO_RIGHT;

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null)
		table.setFont(font);
	if (foreground != null)
		table.setForeground(foreground);
	if (background != null)
		table.setBackground(background);

	// Add popup listeners
	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}

	// add table listeners
	int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
			SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < tableEvents.length; i++) {
		table.addListener(tableEvents[i], listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 13
Source File: TableCombo.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// set style
	int style = getStyle();
	int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		tableStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		tableStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		tableStyle |= SWT.LEFT_TO_RIGHT;

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null)
		table.setFont(font);
	if (foreground != null)
		table.setForeground(foreground);
	if (background != null)
		table.setBackground(background);

	// Add popup listeners
	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}

	// add table listeners
	int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
			SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < tableEvents.length; i++) {
		table.addListener(tableEvents[i], listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 14
Source File: CCombo.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Constructs a new instance of this class given its parent
 * and a style value describing its behavior and appearance.
 * <p>
 * The style value is either one of the style constants defined in
 * class <code>SWT</code> which is applicable to instances of this
 * class, or must be built by <em>bitwise OR</em>'ing together 
 * (that is, using the <code>int</code> "|" operator) two or more
 * of those <code>SWT</code> style constants. The class description
 * lists the style constants that are applicable to the class.
 * Style bits are also inherited from superclasses.
 * </p>
 *
 * @param parent a widget which will be the parent of the new instance (cannot be null)
 * @param style the style of widget to construct
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
 * </ul>
 *
 * @see SWT#BORDER
 * @see SWT#READ_ONLY
 * @see SWT#FLAT
 * @see Widget#getStyle()
 */
public CCombo (Composite parent, int style) {
	super (parent, style = checkStyle (style));
	
	int textStyle = SWT.SINGLE;
	if ((style & SWT.READ_ONLY) != 0) textStyle |= SWT.READ_ONLY;
	if ((style & SWT.FLAT) != 0) textStyle |= SWT.FLAT;
	text = new Text (this, textStyle);
	int arrowStyle = SWT.ARROW | SWT.DOWN;
	if ((style & SWT.FLAT) != 0) arrowStyle |= SWT.FLAT;
	arrow = new Button (this, arrowStyle);

	listener = new Listener () {
		public void handleEvent (Event event) {
			if (popup == event.widget) {
				popupEvent (event);
				return;
			}
			if (text == event.widget) {
				textEvent (event);
				return;
			}
			if (list == event.widget) {
				listEvent (event);
				return;
			}
			if (arrow == event.widget) {
				arrowEvent (event);
				return;
			}
			if (CCombo.this == event.widget) {
				comboEvent (event);
				return;
			}

		}
	};
	
	
	int [] comboEvents = {SWT.Dispose, SWT.Move, SWT.Resize};
	for (int i=0; i<comboEvents.length; i++) this.addListener (comboEvents [i], listener);
	
	int [] textEvents = {SWT.KeyDown, SWT.KeyUp, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.Traverse, SWT.FocusIn, SWT.FocusOut};
	for (int i=0; i<textEvents.length; i++) text.addListener (textEvents [i], listener);
	
	int [] arrowEvents = {SWT.Selection, SWT.FocusIn, SWT.FocusOut};
	for (int i=0; i<arrowEvents.length; i++) arrow.addListener (arrowEvents [i], listener);
	
	createPopup(null, -1);
	initAccessible();
	
}
 
Example 15
Source File: VTracker.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void handleEvent(Event event) {
	switch (event.type){
	case SWT.Traverse:
		lastTraverse = event.detail;
		if(SWT.TRAVERSE_TAB_NEXT == event.detail || SWT.TRAVERSE_TAB_PREVIOUS == event.detail) {
			if(focusControl != null) {
				event.doit = true;
				focusControl.handleEvent(event);
				if(event.doit) {
					Composite comp = focusControl.getWidget();
					if(SWT.TRAVERSE_TAB_NEXT == event.detail) {
						setFocusToNext(comp);
					} else {
						setFocusToPrev(comp);
					}
				}
			}
		}
		break;
	case SWT.FocusIn:
		setFocusControl(getVControl(event.widget));
		break;
	case SWT.MouseDown:
		mouseButton = event.button;
		mouseDown = new Point(event.x, event.y);
		if(activeControl != null && activeControl.setState(VControl.STATE_MOUSE_DOWN, true)) {
			activeControl.redraw();
		}
		break;
	case SWT.MouseMove:
		if(panels.containsKey(event.widget)) {
			VControl vcontrol = panels.get(event.widget).getControl(event.x, event.y, true);
			if(vcontrol != activeControl && (vcontrol == null || vcontrol.isEnabled())) {
				activate(vcontrol);
			}
		} else if(activeControl != null && event.widget != activeControl.getControl()) {
			activeControl.deactivate();
			activeControl = null;
		}
		break;
	case SWT.MouseUp:
		mouseButton = -1;
		mouseDown = null;
		if(activeControl != null && activeControl.setState(VControl.STATE_MOUSE_DOWN, false)) {
			activeControl.redraw();
		}
		break;
	}
}
 
Example 16
Source File: CTreeCombo.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
void createPopup(Collection<CTreeComboItem> items, CTreeComboItem selectedItem) {
	// create shell and list
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
	final int style = getStyle();
	int listStyle = SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE;
	if ((style & SWT.FLAT) != 0) {
		listStyle |= SWT.FLAT;
	}
	if ((style & SWT.RIGHT_TO_LEFT) != 0) {
		listStyle |= SWT.RIGHT_TO_LEFT;
	}
	if ((style & SWT.LEFT_TO_RIGHT) != 0) {
		listStyle |= SWT.LEFT_TO_RIGHT;
	}
	tree = new Tree(popup, listStyle);
	tree.addTreeListener(hookListener);
	if (font != null) {
		tree.setFont(font);
	}
	if (foreground != null) {
		tree.setForeground(foreground);
	}
	if (background != null) {
		tree.setBackground(background);
	}

	final int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}
	final int[] listEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose, SWT.Collapse, SWT.Expand };
	for (int i = 0; i < listEvents.length; i++) {
		tree.addListener(listEvents[i], listener);
	}

	for (final CTreeComboColumn c : columns) {
		final TreeColumn col = new TreeColumn(tree, SWT.NONE);
		c.setRealTreeColumn(col);
	}

	if (items != null) {
		createTreeItems(items.toArray(new CTreeComboItem[0]));
	}

	if (selectedItem != null) {
		tree.setSelection(selectedItem.getRealTreeItem());
	}
}
 
Example 17
Source File: CTreeCombo.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The CTreeCombo class represents a selectable user interface object
 * that combines a text field and a tree and issues notification
 * when an item is selected from the tree.
 * <p>
 * Note that although this class is a subclass of <code>Composite</code>,
 * it does not make sense to add children to it, or set a layout on it.
 * </p>
 * <dl>
 * <dt><b>Styles:</b>
 * <dd>BORDER, READ_ONLY, FLAT</dd>
 * <dt><b>Events:</b>
 * <dd>DefaultSelection, Modify, Selection, Verify</dd>
 * </dl>
 */
public CTreeCombo(Composite parent, int style) {
	super(parent, style = checkStyle(style));

	int textStyle = SWT.SINGLE;
	if ((style & SWT.READ_ONLY) != 0) {
		textStyle |= SWT.READ_ONLY;
	}
	if ((style & SWT.FLAT) != 0) {
		textStyle |= SWT.FLAT;
	}
	text = new Text(this, textStyle);
	int arrowStyle = SWT.ARROW | SWT.DOWN;
	if ((style & SWT.FLAT) != 0) {
		arrowStyle |= SWT.FLAT;
	}
	arrow = new Button(this, arrowStyle);

	listener = new Listener() {
		@Override
		public void handleEvent(Event event) {
			if (popup == event.widget) {
				popupEvent(event);
				return;
			}
			if (text == event.widget) {
				textEvent(event);
				return;
			}
			if (tree == event.widget) {
				treeEvent(event);
				return;
			}
			if (arrow == event.widget) {
				arrowEvent(event);
				return;
			}
			if (CTreeCombo.this == event.widget) {
				comboEvent(event);
				return;
			}
			if (getShell() == event.widget) {
				getDisplay().asyncExec(new Runnable() {
					@Override
					public void run() {
						if (isDisposed()) {
							return;
						}
						handleFocus(SWT.FocusOut);
					}
				});
			}
		}
	};
	filter = (event) -> {
		final Shell shell = ((Control) event.widget).getShell();
		if (shell == CTreeCombo.this.getShell()) {
			handleFocus(SWT.FocusOut);
		}
	};

	final int[] comboEvents = { SWT.Dispose, SWT.FocusIn, SWT.Move, SWT.Resize };
	for (int i = 0; i < comboEvents.length; i++) {
		addListener(comboEvents[i], listener);
	}

	final int[] textEvents = { SWT.DefaultSelection, SWT.KeyDown, SWT.KeyUp, SWT.MenuDetect, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.MouseDoubleClick, SWT.MouseWheel, SWT.Traverse, SWT.FocusIn, SWT.Verify };
	for (int i = 0; i < textEvents.length; i++) {
		text.addListener(textEvents[i], listener);
	}

	final int[] arrowEvents = { SWT.MouseDown, SWT.MouseUp, SWT.Selection, SWT.FocusIn };
	for (int i = 0; i < arrowEvents.length; i++) {
		arrow.addListener(arrowEvents[i], listener);
	}

	createPopup(null, null);
	initAccessible();
}
 
Example 18
Source File: CustomChooserComposite.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
void handleEventCanvasSelection( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusIn :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.FocusOut :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.KeyDown :
		{
			// At this point the widget may have been disposed.
			// If so, do not continue.
			if ( isDisposed( ) )
				break;

			if ( event.keyCode == SWT.ARROW_UP
					|| event.keyCode == SWT.ARROW_DOWN )
			{
				toggleDropDown( );
			}
			break;
		}
		case SWT.Traverse :
		{
			switch ( event.detail )
			{
				case SWT.TRAVERSE_ESCAPE :
					getShell( ).close( );
					break;
				case SWT.TRAVERSE_RETURN :
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
				case SWT.TRAVERSE_ARROW_PREVIOUS :
				case SWT.TRAVERSE_ARROW_NEXT :
					event.doit = true;
					cnvSelection.redraw( );
			}
			break;
		}
		case SWT.MouseDown :
			toggleDropDown( );
			break;
	}
}
 
Example 19
Source File: DateChooser.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Manages event at the calendar level.
 *
 * @param event event
 */
protected void calendarEvent(Event event) {
	switch (event.type) {
		case SWT.Traverse:
			switch (event.detail) {
				case SWT.TRAVERSE_ARROW_NEXT:
				case SWT.TRAVERSE_ARROW_PREVIOUS:
				case SWT.TRAVERSE_PAGE_NEXT:
				case SWT.TRAVERSE_PAGE_PREVIOUS:
					event.doit = false;
					break;
				default:
					event.doit = true;
			}
			break;

		case SWT.FocusIn:
			handleFocus(event.type);
			break;

		case SWT.KeyDown: {
			final boolean ctrl = (event.stateMask & SWT.CTRL) != 0;
			switch (event.keyCode) {
				case SWT.ARROW_LEFT:
					if (event.stateMask != 0) {
						return;
					}
					setFocus(focusIndex - 1);
					break;
				case SWT.ARROW_RIGHT:
					if (event.stateMask != 0) {
						return;
					}
					setFocus(focusIndex + 1);
					break;
				case SWT.ARROW_UP:
					if (event.stateMask != 0) {
						return;
					}
					setFocus(focusIndex - 7);
					break;
				case SWT.ARROW_DOWN:
					if (event.stateMask != 0) {
						return;
					}
					setFocus(focusIndex + 7);
					break;
				case SWT.PAGE_DOWN:
					if (event.stateMask != 0 || !navigationEnabled) {
						return;
					}
					changeCurrentMonth(ctrl ? 12 : 1);
					break;
				case SWT.PAGE_UP:
					if (event.stateMask != 0 || !navigationEnabled) {
						return;
					}
					changeCurrentMonth(ctrl ? -12 : -1);
					break;
				case ' ':
					select(focusIndex, event.stateMask);
					break;
				case SWT.HOME:
					if (event.stateMask != 0) {
						return;
					}
					setFocusOnToday(autoSelectOnFooter);
					break;
				default:
					return;
			}
			if (hasFocus) {
				gridRedraw();
			}
			break;
		}

		case SWT.Dispose: {
			final Display display = getDisplay();
			display.removeFilter(SWT.FocusIn, filter);
			display.removeFilter(SWT.KeyDown, filter);
			hasFocus = false;
			break;
		}
	}
}
 
Example 20
Source File: LineSeriesMarkerSheet.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
void handleEventCanvasMarkers( Event event )
{
	switch ( event.type )
	{
		case SWT.KeyDown :
		{
			if ( event.keyCode == SWT.ARROW_LEFT )
			{
				if ( iSelectedIndex - 1 >= 0 )
				{
					iSelectedIndex--;
					setEnabledState( );
				}
			}
			else if ( event.keyCode == SWT.ARROW_RIGHT )
			{
				if ( iSelectedIndex + 1 < getMarkers( ).size( ) )
				{
					iSelectedIndex++;
					setEnabledState( );
				}
			}
			else if ( event.keyCode == SWT.ARROW_UP )
			{
				if ( iSelectedIndex - MARKER_ROW_MAX_NUMBER >= 0 )
				{
					iSelectedIndex -= MARKER_ROW_MAX_NUMBER;
					setEnabledState( );
				}
			}
			else if ( event.keyCode == SWT.ARROW_DOWN )
			{
				if ( iSelectedIndex + MARKER_ROW_MAX_NUMBER < getMarkers( ).size( ) )
				{
					iSelectedIndex += MARKER_ROW_MAX_NUMBER;
					setEnabledState( );
				}
			}
			
			else if ( event.keyCode == SWT.CR
					|| event.keyCode == SWT.KEYPAD_CR )
			{
				currentMarkerEditor.setFocus( );
			}
			else if ( event.keyCode == SWT.ESC )
			{
				cnvMarkers.getShell( ).close( );
			}
			break;
		}
		case SWT.Traverse :
		{
			switch ( event.detail )
			{
				case SWT.TRAVERSE_RETURN :
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
				case SWT.TRAVERSE_ARROW_PREVIOUS :
				case SWT.TRAVERSE_ARROW_NEXT :
					event.doit = true;
					cnvMarkers.redraw( );
			}
			break;
		}
		case SWT.Paint :
			paintControl( new PaintEvent( event ) );
			break;
		case SWT.MouseDown :
			mouseDown( new MouseEvent( event ) );
			break;
	}
}