Source Code Cross Referenced for Scrollbar.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 1995-2006 Sun Microsystems, Inc.  All Rights Reserved.
0003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004:         *
0005:         * This code is free software; you can redistribute it and/or modify it
0006:         * under the terms of the GNU General Public License version 2 only, as
0007:         * published by the Free Software Foundation.  Sun designates this
0008:         * particular file as subject to the "Classpath" exception as provided
0009:         * by Sun in the LICENSE file that accompanied this code.
0010:         *
0011:         * This code is distributed in the hope that it will be useful, but WITHOUT
0012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0014:         * version 2 for more details (a copy is included in the LICENSE file that
0015:         * accompanied this code).
0016:         *
0017:         * You should have received a copy of the GNU General Public License version
0018:         * 2 along with this work; if not, write to the Free Software Foundation,
0019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020:         *
0021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022:         * CA 95054 USA or visit www.sun.com if you need additional information or
0023:         * have any questions.
0024:         */
0025:        package java.awt;
0026:
0027:        import java.awt.peer.ScrollbarPeer;
0028:        import java.awt.event.*;
0029:        import java.util.EventListener;
0030:        import java.io.ObjectOutputStream;
0031:        import java.io.ObjectInputStream;
0032:        import java.io.IOException;
0033:        import javax.accessibility.*;
0034:
0035:        /**
0036:         * The <code>Scrollbar</code> class embodies a scroll bar, a
0037:         * familiar user-interface object. A scroll bar provides a
0038:         * convenient means for allowing a user to select from a
0039:         * range of values. The following three vertical
0040:         * scroll bars could be used as slider controls to pick
0041:         * the red, green, and blue components of a color:
0042:         * <p>
0043:         * <img src="doc-files/Scrollbar-1.gif" alt="Image shows 3 vertical sliders, side-by-side."
0044:         * ALIGN=center HSPACE=10 VSPACE=7>
0045:         * <p>
0046:         * Each scroll bar in this example could be created with
0047:         * code similar to the following:
0048:         * <p>
0049:         * <hr><blockquote><pre>
0050:         * redSlider=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255);
0051:         * add(redSlider);
0052:         * </pre></blockquote><hr>
0053:         * <p>
0054:         * Alternatively, a scroll bar can represent a range of values. For
0055:         * example, if a scroll bar is used for scrolling through text, the
0056:         * width of the "bubble" (also called the "thumb" or "scroll box")
0057:         * can be used to represent the amount of text that is visible.
0058:         * Here is an example of a scroll bar that represents a range:
0059:         * <p>
0060:         * <img src="doc-files/Scrollbar-2.gif"
0061:         * alt="Image shows horizontal slider with starting range of 0 and ending range of 300. The slider thumb is labeled 60."
0062:         * ALIGN=center HSPACE=10 VSPACE=7>
0063:         * <p>
0064:         * The value range represented by the bubble in this example
0065:         * is the <em>visible amount</em>. The horizontal scroll bar 
0066:         * in this example could be created with code like the following:
0067:         * <p>
0068:         * <hr><blockquote><pre>
0069:         * ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 60, 0, 300);
0070:         * add(ranger);
0071:         * </pre></blockquote><hr>
0072:         * <p>
0073:         * Note that the actual maximum value of the scroll bar is the
0074:         * <code>maximum</code> minus the <code>visible amount</code>.
0075:         * In the previous example, because the <code>maximum</code> is
0076:         * 300 and the <code>visible amount</code> is 60, the actual maximum
0077:         * value is 240.  The range of the scrollbar track is 0 - 300.
0078:         * The left side of the bubble indicates the value of the
0079:         * scroll bar.
0080:         * <p>
0081:         * Normally, the user changes the value of the scroll bar by
0082:         * making a gesture with the mouse. For example, the user can
0083:         * drag the scroll bar's bubble up and down, or click in the
0084:         * scroll bar's unit increment or block increment areas. Keyboard
0085:         * gestures can also be mapped to the scroll bar. By convention,
0086:         * the <b>Page&nbsp;Up</b> and <b>Page&nbsp;Down</b>
0087:         * keys are equivalent to clicking in the scroll bar's block
0088:         * increment and block decrement areas.
0089:         * <p>
0090:         * When the user changes the value of the scroll bar, the scroll bar
0091:         * receives an instance of <code>AdjustmentEvent</code>.
0092:         * The scroll bar processes this event, passing it along to
0093:         * any registered listeners.
0094:         * <p>
0095:         * Any object that wishes to be notified of changes to the
0096:         * scroll bar's value should implement
0097:         * <code>AdjustmentListener</code>, an interface defined in
0098:         * the package <code>java.awt.event</code>.
0099:         * Listeners can be added and removed dynamically by calling
0100:         * the methods <code>addAdjustmentListener</code> and
0101:         * <code>removeAdjustmentListener</code>.
0102:         * <p>
0103:         * The <code>AdjustmentEvent</code> class defines five types
0104:         * of adjustment event, listed here:
0105:         * <p>
0106:         * <ul>
0107:         * <li><code>AdjustmentEvent.TRACK</code> is sent out when the
0108:         * user drags the scroll bar's bubble.
0109:         * <li><code>AdjustmentEvent.UNIT_INCREMENT</code> is sent out
0110:         * when the user clicks in the left arrow of a horizontal scroll
0111:         * bar, or the top arrow of a vertical scroll bar, or makes the
0112:         * equivalent gesture from the keyboard.
0113:         * <li><code>AdjustmentEvent.UNIT_DECREMENT</code> is sent out
0114:         * when the user clicks in the right arrow of a horizontal scroll
0115:         * bar, or the bottom arrow of a vertical scroll bar, or makes the
0116:         * equivalent gesture from the keyboard.
0117:         * <li><code>AdjustmentEvent.BLOCK_INCREMENT</code> is sent out
0118:         * when the user clicks in the track, to the left of the bubble
0119:         * on a horizontal scroll bar, or above the bubble on a vertical
0120:         * scroll bar. By convention, the <b>Page&nbsp;Up</b>
0121:         * key is equivalent, if the user is using a keyboard that
0122:         * defines a <b>Page&nbsp;Up</b> key.
0123:         * <li><code>AdjustmentEvent.BLOCK_DECREMENT</code> is sent out
0124:         * when the user clicks in the track, to the right of the bubble
0125:         * on a horizontal scroll bar, or below the bubble on a vertical
0126:         * scroll bar. By convention, the <b>Page&nbsp;Down</b>
0127:         * key is equivalent, if the user is using a keyboard that
0128:         * defines a <b>Page&nbsp;Down</b> key.
0129:         * </ul>
0130:         * <p>
0131:         * The JDK&nbsp;1.0 event system is supported for backwards
0132:         * compatibility, but its use with newer versions of the platform is
0133:         * discouraged. The five types of adjustment events introduced
0134:         * with JDK&nbsp;1.1 correspond to the five event types
0135:         * that are associated with scroll bars in previous platform versions.
0136:         * The following list gives the adjustment event type,
0137:         * and the corresponding JDK&nbsp;1.0 event type it replaces.
0138:         * <p>
0139:         * <ul>
0140:         * <li><code>AdjustmentEvent.TRACK</code> replaces
0141:         * <code>Event.SCROLL_ABSOLUTE</code>
0142:         * <li><code>AdjustmentEvent.UNIT_INCREMENT</code> replaces
0143:         * <code>Event.SCROLL_LINE_UP</code>
0144:         * <li><code>AdjustmentEvent.UNIT_DECREMENT</code> replaces
0145:         * <code>Event.SCROLL_LINE_DOWN</code>
0146:         * <li><code>AdjustmentEvent.BLOCK_INCREMENT</code> replaces
0147:         * <code>Event.SCROLL_PAGE_UP</code>
0148:         * <li><code>AdjustmentEvent.BLOCK_DECREMENT</code> replaces
0149:         * <code>Event.SCROLL_PAGE_DOWN</code>
0150:         * </ul>
0151:         * <p>
0152:         * <b>Note</b>: We recommend using a <code>Scrollbar</code>
0153:         * for value selection only.  If you want to implement
0154:         * a scrollable component inside a container, we recommend you use
0155:         * a {@link ScrollPane ScrollPane}. If you use a 
0156:         * <code>Scrollbar</code> for this purpose, you are likely to
0157:         * encounter issues with painting, key handling, sizing and 
0158:         * positioning.
0159:         *
0160:         * @version 	1.119, 05/05/07
0161:         * @author 	Sami Shaio
0162:         * @see         java.awt.event.AdjustmentEvent
0163:         * @see         java.awt.event.AdjustmentListener
0164:         * @since       JDK1.0
0165:         */
0166:        public class Scrollbar extends Component implements  Adjustable,
0167:                Accessible {
0168:
0169:            /**
0170:             * A constant that indicates a horizontal scroll bar.
0171:             */
0172:            public static final int HORIZONTAL = 0;
0173:
0174:            /**
0175:             * A constant that indicates a vertical scroll bar.
0176:             */
0177:            public static final int VERTICAL = 1;
0178:
0179:            /**
0180:             * The value of the <code>Scrollbar</code>.
0181:             * This property must be greater than or equal to <code>minimum</code>
0182:             * and less than or equal to 
0183:             * <code>maximum - visibleAmount</code>
0184:             *
0185:             * @serial
0186:             * @see #getValue
0187:             * @see #setValue
0188:             */
0189:            int value;
0190:
0191:            /**
0192:             * The maximum value of the <code>Scrollbar</code>.
0193:             * This value must be greater than the <code>minimum</code>
0194:             * value.<br>
0195:             *
0196:             * @serial
0197:             * @see #getMaximum
0198:             * @see #setMaximum
0199:             */
0200:            int maximum;
0201:
0202:            /**
0203:             * The minimum value of the <code>Scrollbar</code>.
0204:             * This value must be less than the <code>maximum</code>
0205:             * value.<br>
0206:             *
0207:             * @serial
0208:             * @see #getMinimum
0209:             * @see #setMinimum
0210:             */
0211:            int minimum;
0212:
0213:            /**
0214:             * The size of the <code>Scrollbar</code>'s bubble.  
0215:             * When a scroll bar is used to select a range of values,
0216:             * the visibleAmount represents the size of this range.
0217:             * This is visually indicated by the size of the bubble. 
0218:             *
0219:             * @serial
0220:             * @see #getVisibleAmount
0221:             * @see #setVisibleAmount
0222:             */
0223:            int visibleAmount;
0224:
0225:            /**
0226:             * The <code>Scrollbar</code>'s orientation--being either horizontal
0227:             * or vertical.
0228:             * This value should be specified when the scrollbar is created.<BR>
0229:             * orientation can be either : <code>VERTICAL</code> or
0230:             * <code>HORIZONTAL</code> only.
0231:             *
0232:             * @serial
0233:             * @see #getOrientation
0234:             * @see #setOrientation
0235:             */
0236:            int orientation;
0237:
0238:            /**
0239:             * The amount by which the scrollbar value will change when going
0240:             * up or down by a line.
0241:             * This value must be greater than zero.  
0242:             *
0243:             * @serial
0244:             * @see #getLineIncrement
0245:             * @see #setLineIncrement
0246:             */
0247:            int lineIncrement = 1;
0248:
0249:            /**
0250:             * The amount by which the scrollbar value will change when going
0251:             * up or down by a page.
0252:             * This value must be greater than zero. 
0253:             *
0254:             * @serial
0255:             * @see #getPageIncrement
0256:             * @see #setPageIncrement
0257:             */
0258:            int pageIncrement = 10;
0259:
0260:            /**
0261:             * The adjusting status of the <code>Scrollbar</code>.
0262:             * True if the value is in the process of changing as a result of
0263:             * actions being taken by the user.
0264:             *
0265:             * @see #getValueIsAdjusting
0266:             * @see #setValueIsAdjusting
0267:             * @since 1.4
0268:             */
0269:            transient boolean isAdjusting;
0270:
0271:            transient AdjustmentListener adjustmentListener;
0272:
0273:            private static final String base = "scrollbar";
0274:            private static int nameCounter = 0;
0275:
0276:            /*
0277:             * JDK 1.1 serialVersionUID
0278:             */
0279:            private static final long serialVersionUID = 8451667562882310543L;
0280:
0281:            /**
0282:             * Initialize JNI field and method IDs.
0283:             */
0284:            private static native void initIDs();
0285:
0286:            static {
0287:                /* ensure that the necessary native libraries are loaded */
0288:                Toolkit.loadLibraries();
0289:                if (!GraphicsEnvironment.isHeadless()) {
0290:                    initIDs();
0291:                }
0292:            }
0293:
0294:            /**
0295:             * Constructs a new vertical scroll bar.
0296:             * The default properties of the scroll bar are listed in
0297:             * the following table:
0298:             * <p> </p>
0299:             * <table border=1 summary="Scrollbar default properties">
0300:             * <tr>
0301:             *   <th>Property</th>
0302:             *   <th>Description</th>
0303:             *   <th>Default Value</th>
0304:             * </tr>
0305:             * <tr>
0306:             *   <td>orientation</td>
0307:             *   <td>indicates whether the scroll bar is vertical
0308:             *   <br>or horizontal</td>
0309:             *   <td><code>Scrollbar.VERTICAL</code></td>
0310:             * </tr>
0311:             * <tr>
0312:             *   <td>value</td>
0313:             *   <td>value which controls the location
0314:             *   <br>of the scroll bar's bubble</td>
0315:             *   <td>0</td>
0316:             * </tr>
0317:             * <tr>
0318:             *   <td>visible amount</td>
0319:             *   <td>visible amount of the scroll bar's range,
0320:             *   <br>typically represented by the size of the 
0321:             *   <br>scroll bar's bubble</td>
0322:             *   <td>10</td>
0323:             * </tr>
0324:             * <tr>
0325:             *   <td>minimum</td>
0326:             *   <td>minimum value of the scroll bar</td>
0327:             *   <td>0</td>
0328:             * </tr>
0329:             * <tr>
0330:             *   <td>maximum</td>
0331:             *   <td>maximum value of the scroll bar</td>
0332:             *   <td>100</td>
0333:             * </tr>
0334:             * <tr>
0335:             *   <td>unit increment</td>
0336:             *   <td>amount the value changes when the
0337:             *   <br>Line Up or Line Down key is pressed,
0338:             *   <br>or when the end arrows of the scrollbar
0339:             *   <br>are clicked </td>
0340:             *   <td>1</td>
0341:             * </tr>
0342:             * <tr>
0343:             *   <td>block increment</td>
0344:             *   <td>amount the value changes when the
0345:             *   <br>Page Up or Page Down key is pressed,
0346:             *   <br>or when the scrollbar track is clicked 
0347:             *   <br>on either side of the bubble </td>
0348:             *   <td>10</td>
0349:             * </tr>
0350:             * </table>
0351:             *
0352:             * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0353:             * returns true.
0354:             * @see java.awt.GraphicsEnvironment#isHeadless
0355:             */
0356:            public Scrollbar() throws HeadlessException {
0357:                this (VERTICAL, 0, 10, 0, 100);
0358:            }
0359:
0360:            /**
0361:             * Constructs a new scroll bar with the specified orientation.
0362:             * <p>
0363:             * The <code>orientation</code> argument must take one of the two
0364:             * values <code>Scrollbar.HORIZONTAL</code>,
0365:             * or <code>Scrollbar.VERTICAL</code>,
0366:             * indicating a horizontal or vertical scroll bar, respectively.
0367:             * 
0368:             * @param       orientation   indicates the orientation of the scroll bar
0369:             * @exception   IllegalArgumentException    when an illegal value for
0370:             *                    the <code>orientation</code> argument is supplied
0371:             * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0372:             * returns true.
0373:             * @see java.awt.GraphicsEnvironment#isHeadless
0374:             */
0375:            public Scrollbar(int orientation) throws HeadlessException {
0376:                this (orientation, 0, 10, 0, 100);
0377:            }
0378:
0379:            /**
0380:             * Constructs a new scroll bar with the specified orientation,
0381:             * initial value, visible amount, and minimum and maximum values.
0382:             * <p>
0383:             * The <code>orientation</code> argument must take one of the two
0384:             * values <code>Scrollbar.HORIZONTAL</code>,
0385:             * or <code>Scrollbar.VERTICAL</code>,
0386:             * indicating a horizontal or vertical scroll bar, respectively.
0387:             * <p>
0388:             * The parameters supplied to this constructor are subject to the 
0389:             * constraints described in {@link #setValues(int, int, int, int)}. 
0390:             * 
0391:             * @param     orientation   indicates the orientation of the scroll bar.
0392:             * @param     value     the initial value of the scroll bar
0393:             * @param     visible   the visible amount of the scroll bar, typically 
0394:             *                      represented by the size of the bubble 
0395:             * @param     minimum   the minimum value of the scroll bar
0396:             * @param     maximum   the maximum value of the scroll bar
0397:             * @exception IllegalArgumentException    when an illegal value for
0398:             *                    the <code>orientation</code> argument is supplied
0399:             * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0400:             * returns true.
0401:             * @see #setValues
0402:             * @see java.awt.GraphicsEnvironment#isHeadless
0403:             */
0404:            public Scrollbar(int orientation, int value, int visible,
0405:                    int minimum, int maximum) throws HeadlessException {
0406:                GraphicsEnvironment.checkHeadless();
0407:                switch (orientation) {
0408:                case HORIZONTAL:
0409:                case VERTICAL:
0410:                    this .orientation = orientation;
0411:                    break;
0412:                default:
0413:                    throw new IllegalArgumentException(
0414:                            "illegal scrollbar orientation");
0415:                }
0416:                setValues(value, visible, minimum, maximum);
0417:            }
0418:
0419:            /**
0420:             * Constructs a name for this component.  Called by <code>getName</code>
0421:             * when the name is <code>null</code>.
0422:             */
0423:            String constructComponentName() {
0424:                synchronized (Scrollbar.class) {
0425:                    return base + nameCounter++;
0426:                }
0427:            }
0428:
0429:            /**
0430:             * Creates the <code>Scrollbar</code>'s peer.  The peer allows you to modify
0431:             * the appearance of the <code>Scrollbar</code> without changing any of its
0432:             * functionality.
0433:             */
0434:            public void addNotify() {
0435:                synchronized (getTreeLock()) {
0436:                    if (peer == null)
0437:                        peer = getToolkit().createScrollbar(this );
0438:                    super .addNotify();
0439:                }
0440:            }
0441:
0442:            /**
0443:             * Returns the orientation of this scroll bar.
0444:             * 
0445:             * @return    the orientation of this scroll bar, either
0446:             *               <code>Scrollbar.HORIZONTAL</code> or
0447:             *               <code>Scrollbar.VERTICAL</code>
0448:             * @see       java.awt.Scrollbar#setOrientation
0449:             */
0450:            public int getOrientation() {
0451:                return orientation;
0452:            }
0453:
0454:            /**
0455:             * Sets the orientation for this scroll bar.
0456:             * 
0457:             * @param orientation  the orientation of this scroll bar, either
0458:             *               <code>Scrollbar.HORIZONTAL</code> or
0459:             *               <code>Scrollbar.VERTICAL</code>
0460:             * @see       java.awt.Scrollbar#getOrientation
0461:             * @exception   IllegalArgumentException  if the value supplied
0462:             *                   for <code>orientation</code> is not a
0463:             *                   legal value
0464:             * @since     JDK1.1
0465:             */
0466:            public void setOrientation(int orientation) {
0467:                synchronized (getTreeLock()) {
0468:                    if (orientation == this .orientation) {
0469:                        return;
0470:                    }
0471:                    switch (orientation) {
0472:                    case HORIZONTAL:
0473:                    case VERTICAL:
0474:                        this .orientation = orientation;
0475:                        break;
0476:                    default:
0477:                        throw new IllegalArgumentException(
0478:                                "illegal scrollbar orientation");
0479:                    }
0480:                    /* Create a new peer with the specified orientation. */
0481:                    if (peer != null) {
0482:                        removeNotify();
0483:                        addNotify();
0484:                        invalidate();
0485:                    }
0486:                }
0487:                if (accessibleContext != null) {
0488:                    accessibleContext
0489:                            .firePropertyChange(
0490:                                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0491:                                    ((orientation == VERTICAL) ? AccessibleState.HORIZONTAL
0492:                                            : AccessibleState.VERTICAL),
0493:                                    ((orientation == VERTICAL) ? AccessibleState.VERTICAL
0494:                                            : AccessibleState.HORIZONTAL));
0495:                }
0496:            }
0497:
0498:            /**
0499:             * Gets the current value of this scroll bar.
0500:             * 
0501:             * @return      the current value of this scroll bar
0502:             * @see         java.awt.Scrollbar#getMinimum
0503:             * @see         java.awt.Scrollbar#getMaximum
0504:             */
0505:            public int getValue() {
0506:                return value;
0507:            }
0508:
0509:            /**
0510:             * Sets the value of this scroll bar to the specified value.
0511:             * <p>
0512:             * If the value supplied is less than the current <code>minimum</code> 
0513:             * or greater than the current <code>maximum - visibleAmount</code>, 
0514:             * then either <code>minimum</code> or <code>maximum - visibleAmount</code> 
0515:             * is substituted, as appropriate.
0516:             * <p>
0517:             * Normally, a program should change a scroll bar's
0518:             * value only by calling <code>setValues</code>.
0519:             * The <code>setValues</code> method simultaneously
0520:             * and synchronously sets the minimum, maximum, visible amount,
0521:             * and value properties of a scroll bar, so that they are
0522:             * mutually consistent.
0523:             * <p>
0524:             * Calling this method does not fire an
0525:             * <code>AdjustmentEvent</code>.
0526:             * 
0527:             * @param       newValue   the new value of the scroll bar
0528:             * @see         java.awt.Scrollbar#setValues
0529:             * @see         java.awt.Scrollbar#getValue
0530:             * @see         java.awt.Scrollbar#getMinimum
0531:             * @see         java.awt.Scrollbar#getMaximum
0532:             */
0533:            public void setValue(int newValue) {
0534:                // Use setValues so that a consistent policy relating
0535:                // minimum, maximum, visible amount, and value is enforced.
0536:                setValues(newValue, visibleAmount, minimum, maximum);
0537:            }
0538:
0539:            /**
0540:             * Gets the minimum value of this scroll bar.
0541:             * 
0542:             * @return      the minimum value of this scroll bar
0543:             * @see         java.awt.Scrollbar#getValue
0544:             * @see         java.awt.Scrollbar#getMaximum
0545:             */
0546:            public int getMinimum() {
0547:                return minimum;
0548:            }
0549:
0550:            /**
0551:             * Sets the minimum value of this scroll bar.
0552:             * <p>
0553:             * When <code>setMinimum</code> is called, the minimum value 
0554:             * is changed, and other values (including the maximum, the 
0555:             * visible amount, and the current scroll bar value) 
0556:             * are changed to be consistent with the new minimum.  
0557:             * <p>
0558:             * Normally, a program should change a scroll bar's minimum
0559:             * value only by calling <code>setValues</code>.
0560:             * The <code>setValues</code> method simultaneously
0561:             * and synchronously sets the minimum, maximum, visible amount,
0562:             * and value properties of a scroll bar, so that they are
0563:             * mutually consistent.
0564:             * <p>
0565:             * Note that setting the minimum value to <code>Integer.MAX_VALUE</code>
0566:             * will result in the new minimum value being set to 
0567:             * <code>Integer.MAX_VALUE - 1</code>.
0568:             *
0569:             * @param       newMinimum   the new minimum value for this scroll bar
0570:             * @see         java.awt.Scrollbar#setValues
0571:             * @see         java.awt.Scrollbar#setMaximum
0572:             * @since       JDK1.1
0573:             */
0574:            public void setMinimum(int newMinimum) {
0575:                // No checks are necessary in this method since minimum is 
0576:                // the first variable checked in the setValues function.  
0577:
0578:                // Use setValues so that a consistent policy relating 
0579:                // minimum, maximum, visible amount, and value is enforced.
0580:                setValues(value, visibleAmount, newMinimum, maximum);
0581:            }
0582:
0583:            /**
0584:             * Gets the maximum value of this scroll bar.
0585:             * 
0586:             * @return      the maximum value of this scroll bar
0587:             * @see         java.awt.Scrollbar#getValue
0588:             * @see         java.awt.Scrollbar#getMinimum
0589:             */
0590:            public int getMaximum() {
0591:                return maximum;
0592:            }
0593:
0594:            /**
0595:             * Sets the maximum value of this scroll bar.
0596:             * <p>
0597:             * When <code>setMaximum</code> is called, the maximum value 
0598:             * is changed, and other values (including the minimum, the 
0599:             * visible amount, and the current scroll bar value)
0600:             * are changed to be consistent with the new maximum.
0601:             * <p>
0602:             * Normally, a program should change a scroll bar's maximum
0603:             * value only by calling <code>setValues</code>.
0604:             * The <code>setValues</code> method simultaneously
0605:             * and synchronously sets the minimum, maximum, visible amount,
0606:             * and value properties of a scroll bar, so that they are
0607:             * mutually consistent.
0608:             * <p>
0609:             * Note that setting the maximum value to <code>Integer.MIN_VALUE</code>
0610:             * will result in the new maximum value being set to 
0611:             * <code>Integer.MIN_VALUE + 1</code>.
0612:             * 
0613:             * @param       newMaximum   the new maximum value
0614:             *                     for this scroll bar
0615:             * @see         java.awt.Scrollbar#setValues
0616:             * @see         java.awt.Scrollbar#setMinimum
0617:             * @since       JDK1.1
0618:             */
0619:            public void setMaximum(int newMaximum) {
0620:                // minimum is checked first in setValues, so we need to 
0621:                // enforce minimum and maximum checks here.  
0622:                if (newMaximum == Integer.MIN_VALUE) {
0623:                    newMaximum = Integer.MIN_VALUE + 1;
0624:                }
0625:
0626:                if (minimum >= newMaximum) {
0627:                    minimum = newMaximum - 1;
0628:                }
0629:
0630:                // Use setValues so that a consistent policy relating 
0631:                // minimum, maximum, visible amount, and value is enforced.
0632:                setValues(value, visibleAmount, minimum, newMaximum);
0633:            }
0634:
0635:            /**
0636:             * Gets the visible amount of this scroll bar.
0637:             * <p>
0638:             * When a scroll bar is used to select a range of values,
0639:             * the visible amount is used to represent the range of values
0640:             * that are currently visible.  The size of the scroll bar's
0641:             * bubble (also called a thumb or scroll box), usually gives a
0642:             * visual representation of the relationship of the visible
0643:             * amount to the range of the scroll bar.
0644:             * <p>
0645:             * The scroll bar's bubble may not be displayed when it is not 
0646:             * moveable (e.g. when it takes up the entire length of the 
0647:             * scroll bar's track, or when the scroll bar is disabled). 
0648:             * Whether the bubble is displayed or not will not affect 
0649:             * the value returned by <code>getVisibleAmount</code>. 
0650:             * 
0651:             * @return      the visible amount of this scroll bar
0652:             * @see         java.awt.Scrollbar#setVisibleAmount
0653:             * @since       JDK1.1
0654:             */
0655:            public int getVisibleAmount() {
0656:                return getVisible();
0657:            }
0658:
0659:            /**
0660:             * @deprecated As of JDK version 1.1,
0661:             * replaced by <code>getVisibleAmount()</code>.
0662:             */
0663:            @Deprecated
0664:            public int getVisible() {
0665:                return visibleAmount;
0666:            }
0667:
0668:            /**
0669:             * Sets the visible amount of this scroll bar.
0670:             * <p>
0671:             * When a scroll bar is used to select a range of values,
0672:             * the visible amount is used to represent the range of values
0673:             * that are currently visible.  The size of the scroll bar's
0674:             * bubble (also called a thumb or scroll box), usually gives a
0675:             * visual representation of the relationship of the visible
0676:             * amount to the range of the scroll bar.
0677:             * <p>
0678:             * The scroll bar's bubble may not be displayed when it is not 
0679:             * moveable (e.g. when it takes up the entire length of the 
0680:             * scroll bar's track, or when the scroll bar is disabled). 
0681:             * Whether the bubble is displayed or not will not affect 
0682:             * the value returned by <code>getVisibleAmount</code>. 
0683:             * <p>
0684:             * If the visible amount supplied is less than <code>one</code>
0685:             * or greater than the current <code>maximum - minimum</code>, 
0686:             * then either <code>one</code> or <code>maximum - minimum</code> 
0687:             * is substituted, as appropriate.
0688:             * <p>
0689:             * Normally, a program should change a scroll bar's
0690:             * value only by calling <code>setValues</code>.
0691:             * The <code>setValues</code> method simultaneously
0692:             * and synchronously sets the minimum, maximum, visible amount,
0693:             * and value properties of a scroll bar, so that they are
0694:             * mutually consistent.
0695:             * 
0696:             * @param       newAmount the new visible amount
0697:             * @see         java.awt.Scrollbar#getVisibleAmount
0698:             * @see         java.awt.Scrollbar#setValues
0699:             * @since       JDK1.1
0700:             */
0701:            public void setVisibleAmount(int newAmount) {
0702:                // Use setValues so that a consistent policy relating
0703:                // minimum, maximum, visible amount, and value is enforced.
0704:                setValues(value, newAmount, minimum, maximum);
0705:            }
0706:
0707:            /**
0708:             * Sets the unit increment for this scroll bar.
0709:             * <p>
0710:             * The unit increment is the value that is added or subtracted
0711:             * when the user activates the unit increment area of the
0712:             * scroll bar, generally through a mouse or keyboard gesture
0713:             * that the scroll bar receives as an adjustment event.
0714:             * The unit increment must be greater than zero. 
0715:             * Attepts to set the unit increment to a value lower than 1 
0716:             * will result in a value of 1 being set.  
0717:             * 
0718:             * @param        v  the amount by which to increment or decrement
0719:             *                         the scroll bar's value
0720:             * @see          java.awt.Scrollbar#getUnitIncrement
0721:             * @since        JDK1.1
0722:             */
0723:            public void setUnitIncrement(int v) {
0724:                setLineIncrement(v);
0725:            }
0726:
0727:            /**
0728:             * @deprecated As of JDK version 1.1,
0729:             * replaced by <code>setUnitIncrement(int)</code>.
0730:             */
0731:            @Deprecated
0732:            public synchronized void setLineIncrement(int v) {
0733:                int tmp = (v < 1) ? 1 : v;
0734:
0735:                if (lineIncrement == tmp) {
0736:                    return;
0737:                }
0738:                lineIncrement = tmp;
0739:
0740:                ScrollbarPeer peer = (ScrollbarPeer) this .peer;
0741:                if (peer != null) {
0742:                    peer.setLineIncrement(lineIncrement);
0743:                }
0744:            }
0745:
0746:            /**
0747:             * Gets the unit increment for this scrollbar.
0748:             * <p>
0749:             * The unit increment is the value that is added or subtracted
0750:             * when the user activates the unit increment area of the
0751:             * scroll bar, generally through a mouse or keyboard gesture
0752:             * that the scroll bar receives as an adjustment event.
0753:             * The unit increment must be greater than zero. 
0754:             * 
0755:             * @return      the unit increment of this scroll bar
0756:             * @see         java.awt.Scrollbar#setUnitIncrement
0757:             * @since       JDK1.1
0758:             */
0759:            public int getUnitIncrement() {
0760:                return getLineIncrement();
0761:            }
0762:
0763:            /**
0764:             * @deprecated As of JDK version 1.1,
0765:             * replaced by <code>getUnitIncrement()</code>.
0766:             */
0767:            @Deprecated
0768:            public int getLineIncrement() {
0769:                return lineIncrement;
0770:            }
0771:
0772:            /**
0773:             * Sets the block increment for this scroll bar.
0774:             * <p>
0775:             * The block increment is the value that is added or subtracted
0776:             * when the user activates the block increment area of the
0777:             * scroll bar, generally through a mouse or keyboard gesture
0778:             * that the scroll bar receives as an adjustment event.
0779:             * The block increment must be greater than zero. 
0780:             * Attepts to set the block increment to a value lower than 1 
0781:             * will result in a value of 1 being set.  
0782:             * 
0783:             * @param        v  the amount by which to increment or decrement
0784:             *                         the scroll bar's value
0785:             * @see          java.awt.Scrollbar#getBlockIncrement
0786:             * @since        JDK1.1
0787:             */
0788:            public void setBlockIncrement(int v) {
0789:                setPageIncrement(v);
0790:            }
0791:
0792:            /**
0793:             * @deprecated As of JDK version 1.1,
0794:             * replaced by <code>setBlockIncrement()</code>.
0795:             */
0796:            @Deprecated
0797:            public synchronized void setPageIncrement(int v) {
0798:                int tmp = (v < 1) ? 1 : v;
0799:
0800:                if (pageIncrement == tmp) {
0801:                    return;
0802:                }
0803:                pageIncrement = tmp;
0804:
0805:                ScrollbarPeer peer = (ScrollbarPeer) this .peer;
0806:                if (peer != null) {
0807:                    peer.setPageIncrement(pageIncrement);
0808:                }
0809:            }
0810:
0811:            /**
0812:             * Gets the block increment of this scroll bar.
0813:             * <p>
0814:             * The block increment is the value that is added or subtracted
0815:             * when the user activates the block increment area of the
0816:             * scroll bar, generally through a mouse or keyboard gesture
0817:             * that the scroll bar receives as an adjustment event.
0818:             * The block increment must be greater than zero. 
0819:             * 
0820:             * @return      the block increment of this scroll bar
0821:             * @see         java.awt.Scrollbar#setBlockIncrement
0822:             * @since       JDK1.1
0823:             */
0824:            public int getBlockIncrement() {
0825:                return getPageIncrement();
0826:            }
0827:
0828:            /**
0829:             * @deprecated As of JDK version 1.1,
0830:             * replaced by <code>getBlockIncrement()</code>.
0831:             */
0832:            @Deprecated
0833:            public int getPageIncrement() {
0834:                return pageIncrement;
0835:            }
0836:
0837:            /**
0838:             * Sets the values of four properties for this scroll bar: 
0839:             * <code>value</code>, <code>visibleAmount</code>, 
0840:             * <code>minimum</code>, and <code>maximum</code>.
0841:             * If the values supplied for these properties are inconsistent 
0842:             * or incorrect, they will be changed to ensure consistency.  
0843:             * <p>
0844:             * This method simultaneously and synchronously sets the values
0845:             * of four scroll bar properties, assuring that the values of
0846:             * these properties are mutually consistent. It enforces the
0847:             * following constraints:  
0848:             * <code>maximum</code> must be greater than <code>minimum</code>,  
0849:             * <code>maximum - minimum</code> must not be greater 
0850:             *     than <code>Integer.MAX_VALUE</code>,  
0851:             * <code>visibleAmount</code> must be greater than zero. 
0852:             * <code>visibleAmount</code> must not be greater than 
0853:             *     <code>maximum - minimum</code>,  
0854:             * <code>value</code> must not be less than <code>minimum</code>,  
0855:             * and <code>value</code> must not be greater than 
0856:             *     <code>maximum - visibleAmount</code> 
0857:             * <p>
0858:             * Calling this method does not fire an
0859:             * <code>AdjustmentEvent</code>.
0860:             *
0861:             * @param      value is the position in the current window
0862:             * @param      visible is the visible amount of the scroll bar
0863:             * @param      minimum is the minimum value of the scroll bar
0864:             * @param      maximum is the maximum value of the scroll bar
0865:             * @see        #setMinimum
0866:             * @see        #setMaximum
0867:             * @see        #setVisibleAmount
0868:             * @see        #setValue
0869:             */
0870:            public void setValues(int value, int visible, int minimum,
0871:                    int maximum) {
0872:                int oldValue;
0873:                synchronized (this ) {
0874:                    if (minimum == Integer.MAX_VALUE) {
0875:                        minimum = Integer.MAX_VALUE - 1;
0876:                    }
0877:                    if (maximum <= minimum) {
0878:                        maximum = minimum + 1;
0879:                    }
0880:
0881:                    long maxMinusMin = (long) maximum - (long) minimum;
0882:                    if (maxMinusMin > Integer.MAX_VALUE) {
0883:                        maxMinusMin = Integer.MAX_VALUE;
0884:                        maximum = minimum + (int) maxMinusMin;
0885:                    }
0886:                    if (visible > (int) maxMinusMin) {
0887:                        visible = (int) maxMinusMin;
0888:                    }
0889:                    if (visible < 1) {
0890:                        visible = 1;
0891:                    }
0892:
0893:                    if (value < minimum) {
0894:                        value = minimum;
0895:                    }
0896:                    if (value > maximum - visible) {
0897:                        value = maximum - visible;
0898:                    }
0899:
0900:                    oldValue = this .value;
0901:                    this .value = value;
0902:                    this .visibleAmount = visible;
0903:                    this .minimum = minimum;
0904:                    this .maximum = maximum;
0905:                    ScrollbarPeer peer = (ScrollbarPeer) this .peer;
0906:                    if (peer != null) {
0907:                        peer.setValues(value, visibleAmount, minimum, maximum);
0908:                    }
0909:                }
0910:
0911:                if ((oldValue != value) && (accessibleContext != null)) {
0912:                    accessibleContext.firePropertyChange(
0913:                            AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
0914:                            Integer.valueOf(oldValue), Integer.valueOf(value));
0915:                }
0916:            }
0917:
0918:            /**
0919:             * Returns true if the value is in the process of changing as a
0920:             * result of actions being taken by the user.
0921:             *
0922:             * @return the value of the <code>valueIsAdjusting</code> property
0923:             * @see #setValueIsAdjusting
0924:             * @since 1.4
0925:             */
0926:            public boolean getValueIsAdjusting() {
0927:                return isAdjusting;
0928:            }
0929:
0930:            /**
0931:             * Sets the <code>valueIsAdjusting</code> property.
0932:             * 
0933:             * @param b new adjustment-in-progress status
0934:             * @see #getValueIsAdjusting
0935:             * @since 1.4
0936:             */
0937:            public void setValueIsAdjusting(boolean b) {
0938:                boolean oldValue;
0939:
0940:                synchronized (this ) {
0941:                    oldValue = isAdjusting;
0942:                    isAdjusting = b;
0943:                }
0944:
0945:                if ((oldValue != b) && (accessibleContext != null)) {
0946:                    accessibleContext.firePropertyChange(
0947:                            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0948:                            ((oldValue) ? AccessibleState.BUSY : null),
0949:                            ((b) ? AccessibleState.BUSY : null));
0950:                }
0951:            }
0952:
0953:            /**
0954:             * Adds the specified adjustment listener to receive instances of
0955:             * <code>AdjustmentEvent</code> from this scroll bar.
0956:             * If l is <code>null</code>, no exception is thrown and no
0957:             * action is performed.
0958:             * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0959:             * >AWT Threading Issues</a> for details on AWT's threading model.
0960:             *
0961:             * @param        l the adjustment listener
0962:             * @see          #removeAdjustmentListener
0963:             * @see          #getAdjustmentListeners
0964:             * @see          java.awt.event.AdjustmentEvent
0965:             * @see          java.awt.event.AdjustmentListener
0966:             * @since        JDK1.1
0967:             */
0968:            public synchronized void addAdjustmentListener(AdjustmentListener l) {
0969:                if (l == null) {
0970:                    return;
0971:                }
0972:                adjustmentListener = AWTEventMulticaster.add(
0973:                        adjustmentListener, l);
0974:                newEventsOnly = true;
0975:            }
0976:
0977:            /**
0978:             * Removes the specified adjustment listener so that it no longer
0979:             * receives instances of <code>AdjustmentEvent</code> from this scroll bar.
0980:             * If l is <code>null</code>, no exception is thrown and no action
0981:             * is performed.
0982:             * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0983:             * >AWT Threading Issues</a> for details on AWT's threading model.
0984:             *
0985:             * @param        	l    the adjustment listener
0986:             * @see          	#addAdjustmentListener
0987:             * @see          	#getAdjustmentListeners
0988:             * @see          	java.awt.event.AdjustmentEvent
0989:             * @see          	java.awt.event.AdjustmentListener
0990:             * @since        	JDK1.1
0991:             */
0992:            public synchronized void removeAdjustmentListener(
0993:                    AdjustmentListener l) {
0994:                if (l == null) {
0995:                    return;
0996:                }
0997:                adjustmentListener = AWTEventMulticaster.remove(
0998:                        adjustmentListener, l);
0999:            }
1000:
1001:            /**
1002:             * Returns an array of all the adjustment listeners
1003:             * registered on this scrollbar.
1004:             *
1005:             * @return all of this scrollbar's <code>AdjustmentListener</code>s
1006:             *         or an empty array if no adjustment 
1007:             *         listeners are currently registered
1008:             * @see          	#addAdjustmentListener
1009:             * @see          	#removeAdjustmentListener
1010:             * @see          	java.awt.event.AdjustmentEvent
1011:             * @see          	java.awt.event.AdjustmentListener
1012:             * @since 1.4
1013:             */
1014:            public synchronized AdjustmentListener[] getAdjustmentListeners() {
1015:                return (AdjustmentListener[]) (getListeners(AdjustmentListener.class));
1016:            }
1017:
1018:            /**
1019:             * Returns an array of all the objects currently registered
1020:             * as <code><em>Foo</em>Listener</code>s
1021:             * upon this <code>Scrollbar</code>.
1022:             * <code><em>Foo</em>Listener</code>s are registered using the
1023:             * <code>add<em>Foo</em>Listener</code> method.
1024:             * <p>
1025:             * You can specify the <code>listenerType</code> argument
1026:             * with a class literal,  such as
1027:             * <code><em>Foo</em>Listener.class</code>.
1028:             * For example, you can query a
1029:             * <code>Scrollbar</code> <code>c</code>
1030:             * for its mouse listeners with the following code:
1031:             *
1032:             * <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre>
1033:             *
1034:             * If no such listeners exist, this method returns an empty array.
1035:             *
1036:             * @param listenerType the type of listeners requested; this parameter
1037:             *          should specify an interface that descends from
1038:             *          <code>java.util.EventListener</code>
1039:             * @return an array of all objects registered as
1040:             *          <code><em>Foo</em>Listener</code>s on this component,
1041:             *          or an empty array if no such listeners have been added
1042:             * @exception ClassCastException if <code>listenerType</code>
1043:             *          doesn't specify a class or interface that implements
1044:             *          <code>java.util.EventListener</code>
1045:             *
1046:             * @since 1.3
1047:             */
1048:            public <T extends EventListener> T[] getListeners(
1049:                    Class<T> listenerType) {
1050:                EventListener l = null;
1051:                if (listenerType == AdjustmentListener.class) {
1052:                    l = adjustmentListener;
1053:                } else {
1054:                    return super .getListeners(listenerType);
1055:                }
1056:                return AWTEventMulticaster.getListeners(l, listenerType);
1057:            }
1058:
1059:            // REMIND: remove when filtering is done at lower level
1060:            boolean eventEnabled(AWTEvent e) {
1061:                if (e.id == AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED) {
1062:                    if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0
1063:                            || adjustmentListener != null) {
1064:                        return true;
1065:                    }
1066:                    return false;
1067:                }
1068:                return super .eventEnabled(e);
1069:            }
1070:
1071:            /**
1072:             * Processes events on this scroll bar. If the event is an
1073:             * instance of <code>AdjustmentEvent</code>, it invokes the
1074:             * <code>processAdjustmentEvent</code> method.
1075:             * Otherwise, it invokes its superclass's
1076:             * <code>processEvent</code> method.
1077:             * <p>Note that if the event parameter is <code>null</code>
1078:             * the behavior is unspecified and may result in an
1079:             * exception.
1080:             *
1081:             * @param        e the event
1082:             * @see          java.awt.event.AdjustmentEvent
1083:             * @see          java.awt.Scrollbar#processAdjustmentEvent
1084:             * @since        JDK1.1
1085:             */
1086:            protected void processEvent(AWTEvent e) {
1087:                if (e instanceof  AdjustmentEvent) {
1088:                    processAdjustmentEvent((AdjustmentEvent) e);
1089:                    return;
1090:                }
1091:                super .processEvent(e);
1092:            }
1093:
1094:            /**
1095:             * Processes adjustment events occurring on this
1096:             * scrollbar by dispatching them to any registered
1097:             * <code>AdjustmentListener</code> objects.
1098:             * <p>
1099:             * This method is not called unless adjustment events are
1100:             * enabled for this component. Adjustment events are enabled
1101:             * when one of the following occurs:
1102:             * <p><ul>
1103:             * <li>An <code>AdjustmentListener</code> object is registered
1104:             * via <code>addAdjustmentListener</code>.
1105:             * <li>Adjustment events are enabled via <code>enableEvents</code>.
1106:             * </ul><p>
1107:             * <p>Note that if the event parameter is <code>null</code>
1108:             * the behavior is unspecified and may result in an
1109:             * exception.
1110:             *
1111:             * @param       e the adjustment event
1112:             * @see         java.awt.event.AdjustmentEvent
1113:             * @see         java.awt.event.AdjustmentListener
1114:             * @see         java.awt.Scrollbar#addAdjustmentListener
1115:             * @see         java.awt.Component#enableEvents
1116:             * @since       JDK1.1
1117:             */
1118:            protected void processAdjustmentEvent(AdjustmentEvent e) {
1119:                AdjustmentListener listener = adjustmentListener;
1120:                if (listener != null) {
1121:                    listener.adjustmentValueChanged(e);
1122:                }
1123:            }
1124:
1125:            /**
1126:             * Returns a string representing the state of this <code>Scrollbar</code>.
1127:             * This method is intended to be used only for debugging purposes, and the 
1128:             * content and format of the returned string may vary between 
1129:             * implementations. The returned string may be empty but may not be 
1130:             * <code>null</code>.
1131:             *
1132:             * @return      the parameter string of this scroll bar
1133:             */
1134:            protected String paramString() {
1135:                return super .paramString() + ",val=" + value + ",vis="
1136:                        + visibleAmount + ",min=" + minimum + ",max=" + maximum
1137:                        + ((orientation == VERTICAL) ? ",vert" : ",horz")
1138:                        + ",isAdjusting=" + isAdjusting;
1139:            }
1140:
1141:            /* Serialization support.
1142:             */
1143:
1144:            /**
1145:             * The scroll bar's serialized Data Version.
1146:             *
1147:             * @serial
1148:             */
1149:            private int scrollbarSerializedDataVersion = 1;
1150:
1151:            /**
1152:             * Writes default serializable fields to stream.  Writes
1153:             * a list of serializable <code>AdjustmentListeners</code>
1154:             * as optional data. The non-serializable listeners are
1155:             * detected and no attempt is made to serialize them.
1156:             *
1157:             * @param s the <code>ObjectOutputStream</code> to write
1158:             * @serialData <code>null</code> terminated sequence of 0
1159:             *   or more pairs; the pair consists of a <code>String</code> 
1160:             *   and an <code>Object</code>; the <code>String</code> indicates
1161:             *   the type of object and is one of the following:
1162:             *   <code>adjustmentListenerK</code> indicating an
1163:             *     <code>AdjustmentListener</code> object
1164:             *
1165:             * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
1166:             * @see java.awt.Component#adjustmentListenerK
1167:             * @see #readObject(ObjectInputStream)
1168:             */
1169:            private void writeObject(ObjectOutputStream s) throws IOException {
1170:                s.defaultWriteObject();
1171:
1172:                AWTEventMulticaster.save(s, adjustmentListenerK,
1173:                        adjustmentListener);
1174:                s.writeObject(null);
1175:            }
1176:
1177:            /**
1178:             * Reads the <code>ObjectInputStream</code> and if
1179:             * it isn't <code>null</code> adds a listener to
1180:             * receive adjustment events fired by the
1181:             * <code>Scrollbar</code>.
1182:             * Unrecognized keys or values will be ignored.
1183:             * 
1184:             * @param s the <code>ObjectInputStream</code> to read
1185:             * @exception HeadlessException if
1186:             *   <code>GraphicsEnvironment.isHeadless</code> returns
1187:             *   <code>true</code>
1188:             * @see java.awt.GraphicsEnvironment#isHeadless
1189:             * @see #writeObject(ObjectOutputStream)
1190:             */
1191:            private void readObject(ObjectInputStream s)
1192:                    throws ClassNotFoundException, IOException,
1193:                    HeadlessException {
1194:                GraphicsEnvironment.checkHeadless();
1195:                s.defaultReadObject();
1196:
1197:                Object keyOrNull;
1198:                while (null != (keyOrNull = s.readObject())) {
1199:                    String key = ((String) keyOrNull).intern();
1200:
1201:                    if (adjustmentListenerK == key)
1202:                        addAdjustmentListener((AdjustmentListener) (s
1203:                                .readObject()));
1204:
1205:                    else
1206:                        // skip value for unrecognized key
1207:                        s.readObject();
1208:                }
1209:            }
1210:
1211:            /////////////////
1212:            // Accessibility support
1213:            ////////////////
1214:
1215:            /**
1216:             * Gets the <code>AccessibleContext</code> associated with this 
1217:             * <code>Scrollbar</code>. For scrollbars, the
1218:             * <code>AccessibleContext</code> takes the form of an 
1219:             * <code>AccessibleAWTScrollBar</code>. A new
1220:             * <code>AccessibleAWTScrollBar</code> instance is created if necessary.
1221:             *
1222:             * @return an <code>AccessibleAWTScrollBar</code> that serves as the 
1223:             *         <code>AccessibleContext</code> of this <code>ScrollBar</code>
1224:             * @since 1.3
1225:             */
1226:            public AccessibleContext getAccessibleContext() {
1227:                if (accessibleContext == null) {
1228:                    accessibleContext = new AccessibleAWTScrollBar();
1229:                }
1230:                return accessibleContext;
1231:            }
1232:
1233:            /**
1234:             * This class implements accessibility support for the
1235:             * <code>Scrollbar</code> class.  It provides an implementation of
1236:             * the Java Accessibility API appropriate to scrollbar
1237:             * user-interface elements.
1238:             * @since 1.3
1239:             */
1240:            protected class AccessibleAWTScrollBar extends
1241:                    AccessibleAWTComponent implements  AccessibleValue {
1242:                /*
1243:                 * JDK 1.3 serialVersionUID
1244:                 */
1245:                private static final long serialVersionUID = -344337268523697807L;
1246:
1247:                /**
1248:                 * Get the state set of this object.
1249:                 *
1250:                 * @return an instance of <code>AccessibleState</code>
1251:                 *     containing the current state of the object
1252:                 * @see AccessibleState
1253:                 */
1254:                public AccessibleStateSet getAccessibleStateSet() {
1255:                    AccessibleStateSet states = super .getAccessibleStateSet();
1256:                    if (getValueIsAdjusting()) {
1257:                        states.add(AccessibleState.BUSY);
1258:                    }
1259:                    if (getOrientation() == VERTICAL) {
1260:                        states.add(AccessibleState.VERTICAL);
1261:                    } else {
1262:                        states.add(AccessibleState.HORIZONTAL);
1263:                    }
1264:                    return states;
1265:                }
1266:
1267:                /**
1268:                 * Get the role of this object.
1269:                 *
1270:                 * @return an instance of <code>AccessibleRole</code>
1271:                 *     describing the role of the object
1272:                 */
1273:                public AccessibleRole getAccessibleRole() {
1274:                    return AccessibleRole.SCROLL_BAR;
1275:                }
1276:
1277:                /**
1278:                 * Get the <code>AccessibleValue</code> associated with this
1279:                 * object.  In the implementation of the Java Accessibility
1280:                 * API for this class, return this object, which is
1281:                 * responsible for implementing the
1282:                 * <code>AccessibleValue</code> interface on behalf of itself.
1283:                 * 
1284:                 * @return this object
1285:                 */
1286:                public AccessibleValue getAccessibleValue() {
1287:                    return this ;
1288:                }
1289:
1290:                /**
1291:                 * Get the accessible value of this object.
1292:                 *
1293:                 * @return The current value of this object.
1294:                 */
1295:                public Number getCurrentAccessibleValue() {
1296:                    return Integer.valueOf(getValue());
1297:                }
1298:
1299:                /**
1300:                 * Set the value of this object as a Number.
1301:                 *
1302:                 * @return True if the value was set.
1303:                 */
1304:                public boolean setCurrentAccessibleValue(Number n) {
1305:                    if (n instanceof  Integer) {
1306:                        setValue(n.intValue());
1307:                        return true;
1308:                    } else {
1309:                        return false;
1310:                    }
1311:                }
1312:
1313:                /**
1314:                 * Get the minimum accessible value of this object.
1315:                 *
1316:                 * @return The minimum value of this object.
1317:                 */
1318:                public Number getMinimumAccessibleValue() {
1319:                    return Integer.valueOf(getMinimum());
1320:                }
1321:
1322:                /**
1323:                 * Get the maximum accessible value of this object.
1324:                 *
1325:                 * @return The maximum value of this object.
1326:                 */
1327:                public Number getMaximumAccessibleValue() {
1328:                    return Integer.valueOf(getMaximum());
1329:                }
1330:
1331:            } // AccessibleAWTScrollBar
1332:
1333:        }
ww_w_.__j_a__v___a___2___s___._c_o__m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.