Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 256740
Collapse All | Expand All

(-)src/org/eclipse/RWTHostTestSuite.java (+1 lines)
Lines 149-154 Link Here
149
    suite.addTestSuite( MessageBox_Test.class );
149
    suite.addTestSuite( MessageBox_Test.class );
150
    suite.addTestSuite( ExpandBar_Test.class );
150
    suite.addTestSuite( ExpandBar_Test.class );
151
    suite.addTestSuite( ExpandItem_Test.class );
151
    suite.addTestSuite( ExpandItem_Test.class );
152
    suite.addTestSuite( Slider_Test.class );
152
153
153
    suite.addTestSuite( Image_Test.class );
154
    suite.addTestSuite( Image_Test.class );
154
    suite.addTestSuite( ImageData_Test.class );
155
    suite.addTestSuite( ImageData_Test.class );
(-)src/org/eclipse/swt/widgets/Slider_Test.java (+144 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.swt.widgets;
13
14
import junit.framework.TestCase;
15
16
import org.eclipse.rwt.lifecycle.PhaseId;
17
import org.eclipse.swt.RWTFixture;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.graphics.Point;
20
21
public class Slider_Test extends TestCase {
22
23
  protected void setUp() throws Exception {
24
    RWTFixture.setUp();
25
  }
26
27
  protected void tearDown() throws Exception {
28
    RWTFixture.tearDown();
29
  }
30
31
  public void testInitialValues() {
32
    Display display = new Display();
33
    Shell shell = new Shell( display, SWT.NONE );
34
    Slider slider = new Slider( shell, SWT.NONE );
35
    assertEquals( 0, slider.getMinimum() );
36
    assertEquals( 100, slider.getMaximum() );
37
    assertEquals( 0, slider.getSelection() );
38
    assertEquals( 1, slider.getIncrement() );
39
    assertEquals( 10, slider.getPageIncrement() );
40
    assertEquals( 10, slider.getThumb() );
41
  }
42
43
  public void testValues() {
44
    Display display = new Display();
45
    Shell shell = new Shell( display, SWT.NONE );
46
    Slider slider = new Slider( shell, SWT.NONE );
47
48
    slider.setSelection( 34 );
49
    assertEquals( 34, slider.getSelection() );
50
    slider.setMinimum( 10 );
51
    assertEquals( 10, slider.getMinimum() );
52
    slider.setMaximum( 56 );
53
    assertEquals( 56, slider.getMaximum() );
54
    slider.setIncrement( 5 );
55
    assertEquals( 5, slider.getIncrement() );
56
    slider.setPageIncrement( 15 );
57
    assertEquals( 15, slider.getPageIncrement() );
58
    slider.setThumb( 13 );
59
    assertEquals( 13, slider.getThumb() );
60
61
    slider.setMinimum( 40 );
62
    assertEquals( 40, slider.getMinimum() );
63
    assertEquals( 40, slider.getSelection() );
64
65
    slider.setSelection( 55 );
66
    slider.setMaximum( 65 );
67
    assertEquals( 65, slider.getMaximum() );
68
    assertEquals( 43, slider.getSelection() );
69
70
    slider.setMaximum( 30 );
71
    assertEquals( 65, slider.getMaximum() );
72
73
    slider.setSelection( 10 );
74
    assertEquals( 40, slider.getSelection() );
75
76
    slider.setSelection( -10 );
77
    assertEquals( 40, slider.getSelection() );
78
    
79
    slider.setSelection( 73 );
80
    assertEquals( 52, slider.getSelection() );
81
82
    slider.setPageIncrement( -15 );
83
    assertEquals( 15, slider.getPageIncrement() );
84
85
    slider.setIncrement( -5 );
86
    assertEquals( 5, slider.getIncrement() );
87
    
88
    slider.setThumb( -5 );
89
    assertEquals( 13, slider.getThumb() );
90
    
91
    slider.setThumb( 0 );
92
    assertEquals( 13, slider.getThumb() );
93
    
94
    slider.setThumb( 3 );
95
    assertEquals( 3, slider.getThumb() );
96
    
97
    slider.setThumb( 30 );
98
    assertEquals( 25, slider.getThumb() );
99
    assertEquals( 40, slider.getSelection() );
100
  }
101
102
  public void testStyle() {
103
    Display display = new Display();
104
    Shell shell = new Shell( display, SWT.NONE );
105
    // Test SWT.NONE
106
    Slider slider = new Slider( shell, SWT.NONE );
107
    assertTrue( ( slider.getStyle() & SWT.HORIZONTAL ) != 0 );
108
    // Test SWT.BORDER
109
    slider = new Slider( shell, SWT.BORDER );
110
    assertTrue( ( slider.getStyle() & SWT.HORIZONTAL ) != 0 );
111
    assertTrue( ( slider.getStyle() & SWT.BORDER ) != 0 );
112
    // Test SWT.VERTICAL
113
    slider = new Slider( shell, SWT.VERTICAL );
114
    assertTrue( ( slider.getStyle() & SWT.VERTICAL ) != 0 );
115
    // Test combination of SWT.HORIZONTAL | SWT.VERTICAL
116
    slider = new Slider( shell, SWT.HORIZONTAL | SWT.VERTICAL );
117
    assertTrue( ( slider.getStyle() & SWT.HORIZONTAL ) != 0 );
118
    assertTrue( ( slider.getStyle() & SWT.VERTICAL ) == 0 );
119
  }
120
121
  public void testDispose() {
122
    Display display = new Display();
123
    Shell shell = new Shell( display );
124
    Slider slider = new Slider( shell, SWT.NONE );
125
    slider.dispose();
126
    assertTrue( slider.isDisposed() );
127
  }
128
129
  public void testComputeSize() throws Exception {
130
    RWTFixture.fakePhase( PhaseId.PROCESS_ACTION );
131
    Display display = new Display();
132
    Shell shell = new Shell( display );
133
    Slider slider = new Slider( shell, SWT.HORIZONTAL );
134
    Point expected = new Point( 170, 16 );
135
    assertEquals( expected, slider.computeSize( SWT.DEFAULT, SWT.DEFAULT ) );
136
137
    slider = new Slider( shell, SWT.VERTICAL );
138
    expected = new Point( 16, 170 );
139
    assertEquals( expected, slider.computeSize( SWT.DEFAULT, SWT.DEFAULT ) );
140
141
    expected = new Point( 100, 100 );
142
    assertEquals( expected, slider.computeSize( 100, 100 ) );
143
  }
144
}
(-)theme1/theme.css (+41 lines)
Lines 336-338 Link Here
336
Button[PUSH].special-red, Button[TOGGLE].special-red {
336
Button[PUSH].special-red, Button[TOGGLE].special-red {
337
  border: 2px solid red;
337
  border: 2px solid red;
338
}
338
}
339
340
/* Slider */
341
342
Slider {
343
  background-color: #aaaaff;
344
}
345
346
Slider-Thumb {
347
  background-color: #ffaaaa;
348
  border: 2px blue;
349
}
350
351
Slider-Thumb:pressed {
352
  background-color: #ff0000;
353
}
354
355
Slider-MinButton {
356
  background-color: #ffaaaa;
357
  background-image: url( "/theme1/icons/slider-vbut-min-icon.gif" );
358
}
359
360
Slider-MinButton:hover {
361
  background-color: #ffffff;
362
}
363
364
Slider-MinButton:horizontal {
365
  background-image: url( "/theme1/icons/slider-hbut-min-icon.gif" );
366
}
367
368
Slider-MaxButton {
369
  background-color: #ffaaaa;
370
  background-image: url( "/theme1/icons/slider-vbut-max-icon.gif" );
371
}
372
373
Slider-MaxButton:hover {
374
  background-color: #ffffff;
375
}
376
377
Slider-MaxButton:horizontal {
378
  background-image: url( "/theme1/icons/slider-hbut-max-icon.gif" );
379
}
(-)src/org/eclipse/rap/demo/controls/ControlsDemo.java (+1 lines)
Lines 52-57 Link Here
52
    ensureMinTabHeight( topFolder );
52
    ensureMinTabHeight( topFolder );
53
53
54
    final ExampleTab[] tabs = new ExampleTab[] {
54
    final ExampleTab[] tabs = new ExampleTab[] {
55
      new SliderTab( topFolder ),
55
      new ButtonTab( topFolder ),
56
      new ButtonTab( topFolder ),
56
//      new RequestTab( topFolder ),
57
//      new RequestTab( topFolder ),
57
      new CBannerTab( topFolder ),
58
      new CBannerTab( topFolder ),
(-)src/org/eclipse/rap/demo/controls/SliderTab.java (+191 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2008 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.rap.demo.controls;
13
14
import org.eclipse.jface.dialogs.MessageDialog;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.custom.CTabFolder;
17
import org.eclipse.swt.events.*;
18
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.layout.RowLayout;
20
import org.eclipse.swt.widgets.*;
21
22
public class SliderTab extends ExampleTab {  
23
24
  private static final String PROP_CONTEXT_MENU = "contextMenu";
25
  private static final String PROP_SELECTION_LISTENER = "selectionListener";
26
  
27
  Slider slider;  
28
  Spinner minimumSpinner, maximumSpinner, selectionSpinner, thumbSpinner,
29
          incrementSpinner, pageIncrementSpinner;
30
  
31
  public SliderTab( final CTabFolder folder ) {
32
    super( folder, "Slider" );
33
    setDefaultStyle( SWT.HORIZONTAL );
34
  }
35
36
  protected void createStyleControls( final Composite parent ) {   
37
    createStyleButton( parent, "HORIZONTAL", SWT.HORIZONTAL, SWT.RADIO, true );
38
    createStyleButton( parent, "VERTICAL", SWT.VERTICAL, SWT.RADIO, false ); 
39
    createVisibilityButton();
40
    createEnablementButton();      
41
    createBgColorButton();
42
    createBgImageButton(); 
43
    minimumSpinner = createSpinnerControl( parent, "Minimum",
44
                                           0, 100000, 0 );
45
    minimumSpinner.addModifyListener( new ModifyListener() {
46
47
      public void modifyText( ModifyEvent event ) {
48
        int minimum = minimumSpinner.getSelection();
49
        slider.setMinimum( minimum );
50
      }
51
    } );
52
    maximumSpinner = createSpinnerControl( parent, "Maximum",
53
                                           0, 100000, 100 );
54
    maximumSpinner.addModifyListener( new ModifyListener() {
55
56
      public void modifyText( ModifyEvent event ) {
57
        int maximum = maximumSpinner.getSelection();
58
        slider.setMaximum( maximum );
59
      }
60
    } );
61
    selectionSpinner = createSpinnerControl( parent, "Selection",
62
                                             0, 100000, 0 );
63
    selectionSpinner.addModifyListener( new ModifyListener() {
64
65
      public void modifyText( ModifyEvent event ) {
66
        int selection = selectionSpinner.getSelection();
67
        slider.setSelection( selection );
68
      }
69
    } );
70
    thumbSpinner = createSpinnerControl( parent, "Thumb",
71
                                             1, 100000, 10 );
72
    thumbSpinner.addModifyListener( new ModifyListener() {
73
74
      public void modifyText( ModifyEvent event ) {
75
        int thumb = thumbSpinner.getSelection();
76
        slider.setThumb( thumb );
77
      }
78
    } );
79
    incrementSpinner = createSpinnerControl( parent, "Increment",
80
                                             0, 100000, 1 );
81
    incrementSpinner.addModifyListener( new ModifyListener() {
82
83
      public void modifyText( ModifyEvent event ) {
84
        int increment = incrementSpinner.getSelection();
85
        slider.setIncrement( increment );
86
      }
87
    } );
88
    pageIncrementSpinner = createSpinnerControl( parent, "Page Increment",
89
                                                 0, 100000, 10 );
90
    pageIncrementSpinner.addModifyListener( new ModifyListener() {
91
92
      public void modifyText( ModifyEvent event ) {
93
        int pageIncrement = pageIncrementSpinner.getSelection();
94
        slider.setPageIncrement( pageIncrement );
95
      }
96
    } );
97
    createPropertyCheckbox( "Add Context Menu", PROP_CONTEXT_MENU );
98
    createPropertyCheckbox( "Add Selection Listener", PROP_SELECTION_LISTENER );
99
  }
100
101
  protected void createExampleControls( final Composite parent ) {
102
    parent.setLayout( new RowLayout( SWT.VERTICAL ) );
103
    int style = getStyle();
104
    slider = new Slider( parent, style );
105
    if( hasCreateProperty( PROP_CONTEXT_MENU ) ) {
106
      Menu sliderMenu = new Menu( slider );
107
      MenuItem sliderMenuItem = new MenuItem( sliderMenu, SWT.PUSH );
108
      sliderMenuItem.addSelectionListener( new SelectionAdapter() {
109
110
        public void widgetSelected( final SelectionEvent event ) {
111
          String message = "You requested a context menu for the Slider";
112
          MessageDialog.openInformation( slider.getShell(),
113
                                         "Information",
114
                                         message );
115
        }
116
      } );
117
      sliderMenuItem.setText( "Slider context menu item" );
118
      slider.setMenu( sliderMenu );
119
    }
120
    if( hasCreateProperty( PROP_SELECTION_LISTENER ) ) {
121
      slider.addSelectionListener( new SelectionListener() {
122
123
        public void widgetSelected( final SelectionEvent event ) {
124
          String message = "Slider WidgetSelected! Current selection: " + slider.getSelection();
125
          log( message );
126
          selectionSpinner.setSelection( slider.getSelection() );
127
        }
128
129
        public void widgetDefaultSelected( final SelectionEvent event ) {
130
          String message = "Slider WidgetDefaultSelected! Current selection: " + slider.getSelection();
131
          log( message );
132
          selectionSpinner.setSelection( slider.getSelection() );
133
        }
134
      } );
135
    }
136
    if( minimumSpinner != null ) {
137
      slider.setMinimum( minimumSpinner.getSelection() );
138
    }
139
    if( maximumSpinner != null ) {
140
      slider.setMaximum( maximumSpinner.getSelection() );
141
    }
142
    if( selectionSpinner != null ) {
143
      slider.setSelection( selectionSpinner.getSelection() );
144
    }
145
    if( thumbSpinner != null ) {
146
      slider.setThumb( thumbSpinner.getSelection() );
147
    }
148
    if( incrementSpinner != null ) {
149
      slider.setIncrement( incrementSpinner.getSelection() );
150
    }
151
    if( pageIncrementSpinner != null ) {
152
      slider.setPageIncrement( pageIncrementSpinner.getSelection() );
153
    }
154
    registerControl( slider );
155
  }
156
  
157
  protected Button createStyleButton( final Composite parent,
158
                                      final String name,
159
                                      final int style,
160
                                      final int buttonStyle,
161
                                      final boolean checked )
162
  {
163
    Button button = new Button( parent, buttonStyle );
164
    button.setText( name );
165
    button.addSelectionListener( new SelectionAdapter() {
166
167
      public void widgetSelected( final SelectionEvent event ) {
168
        createNew();
169
      }
170
    } );
171
    button.setData( "style", new Integer( style ) );
172
    button.setSelection( checked );
173
    return button;
174
  }
175
  
176
  private Spinner createSpinnerControl( final Composite parent,
177
                                        final String labelText,
178
                                        final int minimum,
179
                                        final int maximum,
180
                                        final int selection ) {
181
    Composite composite = new Composite( parent, SWT.NONE );
182
    composite.setLayout( new GridLayout( 4, false ) );
183
    Label label = new Label( composite, SWT.NONE );
184
    label.setText( labelText );
185
    final Spinner spinner = new Spinner( composite, SWT.BORDER );
186
    spinner.setSelection( selection );
187
    spinner.setMinimum( minimum );
188
    spinner.setMaximum( maximum ); 
189
    return spinner;
190
  }
191
}
(-)src/org/eclipse/RWTQ07TestSuite.java (+2 lines)
Lines 40-45 Link Here
40
import org.eclipse.swt.internal.widgets.sashkit.SashLCA_Test;
40
import org.eclipse.swt.internal.widgets.sashkit.SashLCA_Test;
41
import org.eclipse.swt.internal.widgets.scalekit.ScaleLCA_Test;
41
import org.eclipse.swt.internal.widgets.scalekit.ScaleLCA_Test;
42
import org.eclipse.swt.internal.widgets.shellkit.ShellLCA_Test;
42
import org.eclipse.swt.internal.widgets.shellkit.ShellLCA_Test;
43
import org.eclipse.swt.internal.widgets.sliderkit.SliderLCA_Test;
43
import org.eclipse.swt.internal.widgets.spinnerkit.SpinnerLCA_Test;
44
import org.eclipse.swt.internal.widgets.spinnerkit.SpinnerLCA_Test;
44
import org.eclipse.swt.internal.widgets.tabfolderkit.TabFolderLCA_Test;
45
import org.eclipse.swt.internal.widgets.tabfolderkit.TabFolderLCA_Test;
45
import org.eclipse.swt.internal.widgets.tablecolumnkit.TableColumnLCA_Test;
46
import org.eclipse.swt.internal.widgets.tablecolumnkit.TableColumnLCA_Test;
Lines 124-129 Link Here
124
    suite.addTestSuite( DateTimeLCA_Test.class );
125
    suite.addTestSuite( DateTimeLCA_Test.class );
125
    suite.addTestSuite( ExpandBarLCA_Test.class );
126
    suite.addTestSuite( ExpandBarLCA_Test.class );
126
    suite.addTestSuite( ExpandItemLCA_Test.class );
127
    suite.addTestSuite( ExpandItemLCA_Test.class );
128
    suite.addTestSuite( SliderLCA_Test.class );
127
129
128
    return suite;
130
    return suite;
129
  }
131
  }
(-)src/org/eclipse/swt/internal/widgets/sliderkit/SliderLCA_Test.java (+168 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.swt.internal.widgets.sliderkit;
13
14
import junit.framework.TestCase;
15
16
import org.eclipse.rwt.Fixture;
17
import org.eclipse.rwt.graphics.Graphics;
18
import org.eclipse.rwt.internal.lifecycle.JSConst;
19
import org.eclipse.rwt.lifecycle.IWidgetAdapter;
20
import org.eclipse.rwt.lifecycle.WidgetUtil;
21
import org.eclipse.swt.RWTFixture;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.events.*;
24
import org.eclipse.swt.graphics.*;
25
import org.eclipse.swt.internal.widgets.Props;
26
import org.eclipse.swt.widgets.*;
27
28
public class SliderLCA_Test extends TestCase {
29
30
  public void testSliderPreserveValues() {
31
    Display display = new Display();
32
    Composite shell = new Shell( display, SWT.NONE );
33
    Slider slider = new Slider( shell, SWT.HORIZONTAL );
34
    RWTFixture.markInitialized( display );
35
    // Test preserved minimum, maximum, 
36
    // selection, increment, pageIncrement and thumb
37
    RWTFixture.preserveWidgets();
38
    IWidgetAdapter adapter = WidgetUtil.getAdapter( slider );
39
    Integer minimum
40
      = ( Integer )adapter.getPreserved( SliderLCA.PROP_MINIMUM );
41
    assertEquals( 0, minimum.intValue() );
42
    Integer maximum
43
      = ( Integer )adapter.getPreserved( SliderLCA.PROP_MAXIMUM );
44
    assertEquals( 100, maximum.intValue() );
45
    Integer selection
46
      = ( Integer )adapter.getPreserved( SliderLCA.PROP_SELECTION );
47
    assertEquals( 0, selection.intValue() );
48
    Integer increment
49
      = ( Integer )adapter.getPreserved( SliderLCA.PROP_INCREMENT );
50
    assertEquals( 1, increment.intValue() );
51
    Integer pageIncrement
52
      = ( Integer )adapter.getPreserved( SliderLCA.PROP_PAGE_INCREMENT );
53
    assertEquals( 10, pageIncrement.intValue() );    
54
    Integer thumb
55
    = ( Integer )adapter.getPreserved( SliderLCA.PROP_THUMB );
56
    assertEquals( 10, thumb.intValue() );
57
    RWTFixture.clearPreserved();
58
    // Test preserved control properties
59
    testPreserveControlProperties( slider );
60
    // Test preserved selection listeners
61
    testPreserveSelectionListener( slider );
62
    display.dispose();
63
  } 
64
65
  public void testSelectionEvent() {
66
    Display display = new Display();
67
    Composite shell = new Shell( display, SWT.NONE );
68
    Slider slider = new Slider( shell, SWT.HORIZONTAL );
69
    testSelectionEvent( slider );    
70
  }
71
72
  private void testPreserveControlProperties( final Slider slider ) {
73
    // bound
74
    Rectangle rectangle = new Rectangle( 10, 10, 10, 10 );
75
    slider.setBounds( rectangle );
76
    RWTFixture.preserveWidgets();
77
    IWidgetAdapter adapter = WidgetUtil.getAdapter( slider );
78
    assertEquals( rectangle, adapter.getPreserved( Props.BOUNDS ) );
79
    RWTFixture.clearPreserved();
80
    // enabled
81
    RWTFixture.preserveWidgets();
82
    adapter = WidgetUtil.getAdapter( slider );
83
    assertEquals( Boolean.TRUE, adapter.getPreserved( Props.ENABLED ) );
84
    RWTFixture.clearPreserved();
85
    slider.setEnabled( false );
86
    RWTFixture.preserveWidgets();
87
    adapter = WidgetUtil.getAdapter( slider );
88
    assertEquals( Boolean.FALSE, adapter.getPreserved( Props.ENABLED ) );
89
    RWTFixture.clearPreserved();
90
    // visible
91
    RWTFixture.preserveWidgets();
92
    adapter = WidgetUtil.getAdapter( slider );
93
    assertEquals( Boolean.TRUE, adapter.getPreserved( Props.VISIBLE ) );
94
    RWTFixture.clearPreserved();
95
    slider.setVisible( false );
96
    RWTFixture.preserveWidgets();
97
    adapter = WidgetUtil.getAdapter( slider );
98
    assertEquals( Boolean.FALSE, adapter.getPreserved( Props.VISIBLE ) );
99
    RWTFixture.clearPreserved();
100
    // menu
101
    RWTFixture.preserveWidgets();
102
    adapter = WidgetUtil.getAdapter( slider );
103
    assertEquals( null, adapter.getPreserved( Props.MENU ) );
104
    RWTFixture.clearPreserved();
105
    Menu menu = new Menu( slider );
106
    MenuItem item = new MenuItem( menu, SWT.NONE );
107
    item.setText( "1 Item" );
108
    slider.setMenu( menu );
109
    RWTFixture.preserveWidgets();
110
    adapter = WidgetUtil.getAdapter( slider );
111
    assertEquals( menu, adapter.getPreserved( Props.MENU ) );
112
    RWTFixture.clearPreserved();
113
    //foreground background font
114
    Color background = Graphics.getColor( 122, 33, 203 );
115
    slider.setBackground( background );
116
    RWTFixture.preserveWidgets();
117
    adapter = WidgetUtil.getAdapter( slider );
118
    assertEquals( background, adapter.getPreserved( Props.BACKGROUND ) );
119
    RWTFixture.clearPreserved();
120
  }
121
122
  private void testPreserveSelectionListener( final Slider slider ) {
123
    RWTFixture.preserveWidgets();
124
    IWidgetAdapter adapter = WidgetUtil.getAdapter( slider );
125
    Boolean hasListeners
126
      = ( Boolean )adapter.getPreserved( Props.SELECTION_LISTENERS );
127
    assertEquals( Boolean.FALSE, hasListeners );
128
    RWTFixture.clearPreserved();
129
    SelectionListener selectionListener = new SelectionAdapter() { };
130
    slider.addSelectionListener( selectionListener );
131
    RWTFixture.preserveWidgets();
132
    adapter = WidgetUtil.getAdapter( slider );
133
    hasListeners
134
      = ( Boolean )adapter.getPreserved( Props.SELECTION_LISTENERS );
135
    assertEquals( Boolean.TRUE, hasListeners );
136
    RWTFixture.clearPreserved();
137
  }
138
139
  private void testSelectionEvent( final Slider slider ) {
140
    final StringBuffer log = new StringBuffer();
141
    SelectionListener selectionListener = new SelectionAdapter() {
142
      public void widgetSelected( SelectionEvent event ) {
143
        assertEquals( slider, event.getSource() );
144
        assertEquals( null, event.item );
145
        assertEquals( SWT.NONE, event.detail );
146
        assertEquals( 0, event.x );
147
        assertEquals( 0, event.y );
148
        assertEquals( 0, event.width );
149
        assertEquals( 0, event.height );
150
        assertEquals( true, event.doit );
151
        log.append( "widgetSelected" );
152
      }
153
    };
154
    slider.addSelectionListener( selectionListener );
155
    String dateTimeId = WidgetUtil.getId( slider );
156
    Fixture.fakeRequestParam( JSConst.EVENT_WIDGET_SELECTED, dateTimeId );
157
    RWTFixture.readDataAndProcessAction( slider );
158
    assertEquals( "widgetSelected", log.toString() );
159
  }
160
161
  protected void setUp() throws Exception {
162
    RWTFixture.setUp();
163
  }
164
165
  protected void tearDown() throws Exception {
166
    RWTFixture.tearDown();
167
  }
168
}
(-)src/org/eclipse/swt/internal/widgets/displaykit/QooxdooResourcesUtil.java (+3 lines)
Lines 137-142 Link Here
137
    = "org/eclipse/swt/widgets/ExpandBar.js";
137
    = "org/eclipse/swt/widgets/ExpandBar.js";
138
  private static final String EXPAND_ITEM_JS
138
  private static final String EXPAND_ITEM_JS
139
    = "org/eclipse/swt/widgets/ExpandItem.js";
139
    = "org/eclipse/swt/widgets/ExpandItem.js";
140
  private static final String SLIDER_JS
141
    = "org/eclipse/swt/widgets/Slider.js";
140
142
141
  private QooxdooResourcesUtil() {
143
  private QooxdooResourcesUtil() {
142
    // prevent intance creation
144
    // prevent intance creation
Lines 216-221 Link Here
216
      register( CALENDAR_JS, compress );
218
      register( CALENDAR_JS, compress );
217
      register( EXPAND_BAR_JS, compress );
219
      register( EXPAND_BAR_JS, compress );
218
      register( EXPAND_ITEM_JS, compress );
220
      register( EXPAND_ITEM_JS, compress );
221
      register( SLIDER_JS, compress );
219
222
220
      // register contributions
223
      // register contributions
221
      registerContributions();
224
      registerContributions();
(-)js/org/eclipse/swt/theme/AppearancesBase.js (+77 lines)
Lines 1883-1888 Link Here
1883
      result.cursor = states.disabled ? "default" : "pointer";
1883
      result.cursor = states.disabled ? "default" : "pointer";
1884
      return result;
1884
      return result;
1885
    }
1885
    }
1886
  },
1887
  
1888
  // ------------------------------------------------------------------------
1889
  // Slider
1890
  
1891
  "slider" : {
1892
    style : function( states ) {
1893
      var tv = new org.eclipse.swt.theme.ThemeValues( states );
1894
      return {        
1895
        border : tv.getCssBorder( "*", "border" ),
1896
        font : tv.getCssFont( "*", "font" ),
1897
        textColor : tv.getCssColor( "*", "color" ),
1898
        backgroundColor : tv.getCssColor( "Slider", "background-color" )
1899
      }
1900
    }
1901
  },
1902
1903
  "slider-line" : {
1904
    include : "atom",
1905
    style : function( states ) {
1906
      var result = {};
1907
      result.backgroundColor = "#eeeeee";
1908
      result.opacity = 0;
1909
      // Assigning icon for proper visualization in IE
1910
      result.icon = "static/image/blank.gif";
1911
      if( states.horizontal ){
1912
        result.left = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH;
1913
      } else {
1914
        result.top = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH;
1915
      }
1916
      return result;
1917
    }
1918
  },
1919
  
1920
  "slider-thumb" : {
1921
    include : "atom",
1922
    style : function( states ) {
1923
      var tv = new org.eclipse.swt.theme.ThemeValues( states );
1924
      var result = {};
1925
      result.backgroundColor = tv.getCssColor( "Slider-Thumb", "background-color" );
1926
      result.border = tv.getCssBorder( "Slider-Thumb", "border" );
1927
      // Assigning icon for proper visualization in IE
1928
      result.icon = "static/image/blank.gif";
1929
      return result;
1930
    }
1931
  },
1932
  
1933
  "slider-min-button" : {
1934
    include : "button",
1935
    style : function( states ) {
1936
      var tv = new org.eclipse.swt.theme.ThemeValues( states );
1937
      var result = {};
1938
      result.backgroundColor = tv.getCssColor( "Slider-MinButton", "background-color" );
1939
      result.icon = tv.getCssImage( "Slider-MinButton", "background-image" );
1940
      if( states.horizontal ){
1941
        result.width = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH;
1942
      } else {
1943
        result.height = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH;
1944
      }
1945
      return result;
1946
    }
1947
  },
1948
  
1949
  "slider-max-button" : {
1950
    include : "button",
1951
    style : function( states ) {
1952
      var tv = new org.eclipse.swt.theme.ThemeValues( states );
1953
      var result = {};
1954
      result.backgroundColor = tv.getCssColor( "Slider-MaxButton", "background-color" );
1955
      result.icon = tv.getCssImage( "Slider-MaxButton", "background-image" );
1956
      if( states.horizontal ){        
1957
        result.width = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH;
1958
      } else {
1959
        result.height = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH;
1960
      }
1961
      return result;
1962
    }
1886
  }
1963
  }
1887
}
1964
}
1888
} );
1965
} );
(-)js/org/eclipse/swt/widgets/Slider.js (+537 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Innoopract Informationssysteme GmbH. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
8
 * implementation
9
 ******************************************************************************/
10
11
/**
12
 * This class provides the client-side counterpart for
13
 * org.eclipse.swt.widgets.Slider.
14
 */
15
qx.Class.define( "org.eclipse.swt.widgets.Slider", {
16
  extend : qx.ui.layout.CanvasLayout,
17
18
  construct : function( style ) {
19
    this.base( arguments );
20
    this.setAppearance( "slider" );
21
    // Get styles
22
    this._horizontal = qx.lang.String.contains( style, "horizontal" );
23
    //
24
    this._hasSelectionListener = false;
25
    // Flag indicating that the next request can be sent
26
    this._readyToSendChanges = true;
27
    // Default values
28
    this._selection = 0;
29
    this._minimum = 0;
30
    this._maximum = 100;
31
    this._increment = 1;
32
    this._pageIncrement = 10;
33
    this._thumbWidth = 10;
34
    this._pxStep = 1.38;
35
    this._thumbPressed = false;
36
    // _interactionId: Indicates what element is pressed - minButton,
37
    // maxButton or area behind the thumb (line)
38
    this._interactionId;
39
    // _mousePos: Stores the mouse position, needed when calculating the
40
    // thumb translation after click on the area behind the thumb (line)
41
    this._mousePos;
42
    // Timer: used for continuous scrolling
43
    this._scrollTimer = new qx.client.Timer( 100 );
44
    this._scrollTimer.addEventListener( "interval",
45
                                        this._onScrollTimerInterval, 
46
                                        this );
47
    // _scrollReadyToStart: Flag for starting the scrollTimer
48
    this._scrollReadyToStart = false;
49
    // Line - the area behind the thumb
50
    this._line = new qx.ui.basic.Atom;
51
    if( this._horizontal ) {
52
      this._line.addState( org.eclipse.swt.widgets.Slider.STATE_HORIZONTAL );
53
    }
54
    this._line.setAppearance( "slider-line" );
55
    this._line.addEventListener( "mousedown", this._onLineMouseDown, this );
56
    this._line.addEventListener( "mouseup", 
57
                                 this._onInteractionMouseUpOut, 
58
                                 this );
59
    this._line.addEventListener( "mousemove", this._onLineMouseMove, this );
60
    this._line.addEventListener( "mouseout", 
61
                                 this._onInteractionMouseUpOut,
62
                                 this );
63
    this.add( this._line );
64
    // Thumb
65
    this._thumb = new qx.ui.basic.Atom;
66
    if( this._horizontal ) {
67
      this._thumb.addState( org.eclipse.swt.widgets.Slider.STATE_HORIZONTAL );
68
    }
69
    this._thumb.setAppearance( "slider-thumb" );
70
    this._thumb.addEventListener( "mousedown", this._onThumbMouseDown, this );
71
    this._thumb.addEventListener( "mousemove", this._onThumbMouseMove, this );
72
    this._thumb.addEventListener( "mouseup", this._onThumbMouseUp, this );
73
    // Fix IE Styling issues
74
    org.eclipse.swt.WidgetUtil.fixIEBoxHeight( this._thumb );
75
    this.add( this._thumb );
76
    // Thumb offset
77
    this._thumbOffset = 0;
78
    // Min button
79
    this._minButton = new qx.ui.form.Button;
80
    if( this._horizontal ) {
81
      this._minButton.addState( org.eclipse.swt.widgets.Slider.STATE_HORIZONTAL );
82
    }
83
    this._minButton.addState( "rwt_PUSH" );
84
    this._minButton.setAppearance( "slider-min-button" );
85
    this._minButton.addEventListener( "mousedown", 
86
                                      this._onMinButtonMouseDown,
87
                                      this );
88
    this._minButton.addEventListener( "mouseup", 
89
                                      this._onInteractionMouseUpOut,
90
                                      this );
91
    this._minButton.addEventListener( "mouseout",
92
                                      this._onInteractionMouseUpOut, 
93
                                      this );
94
    // Fix IE Styling issues
95
    org.eclipse.swt.WidgetUtil.fixIEBoxHeight( this._minButton );
96
    this.add( this._minButton );
97
    // Max button
98
    this._maxButton = new qx.ui.form.Button;
99
    if( this._horizontal ) {
100
      this._maxButton.addState( org.eclipse.swt.widgets.Slider.STATE_HORIZONTAL );
101
    }
102
    this._maxButton.addState( "rwt_PUSH" );
103
    this._maxButton.setAppearance( "slider-max-button" );
104
    this._maxButton.addEventListener( "mousedown", 
105
                                      this._onMaxButtonMouseDown,
106
                                      this );
107
    this._maxButton.addEventListener( "mouseup", 
108
                                      this._onInteractionMouseUpOut,
109
                                      this );
110
    this._maxButton.addEventListener( "mouseout",
111
                                      this._onInteractionMouseUpOut, 
112
                                      this );
113
    // Fix IE Styling issues
114
    org.eclipse.swt.WidgetUtil.fixIEBoxHeight( this._maxButton );
115
    this.add( this._maxButton );
116
    // Add events listeners
117
    this.addEventListener( "changeWidth", this._onChangeSize, this );
118
    this.addEventListener( "changeHeight", this._onChangeSize, this );
119
    this.addEventListener( "contextmenu", this._onContextMenu, this );
120
    this.addEventListener( "changeEnabled", this._onChangeEnabled, this );
121
  },
122
123
  destruct : function() {
124
    this._line.removeEventListener( "mousedown", this._onLineMouseDown, this );
125
    this._line.removeEventListener( "mouseup", 
126
                                    this._onInteractionMouseUpOut,
127
                                    this );
128
    this._line.removeEventListener( "mousemove", this._onLineMouseMove, this );
129
    this._line.removeEventListener( "mouseout", 
130
                                    this._onInteractionMouseUpOut,
131
                                    this );
132
    this._minButton.removeEventListener( "mousedown",
133
                                         this._onMinButtonMouseDown, 
134
                                         this );
135
    this._minButton.removeEventListener( "mouseup",
136
                                         this._onInteractionMouseUpOut, 
137
                                         this );
138
    this._minButton.removeEventListener( "mouseout",
139
                                         this._onInteractionMouseUpOut, 
140
                                         this );
141
    this._maxButton.removeEventListener( "mousedown",
142
                                         this._onMaxButtonMouseDown, 
143
                                         this );
144
    this._maxButton.removeEventListener( "mouseup",
145
                                         this._onInteractionMouseUpOut, 
146
                                         this );
147
    this._maxButton.removeEventListener( "mouseout",
148
                                         this._onInteractionMouseUpOut, 
149
                                         this );
150
    this._scrollTimer.removeEventListener( "interval",
151
                                           this._onScrollTimerInterval, 
152
                                           this );
153
    this._thumb.removeEventListener( "mousedown", this._onThumbMouseDown, this );
154
    this._thumb.removeEventListener( "mousemove", this._onThumbMouseMove, this );
155
    this._thumb.removeEventListener( "mouseup", this._onThumbMouseUp, this );
156
    this.removeEventListener( "changeWidth", this._onChangeSize, this );
157
    this.removeEventListener( "changeHeight", this._onChangeSize, this );
158
    this.removeEventListener( "contextmenu", this._onContextMenu, this );
159
    this.removeEventListener( "changeEnabled", this._onChangeEnabled, this );
160
    if( this._scrollTimer != null ) {
161
      this._scrollTimer.stop();
162
      this._scrollTimer.dispose();
163
    }
164
    this._scrollTimer = null;
165
    // this._disposeObjects( "_line", "_thumb", "_minButton", "_maxButton" );
166
    this._line.dispose();
167
    this._thumb.dispose();
168
    this._minButton.dispose();
169
    this._maxButton.dispose();
170
  },
171
172
  statics : {
173
    STATE_HORIZONTAL : "horizontal",
174
    BUTTON_WIDTH : 16,
175
    STATE_PRESSED : "pressed"
176
  },
177
178
  members : {
179
    _onChangeSize : function( evt ) {
180
      if( this._horizontal ) {
181
        var left = this.getWidth()
182
                 - org.eclipse.swt.widgets.Slider.BUTTON_WIDTH;
183
        this._maxButton.setLeft( left );
184
      } else {
185
        var top = this.getHeight()
186
                - org.eclipse.swt.widgets.Slider.BUTTON_WIDTH;
187
        this._maxButton.setTop( top );
188
      }
189
      this._updateLineSize();
190
      this._updateButtonsSize();
191
      this._updateThumbSize();
192
    },
193
194
    _onContextMenu : function( evt ) {
195
      var menu = this.getContextMenu();
196
      if( menu != null ) {
197
        menu.setLocation( evt.getPageX(), evt.getPageY() );
198
        menu.setOpener( this );
199
        menu.show();
200
        evt.stopPropagation();
201
      }
202
    },
203
204
    _onChangeEnabled : function( evt ) {
205
      this._thumb.setVisibility( evt.getValue() );
206
    },
207
208
    _onLineMouseDown : function( evt ) {
209
      this._interactionId = "line";
210
      var pxSel;
211
      var sel;
212
      var thumbMov; // Thumb movement after interaction
213
      if( evt.isLeftButtonPressed() ) {
214
        if( this._horizontal ) {
215
          pxSel = this._thumb.getLeft() + ( this._thumb.getWidth() ) / 2;
216
          this._mousePos = evt.getPageX()
217
                         - qx.html.Location.getClientBoxLeft( this.getElement() );
218
          thumbMov = this._pageIncrement * this._pxStep
219
                   + this._thumb.getWidth() / 2;
220
        } else {
221
          pxSel = this._thumb.getTop() + ( this._thumb.getHeight() ) / 2;
222
          this._mousePos = evt.getPageY()
223
                         - qx.html.Location.getClientBoxTop( this.getElement() );
224
          thumbMov = this._pageIncrement * this._pxStep
225
                   + this._thumb.getHeight() / 2;
226
        }
227
        if( this._mousePos > pxSel ) {
228
          sel = this._selection + this._pageIncrement;
229
        } else {
230
          sel = this._selection - this._pageIncrement;
231
        }
232
        // Check whether to start auto-repeat interaction
233
        if( Math.abs( this._mousePos - pxSel ) > thumbMov ) {
234
          this._scrollReadyToStart = true;
235
        }
236
        if( sel < this._minimum ) {
237
          sel = this._minimum;
238
        }
239
        if( sel > ( this._maximum - this._thumbWidth ) ) {
240
          sel = this._maximum - this._thumbWidth;
241
        }
242
        this.setSelection( sel );
243
      }
244
    },
245
246
    _onLineMouseMove : function( evt ) {
247
      if( this._horizontal ) {
248
        this._mousePos = evt.getPageX()
249
                       - qx.html.Location.getClientBoxLeft( this.getElement() );
250
      } else {
251
        this._mousePos = evt.getPageY()
252
                       - qx.html.Location.getClientBoxTop( this.getElement() );
253
      }
254
    },
255
256
    _onMinButtonMouseDown : function( evt ) {
257
      this._interactionId = "minButton";
258
      var sel;
259
      if( evt.isLeftButtonPressed() ) {
260
        this._scrollReadyToStart = true;
261
        sel = this._selection - this._increment;
262
        if( sel < this._minimum ) {
263
          sel = this._minimum;
264
        }
265
        if( sel > ( this._maximum - this._thumbWidth ) ) {
266
          sel = this._maximum - this._thumbWidth;
267
        }
268
        this.setSelection( sel );
269
      }
270
    },
271
272
    _onMaxButtonMouseDown : function( evt ) {
273
      this._interactionId = "maxButton";
274
      var sel;
275
      if( evt.isLeftButtonPressed() ) {
276
        this._scrollReadyToStart = true;
277
        sel = this._selection + this._increment;
278
        if( sel < this._minimum ) {
279
          sel = this._minimum;
280
        }
281
        if( sel > ( this._maximum - this._thumbWidth ) ) {
282
          sel = this._maximum - this._thumbWidth;
283
        }
284
        this.setSelection( sel );
285
      }
286
    },
287
288
    _onInteractionMouseUpOut : function( evt ) {
289
      this._scrollReadyToStart = false;
290
      this._scrollTimer.stop();
291
    },
292
293
    _scrollTimerStart : function() {
294
      if( this._scrollReadyToStart ) {
295
        this._scrollTimer.start();
296
      }
297
    },
298
299
    _onScrollTimerInterval : function( evt ) {
300
      var sel;
301
      switch( this._interactionId ) {
302
        case "minButton":
303
          sel = this._selection - this._increment;
304
          break;
305
        case "maxButton":
306
          sel = this._selection + this._increment;
307
          break;
308
        case "line":
309
          var pxSel;
310
          var thumbMov; // Thumb movement after interaction
311
          if( this._horizontal ) {
312
            pxSel = this._thumb.getLeft() + this._thumb.getWidth() / 2;
313
            thumbMov = this._pageIncrement * this._pxStep
314
                     + this._thumb.getWidth() / 2;
315
          } else {
316
            pxSel = this._thumb.getTop() + this._thumb.getHeight() / 2;
317
            thumbMov = this._pageIncrement * this._pxStep
318
                     + this._thumb.getHeight() / 2;
319
          }
320
          if( this._mousePos > pxSel ) {
321
            sel = this._selection + this._pageIncrement;
322
          } else {
323
            sel = this._selection - this._pageIncrement;
324
          }
325
          // Check whether to stop auto-repeat interaction
326
          if( Math.abs( this._mousePos - pxSel ) <= thumbMov ) {
327
            this._scrollReadyToStart = false;
328
            this._scrollTimer.stop();
329
          }
330
          break;
331
      }
332
      if( sel < this._minimum ) {
333
        sel = this._minimum;
334
      }
335
      if( sel > ( this._maximum - this._thumbWidth ) ) {
336
        sel = this._maximum - this._thumbWidth;
337
      }
338
      this.setSelection( sel );
339
340
      if( this._readyToSendChanges ) {
341
        this._readyToSendChanges = false;
342
        // Send changes
343
        qx.client.Timer.once( this._sendChanges, this, 500 );
344
      }
345
    },
346
347
    _onThumbMouseDown : function( evt ) {
348
      var mousePos;
349
      this._thumb.addState( org.eclipse.swt.widgets.Slider.STATE_PRESSED );
350
      this._thumbPressed = true;
351
      if( evt.isLeftButtonPressed() ) {
352
        if( this._horizontal ) {
353
          mousePos = evt.getPageX()
354
                   - qx.html.Location.getClientBoxLeft( this.getElement() );
355
          this._thumbOffset = mousePos - this._thumb.getLeft();
356
        } else {
357
          mousePos = evt.getPageY()
358
                   - qx.html.Location.getClientBoxTop( this.getElement() );
359
          this._thumbOffset = mousePos - this._thumb.getTop();
360
        }
361
        this._thumb.setCapture( true );
362
      }
363
    },
364
365
    _onThumbMouseMove : function( evt ) {
366
      var mousePos;
367
      if( this._thumb.getCapture() ) {
368
        if( this._horizontal ) {
369
          mousePos = evt.getPageX()
370
                   - qx.html.Location.getClientBoxLeft( this.getElement() );
371
        } else {
372
          mousePos = evt.getPageY()
373
                   - qx.html.Location.getClientBoxTop( this.getElement() );
374
        }
375
        var sel = this._getSelectionFromThumbPosition( mousePos
376
                - this._thumbOffset );
377
        if( this._selection != sel ) {
378
          this.setSelection( sel );
379
          if( this._readyToSendChanges ) {
380
            this._readyToSendChanges = false;
381
            // Send changes
382
            qx.client.Timer.once( this._sendChanges, this, 500 );
383
          }
384
        }
385
      }
386
    },
387
388
    _onThumbMouseUp : function( evt ) {
389
      this._scrollTimer.stop();
390
      this._thumbPressed = false;
391
      this._thumb.setCapture( false );
392
      this._thumb.removeState( org.eclipse.swt.widgets.Slider.STATE_PRESSED );
393
    },
394
395
    _updateThumbSize : function() {
396
      if( this._horizontal ) {
397
        this._thumb.setWidth( this._thumbWidth * this._line.getWidth()
398
                              / ( this._maximum - this._minimum ) );
399
        this._thumb.setHeight( this.getHeight() );
400
      } else {
401
        this._thumb.setWidth( this.getWidth() );
402
        this._thumb.setHeight( this._thumbWidth * this._line.getHeight()
403
                               / ( this._maximum - this._minimum ) );
404
      }
405
      this._updateStep();
406
    },
407
408
    _updateStep : function() {
409
      var padding;
410
      var numSteps = this._maximum - this._minimum - this._thumbWidth;
411
      if( numSteps != 0 ) {
412
        if( this._horizontal ) {
413
          padding = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH
414
                  + ( this._thumb.getWidth() ) / 2;
415
          this._pxStep = ( this.getWidth() - 2 * padding ) / numSteps;
416
        } else {
417
          padding = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH
418
                  + ( this._thumb.getHeight() ) / 2;
419
          this._pxStep = ( this.getHeight() - 2 * padding ) / numSteps;
420
        }
421
      } else {
422
        this._pxStep = 0;
423
      }
424
      this._updateThumbPosition();
425
    },
426
427
    _updateThumbPosition : function() {
428
      var pos;
429
      if( this._selection >= ( this._maximum - this._thumbWidth ) ) {
430
        pos = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH + this._pxStep
431
            * ( this._maximum - this._minimum - this._thumbWidth );
432
        this._selection = this._maximum - this._thumbWidth;
433
      } else if( this._selection <= this._minimum ) {
434
        pos = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH;
435
        this._selection = this._minimum;
436
      } else {
437
        pos = org.eclipse.swt.widgets.Slider.BUTTON_WIDTH + this._pxStep
438
            * ( this._selection - this._minimum );
439
      }
440
      if( this._horizontal ) {
441
        this._thumb.setLeft( pos );
442
      } else {
443
        this._thumb.setTop( pos );
444
      }
445
      if( this._readyToSendChanges ) {
446
        this._readyToSendChanges = false;
447
        // Send changes
448
        qx.client.Timer.once( this._sendChanges, this, 500 );
449
        // Starting the auto repeat functionality after a 250 ms delay
450
        qx.client.Timer.once( this._scrollTimerStart, this, 250 );
451
      }
452
    },
453
454
    _updateLineSize : function() {
455
      if( this._horizontal ) {
456
        this._line.setWidth( this.getWidth() - 2
457
                           * org.eclipse.swt.widgets.Slider.BUTTON_WIDTH );
458
        this._line.setHeight( this.getHeight() );
459
      } else {
460
        this._line.setWidth( this.getWidth() );
461
        this._line.setHeight( this.getHeight() - 2
462
                            * org.eclipse.swt.widgets.Slider.BUTTON_WIDTH );
463
      }
464
    },
465
466
    _updateButtonsSize : function() {
467
      if( this._horizontal ) {
468
        this._minButton.setHeight( this.getHeight() );
469
        this._maxButton.setHeight( this.getHeight() );
470
      } else {
471
        this._minButton.setWidth( this.getWidth() );
472
        this._maxButton.setWidth( this.getWidth() );
473
      }
474
    },
475
476
    _getSelectionFromThumbPosition : function( position ) {
477
      var sel = ( position - org.eclipse.swt.widgets.Slider.BUTTON_WIDTH )
478
              / this._pxStep + this._minimum;
479
      sel = Math.round( sel );
480
      var sel_final;
481
      if( sel < this._minimum ) {
482
        sel_final = this._minimum;
483
      } else if( sel > ( this._maximum - this._thumbWidth ) ) {
484
        sel_final = this._maximum - this._thumbWidth;
485
      } else {
486
        sel_final = sel;
487
      }
488
      return sel_final;
489
    },
490
491
    _sendChanges : function() {
492
      if( !org_eclipse_rap_rwt_EventUtil_suspend ) {
493
        var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
494
        var req = org.eclipse.swt.Request.getInstance();
495
        var id = widgetManager.findIdByWidget( this );
496
        req.addParameter( id + ".selection", this._selection );
497
        if( this._hasSelectionListener ) {
498
          req.addEvent( "org.eclipse.swt.events.widgetSelected", id );
499
          req.send();
500
        }
501
        this._readyToSendChanges = true;
502
      }
503
    },
504
505
    setHasSelectionListener : function( value ) {
506
      this._hasSelectionListener = value;
507
    },
508
509
    setSelection : function( value ) {
510
      this._selection = value;
511
      this._updateThumbPosition();
512
    },
513
514
    setMinimum : function( value ) {
515
      this._minimum = value;
516
      this._updateThumbSize();
517
    },
518
519
    setMaximum : function( value ) {
520
      this._maximum = value;
521
      this._updateThumbSize();
522
    },
523
524
    setIncrement : function( value ) {
525
      this._increment = value;
526
    },
527
528
    setPageIncrement : function( value ) {
529
      this._pageIncrement = value;
530
    },
531
532
    setThumb : function( value ) {
533
      this._thumbWidth = value;
534
      this._updateThumbSize();
535
    }
536
  }
537
} );
(-)src/org/eclipse/swt/internal/widgets/sliderkit/SliderLCA.java (+190 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.swt.internal.widgets.sliderkit;
13
14
import java.io.IOException;
15
16
import org.eclipse.rwt.lifecycle.*;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.internal.widgets.Props;
20
import org.eclipse.swt.widgets.Slider;
21
import org.eclipse.swt.widgets.Widget;
22
23
24
public class SliderLCA extends AbstractWidgetLCA {
25
  
26
  // Property names for preserveValues
27
  static final String PROP_SELECTION = "selection";
28
  static final String PROP_MAXIMUM = "maximum";
29
  static final String PROP_MINIMUM = "minimum";
30
  static final String PROP_PAGE_INCREMENT = "pageIncrement";
31
  static final String PROP_INCREMENT = "increment";
32
  static final String PROP_THUMB = "thumb";
33
  
34
  // Default values
35
  static final Integer DEFAULT_SELECTION = new Integer( 0 );
36
  static final Integer DEFAULT_MAXIMUM = new Integer( 100 );
37
  static final Integer DEFAULT_MINIMUM = new Integer( 0 );
38
  static final Integer DEFAULT_PAGE_INCREMENT = new Integer( 10 );
39
  static final Integer DEFAULT_INCREMENT = new Integer( 1 );
40
  static final Integer DEFAULT_THUMB = new Integer( 10 );
41
42
  public void preserveValues( final Widget widget ) {
43
    Slider slider = ( Slider )widget;
44
    ControlLCAUtil.preserveValues( slider );
45
    IWidgetAdapter adapter = WidgetUtil.getAdapter( slider );
46
    boolean hasListeners = SelectionEvent.hasListener( slider );
47
    adapter.preserve( Props.SELECTION_LISTENERS,
48
                      Boolean.valueOf( hasListeners ) );
49
    adapter.preserve( PROP_SELECTION, 
50
                      new Integer( slider.getSelection() ) );
51
    adapter.preserve( PROP_MAXIMUM, 
52
                      new Integer( slider.getMaximum() ) );
53
    adapter.preserve( PROP_MINIMUM, 
54
                      new Integer( slider.getMinimum() ) );
55
    adapter.preserve( PROP_PAGE_INCREMENT, 
56
                      new Integer( slider.getPageIncrement() ) );
57
    adapter.preserve( PROP_INCREMENT, 
58
                      new Integer( slider.getIncrement() ) );
59
    adapter.preserve( PROP_THUMB, 
60
                      new Integer( slider.getThumb() ) );
61
  }
62
63
  public void readData( final Widget widget ) {
64
    Slider slider = ( Slider )widget;
65
    String value = WidgetLCAUtil.readPropertyValue( slider, PROP_SELECTION );
66
    if( value != null ) {
67
      slider.setSelection( Integer.parseInt( value ) );
68
    }
69
    ControlLCAUtil.processSelection( slider, null, true );
70
  }
71
72
  public void renderInitialization( final Widget widget ) throws IOException {
73
    Slider slider = ( Slider )widget;
74
    JSWriter writer = JSWriter.getWriterFor( slider );
75
    String style = "";
76
    if( ( slider.getStyle() & SWT.HORIZONTAL ) != 0 ) {
77
      style = "horizontal";
78
    } else {
79
      style = "vertical";
80
    }
81
    Object[] args = new Object[]{
82
      style
83
    };
84
    writer.newWidget( "org.eclipse.swt.widgets.Slider", args );
85
    WidgetLCAUtil.writeCustomVariant( widget );
86
    ControlLCAUtil.writeStyleFlags( slider );
87
  }
88
89
  
90
  public void renderChanges( final Widget widget ) throws IOException {
91
    Slider slider = ( Slider )widget;
92
    ControlLCAUtil.writeChanges( slider );
93
    writeMaximum( slider );
94
    writeMinimum( slider );
95
    writePageIncrement( slider );
96
    writeSelection( slider );
97
    writeIncrement( slider );
98
    writeThumb( slider );
99
    writeListener( slider );
100
  }
101
102
  public void renderDispose( final Widget widget ) throws IOException {
103
    JSWriter writer = JSWriter.getWriterFor( widget );
104
    writer.dispose();
105
  }
106
107
  public void createResetHandlerCalls( final String typePoolId )
108
    throws IOException
109
  {    
110
  }
111
112
  public String getTypePoolId( final Widget widget ) {
113
    return null;
114
  }
115
116
  //////////////////
117
  // Helping methods
118
  private void writeMaximum( final Slider slider ) throws IOException {
119
    Integer newValue = new Integer( slider.getMaximum() );
120
    if( WidgetLCAUtil.hasChanged( slider, 
121
                                  PROP_MAXIMUM,
122
                                  newValue, 
123
                                  DEFAULT_MAXIMUM  ) ) 
124
    {
125
      JSWriter writer = JSWriter.getWriterFor( slider );
126
      writer.set( PROP_MAXIMUM, newValue );
127
    }
128
  }
129
  
130
  private void writeMinimum( final Slider slider ) throws IOException {
131
    Integer newValue = new Integer( slider.getMinimum() );
132
    String prop = PROP_MINIMUM;
133
    Integer defValue = DEFAULT_MINIMUM;
134
    if( WidgetLCAUtil.hasChanged( slider, prop, newValue, defValue ) ) {
135
      JSWriter writer = JSWriter.getWriterFor( slider );
136
      writer.set( PROP_MINIMUM, newValue );
137
    }
138
  }
139
  
140
  private void writeSelection( final Slider slider ) throws IOException {
141
    Integer newValue = new Integer( slider.getSelection() );
142
    String prop = PROP_SELECTION;
143
    Integer defValue = DEFAULT_SELECTION;
144
    if( WidgetLCAUtil.hasChanged( slider, prop, newValue, defValue ) ) {
145
      JSWriter writer = JSWriter.getWriterFor( slider );
146
      writer.set( PROP_SELECTION, newValue );
147
    }
148
  }
149
  
150
  private void writeIncrement( final Slider slider ) throws IOException {
151
    Integer newValue = new Integer( slider.getIncrement() );
152
    String prop = PROP_INCREMENT;
153
    Integer defValue = DEFAULT_INCREMENT;
154
    if( WidgetLCAUtil.hasChanged( slider, prop, newValue, defValue ) ) {
155
      JSWriter writer = JSWriter.getWriterFor( slider );
156
      writer.set( PROP_INCREMENT, newValue );
157
    }
158
  }
159
  
160
  private void writePageIncrement( final Slider slider ) throws IOException {
161
    Integer newValue = new Integer( slider.getPageIncrement() );
162
    String prop = PROP_PAGE_INCREMENT;
163
    Integer defValue = DEFAULT_PAGE_INCREMENT;
164
    if( WidgetLCAUtil.hasChanged( slider, prop, newValue, defValue ) ) {
165
      JSWriter writer = JSWriter.getWriterFor( slider );
166
      writer.set( PROP_PAGE_INCREMENT, newValue );
167
    }
168
  }
169
  
170
  private void writeThumb( final Slider slider ) throws IOException {
171
    Integer newValue = new Integer( slider.getThumb() );
172
    String prop = PROP_THUMB;
173
    Integer defValue = DEFAULT_THUMB;
174
    if( WidgetLCAUtil.hasChanged( slider, prop, newValue, defValue ) ) {
175
      JSWriter writer = JSWriter.getWriterFor( slider );
176
      writer.set( PROP_THUMB, newValue );
177
    }
178
  }
179
  
180
  private void writeListener( final Slider slider ) throws IOException {  
181
    boolean hasListener = SelectionEvent.hasListener( slider );
182
    Boolean newValue = Boolean.valueOf( hasListener );
183
    String prop = Props.SELECTION_LISTENERS;
184
    if( WidgetLCAUtil.hasChanged( slider, prop, newValue, Boolean.FALSE ) ) {
185
      JSWriter writer = JSWriter.getWriterFor( slider );
186
      writer.set( "hasSelectionListener", newValue );
187
    }
188
  }
189
 
190
}
(-)src/org/eclipse/rwt/internal/theme/ThemeManager.java (-1 / +2 lines)
Lines 162-168 Link Here
162
    org.eclipse.swt.widgets.Tree.class,
162
    org.eclipse.swt.widgets.Tree.class,
163
    org.eclipse.swt.widgets.Scale.class,
163
    org.eclipse.swt.widgets.Scale.class,
164
    org.eclipse.swt.widgets.DateTime.class,
164
    org.eclipse.swt.widgets.DateTime.class,
165
    org.eclipse.swt.widgets.ExpandBar.class
165
    org.eclipse.swt.widgets.ExpandBar.class,
166
    org.eclipse.swt.widgets.Slider.class
166
  };
167
  };
167
168
168
  private static ThemeManager instance;
169
  private static ThemeManager instance;
(-)src/org/eclipse/swt/internal/widgets/sliderkit/Slider.default.css (+40 lines)
Added Link Here
1
/* Slider default theme */
2
3
Slider {
4
  background-color: #eeeeee;
5
}
6
7
Slider-Thumb {
8
  background-color: #cccccc;
9
  border: 1px outset;
10
}
11
12
Slider-Thumb:pressed {
13
  background-color: #aaaaaa;
14
}
15
16
Slider-MinButton {
17
  background-color: #cccccc;
18
  background-image: url( resource/widget/rap/slider/vbut_min_icon.gif );
19
}
20
21
Slider-MinButton:hover {
22
  background-color: #eeeeee;
23
}
24
25
Slider-MinButton:horizontal {
26
  background-image: url( resource/widget/rap/slider/hbut_min_icon.gif );
27
}
28
29
Slider-MaxButton {
30
  background-color: #cccccc;
31
  background-image: url( resource/widget/rap/slider/vbut_max_icon.gif );
32
}
33
34
Slider-MaxButton:hover {
35
  background-color: #eeeeee;
36
}
37
38
Slider-MaxButton:horizontal {
39
  background-image: url( resource/widget/rap/slider/hbut_max_icon.gif );
40
}
(-)src/org/eclipse/swt/widgets/Slider.java (+510 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.swt.widgets;
12
13
import org.eclipse.swt.*;
14
import org.eclipse.swt.graphics.*;
15
import org.eclipse.swt.events.*;
16
17
/**
18
 * Instances of this class are selectable user interface
19
 * objects that represent a range of positive, numeric values. 
20
 * <p>
21
 * At any given moment, a given slider will have a 
22
 * single 'selection' that is considered to be its
23
 * value, which is constrained to be within the range of
24
 * values the slider represents (that is, between its
25
 * <em>minimum</em> and <em>maximum</em> values).
26
 * </p><p>
27
 * Typically, sliders will be made up of five areas:
28
 * <ol>
29
 * <li>an arrow button for decrementing the value</li>
30
 * <li>a page decrement area for decrementing the value by a larger amount</li>
31
 * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
32
 * <li>a page increment area for incrementing the value by a larger amount</li>
33
 * <li>an arrow button for incrementing the value</li>
34
 * </ol>
35
 * Based on their style, sliders are either <code>HORIZONTAL</code>
36
 * (which have a left facing button for decrementing the value and a
37
 * right facing button for incrementing it) or <code>VERTICAL</code>
38
 * (which have an upward facing button for decrementing the value
39
 * and a downward facing buttons for incrementing it).
40
 * </p><p>
41
 * On some platforms, the size of the slider's thumb can be
42
 * varied relative to the magnitude of the range of values it
43
 * represents (that is, relative to the difference between its
44
 * maximum and minimum values). Typically, this is used to
45
 * indicate some proportional value such as the ratio of the
46
 * visible area of a document to the total amount of space that
47
 * it would take to display it. SWT supports setting the thumb
48
 * size even if the underlying platform does not, but in this
49
 * case the appearance of the slider will not change.
50
 * </p>
51
 * <dl>
52
 * <dt><b>Styles:</b></dt>
53
 * <dd>HORIZONTAL, VERTICAL</dd>
54
 * <dt><b>Events:</b></dt>
55
 * <dd>Selection</dd>
56
 * </dl>
57
 * <p>
58
 * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
59
 * </p><p>
60
 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
61
 * </p>
62
 *
63
 * @see ScrollBar
64
 * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
65
 * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
66
 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
67
 * @since 1.2
68
 */
69
public class Slider extends Control {
70
	
71
  private final Point PREFERRED_SIZE = new Point( 170, 16 );
72
  
73
  private int increment;
74
  private int maximum;
75
  private int minimum;
76
  private int pageIncrement;
77
  private int selection;
78
  private int thumb;
79
80
  /**
81
   * Constructs a new instance of this class given its parent
82
   * and a style value describing its behavior and appearance.
83
   * <p>
84
   * The style value is either one of the style constants defined in
85
   * class <code>SWT</code> which is applicable to instances of this
86
   * class, or must be built by <em>bitwise OR</em>'ing together 
87
   * (that is, using the <code>int</code> "|" operator) two or more
88
   * of those <code>SWT</code> style constants. The class description
89
   * lists the style constants that are applicable to the class.
90
   * Style bits are also inherited from superclasses.
91
   * </p>
92
   *
93
   * @param parent a composite control which will be the parent of the new instance (cannot be null)
94
   * @param style the style of control to construct
95
   *
96
   * @exception IllegalArgumentException <ul>
97
   *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
98
   * </ul>
99
   * @exception SWTException <ul>
100
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
101
   *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
102
   * </ul>
103
   *
104
   * @see SWT#HORIZONTAL
105
   * @see SWT#VERTICAL
106
   * @see Widget#checkSubclass
107
   * @see Widget#getStyle
108
   */
109
  public Slider( final Composite parent, final int style ) {
110
  	super( parent, checkStyle (style) );
111
  	increment = 1;
112
    maximum = 100;
113
    minimum = 0;
114
    pageIncrement = 10;
115
    selection = 0;
116
    thumb = 10;
117
  }
118
  
119
  /**
120
   * Adds the listener to the collection of listeners who will
121
   * be notified when the user changes the receiver's value, by sending
122
   * it one of the messages defined in the <code>SelectionListener</code>
123
   * interface.
124
   * <p>
125
   * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
126
   * <code>SWT.NONE</code> - for the end of a drag.
127
   * <code>SWT.DRAG</code>.
128
   * <code>SWT.HOME</code>.
129
   * <code>SWT.END</code>.
130
   * <code>SWT.ARROW_DOWN</code>.
131
   * <code>SWT.ARROW_UP</code>.
132
   * <code>SWT.PAGE_DOWN</code>.
133
   * <code>SWT.PAGE_UP</code>.
134
   * <code>widgetDefaultSelected</code> is not called.
135
   * </p>
136
   *
137
   * @param listener the listener which should be notified when the user changes the receiver's value
138
   *
139
   * @exception IllegalArgumentException <ul>
140
   *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
141
   * </ul>
142
   * @exception SWTException <ul>
143
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
144
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
145
   * </ul>
146
   *
147
   * @see SelectionListener
148
   * @see #removeSelectionListener
149
   * @see SelectionEvent
150
   */
151
  public void addSelectionListener( final SelectionListener listener ) {
152
    SelectionEvent.addListener( this, listener );
153
  }
154
  
155
  /**
156
   * Removes the listener from the collection of listeners who will
157
   * be notified when the user changes the receiver's value.
158
   *
159
   * @param listener the listener which should no longer be notified
160
   *
161
   * @exception IllegalArgumentException <ul>
162
   *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
163
   * </ul>
164
   * @exception SWTException <ul>
165
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
166
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
167
   * </ul>
168
   *
169
   * @see SelectionListener
170
   * @see #addSelectionListener
171
   */
172
  public void removeSelectionListener( final SelectionListener listener ) {
173
    SelectionEvent.removeListener( this, listener );
174
  }  
175
  
176
  static int checkStyle( final int style ) {
177
  	return checkBits( style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0 );
178
  }
179
  
180
  public Point computeSize( final int wHint, 
181
                            final int hHint, 
182
                            final boolean changed ) 
183
  {
184
  	checkWidget();
185
    int width, height;
186
    if( ( style & SWT.HORIZONTAL ) != 0 ) {
187
      width = PREFERRED_SIZE.x;
188
      height = PREFERRED_SIZE.y;
189
    } else {
190
      width = PREFERRED_SIZE.y;
191
      height = PREFERRED_SIZE.x;
192
    }
193
    if( wHint != SWT.DEFAULT ) {
194
      width = wHint;
195
    }  
196
    if( hHint != SWT.DEFAULT ) {
197
      height = hHint;
198
    }
199
  	return new Point( width, height );
200
  }
201
  
202
  void createWidget() {
203
  	increment = 1;
204
  	pageIncrement = 10;
205
  	maximum = 100;
206
  	thumb = 10;
207
  }
208
  
209
  public boolean getEnabled() {
210
  	checkWidget();
211
  	return( state & DISABLED ) == 0;
212
  }
213
  
214
  /**
215
   * Returns the amount that the receiver's value will be
216
   * modified by when the up/down (or right/left) arrows
217
   * are pressed.
218
   *
219
   * @return the increment
220
   *
221
   * @exception SWTException <ul>
222
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
223
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
224
   * </ul>
225
   */
226
  public int getIncrement() {
227
  	checkWidget();
228
  	return increment;
229
  }
230
  
231
  /**
232
   * Returns the maximum value which the receiver will allow.
233
   *
234
   * @return the maximum
235
   *
236
   * @exception SWTException <ul>
237
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
238
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
239
   * </ul>
240
   */
241
  public int getMaximum() {
242
  	checkWidget();
243
  	return maximum;
244
  }
245
  
246
  /**
247
   * Returns the minimum value which the receiver will allow.
248
   *
249
   * @return the minimum
250
   *
251
   * @exception SWTException <ul>
252
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
253
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
254
   * </ul>
255
   */
256
  public int getMinimum() {
257
  	checkWidget();
258
  	return minimum;
259
  }
260
  
261
  /**
262
   * Returns the amount that the receiver's value will be
263
   * modified by when the page increment/decrement areas
264
   * are selected.
265
   *
266
   * @return the page increment
267
   *
268
   * @exception SWTException <ul>
269
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
270
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
271
   * </ul>
272
   */
273
  public int getPageIncrement() {
274
  	checkWidget();
275
  	return pageIncrement;
276
  }
277
  
278
  /**
279
   * Returns the 'selection', which is the receiver's value.
280
   *
281
   * @return the selection
282
   *
283
   * @exception SWTException <ul>
284
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
285
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
286
   * </ul>
287
   */
288
  public int getSelection() {
289
  	checkWidget();
290
  	return selection;
291
  }
292
  
293
  /**
294
   * Returns the size of the receiver's thumb relative to the
295
   * difference between its maximum and minimum values.
296
   *
297
   * @return the thumb value
298
   *
299
   * @exception SWTException <ul>
300
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
301
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
302
   * </ul>
303
   */
304
  public int getThumb() {
305
  	checkWidget();
306
  	return thumb;
307
  }
308
  
309
  /**
310
   * Sets the amount that the receiver's value will be
311
   * modified by when the up/down (or right/left) arrows
312
   * are pressed to the argument, which must be at least 
313
   * one.
314
   *
315
   * @param value the new increment (must be greater than zero)
316
   *
317
   * @exception SWTException <ul>
318
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
319
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
320
   * </ul>
321
   */
322
  public void setIncrement( final int value ) {
323
    checkWidget();
324
    if( value >= 1 && value <= maximum - minimum ) {
325
      increment = value;
326
    }
327
  }
328
  
329
  /**
330
   * Sets the maximum. If this value is negative or less than or
331
   * equal to the minimum, the value is ignored. If necessary, first
332
   * the thumb and then the selection are adjusted to fit within the
333
   * new range.
334
   *
335
   * @param value the new maximum, which must be greater than the current minimum
336
   *
337
   * @exception SWTException <ul>
338
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
339
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
340
   * </ul>
341
   */
342
  public void setMaximum( final int value ) {
343
    checkWidget();
344
    if( 0 <= minimum && minimum < value ) {
345
      maximum = value;
346
      if( selection > maximum - thumb ) {
347
        selection = maximum - thumb;
348
      }
349
    }
350
    if( thumb >= maximum - minimum ) {
351
      thumb = maximum - minimum;
352
      selection = minimum;
353
    }
354
  }
355
  
356
  /**
357
   * Sets the minimum value. If this value is negative or greater
358
   * than or equal to the maximum, the value is ignored. If necessary,
359
   * first the thumb and then the selection are adjusted to fit within
360
   * the new range.
361
   *
362
   * @param value the new minimum
363
   *
364
   * @exception SWTException <ul>
365
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
366
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
367
   * </ul>
368
   */
369
  public void setMinimum( final int value ) {
370
    checkWidget();
371
    if( 0 <= value && value < maximum ) {
372
      minimum = value;
373
      if( selection < minimum ) {
374
        selection = minimum;
375
      }
376
    }
377
    if( thumb >= maximum - minimum ) {
378
      thumb = maximum - minimum;
379
      selection = minimum;
380
    }
381
  }
382
  
383
  /**
384
   * Sets the amount that the receiver's value will be
385
   * modified by when the page increment/decrement areas
386
   * are selected to the argument, which must be at least
387
   * one.
388
   *
389
   * @param value the page increment (must be greater than zero)
390
   *
391
   * @exception SWTException <ul>
392
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
393
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
394
   * </ul>
395
   */
396
  public void setPageIncrement( final int value ) {
397
    checkWidget();
398
    if( value >= 1 && value <= maximum - minimum ) {
399
      pageIncrement = value;
400
    }
401
  }
402
  
403
  /**
404
   * Sets the 'selection', which is the receiver's
405
   * value, to the argument which must be greater than or equal
406
   * to zero.
407
   *
408
   * @param value the new selection (must be zero or greater)
409
   *
410
   * @exception SWTException <ul>
411
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
412
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
413
   * </ul>
414
   */
415
  public void setSelection( final int value ) {
416
    checkWidget();
417
    if( value < minimum ) {
418
      selection = minimum;
419
    } else if ( value > maximum - thumb ) {
420
      selection = maximum - thumb;
421
    } else {
422
      selection = value;
423
    }
424
  }
425
  
426
  /**
427
   * Sets the size of the receiver's thumb relative to the
428
   * difference between its maximum and minimum values.  This new
429
   * value will be ignored if it is less than one, and will be
430
   * clamped if it exceeds the receiver's current range.
431
   *
432
   * @param value the new thumb value, which must be at least one and not
433
   * larger than the size of the current range
434
   *
435
   * @exception SWTException <ul>
436
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
437
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
438
   * </ul>
439
   */
440
  public void setThumb( final int value ) {
441
  	checkWidget();
442
  	if( value >= 1 ) {
443
      thumb = value;
444
    }
445
  	if( value >= maximum - minimum ) {
446
  	  thumb = maximum - minimum;
447
  	  selection = minimum;
448
  	}
449
  }
450
  
451
  /**
452
   * Sets the receiver's selection, minimum value, maximum
453
   * value, thumb, increment and page increment all at once.
454
   * <p>
455
   * Note: This is similar to setting the values individually
456
   * using the appropriate methods, but may be implemented in a 
457
   * more efficient fashion on some platforms.
458
   * </p>
459
   *
460
   * @param selection the new selection value
461
   * @param minimum the new minimum value
462
   * @param maximum the new maximum value
463
   * @param thumb the new thumb value
464
   * @param increment the new increment value
465
   * @param pageIncrement the new pageIncrement value
466
   *
467
   * @exception SWTException <ul>
468
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
469
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
470
   * </ul>
471
   */
472
  public void setValues( final int selection, 
473
                         final int minimum, 
474
                         final int maximum, 
475
                         final int thumb, 
476
                         final int increment, 
477
                         final int pageIncrement ) 
478
  {
479
  	checkWidget();
480
  	if( selection >= minimum && selection <= maximum ) {
481
  	  this.selection = selection;
482
    }
483
    if( 0 <= minimum && minimum < maximum ) {
484
      this.minimum = minimum;
485
      if( selection < minimum ) {
486
        this.selection = minimum;
487
      }
488
    }
489
    if( 0 <= minimum && minimum < maximum ) {
490
      this.maximum = maximum;
491
      if( selection > maximum - thumb ) {
492
        this.selection = maximum - thumb;
493
      }
494
    }
495
    if( thumb >= 1 ) {
496
      this.thumb = thumb;
497
    }
498
    if( increment >= 1 && increment <= ( maximum - minimum ) ) {
499
      this.increment = increment;
500
    }
501
    if( pageIncrement >= 1 && pageIncrement <= ( maximum - minimum ) ) {
502
      this.pageIncrement = pageIncrement;
503
    }
504
    if( thumb >= maximum - minimum ) {
505
      this.thumb = maximum - minimum;
506
      this.selection = minimum;
507
    }
508
  }
509
510
}
(-)src/org/eclipse/swt/internal/widgets/sliderkit/Slider.theme.xml (+80 lines)
Added Link Here
1
<?xml version="1.0" encoding="iso-8859-1" ?>
2
<!--
3
 Copyright (c) 2008 Innoopract Informationssysteme GmbH.
4
 All rights reserved. This program and the accompanying materials
5
 are made available under the terms of the Eclipse Public License v1.0
6
 which accompanies this distribution, and is available at
7
 http://www.eclipse.org/legal/epl-v10.html
8
9
 Contributors:
10
     Innoopract Informationssysteme GmbH - initial API and implementation
11
 -->
12
13
<theme>
14
15
  <element name="Slider"
16
      description="Slider controls">
17
18
    <property name="background-color"
19
        type="color"
20
        description="Background color for slider" />
21
22
    <element name="Slider-Thumb"
23
        description="The movable thumb">
24
25
      <property name="background-color"
26
          type="color"
27
          description="Background color for slider thumb" />
28
      
29
      <property name="border"
30
          type="border"
31
          description="Thumb border" />
32
          
33
      <state name="pressed"
34
          description="On thumb pressed" />      
35
36
    </element>
37
    
38
    <element name="Slider-MinButton"
39
        description="The button for decreasing selection value">
40
41
      <property name="background-color"
42
          type="color"
43
          description="Background color for min button" />
44
      
45
      <property name="background-image"
46
          type="image"
47
          description="Icon of the min button - horizontal.
48
                       The max size of the image should be 16 x 16 pixels." />
49
          
50
      <state name="hover"
51
          description="On button roll over" />
52
      
53
      <state name="horizontal"
54
          description="Indicates that the slider is in horizontal state." />    
55
56
    </element>
57
    
58
    <element name="Slider-MaxButton"
59
        description="The button for increasing selection value">
60
61
      <property name="background-color"
62
          type="color"
63
          description="Background color for max button" />
64
          
65
      <property name="background-image"
66
          type="image"
67
          description="Icon of the max button - horizontal.
68
                       The max size of the image should be 16 x 16 pixels." />
69
          
70
      <state name="hover"
71
          description="On button roll over" />
72
          
73
      <state name="horizontal"
74
          description="Indicates that the slider is in horizontal state." />    
75
76
    </element>
77
78
  </element>
79
80
</theme>

Return to bug 256740