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)) log.finer("Setting scroll bar " + this + " size to " + width + "x" + height);


 122         this.width = width;
 123         this.height = height;
 124     }
 125 
 126     /**
 127      * Creates oriented directed arrow
 128      */
 129     protected Polygon createArrowShape(boolean vertical, boolean up) {
 130         Polygon arrow = new Polygon();
 131         // TODO: this should be done polymorphically in subclasses
 132         // FIXME: arrows overlap the thumb for very wide scrollbars
 133         if (vertical) {
 134             int x = width / 2 - getArrowWidth()/2;
 135             int y1 = (up ? ARROW_IND : barLength - ARROW_IND);
 136             int y2 = (up ? getArrowWidth() : barLength - getArrowWidth() - ARROW_IND);
 137             arrow.addPoint(x + getArrowWidth()/2, y1);
 138             arrow.addPoint(x + getArrowWidth(), y2);
 139             arrow.addPoint(x, y2);
 140             arrow.addPoint(x + getArrowWidth()/2, y1);
 141         } else {


 147             arrow.addPoint(x2, y);
 148             arrow.addPoint(x1, y + getArrowWidth()/2);
 149         }
 150         return arrow;
 151     }
 152 
 153     /**
 154      * Gets the area of the scroll track
 155      */
 156     protected abstract Rectangle getThumbArea();
 157 
 158     /**
 159      * paint the scrollbar
 160      * @param g the graphics context to paint into
 161      * @param colors the colors to use when painting the scrollbar
 162      * @param width the width of the scrollbar
 163      * @param height the height of the scrollbar
 164      * @param paintAll paint the whole scrollbar if true, just the thumb is false
 165      */
 166     void paint(Graphics g, Color colors[], boolean paintAll) {
 167         if (log.isLoggable(PlatformLogger.FINER)) log.finer("Painting scrollbar " + this);


 168 
 169         boolean useBufferedImage = false;
 170         Graphics2D g2 = null;
 171         BufferedImage buffer = null;
 172         if (!(g instanceof Graphics2D)) {
 173             // Fix for 5045936, 5055171. While printing, g is an instance
 174             //   of sun.print.ProxyPrintGraphics which extends Graphics.
 175             //   So we use a separate buffered image and its graphics is
 176             //   always Graphics2D instance
 177             X11GraphicsConfig graphicsConfig = (X11GraphicsConfig)(sb.getEventSource().getGraphicsConfiguration());
 178             buffer = graphicsConfig.createCompatibleImage(width, height);
 179             g2 = buffer.createGraphics();
 180             useBufferedImage = true;
 181         } else {
 182             g2 = (Graphics2D)g;
 183         }
 184         try {
 185             Rectangle thumbRect = calculateThumbRect();
 186 
 187 //              if (prevH == thumbH && prevY == thumbPosY) {


 318         }
 319         else {
 320             g.fill(secondArrow);
 321             g.setColor(darkShadow);
 322             g.drawLine(secondArrow.xpoints[0],secondArrow.ypoints[0],
 323                     secondArrow.xpoints[1],secondArrow.ypoints[1]);
 324             g.setColor(lightShadow);
 325             g.drawLine(secondArrow.xpoints[1],secondArrow.ypoints[1],
 326                     secondArrow.xpoints[2],secondArrow.ypoints[2]);
 327             g.drawLine(secondArrow.xpoints[2],secondArrow.ypoints[2],
 328                     secondArrow.xpoints[0],secondArrow.ypoints[0]);
 329 
 330         }
 331 
 332     }
 333 
 334     /**
 335      * Tell the scroller to start scrolling.
 336      */
 337     void startScrolling() {

 338         log.finer("Start scrolling on " + this);

 339         // Make sure that we scroll at least once
 340         scroll();
 341 
 342         // wake up the scroll repeater
 343         if (scroller == null) {
 344             // If there isn't a scroller, then create
 345             // one and start it.
 346             scroller = new XScrollRepeater(this);
 347         } else {
 348             scroller.setScrollbar(this);
 349         }
 350         scroller.start();
 351     }
 352 
 353     /**
 354      * Tell the instance scroller to start scrolling.
 355      * See 6243382 for more information
 356      */
 357     void startScrollingInstance() {

 358         log.finer("Start scrolling on " + this);

 359         // Make sure that we scroll at least once
 360         scroll();
 361 
 362         i_scroller.setScrollbar(this);
 363         i_scroller.start();
 364     }
 365 
 366     /**
 367      * Tell the instance scroller to stop scrolling.
 368      * See 6243382 for more information
 369      */
 370     void stopScrollingInstance() {

 371         log.finer("Stop scrolling on " + this);

 372 
 373         i_scroller.stop();
 374     }
 375 
 376     /**
 377      * The set method for mode property.
 378      * See 6243382 for more information
 379      */
 380     public void setMode(int mode){
 381         this.mode = mode;
 382     }
 383 
 384     /**
 385      * Scroll one unit.
 386      * @see notifyValue
 387      */
 388     void scroll() {
 389         switch (mode) {
 390           case AdjustmentEvent.UNIT_DECREMENT:
 391               notifyValue(val - line);




 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);
 142             arrow.addPoint(x + getArrowWidth()/2, y1);
 143         } else {


 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();
 190 
 191 //              if (prevH == thumbH && prevY == thumbPosY) {


 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) {
 400           case AdjustmentEvent.UNIT_DECREMENT:
 401               notifyValue(val - line);