Coverage Report - org.eclipse.swtbot.swt.finder.widgets.SWTBotScale
 
Classes in this File Line Coverage Branch Coverage Complexity
SWTBotScale
86%
13/15
N/A
1
SWTBotScale$1
100%
3/3
N/A
1
SWTBotScale$2
100%
4/4
N/A
1
SWTBotScale$3
100%
3/3
N/A
1
SWTBotScale$4
100%
3/3
N/A
1
SWTBotScale$5
100%
3/3
N/A
1
SWTBotScale$6
100%
3/3
N/A
1
 
 1  1
 /*******************************************************************************
 2  
  * Copyright (c) 2011 SWTBot Committers and others.
 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  
  *     John Cortell - initial API and implementation
 10  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.swt.finder.widgets;
 12  
 
 13  
 import org.eclipse.swt.SWT;
 14  
 import org.eclipse.swt.widgets.Scale;
 15  
 import org.eclipse.swtbot.swt.finder.ReferenceBy;
 16  
 import org.eclipse.swtbot.swt.finder.SWTBotWidget;
 17  
 import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
 18  
 import org.eclipse.swtbot.swt.finder.results.IntResult;
 19  
 import org.eclipse.swtbot.swt.finder.results.VoidResult;
 20  
 import org.eclipse.swtbot.swt.finder.utils.MessageFormat;
 21  
 import org.hamcrest.SelfDescribing;
 22  
 
 23  
 /**
 24  
  * Represents a scale
 25  
  * 
 26  
  * @author John Cortell
 27  
  */
 28  
 @SWTBotWidget(clasz = Scale.class, preferredName = "scale", referenceBy = { ReferenceBy.LABEL, ReferenceBy.TEXT, ReferenceBy.TOOLTIP })
 29  
 public class SWTBotScale extends AbstractSWTBot<Scale> {
 30  
 
 31  
         /**
 32  
          * Constructs a new instance with the given widget.
 33  
          * 
 34  
          * @param widget the widget.
 35  
          * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
 36  
          */
 37  
         public SWTBotScale(Scale widget) throws WidgetNotFoundException {
 38  0
                 super(widget);
 39  0
         }
 40  
 
 41  
         /**
 42  
          * Constructs an instance with the given widget
 43  
          * 
 44  
          * @param widget the widget.
 45  
          * @param description the description of the widget, this will be reported by {@link #toString()}
 46  
          * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
 47  
          */
 48  
         public SWTBotScale(Scale widget, SelfDescribing description) throws WidgetNotFoundException {
 49  9
                 super(widget, description);
 50  9
         }
 51  
 
 52  
         /**
 53  
          * Return the current value of the scale.
 54  
          * 
 55  
          * @return the current selection in the scale.
 56  
          */
 57  
         public int getValue() {
 58  2
                 return syncExec(new IntResult() {
 59  
                         public Integer run() {
 60  2
                                 return widget.getSelection();
 61  
                         }
 62  
                 });
 63  
         }
 64  
 
 65  
         /**
 66  
          * Set the selection to the specified value.
 67  
          * 
 68  
          * @param value the value to set into the scale.
 69  
          */
 70  
         public void setValue(final int value) {
 71  1
                 log.debug(MessageFormat.format("Setting selection on {0} to {1}", this, value)); //$NON-NLS-1$
 72  1
                 waitForEnabled();
 73  1
                 asyncExec(new VoidResult() {
 74  
                         public void run() {
 75  1
                                 widget.setSelection(value);
 76  1
                         }
 77  
                 });
 78  1
                 notify(SWT.Selection);
 79  1
                 log.debug(MessageFormat.format("Set selection on {0} to {1}", this, value)); //$NON-NLS-1$
 80  1
         }
 81  
 
 82  
         /**
 83  
          * Return the maximum value the scale will accept.
 84  
          * 
 85  
          * @return the maximum of the scale.
 86  
          */
 87  
         public int getMaximum() {
 88  1
                 return syncExec(new IntResult() {
 89  
                         public Integer run() {
 90  1
                                 return widget.getMaximum();
 91  
                         }
 92  
                 });
 93  
         }
 94  
 
 95  
         /**
 96  
          * Return the minimum value the scale will accept.
 97  
          * 
 98  
          * @return the minimum of the scale.
 99  
          */
 100  
         public int getMinimum() {
 101  1
                 return syncExec(new IntResult() {
 102  
                         public Integer run() {
 103  1
                                 return widget.getMinimum();
 104  
                         }
 105  
                 });
 106  
         }
 107  
 
 108  
         /**
 109  
          * Return the increment of the scale.
 110  
          * 
 111  
          * @return the increment of the scale.
 112  
          */
 113  
         public int getIncrement() {
 114  1
                 return syncExec(new IntResult() {
 115  
                         public Integer run() {
 116  1
                                 return widget.getIncrement();
 117  
                         }
 118  
                 });
 119  
         }
 120  
 
 121  
         /**
 122  
          * Return the page increment of the scale.
 123  
          * 
 124  
          * @return the increment of the scale.
 125  
          */
 126  
         public int getPageIncrement() {
 127  1
                 return syncExec(new IntResult() {
 128  
                         public Integer run() {
 129  1
                                 return widget.getPageIncrement();
 130  
                         }
 131  
                 });
 132  
         }
 133  
 }