src/java.desktop/unix/classes/sun/awt/X11/XScrollbar.java

Print this page




  34 
  35 /**
  36 * A simple vertical scroll bar.
  37 */
  38 abstract class XScrollbar {
  39 
  40     private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XScrollbar");
  41     /**
  42      * The thread that asynchronously tells the scrollbar to scroll.
  43      * @see #startScrolling
  44      */
  45     private static XScrollRepeater scroller = new XScrollRepeater(null);
  46     /*
  47      * The repeater that used for concurrent scrolling of the vertical and horizontal scrollbar
  48      * And so there is not static keyword
  49      * See 6243382 for more information
  50      */
  51     private XScrollRepeater i_scroller = new XScrollRepeater(null);
  52 
  53     // Thumb length is always >= MIN_THUMB_H
  54     private final static int MIN_THUMB_H = 5;
  55 
  56     private static final int ARROW_IND = 1;
  57 
  58     XScrollbarClient sb;
  59 
  60     //Use set methods to set scrollbar parameters
  61     private int val;
  62     private int min;
  63     private int max;
  64     private int vis;
  65 
  66     private int line;
  67     private int page;
  68     private boolean needsRepaint = true;
  69     private boolean pressed = false;
  70     private boolean dragging = false;
  71 
  72     Polygon firstArrow, secondArrow;
  73 
  74     int width, height; // Dimensions of the visible part of the parent window


  98         notifyValue(v, false);
  99     }
 100 
 101     void notifyValue(int v, final boolean isAdjusting) {
 102         if (v < min) {
 103             v = min;
 104         } else if (v > max - vis) {
 105             v = max - vis;
 106         }
 107         final int value = v;
 108         final int mode = this.mode;
 109         if ((sb != null) && ((value != val)||(!pressed))) {
 110             SunToolkit.executeOnEventHandlerThread(sb.getEventSource(), new Runnable() {
 111                     public void run() {
 112                         sb.notifyValue(XScrollbar.this, mode, value, isAdjusting);
 113                     }
 114                 });
 115         }
 116     }
 117 
 118     abstract protected void rebuildArrows();
 119 
 120     public void setSize(int width, int height) {
 121         if (log.isLoggable(PlatformLogger.Level.FINER)) {
 122             log.finer("Setting scroll bar " + this + " size to " + width + "x" + height);
 123         }
 124         this.width = width;
 125         this.height = height;
 126     }
 127 
 128     /**
 129      * Creates oriented directed arrow
 130      */
 131     protected Polygon createArrowShape(boolean vertical, boolean up) {
 132         Polygon arrow = new Polygon();
 133         // TODO: this should be done polymorphically in subclasses
 134         // FIXME: arrows overlap the thumb for very wide scrollbars
 135         if (vertical) {
 136             int x = width / 2 - getArrowWidth()/2;
 137             int y1 = (up ? ARROW_IND : barLength - ARROW_IND);
 138             int y2 = (up ? getArrowWidth() : barLength - getArrowWidth() - ARROW_IND);




  34 
  35 /**
  36 * A simple vertical scroll bar.
  37 */
  38 abstract class XScrollbar {
  39 
  40     private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XScrollbar");
  41     /**
  42      * The thread that asynchronously tells the scrollbar to scroll.
  43      * @see #startScrolling
  44      */
  45     private static XScrollRepeater scroller = new XScrollRepeater(null);
  46     /*
  47      * The repeater that used for concurrent scrolling of the vertical and horizontal scrollbar
  48      * And so there is not static keyword
  49      * See 6243382 for more information
  50      */
  51     private XScrollRepeater i_scroller = new XScrollRepeater(null);
  52 
  53     // Thumb length is always >= MIN_THUMB_H
  54     private static final int MIN_THUMB_H = 5;
  55 
  56     private static final int ARROW_IND = 1;
  57 
  58     XScrollbarClient sb;
  59 
  60     //Use set methods to set scrollbar parameters
  61     private int val;
  62     private int min;
  63     private int max;
  64     private int vis;
  65 
  66     private int line;
  67     private int page;
  68     private boolean needsRepaint = true;
  69     private boolean pressed = false;
  70     private boolean dragging = false;
  71 
  72     Polygon firstArrow, secondArrow;
  73 
  74     int width, height; // Dimensions of the visible part of the parent window


  98         notifyValue(v, false);
  99     }
 100 
 101     void notifyValue(int v, final boolean isAdjusting) {
 102         if (v < min) {
 103             v = min;
 104         } else if (v > max - vis) {
 105             v = max - vis;
 106         }
 107         final int value = v;
 108         final int mode = this.mode;
 109         if ((sb != null) && ((value != val)||(!pressed))) {
 110             SunToolkit.executeOnEventHandlerThread(sb.getEventSource(), new Runnable() {
 111                     public void run() {
 112                         sb.notifyValue(XScrollbar.this, mode, value, isAdjusting);
 113                     }
 114                 });
 115         }
 116     }
 117 
 118     protected abstract void rebuildArrows();
 119 
 120     public void setSize(int width, int height) {
 121         if (log.isLoggable(PlatformLogger.Level.FINER)) {
 122             log.finer("Setting scroll bar " + this + " size to " + width + "x" + height);
 123         }
 124         this.width = width;
 125         this.height = height;
 126     }
 127 
 128     /**
 129      * Creates oriented directed arrow
 130      */
 131     protected Polygon createArrowShape(boolean vertical, boolean up) {
 132         Polygon arrow = new Polygon();
 133         // TODO: this should be done polymorphically in subclasses
 134         // FIXME: arrows overlap the thumb for very wide scrollbars
 135         if (vertical) {
 136             int x = width / 2 - getArrowWidth()/2;
 137             int y1 = (up ? ARROW_IND : barLength - ARROW_IND);
 138             int y2 = (up ? getArrowWidth() : barLength - getArrowWidth() - ARROW_IND);