下面列出了怎么用org.eclipse.swt.widgets.Scale的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* @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;
}
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);
}
});
}
public IntValue(Composite parent, int initialValue) {
inputField = new Text(parent, SWT.BORDER | SWT.SINGLE);
outputField = new Label(parent, SWT.NONE);
scale = new Scale(parent, SWT.HORIZONTAL);
inputField.setText(Integer.toString(initialValue));
outputField.setText(msgForValue(initialValue));
scale.setMinimum(0);
scale.setMaximum(100);
scale.setSelection(initialValue);
Layouts.setGrid(parent);
Layouts.setGridData(inputField).grabHorizontal();
Layouts.setGridData(outputField).grabHorizontal();
Layouts.setGridData(scale).grabHorizontal();
}
@Test
public void testControl() {
InteractiveTest.testCoat("Should show the YCbCr plane at various values of Y", cmp -> {
Layouts.setGrid(cmp);
Scale scale = new Scale(cmp, SWT.HORIZONTAL);
scale.setMinimum(0);
scale.setMaximum(255);
scale.setSelection(128);
Layouts.setGridData(scale).grabHorizontal();
ColorPicker colors = new ColorPicker(cmp);
Layouts.setGridData(colors).grabAll();
scale.addListener(SWT.Selection, e -> {
colors.setY(scale.getSelection());
});
});
}
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new GridLayout());
PGroup group = new PGroup(shell, SWT.SMOOTH);
group.setText("Example");
// Optionally, change strategy and toggle
// group.setStrategy(new FormGroupStrategy());
// group.setToggleRenderer(new TwisteToggleRenderer());
group.setLayout(new GridLayout());
Label label = new Label(group,SWT.NONE);
label.setText("Contents");
Button button = new Button(group,SWT.PUSH);
button.setText("Contents");
Scale scale = new Scale(group,SWT.HORIZONTAL);
shell.setSize(200,200);
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
@Override
protected void createUI(Composite parent) {
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
this.setLayout(layout);
pageScale = new Scale(parent, SWT.READ_ONLY);
pageScale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pageScale.addSelectionListener(this);
}
private void createRankGroup(Composite parent) {
Composite prioGroup = new Composite(parent, SWT.NONE);
prioGroup.setLayout(new GridLayout(2, false));
Label minRankLabel = new Label(prioGroup, SWT.NONE);
minRankLabel.setText(getMessage("property.minRank") + System.getProperty("line.separator")
+ getMessage("property.minRank.line2"));
minRankLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
minRankSlider = new Scale(prioGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
minRankSlider.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
minRankSlider.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int rank = minRankSlider.getSelection();
getCurrentProps().getFilterSettings().setMinRank(rank);
updateRankValueLabel();
}
});
minRankSlider.setMinimum(BugRanker.VISIBLE_RANK_MIN);
minRankSlider.setMaximum(BugRanker.VISIBLE_RANK_MAX);
minRankSlider.setSelection(getCurrentProps().getFilterSettings().getMinRank());
minRankSlider.setIncrement(1);
minRankSlider.setPageIncrement(5);
Label dummyLabel = new Label(prioGroup, SWT.NONE);
dummyLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
rankValueLabel = new Label(prioGroup, SWT.NONE);
rankValueLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
updateRankValueLabel();
}
public void showShell() {
if( isShellDisposed() ){
this.shell = new Shell(this.getControl().getShell(), SWT.NO_TRIM );
this.shell.setVisible(false);
this.shell.setLayout(getGridLayout());
this.composite = new Composite(this.shell, SWT.BORDER);
this.composite.setLayout(getGridLayout());
this.composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.scale = new Scale(this.composite, SWT.VERTICAL );
this.scale.setMaximum(this.maximum);
this.scale.setMinimum(this.minimum);
this.scale.setIncrement(this.increment);
this.scale.setPageIncrement(this.increment * 3);
this.scale.setLayoutData(getScaleLayoutData());
this.setValueToScale();
this.scale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTScaleKnob.this.getValueFromScale();
SWTScaleKnob.this.selectionListener.widgetSelected(event);
}
});
this.shell.pack();
this.moveShell();
this.shell.setVisible(true);
}
}
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);
}
private void createScale(Composite composite) {
Scale scale = new Scale(composite, SWT.NONE);
scale.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
double[] values = new double[] { 0.25, 0.5, 0.75, 1.0, 1.5,
2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0 };
scale.setIncrement(9);
scale.setMinimum(0);
scale.setMaximum(99);
Controls.onSelect(scale, (e) -> {
ZoomManager zoom = part.getZoomManager();
zoom.setZoom(values[scale.getSelection() / 9]);
});
scale.setSelection(33);
}
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new GridLayout());
//Set the shell background to something different
shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
//Tell the shell to give its children the same background color or image
shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
//Optionally trying creating a patterned image for the shell background
// final Image backImage = new Image(display,10,10);
// GC gc = new GC(backImage);
// gc.drawLine(0,0,9,9);
// gc.dispose();
// shell.addDisposeListener(new DisposeListener() {
// public void widgetDisposed(DisposeEvent e) {
// backImage.dispose();
// }
// });
// shell.setBackgroundImage(backImage);
PGroup group = new PGroup(shell, SWT.SMOOTH);
group.setText("Example");
group.setLayout(new FillLayout());
group.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
Composite groupClient = new Composite(group,SWT.NONE);
groupClient.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
groupClient.setLayout(new GridLayout());
Label label = new Label(groupClient,SWT.NONE);
label.setText("Contents");
Button button = new Button(groupClient,SWT.PUSH);
button.setText("Contents");
Scale scale = new Scale(groupClient,SWT.HORIZONTAL);
shell.setSize(200,200);
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
public SpinnerWithScale(final Spinner spinner, final Scale scale, final int diff) {
this.spinner = spinner;
this.scale = scale;
this.diff = diff;
}
public SWTScale(SWTContainer<? extends Composite> parent, int orientation) {
super(new Scale(parent.getControl(), SWT.BORDER | orientation), parent);
this.selectionListener = new SWTSelectionListenerManager(this);
}
public SpinnerWithScale(Spinner spinner, Scale scale, int diff) {
this.spinner = spinner;
this.scale = scale;
this.diff = diff;
}
/**
* Create the composite.
* @param parent
* @param style
*/
public LegendPageBar(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(2, false));
lblLegend = new Label(this, SWT.NONE);
lblLegend.setText("Legend ");
btnEnableLegend = new Button(this, SWT.CHECK);
btnEnableLegend.setText("Enable Legend");
Label lblBackgroundColor = new Label(this, SWT.NONE);
GridData gd_lblBackgroundColor = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_lblBackgroundColor.widthHint = 150;
lblBackgroundColor.setLayoutData(gd_lblBackgroundColor);
lblBackgroundColor.setText("Background Color");
labelColorShow = new Label(this, SWT.BORDER);
GridData gd_labelColorShow = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_labelColorShow.widthHint = 100;
labelColorShow.setLayoutData(gd_labelColorShow);
labelColorShow.setText(" ");
labelColorShow.setBackground(PageSupport.getColor(parent, 0));
labelColorShow.addMouseListener(this);
Label lblOutline = new Label(this, SWT.NONE);
lblOutline.setText("Outline Style");
comboOutline = new Combo(this, SWT.READ_ONLY);
comboOutline.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
comboOutline.add("None");
comboOutline.add("Dashed");
comboOutline.add("Dash Dotted");
comboOutline.add("Dotted");
comboOutline.add("Solid");
comboOutline.select(0);
lblMaxPercent = new Label(this, SWT.NONE);
lblMaxPercent.setText("Max. Percent");
scale = new Scale(this, SWT.NONE);
scale.setIncrement(2);
GridData gd_scale = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_scale.widthHint = 309;
scale.setLayoutData(gd_scale);
scale.setPageIncrement(2);
scale.setMaximum(50);
scale.setSelection(10);
scale.addSelectionListener(this);
Label lblPosition = new Label(this, SWT.NONE);
lblPosition.setText("Position");
comboPosition = new Combo(this, SWT.READ_ONLY);
comboPosition.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
comboPosition.add("Right");
comboPosition.add("Left");
comboPosition.add("Below");
comboPosition.add("Top");
comboPosition.select(0);
loadSettings();
}
/**
* Create the composite.
* @param parent
* @param style
*/
public LegendPagePie(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(2, false));
lblLegend = new Label(this, SWT.NONE);
lblLegend.setText("Legend");
btnEnableLegend = new Button(this, SWT.CHECK);
btnEnableLegend.setText("Enable Legend");
Label lblBackgroundColor = new Label(this, SWT.NONE);
GridData gd_lblBackgroundColor = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_lblBackgroundColor.widthHint = 150;
lblBackgroundColor.setLayoutData(gd_lblBackgroundColor);
lblBackgroundColor.setText("Background Color");
labelColorShow = new Label(this, SWT.BORDER);
GridData gd_labelColorShow = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_labelColorShow.widthHint = 100;
labelColorShow.setLayoutData(gd_labelColorShow);
labelColorShow.setText(" ");
labelColorShow.setBackground(PageSupport.getColor(parent, 0));
labelColorShow.addMouseListener(this);
Label lblOutline = new Label(this, SWT.NONE);
lblOutline.setText("Outline Style");
comboOutline = new Combo(this, SWT.READ_ONLY);
comboOutline.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
comboOutline.add("None");
comboOutline.add("Dashed");
comboOutline.add("Dash Dotted");
comboOutline.add("Dotted");
comboOutline.add("Solid");
comboOutline.select(0);
lblMaxPercent = new Label(this, SWT.NONE);
lblMaxPercent.setText("Max. Percent");
scale = new Scale(this, SWT.NONE);
scale.setIncrement(2);
GridData gd_scale = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_scale.widthHint = 309;
scale.setLayoutData(gd_scale);
scale.setPageIncrement(2);
scale.setMaximum(50);
scale.setSelection(10);
scale.addSelectionListener(this);
Label lblPosition = new Label(this, SWT.NONE);
lblPosition.setText("Position");
comboPosition = new Combo(this, SWT.READ_ONLY);
comboPosition.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
comboPosition.add("Right");
comboPosition.add("Left");
comboPosition.add("Below");
comboPosition.add("Top");
comboPosition.select(0);
loadSettings();
}
/**
* Create the controls that compose the console test.
*
*/
protected void createControls(IHierarchicalJaretTableModel hierarchicalModel) {
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_shell.setLayout(gl);
GridData gd = new GridData(GridData.FILL_BOTH);
_jt = new JaretTable(_shell, SWT.V_SCROLL | SWT.H_SCROLL);
_jt.setLayoutData(gd);
IHierarchicalJaretTableModel hmodel = hierarchicalModel;
if (hierarchicalModel == null) {
ITableNode root = new DummyTableNode("tn1", "tn1", "Root", "This the root node");
ITableNode r1 = new DummyTableNode("tn11", "tn12", "1", "Child 1 of the root");
ITableNode r2 = new DummyTableNode("tn12", "tn12", "2", "Child 2 of the root");
ITableNode r3 = new DummyTableNode("tn13", "tn13", "3", "Child 3 of the root");
root.addNode(r1);
root.addNode(r2);
root.addNode(r3);
r1.addNode(new DummyTableNode("tn111", "tn111", "1", "A second level child"));
r1.addNode(new DummyTableNode("tn112", "tn112", "2", "Another second level child"));
ITableNode n1 = new DummyTableNode("tn131", "tn131", "1", "A second level child");
r3.addNode(n1);
ITableNode n2 = new DummyTableNode("tn132", "tn132", "2", "Another second level child");
r3.addNode(n2);
n1.addNode(new DummyTableNode("tn1311", "tn1311", "1", "A third level child"));
n1.addNode(new DummyTableNode("tn1312", "tn1312", "2", "Another third level child"));
DefaultHierarchicalTableModel dhmodel = new DefaultHierarchicalTableModel(root);
hmodel = dhmodel;
if (SUPPORT_DND) {
// init the simple drag and drop handling
initDND(_jt, _shell);
}
}
_jt.setTableModel(hmodel);
StdHierarchicalTableModel model = (StdHierarchicalTableModel) _jt.getTableModel();
IColumn hcol = new HierarchyColumn();
// create and setup hierarchy renderer
final TableHierarchyRenderer hierarchyRenderer = new TableHierarchyRenderer();
hierarchyRenderer.setLabelProvider(new LabelProvider());
hierarchyRenderer.setDrawIcons(true);
hierarchyRenderer.setDrawLabels(true);
_jt.registerCellRenderer(hcol, hierarchyRenderer);
model.addColumn(hcol);
model.addColumn(new PropCol("b1", "column 1", "B1"));
model.addColumn(new PropCol("t1", "column 2", "T1"));
model.addColumn(new PropCol("t2", "column 3", "T2"));
model.addColumn(new PropCol("t3", "column 4", "T3"));
JaretTableActionFactory af = new JaretTableActionFactory();
MenuManager mm = new MenuManager();
mm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_CONFIGURECOLUMNS));
_jt.setHeaderContextMenu(mm.createContextMenu(_jt));
MenuManager rm = new MenuManager();
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTROWHEIGHT));
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTALLROWHEIGHTS));
_jt.setRowContextMenu(rm.createContextMenu(_jt));
TableControlPanel ctrlPanel = new TableControlPanel(_shell, SWT.NULL, _jt);
Label l = new Label(_shell, SWT.NONE);
l.setText("Level width:");
final Scale levelWidthScale = new Scale(_shell, SWT.HORIZONTAL);
levelWidthScale.setMaximum(40);
levelWidthScale.setMinimum(0);
levelWidthScale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent ev) {
int val = levelWidthScale.getSelection();
hierarchyRenderer.setLevelWidth(val);
_jt.redraw();
}
});
}
/**
* Create the controls that compose the console test.
*
*/
protected void createControls(IHierarchicalJaretTableModel hierarchicalModel) {
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_shell.setLayout(gl);
GridData gd = new GridData(GridData.FILL_BOTH);
_jt = new JaretTable(_shell, SWT.V_SCROLL | SWT.H_SCROLL);
_jt.setLayoutData(gd);
IHierarchicalJaretTableModel hmodel = hierarchicalModel;
if (hierarchicalModel == null) {
ITableNode root = new DummyTableNode("tn1", "tn1", "Root", "This the root node");
ITableNode r1 = new DummyTableNode("tn11", "tn12", "1", "Child 1 of the root");
ITableNode r2 = new DummyTableNode("tn12", "tn12", "2", "Child 2 of the root");
ITableNode r3 = new DummyTableNode("tn13", "tn13", "3", "Child 3 of the root");
root.addNode(r1);
root.addNode(r2);
root.addNode(r3);
r1.addNode(new DummyTableNode("tn111", "tn111", "1", "A second level child"));
r1.addNode(new DummyTableNode("tn112", "tn112", "2", "Another second level child"));
ITableNode n1 = new DummyTableNode("tn131", "tn131", "1", "A second level child");
r3.addNode(n1);
ITableNode n2 = new DummyTableNode("tn132", "tn132", "2", "Another second level child");
r3.addNode(n2);
n1.addNode(new DummyTableNode("tn1311", "tn1311", "1", "A third level child"));
n1.addNode(new DummyTableNode("tn1312", "tn1312", "2", "Another third level child"));
DefaultHierarchicalTableModel dhmodel = new DefaultHierarchicalTableModel(root);
hmodel = dhmodel;
if (SUPPORT_DND) {
// init the simple drag and drop handling
initDND(_jt, _shell);
}
}
_jt.setTableModel(hmodel);
StdHierarchicalTableModel model = (StdHierarchicalTableModel) _jt.getTableModel();
IColumn hcol = new HierarchyColumn();
// create and setup hierarchy renderer
final TableHierarchyRenderer hierarchyRenderer = new TableHierarchyRenderer();
hierarchyRenderer.setLabelProvider(new LabelProvider());
hierarchyRenderer.setDrawIcons(true);
hierarchyRenderer.setDrawLabels(true);
_jt.registerCellRenderer(hcol, hierarchyRenderer);
model.addColumn(hcol);
model.addColumn(new PropCol("b1", "column 1", "B1"));
model.addColumn(new PropCol("t1", "column 2", "T1"));
model.addColumn(new PropCol("t2", "column 3", "T2"));
model.addColumn(new PropCol("t3", "column 4", "T3"));
JaretTableActionFactory af = new JaretTableActionFactory();
MenuManager mm = new MenuManager();
mm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_CONFIGURECOLUMNS));
_jt.setHeaderContextMenu(mm.createContextMenu(_jt));
MenuManager rm = new MenuManager();
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTROWHEIGHT));
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTALLROWHEIGHTS));
_jt.setRowContextMenu(rm.createContextMenu(_jt));
TableControlPanel ctrlPanel = new TableControlPanel(_shell, SWT.NULL, _jt);
Label l = new Label(_shell, SWT.NONE);
l.setText("Level width:");
final Scale levelWidthScale = new Scale(_shell, SWT.HORIZONTAL);
levelWidthScale.setMaximum(40);
levelWidthScale.setMinimum(0);
levelWidthScale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent ev) {
int val = levelWidthScale.getSelection();
hierarchyRenderer.setLevelWidth(val);
_jt.redraw();
}
});
}
@Override
protected Control createContents(final Composite parent) {
FormToolkit toolkit = new FormToolkit(Display.getCurrent());
ScrolledForm scrolledForm = toolkit.createScrolledForm(parent);
Composite body = scrolledForm.getBody();
body.setLayout(new FillLayout());
toolkit.paintBordersFor(body);
SashForm sashForm = new SashForm(body, SWT.VERTICAL);
toolkit.adapt(sashForm, true, true);
Section categorySection = toolkit
.createSection(sashForm, ExpandableComposite.NO_TITLE
| ExpandableComposite.EXPANDED);
categorySection.setText("");
Composite composite = toolkit.createComposite(categorySection,
SWT.NONE);
composite.setLayout(new GridLayout());
categorySection.setClient(composite);
toolkit.paintBordersFor(composite);
final Scale scale = new Scale(composite, SWT.NONE);
scale.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
final double[] values = GraphConfig.ZOOM_LEVELS;
final int increment = 100 / (values.length - 1);
scale.setIncrement(increment);
scale.setMinimum(0);
scale.setMaximum(100);
Controls.onSelect(scale, (e) -> {
zoomManager.setZoom(values[scale.getSelection() / increment]);
});
scale.setSelection(increment * (values.length - 1) / 2);
Canvas canvas = new Canvas(composite, SWT.BORDER);
canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
lws = new LightweightSystem(canvas);
thumbnail = new ScrollableThumbnail(port);
thumbnail.setSource(figure);
lws.setContents(thumbnail);
disposeListener = new DisposeListener() {
@Override
public void widgetDisposed(final DisposeEvent e) {
if (thumbnail != null) {
thumbnail.deactivate();
thumbnail = null;
}
if (control != null && !control.isDisposed())
control.removeDisposeListener(disposeListener);
close();
}
};
control.addDisposeListener(disposeListener);
return super.createContents(parent);
}
public static void onSelect(Scale scale, Consumer<SelectionEvent> consumer) {
scale.addSelectionListener(selectionListener(consumer));
}
public SpinnerWithScale(Spinner spinner, Scale scale, int diff) {
this.spinner = spinner;
this.scale = scale;
this.diff = diff;
}