Java Code Examples for org.eclipse.swt.widgets.Spinner#addSelectionListener()

The following examples show how to use org.eclipse.swt.widgets.Spinner#addSelectionListener() . 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: SeriesSheetImpl.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void initZOrderUI( Composite parent )
{
	spnZOrder = new Spinner( parent, SWT.BORDER );
	{
		GridData gd = new GridData( );
		gd.horizontalAlignment = SWT.CENTER;
		spnZOrder.setLayoutData( gd );
		spnZOrder.setMinimum( 0 );
		spnZOrder.setMaximum( 10 );
		if ( getChart( ) instanceof ChartWithAxes
				&& !( getContext( ).getChartType( ) instanceof BubbleChart )
				&& getChart( ).getDimension( ) == ChartDimension.TWO_DIMENSIONAL_LITERAL )
		{
			// Bubble chart has special z order
			spnZOrder.setSelection( seriesDefn.getZOrder( ) );
			spnZOrder.addSelectionListener( this );
		}
		else
		{
			spnZOrder.setEnabled( false );
		}
		ChartUIUtil.addSpinnerScreenReaderAccessbility( spnZOrder,
				Messages.getString( "SeriesSheetImpl.Label.ZOrder" ) ); //$NON-NLS-1$
	}
}
 
Example 2
Source File: SpinnerField.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public SpinnerField(Composite parent, int displayBits, String displayName, int min, int max){
	super(parent, displayBits, displayName);
	final Spinner spinner = new Spinner(this, SWT.NONE);
	spinner.setMaximum(max);
	spinner.setMinimum(min);
	spinner.addSelectionListener(new SelectionAdapter() {
		
		@Override
		public void widgetSelected(SelectionEvent e){
			int v = spinner.getSelection();
			textContents = Integer.toString(v);
			fireChangedEvent();
		}
		
	});
	setControl(spinner);
	
}
 
Example 3
Source File: HorizontalSpinnerSnippet.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private static void createSpinnerGroup(final Shell shell) {
	final Group group = new Group(shell, SWT.NONE);
	group.setLayout(new GridLayout(1, false));

	final Label lbl1 = new Label(group, SWT.NONE);
	lbl1.setText("Simple vertical spinner :");
	final Spinner spinner1 = new Spinner(group, SWT.BORDER);
	spinner1.setMinimum(0);
	spinner1.setMaximum(1000);
	spinner1.setSelection(500);
	spinner1.setIncrement(1);
	spinner1.setPageIncrement(100);

	final Label lbl2 = new Label(group, SWT.NONE);
	lbl2.setText("Floating point values in Spinner :");
	final Spinner spinner2 = new Spinner(group, SWT.NONE);
	// allow 3 decimal places
	spinner2.setDigits(3);
	// set the minimum value to 0.001
	spinner2.setMinimum(1);
	// set the maximum value to 20
	spinner2.setMaximum(20000);
	// set the increment value to 0.010
	spinner2.setIncrement(10);
	// set the seletion to 3.456
	spinner2.setSelection(3456);
	spinner2.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(final SelectionEvent e) {
			final int selection = spinner2.getSelection();
			final int digits = spinner2.getDigits();
			System.out.println("Selection is " + selection / Math.pow(10, digits));
		}
	});

	final Label lbl3 = new Label(group, SWT.NONE);
	lbl3.setText("Validate input in a spinner widget :");
	final Spinner spinner3 = new Spinner(group, SWT.BORDER);
	spinner3.setValues(0, -100, 100, 0, 1, 10);
	spinner3.setLayoutData(new GridData(200, SWT.DEFAULT));
	final ToolTip toolTip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_WARNING);
	spinner3.addModifyListener(e -> {
		final String string = spinner3.getText();
		String message = null;
		try {
			final int value = Integer.parseInt(string);
			final int maximum = spinner3.getMaximum();
			final int minimum = spinner3.getMinimum();
			if (value > maximum) {
				message = "Current input is greater than the maximum limit (" + maximum + ")";
			} else if (value < minimum) {
				message = "Current input is less than the minimum limit (" + minimum + ")";
			}
		} catch (final Exception ex) {
			message = "Current input is not numeric";
		}
		if (message != null) {
			spinner3.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_RED));
			final Rectangle rect = spinner3.getBounds();
			final GC gc = new GC(spinner3);
			final Point pt = gc.textExtent(string);
			gc.dispose();
			toolTip.setLocation(shell.getDisplay().map(shell, null, rect.x + pt.x, rect.y + rect.height));
			toolTip.setMessage(message);
			toolTip.setVisible(true);
		} else {
			toolTip.setVisible(false);
			spinner3.setForeground(null);
		}
	});

}
 
Example 4
Source File: CompositeTableRow.java    From dawnsci with Eclipse Public License 1.0 4 votes vote down vote up
public CompositeTableRow(CompositeEntry entry,
					     Table container,
						 CompositingControl control,
						 boolean disableOp) {
	
	this.name = entry.getName();
	TableItem newItem = new TableItem(container,SWT.DOUBLE_BUFFERED);
	TableEditor editor0 = new TableEditor(container);
	editor0.horizontalAlignment = SWT.CENTER;
	editor0.grabHorizontal = true;
	chkActive = new Button(container,SWT.CHECK);
	chkActive.setSelection(true);
	chkActive.addSelectionListener(control);
	editor0.setEditor(chkActive,newItem,0);
	
	TableEditor editor = new TableEditor(container);
	editor.horizontalAlignment = SWT.CENTER;
	editor.grabHorizontal = true;
	panel = new Composite(container, SWT.NONE);
	panel.setLayout(new GridLayout(2,true));
	slider = new Slider(panel,SWT.HORIZONTAL|SWT.NO_TRIM);
	slider.setValues((int)(entry.getWeight()*100), 0, 104, 5, 1, 5);
	slider.addSelectionListener(this);
	slider.addSelectionListener(control);
	spinner = new Spinner(panel,SWT.DOUBLE_BUFFERED);
	spinner.setMinimum(0);
	spinner.setMaximum(100);
	spinner.setSelection((int)(entry.getWeight()*100));
	spinner.addSelectionListener(control);
	spinner.addSelectionListener(this);
	panel.pack();
	editor.setEditor(panel,newItem,2);
	newItem.setText(1,name);
	TableEditor editor2 = new TableEditor(container);
	editor2.horizontalAlignment = SWT.CENTER;
	editor2.grabHorizontal = true;
	editor2.grabVertical = true;
	op = new Combo(container,SWT.NONE);
	op.add("ADD");
	op.add("SUBTRACT");
	op.add("MULTIPLY");
	op.add("DIVIDE");
	op.add("MINIMUM");
	op.add("MAXIMUM");
	op.select(convertOperationToInt(entry.getOperation()));
	op.pack();
	op.addSelectionListener(control);
	op.setEnabled(!disableOp);
	editor2.setEditor(op,newItem,3);
	TableEditor editor3 = new TableEditor(container);
	editor3.horizontalAlignment = SWT.CENTER;
	editor3.grabHorizontal = true;
	editor3.grabVertical = true;
	chkRed = new Button(container,SWT.CHECK);
	chkRed.setSelection(true);
	chkRed.pack();
	chkRed.addSelectionListener(control);
	editor3.setEditor(chkRed,newItem,4);
	TableEditor editor4 = new TableEditor(container);
	editor4.horizontalAlignment = SWT.CENTER;
	editor4.grabHorizontal = true;
	editor4.grabVertical = true;
	chkGreen = new Button(container,SWT.CHECK);
	chkGreen.pack();
	chkGreen.setSelection(true);
	chkGreen.addSelectionListener(control);
	editor4.setEditor(chkGreen,newItem,5);
	TableEditor editor5 = new TableEditor(container);
	editor5.horizontalAlignment = SWT.CENTER;
	editor5.grabHorizontal = true;
	editor5.grabVertical = true;
	chkBlue = new Button(container,SWT.CHECK);
	chkBlue.pack();
	chkBlue.setSelection(true);
	chkBlue.addSelectionListener(control);
	editor5.setEditor(chkBlue,newItem,6);		
	
}
 
Example 5
Source File: Controls.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
public static void onSelect(Spinner spinner,
		Consumer<SelectionEvent> consumer) {
	spinner.addSelectionListener(selectionListener(consumer));
}