Java Code Examples for org.eclipse.swt.widgets.Scale#addListener()

The following examples show how to use org.eclipse.swt.widgets.Scale#addListener() . 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: PWScale.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @see org.eclipse.nebula.widgets.opal.preferencewindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
 */
@Override
public Control build(final Composite parent) {
	buildLabel(parent, GridData.CENTER);
	final Scale scale = new Scale(parent, SWT.HORIZONTAL);
	addControl(scale);
	scale.setIncrement(this.increment);
	scale.setMinimum(this.min);
	scale.setMaximum(this.max);
	final Integer originalValue = (Integer) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
	scale.setSelection(originalValue.intValue());

	scale.addListener(SWT.Modify, new Listener() {
		@Override
		public void handleEvent(final Event event) {
			PreferenceWindow.getInstance().setValue(getPropertyKey(), Integer.valueOf(scale.getSelection()));
		}
	});

	return scale;
}
 
Example 2
Source File: FindReplaceDialog.java    From pmTrans with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void renderTransparency(final Shell shell) {
	Group group = new Group(shell, SWT.NONE);
	group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 6, 1));
	group.setLayout(new GridLayout(1, false));
	group.setText("Transparency");
	final Scale transparencySlider = new Scale(group, SWT.HORIZONTAL);
	transparencySlider.setMinimum(20);
	transparencySlider.setMaximum(100);
	transparencySlider.setPageIncrement(90);
	transparencySlider.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
	transparencySlider.setSelection(100);
	transparencySlider.addListener(SWT.Selection, new Listener() {

		@Override
		public void handleEvent(Event event) {
			shell.setAlpha(255 * transparencySlider.getSelection() / 100);
		}
	});
}
 
Example 3
Source File: XkcdColorPicker.java    From gradle-and-eclipse-rcp with Apache License 2.0 5 votes vote down vote up
public XkcdColorPicker(Composite parent, RGB initRGB) {
	super(new Composite(parent, SWT.NONE));
	RGB initYCbCr = ColorPicker.toYCbCr(initRGB);

	// create a scale and bind it to an RxBox<Integer>
	RxBox<Integer> luminance = RxBox.of(initYCbCr.red);

	// colorpanel in the center
	ColorPicker cbcrPanel = new ColorPicker(wrapped);
	Rx.subscribe(luminance, cbcrPanel::setY);

	// controls at the right
	Composite rightCmp = new Composite(wrapped, SWT.NONE);

	// scale below
	Scale scale = new Scale(wrapped, SWT.HORIZONTAL);
	scale.setMinimum(0);
	scale.setMaximum(255);
	Rx.subscribe(luminance, scale::setSelection);
	scale.addListener(SWT.Selection, e -> {
		luminance.set(scale.getSelection());
	});

	Layouts.setGrid(wrapped).numColumns(2);
	Layouts.setGridData(cbcrPanel).grabAll();
	Layouts.setGridData(rightCmp).grabVertical().verticalSpan(2);
	Layouts.setGridData(scale).grabHorizontal();

	// populate the bottom
	Layouts.setGrid(rightCmp).margin(0);
	XkcdColors.Lookup xkcdLookup = new XkcdColors.Lookup(rightCmp);

	Group hoverGrp = new Group(rightCmp, SWT.SHADOW_ETCHED_IN);
	hoverGrp.setText("Hover");
	createGroup(hoverGrp, cbcrPanel.rxMouseMove(), xkcdLookup);

	Group clickGrp = new Group(rightCmp, SWT.SHADOW_ETCHED_IN);
	clickGrp.setText("Click");
	createGroup(clickGrp, cbcrPanel.rxMouseDown(), xkcdLookup);
}