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

  1. //
  2. // (c) 1997 Microsoft Corporation.  All rights reserved.
  3. //
  4. import java.awt.Event;
  5. import java.awt.Image;
  6. import java.awt.Insets;
  7. import com.ms.ui.*;
  8.  
  9. public class SDKCtrlPnl extends UIPanel implements SDKConsts, SDKCallbacks
  10. {
  11.     private SpinnerPnl spinner;
  12.     private ScrollBarPnl scroll;
  13.     private SpinnerEditPnl spinedit;
  14.     private SliderPnl slider;
  15.     private ProgressPnl progress;
  16.  
  17.     public SDKCtrlPnl(UIApplet applet, UIFrame frame)
  18.     {
  19.         setLayout(new UIBorderLayout(0,0));
  20.  
  21.         // Initialized load on demand images
  22.         SDKImages.init(applet, frame);
  23.  
  24.         // Create a UIPanel for each demonstrated control
  25.         spinner = new SpinnerPnl(); spinedit = new SpinnerEditPnl();
  26.         scroll = new ScrollBarPnl();    slider = new SliderPnl();
  27.         progress = new ProgressPnl();
  28.  
  29.         // Create main UIGroup, add to this panel...
  30.         SDKInsetGroup main = new SDKInsetGroup("The dead c SCROLLS", 20, 10, 10, 10);
  31.         // ...and split it vertically.
  32.         main.setLayout(new UISplitLayout(0, 240));
  33.  
  34.         // Create panel for left side of main panel...
  35.         SDKInsetPanel nwmain = new SDKInsetPanel();
  36.         // ...and split it horizontally.
  37.         nwmain.setLayout(new UISplitLayout(UISplitLayout.HORIZONTAL, 80));
  38.  
  39.         // Create panel for top half of nwmain panel...
  40.         SDKInsetPanel nwnwmain = new SDKInsetPanel();
  41.         // ... and split it vertically.
  42.         nwnwmain.setLayout(new UISplitLayout(0, 115));
  43.  
  44.         // Create panel for bottom half of nwmain panel...
  45.         SDKInsetPanel senwmain = new SDKInsetPanel();
  46.         // ...and split it horizontally.
  47.         senwmain.setLayout(new UISplitLayout(UISplitLayout.HORIZONTAL, 85));
  48.  
  49.         // add panels to desired locations
  50.         add(main, "Center");
  51.         main.add(nwmain, "nw"); main.add(slider, "se");
  52.         nwmain.add(nwnwmain, "nw"); nwmain.add(senwmain, "se");
  53.         nwnwmain.add(spinner, "nw"); nwnwmain.add(spinedit, "se");
  54.         senwmain.add(scroll, "nw"); senwmain.add(progress, "se");
  55.     }
  56.  
  57.     public void setInitialFocus()
  58.     {
  59.     }
  60.  
  61.     public boolean handleEvent(Event evt)
  62.     {
  63.         int pos, start, end;
  64.  
  65.         switch (evt.id)
  66.         {
  67.             case Event.SCROLL_LINE_UP:
  68.             case Event.SCROLL_LINE_DOWN:
  69.             case Event.SCROLL_PAGE_UP:
  70.             case Event.SCROLL_PAGE_DOWN:
  71.             case Event.SCROLL_ABSOLUTE:
  72.                 if ( evt.arg == spinner.ctrl ) {
  73.                     pos = spinner.ctrl.getScrollPos(); spinner.setImage(pos);
  74.                     spinedit.ctrl.setScrollPos(pos); scroll.ctrl.setScrollPos(pos);
  75.                     slider.ctrl.setScrollPos(MAX_SCROLL - pos);
  76.                     progress.ctrl.setPos(pos);
  77.                 }
  78.                 else if ( evt.arg == spinedit.ctrl ) {
  79.                     pos = spinedit.ctrl.getScrollPos();
  80.                     spinedit.ctrl.setScrollPos(pos);
  81.                     spinner.ctrl.setScrollPos(pos); spinner.setImage(pos);
  82.                     scroll.ctrl.setScrollPos(pos);
  83.                     slider.ctrl.setScrollPos(MAX_SCROLL-pos);
  84.                     progress.ctrl.setPos(pos);
  85.                 }
  86.                 else if ( evt.arg == scroll.ctrl ) {
  87.                     pos = scroll.ctrl.getScrollPos();
  88.                     spinner.ctrl.setScrollPos(pos); spinner.setImage(pos);
  89.                     spinedit.ctrl.setScrollPos(pos);
  90.                     slider.ctrl.setScrollPos(MAX_SCROLL-pos);
  91.                     progress.ctrl.setPos(pos);
  92.                 }
  93.                 else if ( evt.arg == slider.ctrl ) {
  94.                     pos = MAX_SCROLL - slider.ctrl.getScrollPos();
  95.                     spinner.ctrl.setScrollPos(pos); spinner.setImage(pos);
  96.                     spinedit.ctrl.setScrollPos(pos); scroll.ctrl.setScrollPos(pos);
  97.                     progress.ctrl.setPos(pos);
  98.                 }
  99.                 else if ( evt.arg == slider.start )
  100.                     slider.setSelectionStart();
  101.                 else if ( evt.arg == slider.end )
  102.                     slider.setSelectionEnd();
  103.                 break;
  104.         }             
  105.         return super.handleEvent(evt);
  106.     }
  107.  
  108.     public Insets getInsets() { return new Insets(5,5,5,5); }
  109. }
  110.  
  111. class SDKInsetGroup extends UIGroup
  112. {
  113.     private int t, l, b, r;
  114.  
  115.     public SDKInsetGroup(String title, int t, int l, int b, int r)
  116.     {
  117.         super(title);
  118.         this.t = t; this.l = l; this.b = b; this.r = r;
  119.     }
  120.  
  121.     public Insets getInsets() { return new Insets(t, l, b, r); }
  122. }