home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / sdkjava.exe / SDKJava.cab / AFC102 / Samples / Scrolls / Src / SliderPnl.java < prev    next >
Encoding:
Java Source  |  1998-03-05  |  1.5 KB  |  58 lines

  1. //
  2. // (c) 1997 Microsoft Corporation.  All rights reserved.
  3. //
  4. import java.awt.Insets;
  5. import com.ms.ui.*;
  6.  
  7. public class SliderPnl extends UIPanel implements SDKConsts
  8. {
  9.     public UISlider ctrl, start, end;
  10.  
  11.     public SliderPnl()
  12.     {
  13.         setLayout(new UIBorderLayout());
  14.  
  15.         ctrl = new UISlider(UISlider.RANGESELECT | UISlider.VERTICAL,
  16.                                 0, MAX_SCROLL, 16, 1, INIT_POS, 16);
  17.         start = new UISlider(UISlider.POINTDOWN | UISlider.VERTICAL,
  18.                                 0, MAX_SCROLL, 16, 1, SEL_START, 16);
  19.         end = new UISlider(UISlider.POINTUP | UISlider.VERTICAL,
  20.                                 0, MAX_SCROLL, 16, 1, SEL_END, 16);
  21.         ctrl.setSelection(SEL_START, SEL_END);
  22.  
  23.         // Create UIGroup for sliders    
  24.         UIGroup group = new UIGroup("UISlider"); group.setLayout(new UIBorderLayout());
  25.         SDKInsetPanelBL ipnl = new SDKInsetPanelBL(8,10,8,10);
  26.         ipnl.add(start, "west"); ipnl.add(ctrl, "center"); ipnl.add(end, "east");
  27.         group.add(ipnl, "center"); add(group, "center");
  28.     }
  29.  
  30.     public void setSelectionStart()
  31.     {
  32.         int startsel = start.getScrollPos();
  33.         int endsel = end.getScrollPos();
  34.  
  35.         if ( startsel > endsel ) {
  36.             end.setScrollPos(startsel);
  37.             ctrl.setSelection(startsel, startsel);
  38.         }
  39.         else
  40.             ctrl.setSelectionStart(startsel);
  41.     }
  42.  
  43.     public void setSelectionEnd()
  44.     {
  45.         int startsel = start.getScrollPos();
  46.         int endsel = end.getScrollPos();
  47.  
  48.         if ( startsel > endsel ) {
  49.             start.setScrollPos(endsel);
  50.             ctrl.setSelection(endsel, endsel);
  51.         }
  52.         else
  53.             ctrl.setSelectionEnd(endsel);
  54.     }
  55.  
  56.     public Insets getInsets() { return new Insets(0,10,0,0); }
  57. }
  58.