jdk/src/share/classes/javax/swing/ProgressMonitor.java
author dmarkov
Wed, 16 Apr 2014 12:51:25 +0400
changeset 24184 4da2f6ec4dab
parent 23697 e556a715949f
child 25201 4adc75e0c4e5
permissions -rw-r--r--
8032874: ArrayIndexOutOfBoundsException in JTable while clearing data in JTable Reviewed-by: alexp, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.event.WindowListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.event.WindowAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.IllegalComponentStateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/** A class to monitor the progress of some operation. If it looks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * like the operation will take a while, a progress dialog will be popped up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * When the ProgressMonitor is created it is given a numeric range and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * descriptive string. As the operation progresses, call the setProgress method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * to indicate how far along the [min,max] range the operation is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Initially, there is no ProgressDialog. After the first millisToDecideToPopup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * milliseconds (default 500) the progress monitor will predict how long
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * the operation will take.  If it is longer than millisToPopup (default 2000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * 2 seconds) a ProgressDialog will be popped up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * From time to time, when the Dialog box is visible, the progress bar will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * be updated when setProgress is called.  setProgress won't always update
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * the progress bar, it will only be done if the amount of progress is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * visibly significant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * For further documentation and examples see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20157
diff changeset
    74
 href="http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html">How to Monitor Progress</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @see ProgressMonitorInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author James Gosling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @author Lynn Monsanto (accessibility)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 */
1843
267cc4de4221 6776095: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
    81
public class ProgressMonitor implements Accessible
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private ProgressMonitor root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private JDialog         dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private JOptionPane     pane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private JProgressBar    myBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private JLabel          noteLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private Component       parentComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private String          note;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private Object[]        cancelOption = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private Object          message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private long            T0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private int             millisToDecideToPopup = 500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private int             millisToPopup = 2000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private int             min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private int             max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Constructs a graphic object that shows progress, typically by filling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * in a rectangular bar as the process nears completion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param parentComponent the parent component for the dialog box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param message a descriptive message that will be shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *        to the user to indicate what operation is being monitored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *        This does not change as the operation progresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *        See the message parameters to methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *        {@link JOptionPane#message}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *        for the range of values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param note a short note describing the state of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *        operation.  As the operation progresses, you can call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *        setNote to change the note displayed.  This is used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *        for example, in operations that iterate through a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *        list of files to show the name of the file being processes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *        If note is initially null, there will be no note line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *        in the dialog box and setNote will be ineffective
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param min the lower bound of the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param max the upper bound of the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @see JDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @see JOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public ProgressMonitor(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                           Object message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                           String note,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                           int min,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                           int max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this(parentComponent, message, note, min, max, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private ProgressMonitor(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                            Object message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                            String note,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                            int min,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                            int max,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                            ProgressMonitor group) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        this.min = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        this.max = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        this.parentComponent = parentComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        cancelOption = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        cancelOption[0] = UIManager.getString("OptionPane.cancelButtonText");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        this.message = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        this.note = note;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (group != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            root = (group.root != null) ? group.root : group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            T0 = root.T0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            dialog = root.dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            T0 = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   156
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private class ProgressOptionPane extends JOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        ProgressOptionPane(Object messageList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            super(messageList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                  JOptionPane.INFORMATION_MESSAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                  JOptionPane.DEFAULT_OPTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                  null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                  ProgressMonitor.this.cancelOption,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                  null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        public int getMaxCharactersPerLineCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            return 60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        // Equivalent to JOptionPane.createDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // but create a modeless dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        // This is necessary because the Solaris implementation doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        // support Dialog.setModal yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        public JDialog createDialog(Component parentComponent, String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            final JDialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            Window window = JOptionPane.getWindowForComponent(parentComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (window instanceof Frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                dialog = new JDialog((Frame)window, title, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                dialog = new JDialog((Dialog)window, title, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (window instanceof SwingUtilities.SharedOwnerFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                WindowListener ownerShutdownListener =
1843
267cc4de4221 6776095: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   189
                        SwingUtilities.getSharedOwnerFrameShutdownListener();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                dialog.addWindowListener(ownerShutdownListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            Container contentPane = dialog.getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            contentPane.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            contentPane.add(this, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            dialog.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            dialog.setLocationRelativeTo(parentComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            dialog.addWindowListener(new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                boolean gotFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                public void windowClosing(WindowEvent we) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    setValue(cancelOption[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                public void windowActivated(WindowEvent we) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    // Once window gets focus, set initial focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    if (!gotFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        selectInitialValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                        gotFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            addPropertyChangeListener(new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    if(dialog.isVisible() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                       event.getSource() == ProgressOptionPane.this &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                       (event.getPropertyName().equals(VALUE_PROPERTY) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                        event.getPropertyName().equals(INPUT_VALUE_PROPERTY))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                        dialog.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        /////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // Accessibility support for ProgressOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        ////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         * Gets the AccessibleContext for the ProgressOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         * @return the AccessibleContext for the ProgressOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return ProgressMonitor.this.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
         * Returns the AccessibleJOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        private AccessibleContext getAccessibleJOptionPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return super.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Indicate the progress of the operation being monitored.
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   254
     * If the specified value is &gt;= the maximum, the progress
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * monitor is closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param nv an int specifying the current value, between the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *        maximum and minimum specified for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @see #close
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void setProgress(int nv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (nv >= max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (myBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                myBar.setValue(nv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                long T = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                long dT = (int)(T-T0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                if (dT >= millisToDecideToPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    int predictedCompletionTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    if (nv > min) {
1843
267cc4de4221 6776095: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   276
                        predictedCompletionTime = (int)(dT *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                                        (max - min) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                                        (nv - min));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                        predictedCompletionTime = millisToPopup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    if (predictedCompletionTime >= millisToPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        myBar = new JProgressBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                        myBar.setMinimum(min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                        myBar.setMaximum(max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                        myBar.setValue(nv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        if (note != null) noteLabel = new JLabel(note);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        pane = new ProgressOptionPane(new Object[] {message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                                                    noteLabel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                                                    myBar});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                        dialog = pane.createDialog(parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                            UIManager.getString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                "ProgressMonitor.progressText"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Indicate that the operation is complete.  This happens automatically
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   305
     * when the value set by setProgress is &gt;= max, but it may be called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * earlier if the operation ends early.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public void close() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (dialog != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            dialog.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            dialog = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            pane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            myBar = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Returns the minimum value -- the lower end of the progress value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return an int representing the minimum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public int getMinimum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Specifies the minimum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @param m  an int specifying the minimum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @see #getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public void setMinimum(int m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (myBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            myBar.setMinimum(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        min = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Returns the maximum value -- the higher end of the progress value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return an int representing the maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    public int getMaximum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        return max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Specifies the maximum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @param m  an int specifying the maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @see #getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public void setMaximum(int m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if (myBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            myBar.setMaximum(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        max = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Returns true if the user hits the Cancel button in the progress dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public boolean isCanceled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (pane == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        Object v = pane.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return ((v != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                (cancelOption.length == 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                (v.equals(cancelOption[0])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Specifies the amount of time to wait before deciding whether or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * not to popup a progress monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @param millisToDecideToPopup  an int specifying the time to wait,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *        in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @see #getMillisToDecideToPopup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public void setMillisToDecideToPopup(int millisToDecideToPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        this.millisToDecideToPopup = millisToDecideToPopup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Returns the amount of time this object waits before deciding whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * or not to popup a progress monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @see #setMillisToDecideToPopup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public int getMillisToDecideToPopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return millisToDecideToPopup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * Specifies the amount of time it will take for the popup to appear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * (If the predicted time remaining is less than this time, the popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * won't be displayed.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @param millisToPopup  an int specifying the time in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @see #getMillisToPopup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void setMillisToPopup(int millisToPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        this.millisToPopup = millisToPopup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Returns the amount of time it will take for the popup to appear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see #setMillisToPopup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public int getMillisToPopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        return millisToPopup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Specifies the additional note that is displayed along with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * progress message. Used, for example, to show which file the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * is currently being copied during a multiple-file copy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @param note  a String specifying the note to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @see #getNote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public void setNote(String note) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        this.note = note;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        if (noteLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            noteLabel.setText(note);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Specifies the additional note that is displayed along with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * progress message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @return a String specifying the note to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @see #setNote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public String getNote() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return note;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    // Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    ////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * The <code>AccessibleContext</code> for the <code>ProgressMonitor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    protected AccessibleContext accessibleContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    private AccessibleContext accessibleJOptionPane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Gets the <code>AccessibleContext</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * <code>ProgressMonitor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @return the <code>AccessibleContext</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * <code>ProgressMonitor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            accessibleContext = new AccessibleProgressMonitor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (pane != null && accessibleJOptionPane == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            // Notify the AccessibleProgressMonitor that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            // ProgressOptionPane was created. It is necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            // to poll for ProgressOptionPane creation because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            // the ProgressMonitor does not have a Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            // to add a listener to until the ProgressOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            // is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            if (accessibleContext instanceof AccessibleProgressMonitor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                ((AccessibleProgressMonitor)accessibleContext).optionPaneCreated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * <code>AccessibleProgressMonitor</code> implements accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * support for the <code>ProgressMonitor</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    protected class AccessibleProgressMonitor extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        implements AccessibleText, ChangeListener, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         * The accessibility hierarchy for ProgressMonitor is a flattened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         * version of the ProgressOptionPane component hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         * The ProgressOptionPane component hierarchy is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         *   JDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         *     ProgressOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         *       JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
         *         JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
         *           JLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
         *           JLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         *           JProgressBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         * The AccessibleProgessMonitor accessibility hierarchy is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         *   AccessibleJDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         *     AccessibleProgressMonitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         *       AccessibleJLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         *       AccessibleJLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
         *       AccessibleJProgressBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         * The abstraction presented to assitive technologies by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         * the AccessibleProgressMonitor is that a dialog contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         * progress monitor with three children: a message, a note
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         * label and a progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        private Object oldModelValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         * AccessibleProgressMonitor constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        protected AccessibleProgressMonitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
         * Initializes the AccessibleContext now that the ProgressOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
         * has been created. Because the ProgressMonitor is not a Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
         * implementing the Accessible interface, an AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
         * must be synthesized from the ProgressOptionPane and its children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         * For other AWT and Swing classes, the inner class that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         * accessibility for the class extends the inner class that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
         * implements accessibility for the super class. AccessibleProgressMonitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
         * cannot extend AccessibleJOptionPane and must therefore delegate calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
         * to the AccessibleJOptionPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        private void optionPaneCreated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            accessibleJOptionPane =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                ((ProgressOptionPane)pane).getAccessibleJOptionPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            // add a listener for progress bar ChangeEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            if (myBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                myBar.addChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            // add a listener for note label PropertyChangeEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            if (noteLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                noteLabel.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
         * Invoked when the target of the listener has changed its state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
         * @param e  a <code>ChangeEvent</code> object. Must not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
         * @throws NullPointerException if the parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            if (myBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                // the progress bar value changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                Object newModelValue = myBar.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                firePropertyChange(ACCESSIBLE_VALUE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                   oldModelValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                   newModelValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                oldModelValue = newModelValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         * This method gets called when a bound property is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
         * @param e A <code>PropertyChangeEvent</code> object describing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
         * the event source and the property that has changed. Must not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
         * @throws NullPointerException if the parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            if (e.getSource() == noteLabel && e.getPropertyName() == "text") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                // the note label text changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                firePropertyChange(ACCESSIBLE_TEXT_PROPERTY, null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        /* ===== Begin AccessileContext ===== */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
         * Gets the accessibleName property of this object.  The accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
         * property of an object is a localized String that designates the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
         * of the object.  For example, the accessibleName property of a label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
         * or button might be the text of the label or button itself.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
         * case of an object that doesn't display its name, the accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
         * should still be set.  For example, in the case of a text field used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
         * to enter the name of a city, the accessibleName for the en_US locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
         * could be 'city.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
         * @return the localized name of the object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
         * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
         * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (accessibleName != null) { // defined in AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            } else if (accessibleJOptionPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                // delegate to the AccessibleJOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                return accessibleJOptionPane.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
         * Gets the accessibleDescription property of this object.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         * accessibleDescription property of this object is a short localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
         * phrase describing the purpose of the object.  For example, in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
         * case of a 'Cancel' button, the accessibleDescription could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
         * 'Ignore changes and close dialog box.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         * @return the localized description of the object; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         * this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
         * @see #setAccessibleDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            if (accessibleDescription != null) { // defined in AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                return accessibleDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            } else if (accessibleJOptionPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                // delegate to the AccessibleJOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                return accessibleJOptionPane.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         * Gets the role of this object.  The role of the object is the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
         * purpose or use of the class of this object.  For example, the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         * of a push button is AccessibleRole.PUSH_BUTTON.  The roles in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         * AccessibleRole are provided so component developers can pick from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
         * a set of predefined roles.  This enables assistive technologies to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         * provide a consistent interface to various tweaked subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20455
diff changeset
   653
         * that act like a push button) as well as distinguish between subclasses
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
         * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
         * and AccessibleRole.RADIO_BUTTON for radio buttons).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
         * <p>Note that the AccessibleRole class is also extensible, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         * custom component developers can define their own AccessibleRole's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
         * if the set of predefined roles is inadequate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
         * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            return AccessibleRole.PROGRESS_MONITOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
         * Gets the state set of this object.  The AccessibleStateSet of an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
         * is composed of a set of unique AccessibleStates.  A change in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
         * AccessibleStateSet of an object will cause a PropertyChangeEvent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
         * be fired for the ACCESSIBLE_STATE_PROPERTY property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
         * @return an instance of AccessibleStateSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
         * current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
         * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
         * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            if (accessibleJOptionPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                // delegate to the AccessibleJOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                return accessibleJOptionPane.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
         * Gets the Accessible parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
         * @return the Accessible parent of this object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
         * object does not have an Accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        public Accessible getAccessibleParent() {
1843
267cc4de4221 6776095: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   694
            return dialog;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
         * Returns the parent AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        private AccessibleContext getParentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            if (dialog != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                return dialog.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
         * Gets the 0-based index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
         * @return the 0-based index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
         * object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
         * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
         * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
         * @see #getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            if (accessibleJOptionPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                // delegate to the AccessibleJOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                return accessibleJOptionPane.getAccessibleIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
         * Returns the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
         * @return the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            // return the number of children in the JPanel containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            // the message, note label and progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            AccessibleContext ac = getPanelAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                return ac.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
         * Returns the specified Accessible child of the object.  The Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         * children of an Accessible object are zero-based, so the first child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         * of an Accessible child is at index 0, the second child is at index 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         * and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         * @return the Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
         * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            // return a child in the JPanel containing the message, note label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            // and progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            AccessibleContext ac = getPanelAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                return ac.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
         * Returns the AccessibleContext for the JPanel containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
         * message, note label and progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        private AccessibleContext getPanelAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            if (myBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                Component c = myBar.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                if (c instanceof Accessible) {
1843
267cc4de4221 6776095: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   768
                    return c.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         * Gets the locale of the component. If the component does not have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * locale, then the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         * @return this component's locale.  If this component does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         * a locale, the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         * @exception IllegalComponentStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         * If the Component does not have its own locale and has not yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * added to a containment hierarchy such that the locale can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         * determined from the containing parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        public Locale getLocale() throws IllegalComponentStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            if (accessibleJOptionPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                // delegate to the AccessibleJOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                return accessibleJOptionPane.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        /* ===== end AccessibleContext ===== */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
         * Gets the AccessibleComponent associated with this object that has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
         * graphical representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
         * @return AccessibleComponent if supported by object; else return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
         * @see AccessibleComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            if (accessibleJOptionPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                // delegate to the AccessibleJOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                return accessibleJOptionPane.getAccessibleComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
         * Gets the AccessibleValue associated with this object that supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
         * Numerical value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
         * @return AccessibleValue if supported by object; else return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
         * @see AccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            if (myBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                // delegate to the AccessibleJProgressBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                return myBar.getAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
         * Gets the AccessibleText associated with this object presenting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
         * text on the display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
         * @return AccessibleText if supported by object; else return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
         * @see AccessibleText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            if (getNoteLabelAccessibleText() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
         * Returns the note label AccessibleText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        private AccessibleText getNoteLabelAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            if (noteLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                // AccessibleJLabel implements AccessibleText if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                return noteLabel.getAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        /* ===== Begin AccessibleText impl ===== */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
         * Given a point in local coordinates, return the zero-based index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
         * of the character under that Point.  If the point is invalid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
         * this method returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
         * @param p the Point in local coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
         * @return the zero-based index of the character under Point p; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
         * Point is invalid return -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        public int getIndexAtPoint(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            if (at != null && sameWindowAncestor(pane, noteLabel)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                // convert point from the option pane bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                // to the note label bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                Point noteLabelPoint = SwingUtilities.convertPoint(pane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                                                                   p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                                                                   noteLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                if (noteLabelPoint != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                    return at.getIndexAtPoint(noteLabelPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
         * Determines the bounding box of the character at the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         * index into the string.  The bounds are returned in local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         * coordinates.  If the index is invalid an empty rectangle is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         * @param i the index into the String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * @return the screen coordinates of the character's bounding box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         * if index is invalid return an empty rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        public Rectangle getCharacterBounds(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            if (at != null && sameWindowAncestor(pane, noteLabel)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                // return rectangle in the option pane bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                Rectangle noteLabelRect = at.getCharacterBounds(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                if (noteLabelRect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                    return SwingUtilities.convertRectangle(noteLabel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                                                           noteLabelRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                                                           pane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
         * Returns whether source and destination components have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
         * same window ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        private boolean sameWindowAncestor(Component src, Component dest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            if (src == null || dest == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            return SwingUtilities.getWindowAncestor(src) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                SwingUtilities.getWindowAncestor(dest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
         * Returns the number of characters (valid indicies)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
         * @return the number of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        public int getCharCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            if (at != null) {   // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                return at.getCharCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         * Returns the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
         * Note: That to the right of the caret will have the same index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
         * value as the offset (the caret is between two characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
         * @return the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        public int getCaretPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            if (at != null) {   // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                return at.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
         * Returns the String at a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
         * @param part the CHARACTER, WORD, or SENTENCE to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
         * @param index an index within the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
         * @return the letter, word, or sentence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        public String getAtIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            if (at != null) {   // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                return at.getAtIndex(part, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
         * Returns the String after a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
         * @param part the CHARACTER, WORD, or SENTENCE to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
         * @param index an index within the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
         * @return the letter, word, or sentence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        public String getAfterIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            if (at != null) {   // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                return at.getAfterIndex(part, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
         * Returns the String before a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
         * @param part the CHARACTER, WORD, or SENTENCE to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
         * @param index an index within the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
         * @return the letter, word, or sentence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        public String getBeforeIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            if (at != null) {   // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                return at.getBeforeIndex(part, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
         * Returns the AttributeSet for a given character at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
         * @param i the zero-based index into the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
         * @return the AttributeSet of the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        public AttributeSet getCharacterAttribute(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            if (at != null) {   // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                return at.getCharacterAttribute(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
         * Returns the start offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
         * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
         * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
         * @return the index into the text of the start of the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        public int getSelectionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            if (at != null) {   // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                return at.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
         * Returns the end offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
         * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
         * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
         *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20455
diff changeset
  1020
         * @return the index into the text of the end of the selection
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        public int getSelectionEnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            if (at != null) {   // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                return at.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
         * Returns the portion of the text that is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
         * @return the String portion of the text that is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        public String getSelectedText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            AccessibleText at = getNoteLabelAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            if (at != null) {   // JLabel contains HTML text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                return at.getSelectedText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        /* ===== End AccessibleText impl ===== */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    // inner class AccessibleProgressMonitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
}