1 /* 2 * Copyright (c) 2006 Stiftung Deutsches Elektronen-Synchroton, 3 * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY. 4 * 5 * THIS SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "../AS IS" BASIS. 6 * WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED 7 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR PARTICULAR PURPOSE AND 8 * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 9 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 10 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 11 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. SHOULD THE SOFTWARE PROVE DEFECTIVE 12 * IN ANY RESPECT, THE USER ASSUMES THE COST OF ANY NECESSARY SERVICING, REPAIR OR 13 * CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. 14 * NO USE OF ANY SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. 15 * DESY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, 16 * OR MODIFICATIONS. 17 * THE FULL LICENSE SPECIFYING FOR THE SOFTWARE THE REDISTRIBUTION, MODIFICATION, 18 * USAGE AND OTHER RIGHTS AND OBLIGATIONS IS INCLUDED WITH THE DISTRIBUTION OF THIS 19 * PROJECT IN THE FILE LICENSE.HTML. IF THE LICENSE IS NOT INCLUDED YOU MAY FIND A COPY 20 * AT HTTP://WWW.DESY.DE/LEGAL/LICENSE.HTM 21 */ 22 23 package de.desy.acop.demo.example; 24 25 import java.awt.Color; 26 import java.beans.PropertyVetoException; 27 28 import com.cosylab.gui.adapters.Converter; 29 import com.cosylab.gui.adapters.ConverterChain; 30 import com.cosylab.gui.adapters.LinearConverter; 31 import com.cosylab.gui.adapters.LogarithmicConverter; 32 import com.cosylab.gui.components.SliderSetMode; 33 import com.cosylab.gui.components.Slider.Button; 34 import com.cosylab.gui.components.util.IconHelper; 35 import com.cosylab.util.CommonException; 36 37 import de.desy.acop.displayers.AcopSlider; 38 import de.desy.acop.transport.AccessMode; 39 import de.desy.acop.transport.ConnectionParameters; 40 41 public class SliderExample { 42 43 public static void main(String[] args) { 44 45 //How to connect slider to a remote property? 46 //First we create an instance of the AcopSlider object. 47 AcopSlider slider = new AcopSlider(); 48 //We require ConnectionParameters which describe the remote property 49 ConnectionParameters parameters = new ConnectionParameters("TINE", 50 "context", "server", "device", "property", AccessMode.POLL, 1000); 51 //These parameters describe a remote property 'context/server/device/property' 52 //in the TINE control system. We will request a constant monitoring, 53 //therefore AccessMode.POLL was used. Polling rate is set to 1000 milliseconds, 54 //which means that value on the slider will be updated every 1000 milliseconds. 55 //Parameters are then attached to the slider. Connection is created automatically. 56 try { 57 slider.setConnectionParameters(parameters); 58 } catch (CommonException e) { 59 e.printStackTrace(); 60 } catch (PropertyVetoException e) { 61 e.printStackTrace(); 62 } 63 //If no exception occurred, slider should show the remote value. 64 65 66 //The slider will set the value on the property each time when a user 67 //drags the slider thumb. We want to avoid the overload and only change the 68 //value when one releases the thumb. 69 slider.setSetMode(SliderSetMode.SET_ON_RELEASE); 70 //Or we can use a set button to send values. In this case a value will be 71 //sent only after the set button will be pressed. The current thumb position will 72 //be set. 73 slider.setSetMode(SliderSetMode.SET_MANUAL); 74 75 76 //The navigation buttons are moving thumb in too small steps. We want to change 77 //the '+' button command to change the value for 2% of the total slider extent 78 //If (slider max - slider min = 500) then 2% of this is 10. 79 slider.setBitStepRelative(true); 80 slider.setBitStep(2.0); 81 //Or we want to explicitly define that the thumb should move for 11 points 82 //when the button is pressed 83 slider.setBitStepRelative(false); 84 slider.setBitStep(11); 85 //Similarly we can program the the 'forward' and 'fastForward' buttons. We want 86 //the forward button to move the thumb for 32.1 units and the fast forward for 87 //53.8 units 88 slider.setSmallStepRelative(false); 89 slider.setSmallStep(32.1); 90 slider.setLargeStepRelative(false); 91 slider.setLargeStep(53.8); 92 93 //The incoming values are too large (large exponents) and have a large extent. 94 //We want to show values in more readable form. Let us show the logarithm of 95 //the value. For this we will use a logarithmic converter with logarithm base 10: 96 LogarithmicConverter logConverter = new LogarithmicConverter(10); 97 try { 98 slider.setConverter(logConverter); 99 } catch (PropertyVetoException e) { 100 e.printStackTrace(); 101 } 102 //Instead of real value 'x' slider will now show log_10(x). 103 //Similarly we can shift the values to be comparable with some other property. 104 //We will use linear converter: 105 LinearConverter linConverter = new LinearConverter(5,4); 106 try { 107 slider.setConverter(linConverter); 108 } catch (PropertyVetoException e) { 109 e.printStackTrace(); 110 } 111 //Instead of value 'x' slider will now show 5 x + 4. We can even combine both 112 //converters into a single one. 113 try { 114 ConverterChain chain = new ConverterChain(new Converter[]{logConverter, linConverter}); 115 slider.setConverter(chain); 116 } catch (PropertyVetoException e) { 117 e.printStackTrace(); 118 } 119 //Slider will now show 5 (log_10(x)) + 4. 120 121 //If slider is used to show a value that changes because of a 3rd party, 122 //we don't want the slider thumb to be out of sync each time the value 123 //changes, but want the thumb to move together with the slider. We will 124 //set the automatic synchronization with 5 seconds time 125 slider.setAutoSynchronize(true); 126 slider.setAutoSynchronizeDelay(5000); 127 //or if we don't want to change the values at all (just use the slider 128 //as a monitor displayer) we can put slider in read only mode 129 slider.setEditable(false); 130 //Or we can set slider to use only one thumb to present a value. In this 131 //case the trailer shadow will not be painted. The thumb of the slider can 132 //be dragged to any position and that value will be set on the slider. 133 //However, when response is received from the connection point, the thumb 134 //will move to the actual value of the property. 135 slider.setSyncButtonVisible(false); 136 137 //Let's say that we have good settings on the properties, but would like to 138 //fine tune it. However, if tuning produces worse results than the current 139 //state of the machine we want to restore the value. First we have to 140 //store the value. This can be done in two way: one can store the current 141 //slider readback value 142 slider.storeValue(); 143 //or explicitely define a value 144 slider.setStoredValue(100.); 145 //At any later time we can restore the value to the last stored value 146 slider.restoreValue(); 147 //We can also enable store and restore buttons which can be used in runtime 148 //to store or restore the value. The store button will always store current 149 //readback value. 150 slider.setStorageButtonsVisible(true); 151 152 //Slider will display ticks along the slider line according to the space 153 //available. If one is not satisfied with automatic tick configurations, 154 //ticks can be explicitely defined. First we have to provide which values 155 //will be marked as major ticks 156 slider.setMajorTicks(new double[]{0,20,40,60,80,100}); 157 //Then we define which of these major ticks will have value labels printed 158 slider.setMajorTickLabels(new double[]{0,40,60,100}); 159 //At last we define, the step of the minor ticks (distance between two minor 160 //ticks) 161 slider.setMinorTicksStep(5); 162 163 //Slider can operate in continuous mode, meaning that on button press 164 //and hold, value will be automatically incremented/decremented 165 //accordig to the step defined by which button is used. 166 //ContinuousModeDelayTime time defines the initial delay time in 167 //milliseconds between button press and first automatic repetition. 168 //ContinuousModeRepeatTime defines the time interval in milliseconds 169 //between two repetitions. 170 //If ContinuousControlVisible is set to false, user will not be able 171 //to engage or disengage auto incrementation/decremtnation, but the 172 //mode of operation will remain. 173 174 slider.setContinuousModeDelayTime(1000); 175 slider.setContinuousModeRepeatTime(100); 176 177 slider.setContinuousModeEnabled(true); 178 slider.setContinuousControlVisible(true); 179 180 //When setting the value on the slider, the position of the slider will 181 //show the exact value as set by the data source or through UI, even if 182 //the provided value does not fall to the tick printed on the slider. 183 //If one want the slider to snap to the tick value, snap to ticks option 184 //can be switched on. 185 slider.setSnapToTicks(true); 186 187 //TooltipText 188 //String provided will be set as tooltip text to the surrounding 189 //area not regarding button and other similar control components. 190 slider.setToolTipText("Value"); 191 192 //Button icons 193 //Navigation button icons can be changed, by supplying the button 194 //enumeration and Icon object. 195 slider.setButtonIcon(Button.BIT_DECREMENT, IconHelper.createIcon("icons/navigation/ArrowLeft16.gif")); 196 197 //Button text 198 //Navigation button text can be changed or added, by supplying the 199 //button enumeration and string containing the desired text. 200 201 slider.setButtonText(Button.BIT_DECREMENT, "Bit decrement"); 202 203 //Other properties of the slider can also simply be adjusted by calling the 204 //appropriate setter methods. These properties include maximum/minimum value 205 //background/foreground color, title etc.: 206 slider.setMaximum(100); 207 slider.setMinimum(5.2); 208 slider.setBackground(Color.RED); 209 slider.setForeground(Color.GREEN); 210 } 211 }