src/solaris/classes/sun/awt/X11/XScrollbar.java

Print this page




 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.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);
 139             arrow.addPoint(x + getArrowWidth()/2, y1);
 140             arrow.addPoint(x + getArrowWidth(), y2);
 141             arrow.addPoint(x, y2);


 149             arrow.addPoint(x2, y);
 150             arrow.addPoint(x1, y + getArrowWidth()/2);
 151         }
 152         return arrow;
 153     }
 154 
 155     /**
 156      * Gets the area of the scroll track
 157      */
 158     protected abstract Rectangle getThumbArea();
 159 
 160     /**
 161      * paint the scrollbar
 162      * @param g the graphics context to paint into
 163      * @param colors the colors to use when painting the scrollbar
 164      * @param width the width of the scrollbar
 165      * @param height the height of the scrollbar
 166      * @param paintAll paint the whole scrollbar if true, just the thumb is false
 167      */
 168     void paint(Graphics g, Color colors[], boolean paintAll) {
 169         if (log.isLoggable(PlatformLogger.FINER)) {
 170             log.finer("Painting scrollbar " + this);
 171         }
 172 
 173         boolean useBufferedImage = false;
 174         Graphics2D g2 = null;
 175         BufferedImage buffer = null;
 176         if (!(g instanceof Graphics2D)) {
 177             // Fix for 5045936, 5055171. While printing, g is an instance
 178             //   of sun.print.ProxyPrintGraphics which extends Graphics.
 179             //   So we use a separate buffered image and its graphics is
 180             //   always Graphics2D instance
 181             X11GraphicsConfig graphicsConfig = (X11GraphicsConfig)(sb.getEventSource().getGraphicsConfiguration());
 182             buffer = graphicsConfig.createCompatibleImage(width, height);
 183             g2 = buffer.createGraphics();
 184             useBufferedImage = true;
 185         } else {
 186             g2 = (Graphics2D)g;
 187         }
 188         try {
 189             Rectangle thumbRect = calculateThumbRect();


 322         }
 323         else {
 324             g.fill(secondArrow);
 325             g.setColor(darkShadow);
 326             g.drawLine(secondArrow.xpoints[0],secondArrow.ypoints[0],
 327                     secondArrow.xpoints[1],secondArrow.ypoints[1]);
 328             g.setColor(lightShadow);
 329             g.drawLine(secondArrow.xpoints[1],secondArrow.ypoints[1],
 330                     secondArrow.xpoints[2],secondArrow.ypoints[2]);
 331             g.drawLine(secondArrow.xpoints[2],secondArrow.ypoints[2],
 332                     secondArrow.xpoints[0],secondArrow.ypoints[0]);
 333 
 334         }
 335 
 336     }
 337 
 338     /**
 339      * Tell the scroller to start scrolling.
 340      */
 341     void startScrolling() {
 342         if (log.isLoggable(PlatformLogger.FINER)) {
 343             log.finer("Start scrolling on " + this);
 344         }
 345         // Make sure that we scroll at least once
 346         scroll();
 347 
 348         // wake up the scroll repeater
 349         if (scroller == null) {
 350             // If there isn't a scroller, then create
 351             // one and start it.
 352             scroller = new XScrollRepeater(this);
 353         } else {
 354             scroller.setScrollbar(this);
 355         }
 356         scroller.start();
 357     }
 358 
 359     /**
 360      * Tell the instance scroller to start scrolling.
 361      * See 6243382 for more information
 362      */
 363     void startScrollingInstance() {
 364         if (log.isLoggable(PlatformLogger.FINER)) {
 365             log.finer("Start scrolling on " + this);
 366         }
 367         // Make sure that we scroll at least once
 368         scroll();
 369 
 370         i_scroller.setScrollbar(this);
 371         i_scroller.start();
 372     }
 373 
 374     /**
 375      * Tell the instance scroller to stop scrolling.
 376      * See 6243382 for more information
 377      */
 378     void stopScrollingInstance() {
 379         if (log.isLoggable(PlatformLogger.FINER)) {
 380             log.finer("Stop scrolling on " + this);
 381         }
 382 
 383         i_scroller.stop();
 384     }
 385 
 386     /**
 387      * The set method for mode property.
 388      * See 6243382 for more information
 389      */
 390     public void setMode(int mode){
 391         this.mode = mode;
 392     }
 393 
 394     /**
 395      * Scroll one unit.
 396      * @see notifyValue
 397      */
 398     void scroll() {
 399         switch (mode) {


 447     }
 448 
 449     abstract boolean beforeThumb(int x, int y);
 450 
 451     /**
 452      *
 453      * @see java.awt.event.MouseEvent
 454      * MouseEvent.MOUSE_CLICKED
 455      * MouseEvent.MOUSE_PRESSED
 456      * MouseEvent.MOUSE_RELEASED
 457      * MouseEvent.MOUSE_MOVED
 458      * MouseEvent.MOUSE_ENTERED
 459      * MouseEvent.MOUSE_EXITED
 460      * MouseEvent.MOUSE_DRAGGED
 461      */
 462     public void handleMouseEvent(int id, int modifiers, int x, int y) {
 463         if ((modifiers & InputEvent.BUTTON1_MASK) == 0) {
 464             return;
 465         }
 466 
 467         if (log.isLoggable(PlatformLogger.FINER)) {
 468              String type;
 469              switch (id) {
 470                 case MouseEvent.MOUSE_PRESSED:
 471                     type = "press";
 472                     break;
 473                 case MouseEvent.MOUSE_RELEASED:
 474                     type = "release";
 475                     break;
 476                 case MouseEvent.MOUSE_DRAGGED:
 477                     type = "drag";
 478                     break;
 479                 default:
 480                     type = "other";
 481              }
 482              log.finer("Mouse " + type + " event in scroll bar " + this +
 483                                                    "x = " + x + ", y = " + y +
 484                                                    ", on arrow: " + isInArrow(x, y) +
 485                                                    ", on thumb: " + isInThumb(x, y) + ", before thumb: " + beforeThumb(x, y)
 486                                                    + ", thumb rect" + calculateThumbRect());
 487         }




 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);
 139             arrow.addPoint(x + getArrowWidth()/2, y1);
 140             arrow.addPoint(x + getArrowWidth(), y2);
 141             arrow.addPoint(x, y2);


 149             arrow.addPoint(x2, y);
 150             arrow.addPoint(x1, y + getArrowWidth()/2);
 151         }
 152         return arrow;
 153     }
 154 
 155     /**
 156      * Gets the area of the scroll track
 157      */
 158     protected abstract Rectangle getThumbArea();
 159 
 160     /**
 161      * paint the scrollbar
 162      * @param g the graphics context to paint into
 163      * @param colors the colors to use when painting the scrollbar
 164      * @param width the width of the scrollbar
 165      * @param height the height of the scrollbar
 166      * @param paintAll paint the whole scrollbar if true, just the thumb is false
 167      */
 168     void paint(Graphics g, Color colors[], boolean paintAll) {
 169         if (log.isLoggable(PlatformLogger.Level.FINER)) {
 170             log.finer("Painting scrollbar " + this);
 171         }
 172 
 173         boolean useBufferedImage = false;
 174         Graphics2D g2 = null;
 175         BufferedImage buffer = null;
 176         if (!(g instanceof Graphics2D)) {
 177             // Fix for 5045936, 5055171. While printing, g is an instance
 178             //   of sun.print.ProxyPrintGraphics which extends Graphics.
 179             //   So we use a separate buffered image and its graphics is
 180             //   always Graphics2D instance
 181             X11GraphicsConfig graphicsConfig = (X11GraphicsConfig)(sb.getEventSource().getGraphicsConfiguration());
 182             buffer = graphicsConfig.createCompatibleImage(width, height);
 183             g2 = buffer.createGraphics();
 184             useBufferedImage = true;
 185         } else {
 186             g2 = (Graphics2D)g;
 187         }
 188         try {
 189             Rectangle thumbRect = calculateThumbRect();


 322         }
 323         else {
 324             g.fill(secondArrow);
 325             g.setColor(darkShadow);
 326             g.drawLine(secondArrow.xpoints[0],secondArrow.ypoints[0],
 327                     secondArrow.xpoints[1],secondArrow.ypoints[1]);
 328             g.setColor(lightShadow);
 329             g.drawLine(secondArrow.xpoints[1],secondArrow.ypoints[1],
 330                     secondArrow.xpoints[2],secondArrow.ypoints[2]);
 331             g.drawLine(secondArrow.xpoints[2],secondArrow.ypoints[2],
 332                     secondArrow.xpoints[0],secondArrow.ypoints[0]);
 333 
 334         }
 335 
 336     }
 337 
 338     /**
 339      * Tell the scroller to start scrolling.
 340      */
 341     void startScrolling() {
 342         if (log.isLoggable(PlatformLogger.Level.FINER)) {
 343             log.finer("Start scrolling on " + this);
 344         }
 345         // Make sure that we scroll at least once
 346         scroll();
 347 
 348         // wake up the scroll repeater
 349         if (scroller == null) {
 350             // If there isn't a scroller, then create
 351             // one and start it.
 352             scroller = new XScrollRepeater(this);
 353         } else {
 354             scroller.setScrollbar(this);
 355         }
 356         scroller.start();
 357     }
 358 
 359     /**
 360      * Tell the instance scroller to start scrolling.
 361      * See 6243382 for more information
 362      */
 363     void startScrollingInstance() {
 364         if (log.isLoggable(PlatformLogger.Level.FINER)) {
 365             log.finer("Start scrolling on " + this);
 366         }
 367         // Make sure that we scroll at least once
 368         scroll();
 369 
 370         i_scroller.setScrollbar(this);
 371         i_scroller.start();
 372     }
 373 
 374     /**
 375      * Tell the instance scroller to stop scrolling.
 376      * See 6243382 for more information
 377      */
 378     void stopScrollingInstance() {
 379         if (log.isLoggable(PlatformLogger.Level.FINER)) {
 380             log.finer("Stop scrolling on " + this);
 381         }
 382 
 383         i_scroller.stop();
 384     }
 385 
 386     /**
 387      * The set method for mode property.
 388      * See 6243382 for more information
 389      */
 390     public void setMode(int mode){
 391         this.mode = mode;
 392     }
 393 
 394     /**
 395      * Scroll one unit.
 396      * @see notifyValue
 397      */
 398     void scroll() {
 399         switch (mode) {


 447     }
 448 
 449     abstract boolean beforeThumb(int x, int y);
 450 
 451     /**
 452      *
 453      * @see java.awt.event.MouseEvent
 454      * MouseEvent.MOUSE_CLICKED
 455      * MouseEvent.MOUSE_PRESSED
 456      * MouseEvent.MOUSE_RELEASED
 457      * MouseEvent.MOUSE_MOVED
 458      * MouseEvent.MOUSE_ENTERED
 459      * MouseEvent.MOUSE_EXITED
 460      * MouseEvent.MOUSE_DRAGGED
 461      */
 462     public void handleMouseEvent(int id, int modifiers, int x, int y) {
 463         if ((modifiers & InputEvent.BUTTON1_MASK) == 0) {
 464             return;
 465         }
 466 
 467         if (log.isLoggable(PlatformLogger.Level.FINER)) {
 468              String type;
 469              switch (id) {
 470                 case MouseEvent.MOUSE_PRESSED:
 471                     type = "press";
 472                     break;
 473                 case MouseEvent.MOUSE_RELEASED:
 474                     type = "release";
 475                     break;
 476                 case MouseEvent.MOUSE_DRAGGED:
 477                     type = "drag";
 478                     break;
 479                 default:
 480                     type = "other";
 481              }
 482              log.finer("Mouse " + type + " event in scroll bar " + this +
 483                                                    "x = " + x + ", y = " + y +
 484                                                    ", on arrow: " + isInArrow(x, y) +
 485                                                    ", on thumb: " + isInThumb(x, y) + ", before thumb: " + beforeThumb(x, y)
 486                                                    + ", thumb rect" + calculateThumbRect());
 487         }