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