144 int y = height / 2 - getArrowWidth()/2;
145 int x1 = (up ? ARROW_IND : barLength - ARROW_IND);
146 int x2 = (up ? getArrowWidth() : barLength - getArrowWidth() - ARROW_IND);
147 arrow.addPoint(x1, y + getArrowWidth()/2);
148 arrow.addPoint(x2, y + getArrowWidth());
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 {
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) {
400 case AdjustmentEvent.UNIT_DECREMENT:
401 notifyValue(val - line);
402 return;
403
404 case AdjustmentEvent.UNIT_INCREMENT:
405 notifyValue(val + line);
406 return;
407
408 case AdjustmentEvent.BLOCK_DECREMENT:
409 notifyValue(val - page);
410 return;
411
412 case AdjustmentEvent.BLOCK_INCREMENT:
413 notifyValue(val + page);
414 return;
415 }
416 return;
590 if (value < minimum) {
591 value = minimum;
592 }
593 if (value > maximum - visible) {
594 value = maximum - visible;
595 }
596
597 this.val = value;
598 this.vis = visible;
599 this.min = minimum;
600 this.max = maximum;
601 }
602
603 /**
604 * Sets param of this Scrollbar to the specified values.
605 * @param value is the position in the current window.
606 * @param visible is the amount visible per page
607 * @param minimum is the minimum value of the scrollbar
608 * @param maximum is the maximum value of the scrollbar
609 * @param unitSize is the unit size for increment or decrement of the value
610 * @param page is the block size for increment or decrement of the value
611 * @see #setValues
612 */
613 synchronized void setValues(int value, int visible, int minimum, int maximum,
614 int unitSize, int blockSize) {
615 /* Use setValues so that a consistent policy
616 * relating minimum, maximum, and value is enforced.
617 */
618 setValues(value, visible, minimum, maximum);
619 setUnitIncrement(unitSize);
620 setBlockIncrement(blockSize);
621 }
622
623 /**
624 * Returns the current value of this Scrollbar.
625 * @see #getMinimum
626 * @see #getMaximum
627 */
628 int getValue() {
629 return val;
630 }
631
632 /**
633 * Sets the value of this Scrollbar to the specified value.
634 * @param value the new value of the Scrollbar. If this value is
635 * below the current minimum or above the current maximum minus
636 * the visible amount, it becomes the new one of those values,
637 * respectively.
638 * @see #getValue
639 */
640 synchronized void setValue(int newValue) {
641 /* Use setValues so that a consistent policy
642 * relating minimum, maximum, and value is enforced.
643 */
644 setValues(newValue, vis, min, max);
645 }
646
647 /**
648 * Returns the minimum value of this Scrollbar.
649 * @see #getMaximum
650 * @see #getValue
651 */
652 int getMinimum() {
653 return min;
654 }
655
656 /**
657 * Sets the minimum value for this Scrollbar.
658 * @param minimum the minimum value of the scrollbar
659 */
660 synchronized void setMinimum(int newMinimum) {
661 /* Use setValues so that a consistent policy
662 * relating minimum, maximum, and value is enforced.
663 */
664 setValues(val, vis, newMinimum, max);
665 }
666
667 /**
668 * Returns the maximum value of this Scrollbar.
669 * @see #getMinimum
670 * @see #getValue
671 */
672 int getMaximum() {
673 return max;
674 }
675
676 /**
677 * Sets the maximum value for this Scrollbar.
678 * @param maximum the maximum value of the scrollbar
679 */
680 synchronized void setMaximum(int newMaximum) {
681 /* Use setValues so that a consistent policy
682 * relating minimum, maximum, and value is enforced.
683 */
684 setValues(val, vis, min, newMaximum);
685 }
686
687 /**
688 * Returns the visible amount of this Scrollbar.
689 */
690 int getVisibleAmount() {
691 return vis;
692 }
693
694 /**
695 * Sets the visible amount of this Scrollbar, which is the range
696 * of values represented by the width of the scroll bar's bubble.
697 * @param visible the amount visible per page
698 */
699 synchronized void setVisibleAmount(int newAmount) {
700 setValues(val, newAmount, min, max);
701 }
702
703 /**
704 * Sets the unit increment for this scrollbar. This is the value
705 * that will be added (subtracted) when the user hits the unit down
706 * (up) gadgets.
707 * @param unitSize is the unit size for increment or decrement of the value
708 */
709 synchronized void setUnitIncrement(int unitSize) {
710 line = unitSize;
711 }
712
713 /**
714 * Gets the unit increment for this scrollbar.
715 */
716 int getUnitIncrement() {
717 return line;
742 }
743
744 /**
745 * Width of the area reserved for arrow
746 */
747 int getArrowAreaWidth() {
748 return arrowArea;
749 }
750
751 void calculateArrowWidth() {
752 if (barLength < 2*barWidth + MIN_THUMB_H + 2) {
753 arrowArea = (barLength - MIN_THUMB_H + 2*ARROW_IND)/2 - 1;
754 }
755 else {
756 arrowArea = barWidth - 1;
757 }
758 }
759
760 /**
761 * Returns the scale factor for the thumbArea ( thumbAreaH / (max - min)).
762 * @see #getArrowAreaSize
763 */
764 private double getScaleFactor(){
765 double f = (double)(barLength - 2*getArrowAreaWidth()) / Math.max(1,(max - min));
766 return f;
767 }
768
769 /**
770 * Method to calculate the scroll thumb's size and position. This is
771 * based on CalcSliderRect in ScrollBar.c of Motif source.
772 *
773 * If we ever cache the thumb rect, we'll need to use a clone in
774 * isInThumb().
775 */
776 protected Rectangle calculateThumbRect() {
777 float range;
778 float trueSize; // Area of scroll track
779 float factor;
780 float slideSize;
781 int minSliderWidth;
782 int minSliderHeight;
|
144 int y = height / 2 - getArrowWidth()/2;
145 int x1 = (up ? ARROW_IND : barLength - ARROW_IND);
146 int x2 = (up ? getArrowWidth() : barLength - getArrowWidth() - ARROW_IND);
147 arrow.addPoint(x1, y + getArrowWidth()/2);
148 arrow.addPoint(x2, y + getArrowWidth());
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 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.Level.FINER)) {
168 log.finer("Painting scrollbar " + this);
169 }
170
171 boolean useBufferedImage = false;
172 Graphics2D g2 = null;
173 BufferedImage buffer = null;
174 if (!(g instanceof Graphics2D)) {
175 // Fix for 5045936, 5055171. While printing, g is an instance
176 // of sun.print.ProxyPrintGraphics which extends Graphics.
177 // So we use a separate buffered image and its graphics is
178 // always Graphics2D instance
179 X11GraphicsConfig graphicsConfig = (X11GraphicsConfig)(sb.getEventSource().getGraphicsConfiguration());
180 buffer = graphicsConfig.createCompatibleImage(width, height);
181 g2 = buffer.createGraphics();
182 useBufferedImage = true;
183 } else {
374 * See 6243382 for more information
375 */
376 void stopScrollingInstance() {
377 if (log.isLoggable(PlatformLogger.Level.FINER)) {
378 log.finer("Stop scrolling on " + this);
379 }
380
381 i_scroller.stop();
382 }
383
384 /**
385 * The set method for mode property.
386 * See 6243382 for more information
387 */
388 public void setMode(int mode){
389 this.mode = mode;
390 }
391
392 /**
393 * Scroll one unit.
394 * @see #notifyValue
395 */
396 void scroll() {
397 switch (mode) {
398 case AdjustmentEvent.UNIT_DECREMENT:
399 notifyValue(val - line);
400 return;
401
402 case AdjustmentEvent.UNIT_INCREMENT:
403 notifyValue(val + line);
404 return;
405
406 case AdjustmentEvent.BLOCK_DECREMENT:
407 notifyValue(val - page);
408 return;
409
410 case AdjustmentEvent.BLOCK_INCREMENT:
411 notifyValue(val + page);
412 return;
413 }
414 return;
588 if (value < minimum) {
589 value = minimum;
590 }
591 if (value > maximum - visible) {
592 value = maximum - visible;
593 }
594
595 this.val = value;
596 this.vis = visible;
597 this.min = minimum;
598 this.max = maximum;
599 }
600
601 /**
602 * Sets param of this Scrollbar to the specified values.
603 * @param value is the position in the current window.
604 * @param visible is the amount visible per page
605 * @param minimum is the minimum value of the scrollbar
606 * @param maximum is the maximum value of the scrollbar
607 * @param unitSize is the unit size for increment or decrement of the value
608 * @see #setValues
609 */
610 synchronized void setValues(int value, int visible, int minimum, int maximum,
611 int unitSize, int blockSize) {
612 /* Use setValues so that a consistent policy
613 * relating minimum, maximum, and value is enforced.
614 */
615 setValues(value, visible, minimum, maximum);
616 setUnitIncrement(unitSize);
617 setBlockIncrement(blockSize);
618 }
619
620 /**
621 * Returns the current value of this Scrollbar.
622 * @see #getMinimum
623 * @see #getMaximum
624 */
625 int getValue() {
626 return val;
627 }
628
629 /**
630 * Sets the value of this Scrollbar to the specified value.
631 * @param newValue the new value of the Scrollbar. If this value is
632 * below the current minimum or above the current maximum minus
633 * the visible amount, it becomes the new one of those values,
634 * respectively.
635 * @see #getValue
636 */
637 synchronized void setValue(int newValue) {
638 /* Use setValues so that a consistent policy
639 * relating minimum, maximum, and value is enforced.
640 */
641 setValues(newValue, vis, min, max);
642 }
643
644 /**
645 * Returns the minimum value of this Scrollbar.
646 * @see #getMaximum
647 * @see #getValue
648 */
649 int getMinimum() {
650 return min;
651 }
652
653 /**
654 * Sets the minimum value for this Scrollbar.
655 * @param newMinimum the minimum value of the scrollbar
656 */
657 synchronized void setMinimum(int newMinimum) {
658 /* Use setValues so that a consistent policy
659 * relating minimum, maximum, and value is enforced.
660 */
661 setValues(val, vis, newMinimum, max);
662 }
663
664 /**
665 * Returns the maximum value of this Scrollbar.
666 * @see #getMinimum
667 * @see #getValue
668 */
669 int getMaximum() {
670 return max;
671 }
672
673 /**
674 * Sets the maximum value for this Scrollbar.
675 * @param newMaximum the maximum value of the scrollbar
676 */
677 synchronized void setMaximum(int newMaximum) {
678 /* Use setValues so that a consistent policy
679 * relating minimum, maximum, and value is enforced.
680 */
681 setValues(val, vis, min, newMaximum);
682 }
683
684 /**
685 * Returns the visible amount of this Scrollbar.
686 */
687 int getVisibleAmount() {
688 return vis;
689 }
690
691 /**
692 * Sets the visible amount of this Scrollbar, which is the range
693 * of values represented by the width of the scroll bar's bubble.
694 * @param newAmount the amount visible per page
695 */
696 synchronized void setVisibleAmount(int newAmount) {
697 setValues(val, newAmount, min, max);
698 }
699
700 /**
701 * Sets the unit increment for this scrollbar. This is the value
702 * that will be added (subtracted) when the user hits the unit down
703 * (up) gadgets.
704 * @param unitSize is the unit size for increment or decrement of the value
705 */
706 synchronized void setUnitIncrement(int unitSize) {
707 line = unitSize;
708 }
709
710 /**
711 * Gets the unit increment for this scrollbar.
712 */
713 int getUnitIncrement() {
714 return line;
739 }
740
741 /**
742 * Width of the area reserved for arrow
743 */
744 int getArrowAreaWidth() {
745 return arrowArea;
746 }
747
748 void calculateArrowWidth() {
749 if (barLength < 2*barWidth + MIN_THUMB_H + 2) {
750 arrowArea = (barLength - MIN_THUMB_H + 2*ARROW_IND)/2 - 1;
751 }
752 else {
753 arrowArea = barWidth - 1;
754 }
755 }
756
757 /**
758 * Returns the scale factor for the thumbArea ( thumbAreaH / (max - min)).
759 * @see #getArrowAreaWidth
760 */
761 private double getScaleFactor(){
762 double f = (double)(barLength - 2*getArrowAreaWidth()) / Math.max(1,(max - min));
763 return f;
764 }
765
766 /**
767 * Method to calculate the scroll thumb's size and position. This is
768 * based on CalcSliderRect in ScrollBar.c of Motif source.
769 *
770 * If we ever cache the thumb rect, we'll need to use a clone in
771 * isInThumb().
772 */
773 protected Rectangle calculateThumbRect() {
774 float range;
775 float trueSize; // Area of scroll track
776 float factor;
777 float slideSize;
778 int minSliderWidth;
779 int minSliderHeight;
|