API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.swing. ProgressMonitor View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032

/*
 * @(#)ProgressMonitor.java	1.37 06/04/12
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */



package javax.swing;



import java.io.*;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Dialog;
import java.awt.Window;
import java.awt.Component;
import java.awt.Container;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.awt.event.WindowListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import java.awt.IllegalComponentStateException;
import java.awt.Point;
import java.awt.Rectangle;
import java.text.*;
import java.util.Locale;
import javax.accessibility.*;
import javax.swing.event.*;
import javax.swing.text.*;


/** A class to monitor the progress of some operation. If it looks
 * like the operation will take a while, a progress dialog will be popped up.
 * When the ProgressMonitor is created it is given a numeric range and a
 * descriptive string. As the operation progresses, call the setProgress method
 * to indicate how far along the [min,max] range the operation is.
 * Initially, there is no ProgressDialog. After the first millisToDecideToPopup
 * milliseconds (default 500) the progress monitor will predict how long
 * the operation will take.  If it is longer than millisToPopup (default 2000,
 * 2 seconds) a ProgressDialog will be popped up.
 * <p>
 * From time to time, when the Dialog box is visible, the progress bar will
 * be updated when setProgress is called.  setProgress won't always update
 * the progress bar, it will only be done if the amount of progress is
 * visibly significant.
 *
 * <p>
 * 
 * For further documentation and examples see
 * <a
 href="http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html">How to Monitor Progress</a>,
 * a section in <em>The Java Tutorial.</em>
 *
 * @see ProgressMonitorInputStream
 * @author James Gosling
 * @author Lynn Monsanto (accessibility) 
 * @version 1.37 04/12/06
 */
public class ProgressMonitor extends Object implements Accessible
{
    private ProgressMonitor root;
    private JDialog         dialog;
    private JOptionPane     pane;
    private JProgressBar    myBar;
    private JLabel          noteLabel;
    private Component       parentComponent;
    private String          note;
    private Object[]        cancelOption = null;
    private Object          message;
    private long            T0;
    private int             millisToDecideToPopup = 500;
    private int             millisToPopup = 2000;
    private int             min;
    private int             max;


    /**
     * Constructs a graphic object that shows progress, typically by filling
     * in a rectangular bar as the process nears completion.
     *
     * @param parentComponent the parent component for the dialog box
     * @param message a descriptive message that will be shown
     *        to the user to indicate what operation is being monitored.
     *        This does not change as the operation progresses.
     *        See the message parameters to methods in
     *        {@link JOptionPane#message}
     *        for the range of values.
     * @param note a short note describing the state of the
     *        operation.  As the operation progresses, you can call
     *        setNote to change the note displayed.  This is used,
     *        for example, in operations that iterate through a
     *        list of files to show the name of the file being processes.
     *        If note is initially null, there will be no note line
     *        in the dialog box and setNote will be ineffective
     * @param min the lower bound of the range
     * @param max the upper bound of the range
     * @see JDialog
     * @see JOptionPane
     */
    public ProgressMonitor(Component parentComponent,
                           Object message,
                           String note,
                           int min,
                           int max) {
        this(parentComponent, message, note, min, max, null);
    }


    private ProgressMonitor(Component parentComponent,
                            Object message,
                            String note,
                            int min,
                            int max,
                            ProgressMonitor group) {
        this.min = min;
        this.max = max;
        this.parentComponent = parentComponent;

        cancelOption = new Object[1];
        cancelOption[0] = UIManager.getString("OptionPane.cancelButtonText");

        this.message = message;
        this.note = note;
        if (group != null) {
            root = (group.root != null) ? group.root : group;
            T0 = root.T0;
            dialog = root.dialog;
        }
        else {
            T0 = System.currentTimeMillis();
        }
    }


    private class ProgressOptionPane extends JOptionPane
    {
        ProgressOptionPane(Object messageList) {
            super(messageList,
                  JOptionPane.INFORMATION_MESSAGE,
                  JOptionPane.DEFAULT_OPTION,
                  null,
                  ProgressMonitor.this.cancelOption,
                  null);
        }


        public int getMaxCharactersPerLineCount() {
            return 60;
        }


        // Equivalent to JOptionPane.createDialog,
        // but create a modeless dialog.
        // This is necessary because the Solaris implementation doesn't
        // support Dialog.setModal yet.
        public JDialog createDialog(Component parentComponent, String title) {
            final JDialog dialog;
	    
	    Window window = JOptionPane.getWindowForComponent(parentComponent);
	    if (window instanceof Frame) {
		dialog = new JDialog((Frame)window, title, false);	
	    } else {
		dialog = new JDialog((Dialog)window, title, false);
	    }
  	    if (window instanceof SwingUtilities.SharedOwnerFrame) {
  		WindowListener ownerShutdownListener =
  		    (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
  		dialog.addWindowListener(ownerShutdownListener);
  	    }
            Container contentPane = dialog.getContentPane();

            contentPane.setLayout(new BorderLayout());
            contentPane.add(this, BorderLayout.CENTER);
            dialog.pack();
            dialog.setLocationRelativeTo(parentComponent);
            dialog.addWindowListener(new WindowAdapter() {
                boolean gotFocus = false;

                public void windowClosing(WindowEvent we) {
                    setValue(cancelOption[0]);
                }

                public void windowActivated(WindowEvent we) {
                    // Once window gets focus, set initial focus
                    if (!gotFocus) {
                        selectInitialValue();
                        gotFocus = true;
                    }
                }
            });

            addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent event) {
                    if(dialog.isVisible() && 
                       event.getSource() == ProgressOptionPane.this &&
                       (event.getPropertyName().equals(VALUE_PROPERTY) ||
                        event.getPropertyName().equals(INPUT_VALUE_PROPERTY))){
                        dialog.setVisible(false);
                        dialog.dispose();
                    }
                }
            });

            return dialog;
        }
        
	/////////////////
	// Accessibility support for ProgressOptionPane
	////////////////
	    
	/**
	 * Gets the AccessibleContext for the ProgressOptionPane
	 *
	 * @return the AccessibleContext for the ProgressOptionPane
	 * @since 1.5
	 */
	public AccessibleContext getAccessibleContext() {
	    return ProgressMonitor.this.getAccessibleContext();
	}

	/*
	 * Returns the AccessibleJOptionPane
	 */
	private AccessibleContext getAccessibleJOptionPane() {
	    return super.getAccessibleContext();
	}
    }


    /** 
     * Indicate the progress of the operation being monitored.
     * If the specified value is >= the maximum, the progress
     * monitor is closed. 
     * @param nv an int specifying the current value, between the
     *        maximum and minimum specified for this component
     * @see #setMinimum
     * @see #setMaximum
     * @see #close
     */
    public void setProgress(int nv) {
        if (nv >= max) {
            close();
        }
        else {
            if (myBar != null) {
                myBar.setValue(nv);
            }
            else {
                long T = System.currentTimeMillis();
                long dT = (int)(T-T0);
                if (dT >= millisToDecideToPopup) {
                    int predictedCompletionTime;
                    if (nv > min) {
                        predictedCompletionTime = (int)((long)dT *
                                                        (max - min) /
                                                        (nv - min));
                    }
                    else {
                        predictedCompletionTime = millisToPopup;
                    }
                    if (predictedCompletionTime >= millisToPopup) {
                        myBar = new JProgressBar();
                        myBar.setMinimum(min);
                        myBar.setMaximum(max);
                        myBar.setValue(nv);
                        if (note != null) noteLabel = new JLabel(note);
                        pane = new ProgressOptionPane(new Object[] {message,
                                                                    noteLabel,
                                                                    myBar});
                        dialog = pane.createDialog(parentComponent,
                            UIManager.getString(
                                "ProgressMonitor.progressText"));
                        dialog.show();
                    }
                }
            }
        }
    }


    /** 
     * Indicate that the operation is complete.  This happens automatically
     * when the value set by setProgress is >= max, but it may be called
     * earlier if the operation ends early.
     */
    public void close() {
        if (dialog != null) {
            dialog.setVisible(false);
            dialog.dispose();
            dialog = null;
            pane = null;
            myBar = null;
        }
    }


    /**
     * Returns the minimum value -- the lower end of the progress value.
     *
     * @return an int representing the minimum value
     * @see #setMinimum
     */
    public int getMinimum() {
        return min;
    }


    /**
     * Specifies the minimum value.
     *
     * @param m  an int specifying the minimum value
     * @see #getMinimum
     */
    public void setMinimum(int m) {
        if (myBar != null) {
            myBar.setMinimum(m);
        }
        min = m;
    }


    /**
     * Returns the maximum value -- the higher end of the progress value.
     *
     * @return an int representing the maximum value
     * @see #setMaximum
     */
    public int getMaximum() {
        return max;
    }


    /**
     * Specifies the maximum value.
     *
     * @param m  an int specifying the maximum value
     * @see #getMaximum
     */
    public void setMaximum(int m) {
        if (myBar != null) {
            myBar.setMaximum(m);
        }
        max = m;
    }


    /** 
     * Returns true if the user hits the Cancel button in the progress dialog.
     */
    public boolean isCanceled() {
        if (pane == null) return false;
        Object v = pane.getValue();
        return ((v != null) &&
                (cancelOption.length == 1) &&
                (v.equals(cancelOption[0])));
    }


    /**
     * Specifies the amount of time to wait before deciding whether or
     * not to popup a progress monitor.
     *
     * @param millisToDecideToPopup  an int specifying the time to wait,
     *        in milliseconds
     * @see #getMillisToDecideToPopup
     */
    public void setMillisToDecideToPopup(int millisToDecideToPopup) {
        this.millisToDecideToPopup = millisToDecideToPopup;
    }


    /**
     * Returns the amount of time this object waits before deciding whether
     * or not to popup a progress monitor.
     *
     * @see #setMillisToDecideToPopup
     */
    public int getMillisToDecideToPopup() {
        return millisToDecideToPopup;
    }


    /**
     * Specifies the amount of time it will take for the popup to appear.
     * (If the predicted time remaining is less than this time, the popup
     * won't be displayed.)
     *
     * @param millisToPopup  an int specifying the time in milliseconds
     * @see #getMillisToPopup
     */
    public void setMillisToPopup(int millisToPopup) {
        this.millisToPopup = millisToPopup;
    }


    /**
     * Returns the amount of time it will take for the popup to appear.
     *
     * @see #setMillisToPopup
     */
    public int getMillisToPopup() {
        return millisToPopup;
    }


    /**
     * Specifies the additional note that is displayed along with the
     * progress message. Used, for example, to show which file the
     * is currently being copied during a multiple-file copy.
     *
     * @param note  a String specifying the note to display
     * @see #getNote
     */
    public void setNote(String note) {
        this.note = note;
        if (noteLabel != null) {
            noteLabel.setText(note);
        }
    }


    /**
     * Specifies the additional note that is displayed along with the
     * progress message.
     *
     * @return a String specifying the note to display
     * @see #setNote
     */
    public String getNote() {
        return note;
    }

    /////////////////
    // Accessibility support
    ////////////////
	
    /**
     * The <code>AccessibleContext</code> for the <code>ProgressMonitor</code> 
     * @since 1.5
     */
    protected AccessibleContext accessibleContext = null;

    private AccessibleContext accessibleJOptionPane = null;

    /**
     * Gets the <code>AccessibleContext</code> for the 
     * <code>ProgressMonitor</code> 
     *
     * @return the <code>AccessibleContext</code> for the
     * <code>ProgressMonitor</code>
     * @since 1.5
     */
    public AccessibleContext getAccessibleContext() {
	if (accessibleContext == null) {
	    accessibleContext = new AccessibleProgressMonitor();
	}
	if (pane != null && accessibleJOptionPane == null) {
	    // Notify the AccessibleProgressMonitor that the
	    // ProgressOptionPane was created. It is necessary
	    // to poll for ProgressOptionPane creation because
	    // the ProgressMonitor does not have a Component 
	    // to add a listener to until the ProgressOptionPane
	    // is created.
	    if (accessibleContext instanceof AccessibleProgressMonitor) {
		((AccessibleProgressMonitor)accessibleContext).optionPaneCreated();
	    }
	}
	return accessibleContext;
    }
    
    /**
     * <code>AccessibleProgressMonitor</code> implements accessibility 
     * support for the <code>ProgressMonitor</code> class. 
     * @since 1.5 
     */
    protected class AccessibleProgressMonitor extends AccessibleContext
        implements AccessibleText, ChangeListener, PropertyChangeListener {

	/*
	 * The accessibility hierarchy for ProgressMonitor is a flattened 
	 * version of the ProgressOptionPane component hierarchy. 
	 *
	 * The ProgressOptionPane component hierarchy is:
	 *   JDialog
	 *     ProgressOptionPane
	 *       JPanel
	 *         JPanel
	 *           JLabel
	 *           JLabel
	 *           JProgressBar
	 *
	 * The AccessibleProgessMonitor accessibility hierarchy is:
	 *   AccessibleJDialog
	 *     AccessibleProgressMonitor
	 *       AccessibleJLabel
	 *       AccessibleJLabel
	 *       AccessibleJProgressBar
	 *
	 * The abstraction presented to assitive technologies by
	 * the AccessibleProgressMonitor is that a dialog contains a 
	 * progress monitor with three children: a message, a note
	 * label and a progress bar.
	 */

	private Object oldModelValue;

	/**
	 * AccessibleProgressMonitor constructor
	 */
	protected AccessibleProgressMonitor() {
	}

	/*
	 * Initializes the AccessibleContext now that the ProgressOptionPane 
	 * has been created. Because the ProgressMonitor is not a Component
	 * implementing the Accessible interface, an AccessibleContext
	 * must be synthesized from the ProgressOptionPane and its children.
	 *
	 * For other AWT and Swing classes, the inner class that implements
	 * accessibility for the class extends the inner class that implements
	 * implements accessibility for the super class. AccessibleProgressMonitor 
	 * cannot extend AccessibleJOptionPane and must therefore delegate calls 
	 * to the AccessibleJOptionPane.
	 */
	private void optionPaneCreated() {
	    accessibleJOptionPane = 
		((ProgressOptionPane)pane).getAccessibleJOptionPane();

	    // add a listener for progress bar ChangeEvents
	    if (myBar != null) {
		myBar.addChangeListener(this);
	    }

	    // add a listener for note label PropertyChangeEvents
	    if (noteLabel != null) {
		noteLabel.addPropertyChangeListener(this);
	    }
	}

        /**
         * Invoked when the target of the listener has changed its state.
         *
         * @param e  a <code>ChangeEvent</code> object. Must not be null.
	 * @throws NullPointerException if the parameter is null.
	 */  
	public void stateChanged(ChangeEvent e) {
            if (e == null) {
                return;
            }
	    if (myBar != null) {
		// the progress bar value changed
		Object newModelValue = myBar.getValue();
		firePropertyChange(ACCESSIBLE_VALUE_PROPERTY, 
				   oldModelValue, 
				   newModelValue);
		oldModelValue = newModelValue;
	    }
	}

	/**
	 * This method gets called when a bound property is changed.
	 *
	 * @param e A <code>PropertyChangeEvent</code> object describing
	 * the event source and the property that has changed. Must not be null.
	 * @throws NullPointerException if the parameter is null.
	 */ 
	public void propertyChange(PropertyChangeEvent e) {
	    if (e.getSource() == noteLabel && e.getPropertyName() == "text") {
		// the note label text changed
		firePropertyChange(ACCESSIBLE_TEXT_PROPERTY, null, 0);
	    } 
	}

	/* ===== Begin AccessileContext ===== */

	/**
	 * Gets the accessibleName property of this object.  The accessibleName
	 * property of an object is a localized String that designates the purpose
	 * of the object.  For example, the accessibleName property of a label
	 * or button might be the text of the label or button itself.  In the
	 * case of an object that doesn't display its name, the accessibleName
	 * should still be set.  For example, in the case of a text field used
	 * to enter the name of a city, the accessibleName for the en_US locale
	 * could be 'city.'
	 *
	 * @return the localized name of the object; null if this 
	 * object does not have a name
	 *
	 * @see #setAccessibleName
	 */
	public String getAccessibleName() {
	    if (accessibleName != null) { // defined in AccessibleContext
		return accessibleName;
	    } else if (accessibleJOptionPane != null) {
		// delegate to the AccessibleJOptionPane
		return accessibleJOptionPane.getAccessibleName();
	    } 
	    return null;
	}
	
	/**
	 * Gets the accessibleDescription property of this object.  The
	 * accessibleDescription property of this object is a short localized
	 * phrase describing the purpose of the object.  For example, in the 
	 * case of a 'Cancel' button, the accessibleDescription could be
	 * 'Ignore changes and close dialog box.'
	 *
	 * @return the localized description of the object; null if 
	 * this object does not have a description
	 *
	 * @see #setAccessibleDescription
	 */
	public String getAccessibleDescription() {
	    if (accessibleDescription != null) { // defined in AccessibleContext
		return accessibleDescription; 
	    } else if (accessibleJOptionPane != null) {
		// delegate to the AccessibleJOptionPane
		return accessibleJOptionPane.getAccessibleDescription();
	    } 
	    return null;
	}

	/**
	 * Gets the role of this object.  The role of the object is the generic
	 * purpose or use of the class of this object.  For example, the role
	 * of a push button is AccessibleRole.PUSH_BUTTON.  The roles in 
	 * AccessibleRole are provided so component developers can pick from
	 * a set of predefined roles.  This enables assistive technologies to
	 * provide a consistent interface to various tweaked subclasses of 
	 * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
	 * that act like a push button) as well as distinguish between sublasses
	 * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
	 * and AccessibleRole.RADIO_BUTTON for radio buttons).
	 * <p>Note that the AccessibleRole class is also extensible, so 
	 * custom component developers can define their own AccessibleRole's
	 * if the set of predefined roles is inadequate.
	 *
	 * @return an instance of AccessibleRole describing the role of the object
	 * @see AccessibleRole
	 */
	public AccessibleRole getAccessibleRole() {
	    return AccessibleRole.PROGRESS_MONITOR;
	}
    
	/**
	 * Gets the state set of this object.  The AccessibleStateSet of an object
	 * is composed of a set of unique AccessibleStates.  A change in the 
	 * AccessibleStateSet of an object will cause a PropertyChangeEvent to 
	 * be fired for the ACCESSIBLE_STATE_PROPERTY property.
	 *
	 * @return an instance of AccessibleStateSet containing the 
	 * current state set of the object
	 * @see AccessibleStateSet
	 * @see AccessibleState
	 * @see #addPropertyChangeListener
	 */
	public AccessibleStateSet getAccessibleStateSet() {
	    if (accessibleJOptionPane != null) {
		// delegate to the AccessibleJOptionPane
		return accessibleJOptionPane.getAccessibleStateSet();
	    } 
	    return null;
	}

	/**
	 * Gets the Accessible parent of this object.
	 *
	 * @return the Accessible parent of this object; null if this
	 * object does not have an Accessible parent
	 */
	public Accessible getAccessibleParent() {
	    if (dialog != null) {
		return (Accessible)dialog;
	    }
	    return null;
	}

	/*
	 * Returns the parent AccessibleContext
	 */
	private AccessibleContext getParentAccessibleContext() {
	    if (dialog != null) {
		return dialog.getAccessibleContext();
	    }
	    return null;
	}

	/**
	 * Gets the 0-based index of this object in its accessible parent.
	 *
	 * @return the 0-based index of this object in its parent; -1 if this 
	 * object does not have an accessible parent.
	 *
	 * @see #getAccessibleParent 
	 * @see #getAccessibleChildrenCount
	 * @see #getAccessibleChild
	 */
	public int getAccessibleIndexInParent() {
	    if (accessibleJOptionPane != null) {
		// delegate to the AccessibleJOptionPane
		return accessibleJOptionPane.getAccessibleIndexInParent();
	    }
	    return -1;
	}

	/**
	 * Returns the number of accessible children of the object.
	 *
	 * @return the number of accessible children of the object.
	 */
	public int getAccessibleChildrenCount() {
	    // return the number of children in the JPanel containing
	    // the message, note label and progress bar
	    AccessibleContext ac = getPanelAccessibleContext();
	    if (ac != null) {
		return ac.getAccessibleChildrenCount();
	    }
	    return 0;
	}

	/**
	 * Returns the specified Accessible child of the object.  The Accessible
	 * children of an Accessible object are zero-based, so the first child 
	 * of an Accessible child is at index 0, the second child is at index 1,
	 * and so on.
	 *
	 * @param i zero-based index of child
	 * @return the Accessible child of the object
	 * @see #getAccessibleChildrenCount
	 */
	public Accessible getAccessibleChild(int i) {
	    // return a child in the JPanel containing the message, note label 
	    // and progress bar
	    AccessibleContext ac = getPanelAccessibleContext();
	    if (ac != null) {
		return ac.getAccessibleChild(i);
	    }
	    return null;
	}
	
	/*
	 * Returns the AccessibleContext for the JPanel containing the
	 * message, note label and progress bar
	 */
	private AccessibleContext getPanelAccessibleContext() {
	    if (myBar != null) {
		Component c = myBar.getParent();
		if (c instanceof Accessible) {
		    return ((Accessible)c).getAccessibleContext();
		}
	    }
	    return null;
	}

	/** 
	 * Gets the locale of the component. If the component does not have a 
	 * locale, then the locale of its parent is returned.  
	 *
	 * @return this component's locale.  If this component does not have 
	 * a locale, the locale of its parent is returned.
	 *
	 * @exception IllegalComponentStateException 
	 * If the Component does not have its own locale and has not yet been 
	 * added to a containment hierarchy such that the locale can be
	 * determined from the containing parent. 
	 */
	public Locale getLocale() throws IllegalComponentStateException {
	    if (accessibleJOptionPane != null) {
		// delegate to the AccessibleJOptionPane
		return accessibleJOptionPane.getLocale();
	    }
	    return null;
	}

	/* ===== end AccessibleContext ===== */

	/**
	 * Gets the AccessibleComponent associated with this object that has a 
	 * graphical representation.
	 *
	 * @return AccessibleComponent if supported by object; else return null
	 * @see AccessibleComponent
	 */
	public AccessibleComponent getAccessibleComponent() {
	    if (accessibleJOptionPane != null) {
		// delegate to the AccessibleJOptionPane
		return accessibleJOptionPane.getAccessibleComponent();
	    }
	    return null;
	}

	/**
	 * Gets the AccessibleValue associated with this object that supports a 
	 * Numerical value. 
	 * 
	 * @return AccessibleValue if supported by object; else return null 
	 * @see AccessibleValue
	 */
        public AccessibleValue getAccessibleValue() {
	    if (myBar != null) {
		// delegate to the AccessibleJProgressBar
		return myBar.getAccessibleContext().getAccessibleValue();
	    }
	    return null;
        }

	/**
	 * Gets the AccessibleText associated with this object presenting 
	 * text on the display.
	 *
	 * @return AccessibleText if supported by object; else return null
	 * @see AccessibleText
	 */
	public AccessibleText getAccessibleText() {
	    if (getNoteLabelAccessibleText() != null) {
		return this;
	    }
	    return null;
	}

	/*
	 * Returns the note label AccessibleText
	 */
	private AccessibleText getNoteLabelAccessibleText() {
	    if (noteLabel != null) {
		// AccessibleJLabel implements AccessibleText if the
		// JLabel contains HTML text
		return noteLabel.getAccessibleContext().getAccessibleText();
	    }
	    return null;
	}

	/* ===== Begin AccessibleText impl ===== */

	/**
	 * Given a point in local coordinates, return the zero-based index
	 * of the character under that Point.  If the point is invalid,
	 * this method returns -1.
	 *
	 * @param p the Point in local coordinates
	 * @return the zero-based index of the character under Point p; if 
	 * Point is invalid return -1.
	 */
	public int getIndexAtPoint(Point p) {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null && sameWindowAncestor(pane, noteLabel)) {
		// convert point from the option pane bounds
		// to the note label bounds.
		Point noteLabelPoint = SwingUtilities.convertPoint(pane,
								   p,
								   noteLabel);
		if (noteLabelPoint != null) {
		    return at.getIndexAtPoint(noteLabelPoint);
		}
	    }
	    return -1;
	}

	/**
	 * Determines the bounding box of the character at the given 
	 * index into the string.  The bounds are returned in local
	 * coordinates.  If the index is invalid an empty rectangle is returned.
	 *
	 * @param i the index into the String
	 * @return the screen coordinates of the character's bounding box,
	 * if index is invalid return an empty rectangle.
	 */
	public Rectangle getCharacterBounds(int i) {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null && sameWindowAncestor(pane, noteLabel)) {
		// return rectangle in the option pane bounds
		Rectangle noteLabelRect = at.getCharacterBounds(i);
		if (noteLabelRect != null) {
		    return SwingUtilities.convertRectangle(noteLabel,
							   noteLabelRect,
							   pane);
		}
	    }
	    return null;
	}

	/*
	 * Returns whether source and destination components have the
	 * same window ancestor
	 */
	private boolean sameWindowAncestor(Component src, Component dest) {
	    if (src == null || dest == null) {
		return false;
	    }
	    return SwingUtilities.getWindowAncestor(src) ==
		SwingUtilities.getWindowAncestor(dest);
	}

	/**
	 * Returns the number of characters (valid indicies) 
	 *
	 * @return the number of characters
	 */
	public int getCharCount() {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null) {	// JLabel contains HTML text
		return at.getCharCount();
	    } 
	    return -1;
	}

	/**
	 * Returns the zero-based offset of the caret.
	 *
	 * Note: That to the right of the caret will have the same index
	 * value as the offset (the caret is between two characters).
	 * @return the zero-based offset of the caret.
	 */
	public int getCaretPosition() {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null) {	// JLabel contains HTML text
		return at.getCaretPosition();
	    }
	    return -1;
	}

	/**
	 * Returns the String at a given index. 
	 *
	 * @param part the CHARACTER, WORD, or SENTENCE to retrieve
	 * @param index an index within the text
	 * @return the letter, word, or sentence
	 */
	public String getAtIndex(int part, int index) {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null) {	// JLabel contains HTML text
		return at.getAtIndex(part, index);
	    }
	    return null;
	}

	/**
	 * Returns the String after a given index.
	 *
	 * @param part the CHARACTER, WORD, or SENTENCE to retrieve
	 * @param index an index within the text
	 * @return the letter, word, or sentence
	 */
	public String getAfterIndex(int part, int index) {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null) {	// JLabel contains HTML text
		return at.getAfterIndex(part, index);
	    }
	    return null;
	}

	/**
	 * Returns the String before a given index.
	 *
	 * @param part the CHARACTER, WORD, or SENTENCE to retrieve
	 * @param index an index within the text
	 * @return the letter, word, or sentence
	 */
	public String getBeforeIndex(int part, int index) {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null) {	// JLabel contains HTML text
		return at.getBeforeIndex(part, index);
	    }
	    return null;
	}

	/**
	 * Returns the AttributeSet for a given character at a given index
	 *
	 * @param i the zero-based index into the text 
	 * @return the AttributeSet of the character
	 */
	public AttributeSet getCharacterAttribute(int i) {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null) {	// JLabel contains HTML text
		return at.getCharacterAttribute(i);
	    }
	    return null;
	}

	/**
	 * Returns the start offset within the selected text.
	 * If there is no selection, but there is
	 * a caret, the start and end offsets will be the same.
	 *
	 * @return the index into the text of the start of the selection
	 */
	public int getSelectionStart() {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null) {	// JLabel contains HTML text
		return at.getSelectionStart();
	    }
	    return -1;
	}

	/**
	 * Returns the end offset within the selected text.
	 * If there is no selection, but there is
	 * a caret, the start and end offsets will be the same.
	 *
	 * @return the index into teh text of the end of the selection
	 */
	public int getSelectionEnd() {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null) {	// JLabel contains HTML text
		return at.getSelectionEnd();
	    }
	    return -1;
	}

	/**
	 * Returns the portion of the text that is selected. 
	 *
	 * @return the String portion of the text that is selected
	 */
	public String getSelectedText() {
	    AccessibleText at = getNoteLabelAccessibleText();
	    if (at != null) {	// JLabel contains HTML text
		return at.getSelectedText();
	    }
	    return null;
	}
	/* ===== End AccessibleText impl ===== */
    } 
    // inner class AccessibleProgressMonitor

}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar