下面列出了怎么用org.eclipse.swt.widgets.Spinner的API类实例代码及写法,或者点击链接到github查看源代码。
private void createAnimationGroup(Composite parent) {
Group animationGroup = createEmptyGroup(parent, "Animation");
animationGroup.setLayout(new RowLayout());
bAnimation = createButton(animationGroup, SWT.CHECK, "Animations", false, false);
bAnimation.addListener(SWT.Selection, groupParamSelectionListener);
cAnimationMovement = new Combo(animationGroup, SWT.READ_ONLY);
cAnimationMovement.setItems(new String[] { "ExpoOut", "BounceOut", "ElasticOut", "LinearInOut" });
cAnimationMovement.setText("ExpoOut");
cAnimationMovement.addListener(SWT.Selection, groupParamSelectionListener);
sAnimationDuration = new Spinner(animationGroup, SWT.NONE);
sAnimationDuration.setMinimum(250);
sAnimationDuration.setMaximum(5000);
sAnimationDuration.setIncrement(100);
sAnimationDuration.setSelection(500);
sAnimationDuration.addListener(SWT.Selection, groupParamSelectionListener);
}
private void createDecoratorsGroup(Composite parent) {
Group dataGroup = createEmptyGroup(parent, "Decorators");
dataGroup.setLayout(new RowLayout());
sDecoratorNumber = new Spinner(dataGroup, SWT.NONE);
sDecoratorNumber.setMinimum(1);
sDecoratorNumber.setMaximum(5);
sDecoratorNumber.setIncrement(1);
sDecoratorNumber.setSelection(1);
sDecoratorNumber.addListener(SWT.Selection, contentParamSelectionListener);
bDecoratorLeft = createButton(dataGroup, SWT.CHECK, "Top Left", false, false);
bDecoratorLeft.addListener(SWT.Selection, contentParamSelectionListener);
bDecoratorUp = createButton(dataGroup, SWT.CHECK, "Top Right", false, false);
bDecoratorUp.addListener(SWT.Selection, contentParamSelectionListener);
bDecoratorRight = createButton(dataGroup, SWT.CHECK, "Bottom Right", false, false);
bDecoratorRight.addListener(SWT.Selection, contentParamSelectionListener);
bDecoratorDown = createButton(dataGroup, SWT.CHECK, "Bottom Left", false, false);
bDecoratorDown.addListener(SWT.Selection, contentParamSelectionListener);
}
private void createItemParametersGroup(Composite parent) {
Group dataGroup = createEmptyGroup(parent, "Item parameters");
dataGroup.setLayout(new RowLayout());
cItemRenderer = new Combo(dataGroup, SWT.READ_ONLY);
cItemRenderer.setItems(new String[] { "Icon", "List" });
cItemRenderer.setText("Icon");
cItemRenderer.addListener(SWT.Selection, itemRendererParamSelectionListener);
bItemDropShadow = createButton(dataGroup, SWT.CHECK, "Drop shadow", false, true);
sItemDropShadowSize = new Spinner(dataGroup, SWT.NONE);
sItemDropShadowSize.setMinimum(0);
sItemDropShadowSize.setMaximum(20);
sItemDropShadowSize.setIncrement(1);
sItemDropShadowSize.setSelection(5);
sItemDropShadowSize.addListener(SWT.Selection, itemRendererParamSelectionListener);
bItemLabel = createButton(dataGroup, SWT.CHECK, "Display labels", false, true);
}
/**
* @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 Spinner spinner = new Spinner(parent, SWT.HORIZONTAL | SWT.BORDER);
addControl(spinner);
spinner.setMinimum(min);
spinner.setMaximum(max);
final Integer originalValue = (Integer) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
spinner.setSelection(originalValue.intValue());
spinner.addListener(SWT.Modify, event -> {
PreferenceWindow.getInstance().setValue(getPropertyKey(), Integer.valueOf(spinner.getSelection()));
});
return spinner;
}
public void testSpinnerFieldNext() throws Exception {
VNative<Spinner> spinner = tester.getSpinner();
assertNotNull(spinner);
int original = tester.getCDateTime().activeField;
System.out.println(original);
moveToEdge(tester.getCDateTime(), SWT.RIGHT);
moveX(-10);
click(2);
int active = tester.getCDateTime().activeField;
System.out.println(active);
assertTrue(active > original);
}
@Override
public void createControl(Composite parent) {
resComposite = new Composite(parent, SWT.NONE);
resComposite.setLayout(new GridLayout(2, false));
resComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
new Label(resComposite, SWT.NONE).setText(Messages.AttachTab_address);
this.addressText = new Text(resComposite, SWT.BORDER);
this.addressText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
this.addressText.addModifyListener(event -> {
setDirty(true);
updateLaunchConfigurationDialog();
});
new Label(resComposite, SWT.NONE).setText(Messages.AttachTab_port);
this.portSpinner = new Spinner(resComposite, SWT.BORDER);
this.portSpinner.setMinimum(0);
this.portSpinner.setMaximum(65535);
this.portSpinner.addModifyListener(e -> {
setDirty(true);
updateLaunchConfigurationDialog();
});
setControl(resComposite);
}
@Override public void createControl(Composite parent) {
Composite res = new Composite(parent, SWT.NONE);
res.setLayout(new GridLayout(3, false));
Label pidLabel = new Label(res, SWT.NONE);
pidLabel.setText(Messages.AttachMainTab_processId);
// As pid is volatile, additionally to PID, we should store the
// CLI param of selected PID to easily discover other PID started
// with same params.
pidText = new Spinner(res, SWT.BORDER);
pidText.setMinimum(0);
pidText.setMaximum(Integer.MAX_VALUE);
pidText.setLayoutData(new GridData(120, SWT.DEFAULT));
pidText.addModifyListener(e -> {
setDirty(true);
updateLaunchConfigurationDialog();
});
// with Java 9, add a Search button showing a "ProcessSelectionDialog"
// filtering process using dotnet as command.
setControl(res);
}
/**
* Retrieves the control from the viewer
*/
public static Control getWidget(Object control) {
if (control instanceof Viewer) {
return ((Viewer) control).getControl();
} else if (control instanceof Text) {
return (Text) control;
} else if (control instanceof Button) {
return (Control) control;
} else if (control instanceof Spinner) {
return (Control) control;
} else if (control instanceof Combo) {
return (Control) control;
} else if (control instanceof Control) {
// why not return the control when object is instanceof control?
return null;
}
return null;
}
/**
* Construct the {@code RangeTool} UI with the given set of options.
*
* @param parent containing window for range tool
* @param style basic presentation options
*/
public RangeTool(Composite parent, int style,
String label, RelationCount.RangeData setup) {
super(parent, style);
setLayout(new RowLayout());
Label rangeLabel = new Label(this, SWT.LEFT);
rangeLabel.setText(label);
rangeOp = createRangeOp(setup.option);
loLabel = new Label(this, SWT.LEFT);
loLimit = new Spinner(this, style);
hiLabel = new Label(this, SWT.LEFT);
hiLimit = new Spinner(this, style);
setLimits(setup);
}
private void handleDirectionChange(Spinner input) {
// Ignore bad input
float value;
try {
String text = input.getText();
value = Float.parseFloat(text);
} catch (NumberFormatException e) {
return;
}
if (xdirInput.isControl(input)) {
fireXChanged(value);
} else if (ydirInput.isControl(input)) {
fireYChanged(value);
} else if (zdirInput.isControl(input)) {
fireZChanged(value);
}
}
private void handlePositionChange(Spinner input) {
// Ignore bad input
float value;
try {
String text = input.getText();
value = Float.parseFloat(text);
} catch (NumberFormatException e) {
return;
}
if (xposInput.isControl(input)) {
fireXChanged(value);
} else if (yposInput.isControl(input)) {
fireYChanged(value);
} else if (zposInput.isControl(input)) {
fireZChanged(value);
}
}
/**
* @param parent
* @param min
* @param max
* @param hspan
* @param style
* @return
*/
public static Spinner createSpinner(Composite parent, int min, int max, int hspan, int style)
{
Spinner spinner = new Spinner(parent, SWT.BORDER | style);
spinner.setMinimum(min);
spinner.setMaximum(max);
GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false, hspan, 1);
PixelConverter pc = new PixelConverter(spinner);
// See http://jira.appcelerator.org/browse/APSTUD-3215
// We need to add some extra spacing to the MacOSX spinner in order to adjust the size to the way Mac draws
// spinners.
int extraWidth = Platform.OS_MACOSX.equals(Platform.getOS()) ? 25 : 0;
gd.widthHint = pc.convertWidthInCharsToPixels(2) + extraWidth;
spinner.setLayoutData(gd);
return spinner;
}
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$
}
}
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);
}
/**
* @param parent
* @param text1
* the text to display in front of the spinner
* @param text2
* the text to display between spinner and DatePicker
* @param text1Neg
* the text to display in front of the spinner if date is before today
* @param text2Neg
* the text to display between spinner and DatePicker if date is before today
* @since 3.1
*/
public DayDateCombo(Composite parent, String text1, String text2, String text1Neg,
String text2Neg){
super(parent, SWT.NONE);
this.text1 = text1;
this.text2 = text2;
this.text1Neg = text1Neg;
this.text2Neg = text2Neg;
ttNow = new TimeTool();
ttNow.chop(3);
setLayout(new RowLayout(SWT.HORIZONTAL));
frontLabel = UiDesk.getToolkit().createLabel(this, text1);
spl = new SpinnerListener();
dl = new DateListener();
spinner = new Spinner(this, SWT.NONE);
middleLabel = UiDesk.getToolkit().createLabel(this, text2);
dp = new DatePickerCombo(this, SWT.NONE);
setListeners();
}
private void createCutoffSpinner(FormToolkit tk, Composite comp) {
tk.createLabel(comp, M.DontShowSmallerThen);
Composite inner = tk.createComposite(comp);
UI.gridLayout(inner, 2, 10, 0);
Spinner spinner = new Spinner(inner, SWT.BORDER);
spinner.setIncrement(100);
spinner.setMinimum(0);
spinner.setMaximum(100000);
spinner.setDigits(3);
spinner.setSelection((int) (cutoff * 100000));
spinner.addModifyListener(e -> {
cutoff = spinner.getSelection() / 100000d;
});
tk.adapt(spinner);
tk.createLabel(inner, "%");
}
private Spinner createPageCountSpinner(Composite parent,
Listener selectionListener) {
Spinner spinner = new Spinner(parent, SWT.BORDER);
spinner.setMinimum(1);
spinner.setMaximum(99);
spinner.addListener(SWT.Selection, selectionListener);
return spinner;
}
private Spinner createPageCountSpinner(Composite parent,
Listener selectionListener) {
Spinner spinner = new Spinner(parent, SWT.BORDER);
spinner.setMinimum(1);
spinner.setMaximum(99);
spinner.addListener(SWT.Selection, selectionListener);
return spinner;
}
public void testSpinnerSelection() throws Exception {
VNative<Spinner> spinner = tester.getSpinner();
assertNotNull(spinner);
long original = tester.getSelection().getTime();
moveToEdge(tester.getCDateTime(), SWT.RIGHT | SWT.TOP);
// sleep(5000);
// System.out.println(tester.getSelection().getTime());
moveX(-15);
moveY(5);
// sleep(5000);
click();
// System.out.println(tester.getSelection().getTime());
long time = tester.getSelection().getTime();
assertTrue("Difference = " + (original - time), time == original + (60 * 60 * 1000));
keyPress(SWT.ARROW_RIGHT);
moveToEdge(tester.getCDateTime(), SWT.RIGHT | SWT.BOTTOM);
moveX(-15);
moveY(-8);
click();
original = time;
time = tester.getSelection().getTime();
assertTrue("Difference = " + (original - time), time == original - (60 * 1000));
}
private void createTimedGroup ( final Composite parent )
{
parent.setLayout ( new GridLayout ( 4, false ) );
new Label ( parent, SWT.NONE ).setText ( Messages.getString ( "BooleanGeneratorPage.timedGroup.beforeDelay" ) ); //$NON-NLS-1$
new Label ( parent, SWT.NONE ).setText ( Messages.getString ( "BooleanGeneratorPage.timedGroup.0to1" ) ); //$NON-NLS-1$
new Label ( parent, SWT.NONE ).setText ( Messages.getString ( "BooleanGeneratorPage.timedGroup.afterDelay" ) ); //$NON-NLS-1$
new Label ( parent, SWT.NONE ).setText ( Messages.getString ( "BooleanGeneratorPage.timedGroup.1to0" ) ); //$NON-NLS-1$
this.startDelaySpinner = new Spinner ( parent, SWT.BORDER );
this.startDelaySpinner.setValues ( 1000, 0, Integer.MAX_VALUE, 0, 100, 1000 );
new Label ( parent, SWT.NONE ).setText ( Messages.getString ( "BooleanGeneratorPage.timedGroup.transition" ) ); //$NON-NLS-1$
this.endDelaySpinner = new Spinner ( parent, SWT.BORDER );
this.endDelaySpinner.setValues ( 1000, 0, Integer.MAX_VALUE, 0, 100, 1000 );
}
private void setMarginSpinner(final Spinner spinner) {
spinner.setDigits(1);
spinner.setIncrement(5);
spinner.setMinimum(0);
spinner.setMaximum(1000);
spinner.setSelection(20);
}
/**
* Create the composite.
* @param parent
* @param style
*/
public ProxyConfigComposite(Composite parent, int style) {
super(parent, style);
this.setLayout(new GridLayout(4, false));
this.useProxyButton = new Button(this, SWT.CHECK);
this.useProxyButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
this.useProxyButton.setText("接続にプロキシを使用する*");
this.useProxyButton.setSelection(AppConfig.get().isUseProxy());
Label proxyHostLabel = new Label(this, SWT.NONE);
proxyHostLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
proxyHostLabel.setText("ホスト:");
this.proxyHostText = new Text(this, SWT.BORDER);
GridData gdProxyHostText = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gdProxyHostText.widthHint = 100;
this.proxyHostText.setLayoutData(gdProxyHostText);
this.proxyHostText.setText(AppConfig.get().getProxyHost());
Label proxyPortLabel = new Label(this, SWT.NONE);
proxyPortLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
proxyPortLabel.setText("ポート:");
this.proxyPortSpinner = new Spinner(this, SWT.BORDER);
this.proxyPortSpinner.setMaximum(65535);
this.proxyPortSpinner.setMinimum(1);
this.proxyPortSpinner.setSelection(AppConfig.get().getProxyPort());
GridData gdProxyPortSpinner = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gdProxyPortSpinner.widthHint = 55;
this.proxyPortSpinner.setLayoutData(gdProxyPortSpinner);
}
private Spinner setupDirection(Composite parent) {
Spinner result = new Spinner(parent, SWT.NONE);
result.setMinimum(-180);
result.setMaximum(180);
result.setIncrement(1);
result.setPageIncrement(10);
return result;
}
public ControlBindingManager(IPreferenceDelegate delegate, IStatusChangeListener listener)
{
this.checkBoxControls = new HashMap<Button, Object>();
this.comboControls = new HashMap<Combo, Object>();
this.textControls = new HashMap<Text, Object>();
this.radioControls = new HashMap<Button, String>();
this.spinnerControls = new HashMap<Spinner, Object>();
this.listControls = new HashMap<CListViewer, Object>();
this.validatorManager = new ValidatorManager();
this.dependencyManager = new DependencyManager();
this.changeListener = listener;
this.preferenceDelegate = delegate;
}
private void initSpinners()
{
Iterator<Spinner> it = spinnerControls.keySet().iterator();
while (it.hasNext())
{
final Spinner spinner = it.next();
final Object key = spinnerControls.get(spinner);
String value = preferenceDelegate.getString(key);
if (!StringUtil.isEmpty(value))
{
spinner.setSelection(Integer.parseInt(value));
}
}
}
private void setMarginSpinner(Spinner spinner) {
spinner.setDigits(1);
spinner.setIncrement(5);
spinner.setMinimum(0);
spinner.setMaximum(1000);
spinner.setSelection(20);
}
protected void placeComponents( int styles, boolean enabled, String label, String endLabel )
{
int colNum = 1;
if ( label != null )
colNum++;
if ( endLabel != null )
colNum++;
GridLayout gl = new GridLayout( );
gl.numColumns = colNum;
gl.makeColumnsEqualWidth = false;
gl.marginBottom = 0;
gl.marginHeight = 0;
gl.marginLeft = 0;
gl.marginRight = 0;
gl.marginTop = 0;
gl.marginWidth = 0;
this.setLayout( gl );
if ( label != null )
{
lblLabel = new Label( this, SWT.NONE );
lblLabel.setText( label );
}
spinner = new Spinner( this, styles );
GridData gd = new GridData( GridData.FILL_BOTH );
spinner.setLayoutData( gd );
setEnabled( enabled );
if ( endLabel != null )
{
lblEndLabel = new Label( this, SWT.NONE );
lblEndLabel.setText( endLabel );
}
}
/**
* Add specified description to composite to support Screen Reader tool.
*
* @param composite composite
* @param description description
*/
public static void addScreenReaderAccessbility( Control composite,
final String description )
{
if ( composite == null )
{
// if control component is null, do nothing.
return;
}
if ( description != null )
{
if ( composite instanceof Spinner )
{
addSpinnerScreenReaderAccessbility( (Spinner) composite, description );
}
else
{
composite.getAccessible( )
.addAccessibleListener( new AccessibleAdapter( ) {
public void getName( AccessibleEvent e )
{
e.result = description.replaceAll( "&", IConstants.EMPTY_STRING ) //$NON-NLS-1$
.replaceAll( ":", IConstants.EMPTY_STRING ) //$NON-NLS-1$
.replaceAll( "\\*", IConstants.EMPTY_STRING ); //$NON-NLS-1$
}
} );
}
}
}
public static Spinner createFieldSpinner(FieldWidget<Integer> field, Composite parent, int style) {
final Spinner spinner = new Spinner(parent, style);
spinner.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
field.setFieldValueFromControl(spinner.getSelection());
}
});
return spinner;
}
public static Long getWidgetMillisecondAsLong(Spinner yearSpinner,Spinner monthSpinner,Spinner daySpinner, Spinner hourSpinner,Spinner minutesSpinner,Spinner secondsSpinner) {
long duration = 0;
if(yearSpinner != null && !yearSpinner.isDisposed()){
duration = (long)((long)yearSpinner.getSelection()*(long)3600000*(long)24*(long)30*(long)12) ;
}
if(monthSpinner != null && !monthSpinner.isDisposed()){
duration += (long)((long)monthSpinner.getSelection()*(long)3600000* (long)24* (long) 30) ;
}
if(daySpinner != null && !daySpinner.isDisposed()){
duration += (long)((long)daySpinner.getSelection()*(long)(3600000*(long)24)) ;
}
if(hourSpinner != null && !hourSpinner.isDisposed()){
duration += (long)((long)hourSpinner.getSelection()*(long)(3600000)) ;
}
if(minutesSpinner != null && !minutesSpinner.isDisposed()){
duration += (long)((long)minutesSpinner.getSelection()*(long)(60000)) ;
}
if(secondsSpinner != null && !secondsSpinner.isDisposed()){
duration += (long)((long)secondsSpinner.getSelection()*(long)(1000)) ;
}
return duration;
}