0N/A/*
2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/A
0N/Apackage javax.swing;
0N/A
0N/A
0N/A
0N/Aimport java.io.*;
0N/Aimport java.awt.BorderLayout;
0N/Aimport java.awt.Frame;
0N/Aimport java.awt.Dialog;
0N/Aimport java.awt.Window;
0N/Aimport java.awt.Component;
0N/Aimport java.awt.Container;
0N/Aimport java.beans.PropertyChangeEvent;
0N/Aimport java.beans.PropertyChangeListener;
0N/Aimport java.awt.event.WindowListener;
0N/Aimport java.awt.event.WindowAdapter;
0N/Aimport java.awt.event.WindowEvent;
0N/A
0N/Aimport java.awt.IllegalComponentStateException;
0N/Aimport java.awt.Point;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.text.*;
0N/Aimport java.util.Locale;
0N/Aimport javax.accessibility.*;
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.text.*;
0N/A
0N/A
0N/A/** A class to monitor the progress of some operation. If it looks
0N/A * like the operation will take a while, a progress dialog will be popped up.
0N/A * When the ProgressMonitor is created it is given a numeric range and a
0N/A * descriptive string. As the operation progresses, call the setProgress method
0N/A * to indicate how far along the [min,max] range the operation is.
0N/A * Initially, there is no ProgressDialog. After the first millisToDecideToPopup
0N/A * milliseconds (default 500) the progress monitor will predict how long
0N/A * the operation will take. If it is longer than millisToPopup (default 2000,
0N/A * 2 seconds) a ProgressDialog will be popped up.
0N/A * <p>
0N/A * From time to time, when the Dialog box is visible, the progress bar will
0N/A * be updated when setProgress is called. setProgress won't always update
0N/A * the progress bar, it will only be done if the amount of progress is
0N/A * visibly significant.
0N/A *
0N/A * <p>
0N/A *
0N/A * For further documentation and examples see
0N/A * <a
0N/A href="http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html">How to Monitor Progress</a>,
0N/A * a section in <em>The Java Tutorial.</em>
0N/A *
0N/A * @see ProgressMonitorInputStream
0N/A * @author James Gosling
0N/A * @author Lynn Monsanto (accessibility)
0N/A */
826N/Apublic class ProgressMonitor implements Accessible
0N/A{
0N/A private ProgressMonitor root;
0N/A private JDialog dialog;
0N/A private JOptionPane pane;
0N/A private JProgressBar myBar;
0N/A private JLabel noteLabel;
0N/A private Component parentComponent;
0N/A private String note;
0N/A private Object[] cancelOption = null;
0N/A private Object message;
0N/A private long T0;
0N/A private int millisToDecideToPopup = 500;
0N/A private int millisToPopup = 2000;
0N/A private int min;
0N/A private int max;
0N/A
0N/A
0N/A /**
0N/A * Constructs a graphic object that shows progress, typically by filling
0N/A * in a rectangular bar as the process nears completion.
0N/A *
0N/A * @param parentComponent the parent component for the dialog box
0N/A * @param message a descriptive message that will be shown
0N/A * to the user to indicate what operation is being monitored.
0N/A * This does not change as the operation progresses.
0N/A * See the message parameters to methods in
0N/A * {@link JOptionPane#message}
0N/A * for the range of values.
0N/A * @param note a short note describing the state of the
0N/A * operation. As the operation progresses, you can call
0N/A * setNote to change the note displayed. This is used,
0N/A * for example, in operations that iterate through a
0N/A * list of files to show the name of the file being processes.
0N/A * If note is initially null, there will be no note line
0N/A * in the dialog box and setNote will be ineffective
0N/A * @param min the lower bound of the range
0N/A * @param max the upper bound of the range
0N/A * @see JDialog
0N/A * @see JOptionPane
0N/A */
0N/A public ProgressMonitor(Component parentComponent,
0N/A Object message,
0N/A String note,
0N/A int min,
0N/A int max) {
0N/A this(parentComponent, message, note, min, max, null);
0N/A }
0N/A
0N/A
0N/A private ProgressMonitor(Component parentComponent,
0N/A Object message,
0N/A String note,
0N/A int min,
0N/A int max,
0N/A ProgressMonitor group) {
0N/A this.min = min;
0N/A this.max = max;
0N/A this.parentComponent = parentComponent;
0N/A
0N/A cancelOption = new Object[1];
0N/A cancelOption[0] = UIManager.getString("OptionPane.cancelButtonText");
0N/A
0N/A this.message = message;
0N/A this.note = note;
0N/A if (group != null) {
0N/A root = (group.root != null) ? group.root : group;
0N/A T0 = root.T0;
0N/A dialog = root.dialog;
0N/A }
0N/A else {
0N/A T0 = System.currentTimeMillis();
0N/A }
0N/A }
0N/A
0N/A
0N/A private class ProgressOptionPane extends JOptionPane
0N/A {
0N/A ProgressOptionPane(Object messageList) {
0N/A super(messageList,
0N/A JOptionPane.INFORMATION_MESSAGE,
0N/A JOptionPane.DEFAULT_OPTION,
0N/A null,
0N/A ProgressMonitor.this.cancelOption,
0N/A null);
0N/A }
0N/A
0N/A
0N/A public int getMaxCharactersPerLineCount() {
0N/A return 60;
0N/A }
0N/A
0N/A
0N/A // Equivalent to JOptionPane.createDialog,
0N/A // but create a modeless dialog.
0N/A // This is necessary because the Solaris implementation doesn't
0N/A // support Dialog.setModal yet.
0N/A public JDialog createDialog(Component parentComponent, String title) {
0N/A final JDialog dialog;
0N/A
0N/A Window window = JOptionPane.getWindowForComponent(parentComponent);
0N/A if (window instanceof Frame) {
0N/A dialog = new JDialog((Frame)window, title, false);
0N/A } else {
0N/A dialog = new JDialog((Dialog)window, title, false);
0N/A }
0N/A if (window instanceof SwingUtilities.SharedOwnerFrame) {
0N/A WindowListener ownerShutdownListener =
826N/A SwingUtilities.getSharedOwnerFrameShutdownListener();
0N/A dialog.addWindowListener(ownerShutdownListener);
0N/A }
0N/A Container contentPane = dialog.getContentPane();
0N/A
0N/A contentPane.setLayout(new BorderLayout());
0N/A contentPane.add(this, BorderLayout.CENTER);
0N/A dialog.pack();
0N/A dialog.setLocationRelativeTo(parentComponent);
0N/A dialog.addWindowListener(new WindowAdapter() {
0N/A boolean gotFocus = false;
0N/A
0N/A public void windowClosing(WindowEvent we) {
0N/A setValue(cancelOption[0]);
0N/A }
0N/A
0N/A public void windowActivated(WindowEvent we) {
0N/A // Once window gets focus, set initial focus
0N/A if (!gotFocus) {
0N/A selectInitialValue();
0N/A gotFocus = true;
0N/A }
0N/A }
0N/A });
0N/A
0N/A addPropertyChangeListener(new PropertyChangeListener() {
0N/A public void propertyChange(PropertyChangeEvent event) {
0N/A if(dialog.isVisible() &&
0N/A event.getSource() == ProgressOptionPane.this &&
0N/A (event.getPropertyName().equals(VALUE_PROPERTY) ||
0N/A event.getPropertyName().equals(INPUT_VALUE_PROPERTY))){
0N/A dialog.setVisible(false);
0N/A dialog.dispose();
0N/A }
0N/A }
0N/A });
0N/A
0N/A return dialog;
0N/A }
0N/A
0N/A /////////////////
0N/A // Accessibility support for ProgressOptionPane
0N/A ////////////////
0N/A
0N/A /**
0N/A * Gets the AccessibleContext for the ProgressOptionPane
0N/A *
0N/A * @return the AccessibleContext for the ProgressOptionPane
0N/A * @since 1.5
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A return ProgressMonitor.this.getAccessibleContext();
0N/A }
0N/A
0N/A /*
0N/A * Returns the AccessibleJOptionPane
0N/A */
0N/A private AccessibleContext getAccessibleJOptionPane() {
0N/A return super.getAccessibleContext();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Indicate the progress of the operation being monitored.
0N/A * If the specified value is >= the maximum, the progress
0N/A * monitor is closed.
0N/A * @param nv an int specifying the current value, between the
0N/A * maximum and minimum specified for this component
0N/A * @see #setMinimum
0N/A * @see #setMaximum
0N/A * @see #close
0N/A */
0N/A public void setProgress(int nv) {
0N/A if (nv >= max) {
0N/A close();
0N/A }
0N/A else {
0N/A if (myBar != null) {
0N/A myBar.setValue(nv);
0N/A }
0N/A else {
0N/A long T = System.currentTimeMillis();
0N/A long dT = (int)(T-T0);
0N/A if (dT >= millisToDecideToPopup) {
0N/A int predictedCompletionTime;
0N/A if (nv > min) {
826N/A predictedCompletionTime = (int)(dT *
0N/A (max - min) /
0N/A (nv - min));
0N/A }
0N/A else {
0N/A predictedCompletionTime = millisToPopup;
0N/A }
0N/A if (predictedCompletionTime >= millisToPopup) {
0N/A myBar = new JProgressBar();
0N/A myBar.setMinimum(min);
0N/A myBar.setMaximum(max);
0N/A myBar.setValue(nv);
0N/A if (note != null) noteLabel = new JLabel(note);
0N/A pane = new ProgressOptionPane(new Object[] {message,
0N/A noteLabel,
0N/A myBar});
0N/A dialog = pane.createDialog(parentComponent,
0N/A UIManager.getString(
0N/A "ProgressMonitor.progressText"));
0N/A dialog.show();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Indicate that the operation is complete. This happens automatically
0N/A * when the value set by setProgress is >= max, but it may be called
0N/A * earlier if the operation ends early.
0N/A */
0N/A public void close() {
0N/A if (dialog != null) {
0N/A dialog.setVisible(false);
0N/A dialog.dispose();
0N/A dialog = null;
0N/A pane = null;
0N/A myBar = null;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the minimum value -- the lower end of the progress value.
0N/A *
0N/A * @return an int representing the minimum value
0N/A * @see #setMinimum
0N/A */
0N/A public int getMinimum() {
0N/A return min;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Specifies the minimum value.
0N/A *
0N/A * @param m an int specifying the minimum value
0N/A * @see #getMinimum
0N/A */
0N/A public void setMinimum(int m) {
0N/A if (myBar != null) {
0N/A myBar.setMinimum(m);
0N/A }
0N/A min = m;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the maximum value -- the higher end of the progress value.
0N/A *
0N/A * @return an int representing the maximum value
0N/A * @see #setMaximum
0N/A */
0N/A public int getMaximum() {
0N/A return max;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Specifies the maximum value.
0N/A *
0N/A * @param m an int specifying the maximum value
0N/A * @see #getMaximum
0N/A */
0N/A public void setMaximum(int m) {
0N/A if (myBar != null) {
0N/A myBar.setMaximum(m);
0N/A }
0N/A max = m;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns true if the user hits the Cancel button in the progress dialog.
0N/A */
0N/A public boolean isCanceled() {
0N/A if (pane == null) return false;
0N/A Object v = pane.getValue();
0N/A return ((v != null) &&
0N/A (cancelOption.length == 1) &&
0N/A (v.equals(cancelOption[0])));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Specifies the amount of time to wait before deciding whether or
0N/A * not to popup a progress monitor.
0N/A *
0N/A * @param millisToDecideToPopup an int specifying the time to wait,
0N/A * in milliseconds
0N/A * @see #getMillisToDecideToPopup
0N/A */
0N/A public void setMillisToDecideToPopup(int millisToDecideToPopup) {
0N/A this.millisToDecideToPopup = millisToDecideToPopup;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the amount of time this object waits before deciding whether
0N/A * or not to popup a progress monitor.
0N/A *
0N/A * @see #setMillisToDecideToPopup
0N/A */
0N/A public int getMillisToDecideToPopup() {
0N/A return millisToDecideToPopup;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Specifies the amount of time it will take for the popup to appear.
0N/A * (If the predicted time remaining is less than this time, the popup
0N/A * won't be displayed.)
0N/A *
0N/A * @param millisToPopup an int specifying the time in milliseconds
0N/A * @see #getMillisToPopup
0N/A */
0N/A public void setMillisToPopup(int millisToPopup) {
0N/A this.millisToPopup = millisToPopup;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the amount of time it will take for the popup to appear.
0N/A *
0N/A * @see #setMillisToPopup
0N/A */
0N/A public int getMillisToPopup() {
0N/A return millisToPopup;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Specifies the additional note that is displayed along with the
0N/A * progress message. Used, for example, to show which file the
0N/A * is currently being copied during a multiple-file copy.
0N/A *
0N/A * @param note a String specifying the note to display
0N/A * @see #getNote
0N/A */
0N/A public void setNote(String note) {
0N/A this.note = note;
0N/A if (noteLabel != null) {
0N/A noteLabel.setText(note);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Specifies the additional note that is displayed along with the
0N/A * progress message.
0N/A *
0N/A * @return a String specifying the note to display
0N/A * @see #setNote
0N/A */
0N/A public String getNote() {
0N/A return note;
0N/A }
0N/A
0N/A /////////////////
0N/A // Accessibility support
0N/A ////////////////
0N/A
0N/A /**
0N/A * The <code>AccessibleContext</code> for the <code>ProgressMonitor</code>
0N/A * @since 1.5
0N/A */
0N/A protected AccessibleContext accessibleContext = null;
0N/A
0N/A private AccessibleContext accessibleJOptionPane = null;
0N/A
0N/A /**
0N/A * Gets the <code>AccessibleContext</code> for the
0N/A * <code>ProgressMonitor</code>
0N/A *
0N/A * @return the <code>AccessibleContext</code> for the
0N/A * <code>ProgressMonitor</code>
0N/A * @since 1.5
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleProgressMonitor();
0N/A }
0N/A if (pane != null && accessibleJOptionPane == null) {
0N/A // Notify the AccessibleProgressMonitor that the
0N/A // ProgressOptionPane was created. It is necessary
0N/A // to poll for ProgressOptionPane creation because
0N/A // the ProgressMonitor does not have a Component
0N/A // to add a listener to until the ProgressOptionPane
0N/A // is created.
0N/A if (accessibleContext instanceof AccessibleProgressMonitor) {
0N/A ((AccessibleProgressMonitor)accessibleContext).optionPaneCreated();
0N/A }
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * <code>AccessibleProgressMonitor</code> implements accessibility
0N/A * support for the <code>ProgressMonitor</code> class.
0N/A * @since 1.5
0N/A */
0N/A protected class AccessibleProgressMonitor extends AccessibleContext
0N/A implements AccessibleText, ChangeListener, PropertyChangeListener {
0N/A
0N/A /*
0N/A * The accessibility hierarchy for ProgressMonitor is a flattened
0N/A * version of the ProgressOptionPane component hierarchy.
0N/A *
0N/A * The ProgressOptionPane component hierarchy is:
0N/A * JDialog
0N/A * ProgressOptionPane
0N/A * JPanel
0N/A * JPanel
0N/A * JLabel
0N/A * JLabel
0N/A * JProgressBar
0N/A *
0N/A * The AccessibleProgessMonitor accessibility hierarchy is:
0N/A * AccessibleJDialog
0N/A * AccessibleProgressMonitor
0N/A * AccessibleJLabel
0N/A * AccessibleJLabel
0N/A * AccessibleJProgressBar
0N/A *
0N/A * The abstraction presented to assitive technologies by
0N/A * the AccessibleProgressMonitor is that a dialog contains a
0N/A * progress monitor with three children: a message, a note
0N/A * label and a progress bar.
0N/A */
0N/A
0N/A private Object oldModelValue;
0N/A
0N/A /**
0N/A * AccessibleProgressMonitor constructor
0N/A */
0N/A protected AccessibleProgressMonitor() {
0N/A }
0N/A
0N/A /*
0N/A * Initializes the AccessibleContext now that the ProgressOptionPane
0N/A * has been created. Because the ProgressMonitor is not a Component
0N/A * implementing the Accessible interface, an AccessibleContext
0N/A * must be synthesized from the ProgressOptionPane and its children.
0N/A *
0N/A * For other AWT and Swing classes, the inner class that implements
0N/A * accessibility for the class extends the inner class that implements
0N/A * implements accessibility for the super class. AccessibleProgressMonitor
0N/A * cannot extend AccessibleJOptionPane and must therefore delegate calls
0N/A * to the AccessibleJOptionPane.
0N/A */
0N/A private void optionPaneCreated() {
0N/A accessibleJOptionPane =
0N/A ((ProgressOptionPane)pane).getAccessibleJOptionPane();
0N/A
0N/A // add a listener for progress bar ChangeEvents
0N/A if (myBar != null) {
0N/A myBar.addChangeListener(this);
0N/A }
0N/A
0N/A // add a listener for note label PropertyChangeEvents
0N/A if (noteLabel != null) {
0N/A noteLabel.addPropertyChangeListener(this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Invoked when the target of the listener has changed its state.
0N/A *
0N/A * @param e a <code>ChangeEvent</code> object. Must not be null.
0N/A * @throws NullPointerException if the parameter is null.
0N/A */
0N/A public void stateChanged(ChangeEvent e) {
0N/A if (e == null) {
0N/A return;
0N/A }
0N/A if (myBar != null) {
0N/A // the progress bar value changed
0N/A Object newModelValue = myBar.getValue();
0N/A firePropertyChange(ACCESSIBLE_VALUE_PROPERTY,
0N/A oldModelValue,
0N/A newModelValue);
0N/A oldModelValue = newModelValue;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * This method gets called when a bound property is changed.
0N/A *
0N/A * @param e A <code>PropertyChangeEvent</code> object describing
0N/A * the event source and the property that has changed. Must not be null.
0N/A * @throws NullPointerException if the parameter is null.
0N/A */
0N/A public void propertyChange(PropertyChangeEvent e) {
0N/A if (e.getSource() == noteLabel && e.getPropertyName() == "text") {
0N/A // the note label text changed
0N/A firePropertyChange(ACCESSIBLE_TEXT_PROPERTY, null, 0);
0N/A }
0N/A }
0N/A
0N/A /* ===== Begin AccessileContext ===== */
0N/A
0N/A /**
0N/A * Gets the accessibleName property of this object. The accessibleName
0N/A * property of an object is a localized String that designates the purpose
0N/A * of the object. For example, the accessibleName property of a label
0N/A * or button might be the text of the label or button itself. In the
0N/A * case of an object that doesn't display its name, the accessibleName
0N/A * should still be set. For example, in the case of a text field used
0N/A * to enter the name of a city, the accessibleName for the en_US locale
0N/A * could be 'city.'
0N/A *
0N/A * @return the localized name of the object; null if this
0N/A * object does not have a name
0N/A *
0N/A * @see #setAccessibleName
0N/A */
0N/A public String getAccessibleName() {
0N/A if (accessibleName != null) { // defined in AccessibleContext
0N/A return accessibleName;
0N/A } else if (accessibleJOptionPane != null) {
0N/A // delegate to the AccessibleJOptionPane
0N/A return accessibleJOptionPane.getAccessibleName();
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the accessibleDescription property of this object. The
0N/A * accessibleDescription property of this object is a short localized
0N/A * phrase describing the purpose of the object. For example, in the
0N/A * case of a 'Cancel' button, the accessibleDescription could be
0N/A * 'Ignore changes and close dialog box.'
0N/A *
0N/A * @return the localized description of the object; null if
0N/A * this object does not have a description
0N/A *
0N/A * @see #setAccessibleDescription
0N/A */
0N/A public String getAccessibleDescription() {
0N/A if (accessibleDescription != null) { // defined in AccessibleContext
0N/A return accessibleDescription;
0N/A } else if (accessibleJOptionPane != null) {
0N/A // delegate to the AccessibleJOptionPane
0N/A return accessibleJOptionPane.getAccessibleDescription();
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the role of this object. The role of the object is the generic
0N/A * purpose or use of the class of this object. For example, the role
0N/A * of a push button is AccessibleRole.PUSH_BUTTON. The roles in
0N/A * AccessibleRole are provided so component developers can pick from
0N/A * a set of predefined roles. This enables assistive technologies to
0N/A * provide a consistent interface to various tweaked subclasses of
0N/A * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
0N/A * that act like a push button) as well as distinguish between sublasses
0N/A * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
0N/A * and AccessibleRole.RADIO_BUTTON for radio buttons).
0N/A * <p>Note that the AccessibleRole class is also extensible, so
0N/A * custom component developers can define their own AccessibleRole's
0N/A * if the set of predefined roles is inadequate.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.PROGRESS_MONITOR;
0N/A }
0N/A
0N/A /**
0N/A * Gets the state set of this object. The AccessibleStateSet of an object
0N/A * is composed of a set of unique AccessibleStates. A change in the
0N/A * AccessibleStateSet of an object will cause a PropertyChangeEvent to
0N/A * be fired for the ACCESSIBLE_STATE_PROPERTY property.
0N/A *
0N/A * @return an instance of AccessibleStateSet containing the
0N/A * current state set of the object
0N/A * @see AccessibleStateSet
0N/A * @see AccessibleState
0N/A * @see #addPropertyChangeListener
0N/A */
0N/A public AccessibleStateSet getAccessibleStateSet() {
0N/A if (accessibleJOptionPane != null) {
0N/A // delegate to the AccessibleJOptionPane
0N/A return accessibleJOptionPane.getAccessibleStateSet();
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the Accessible parent of this object.
0N/A *
0N/A * @return the Accessible parent of this object; null if this
0N/A * object does not have an Accessible parent
0N/A */
0N/A public Accessible getAccessibleParent() {
826N/A return dialog;
0N/A }
0N/A
0N/A /*
0N/A * Returns the parent AccessibleContext
0N/A */
0N/A private AccessibleContext getParentAccessibleContext() {
0N/A if (dialog != null) {
0N/A return dialog.getAccessibleContext();
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the 0-based index of this object in its accessible parent.
0N/A *
0N/A * @return the 0-based index of this object in its parent; -1 if this
0N/A * object does not have an accessible parent.
0N/A *
0N/A * @see #getAccessibleParent
0N/A * @see #getAccessibleChildrenCount
0N/A * @see #getAccessibleChild
0N/A */
0N/A public int getAccessibleIndexInParent() {
0N/A if (accessibleJOptionPane != null) {
0N/A // delegate to the AccessibleJOptionPane
0N/A return accessibleJOptionPane.getAccessibleIndexInParent();
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of accessible children of the object.
0N/A *
0N/A * @return the number of accessible children of the object.
0N/A */
0N/A public int getAccessibleChildrenCount() {
0N/A // return the number of children in the JPanel containing
0N/A // the message, note label and progress bar
0N/A AccessibleContext ac = getPanelAccessibleContext();
0N/A if (ac != null) {
0N/A return ac.getAccessibleChildrenCount();
0N/A }
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Returns the specified Accessible child of the object. The Accessible
0N/A * children of an Accessible object are zero-based, so the first child
0N/A * of an Accessible child is at index 0, the second child is at index 1,
0N/A * and so on.
0N/A *
0N/A * @param i zero-based index of child
0N/A * @return the Accessible child of the object
0N/A * @see #getAccessibleChildrenCount
0N/A */
0N/A public Accessible getAccessibleChild(int i) {
0N/A // return a child in the JPanel containing the message, note label
0N/A // and progress bar
0N/A AccessibleContext ac = getPanelAccessibleContext();
0N/A if (ac != null) {
0N/A return ac.getAccessibleChild(i);
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /*
0N/A * Returns the AccessibleContext for the JPanel containing the
0N/A * message, note label and progress bar
0N/A */
0N/A private AccessibleContext getPanelAccessibleContext() {
0N/A if (myBar != null) {
0N/A Component c = myBar.getParent();
0N/A if (c instanceof Accessible) {
826N/A return c.getAccessibleContext();
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the locale of the component. If the component does not have a
0N/A * locale, then the locale of its parent is returned.
0N/A *
0N/A * @return this component's locale. If this component does not have
0N/A * a locale, the locale of its parent is returned.
0N/A *
0N/A * @exception IllegalComponentStateException
0N/A * If the Component does not have its own locale and has not yet been
0N/A * added to a containment hierarchy such that the locale can be
0N/A * determined from the containing parent.
0N/A */
0N/A public Locale getLocale() throws IllegalComponentStateException {
0N/A if (accessibleJOptionPane != null) {
0N/A // delegate to the AccessibleJOptionPane
0N/A return accessibleJOptionPane.getLocale();
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /* ===== end AccessibleContext ===== */
0N/A
0N/A /**
0N/A * Gets the AccessibleComponent associated with this object that has a
0N/A * graphical representation.
0N/A *
0N/A * @return AccessibleComponent if supported by object; else return null
0N/A * @see AccessibleComponent
0N/A */
0N/A public AccessibleComponent getAccessibleComponent() {
0N/A if (accessibleJOptionPane != null) {
0N/A // delegate to the AccessibleJOptionPane
0N/A return accessibleJOptionPane.getAccessibleComponent();
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the AccessibleValue associated with this object that supports a
0N/A * Numerical value.
0N/A *
0N/A * @return AccessibleValue if supported by object; else return null
0N/A * @see AccessibleValue
0N/A */
0N/A public AccessibleValue getAccessibleValue() {
0N/A if (myBar != null) {
0N/A // delegate to the AccessibleJProgressBar
0N/A return myBar.getAccessibleContext().getAccessibleValue();
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the AccessibleText associated with this object presenting
0N/A * text on the display.
0N/A *
0N/A * @return AccessibleText if supported by object; else return null
0N/A * @see AccessibleText
0N/A */
0N/A public AccessibleText getAccessibleText() {
0N/A if (getNoteLabelAccessibleText() != null) {
0N/A return this;
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /*
0N/A * Returns the note label AccessibleText
0N/A */
0N/A private AccessibleText getNoteLabelAccessibleText() {
0N/A if (noteLabel != null) {
0N/A // AccessibleJLabel implements AccessibleText if the
0N/A // JLabel contains HTML text
0N/A return noteLabel.getAccessibleContext().getAccessibleText();
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /* ===== Begin AccessibleText impl ===== */
0N/A
0N/A /**
0N/A * Given a point in local coordinates, return the zero-based index
0N/A * of the character under that Point. If the point is invalid,
0N/A * this method returns -1.
0N/A *
0N/A * @param p the Point in local coordinates
0N/A * @return the zero-based index of the character under Point p; if
0N/A * Point is invalid return -1.
0N/A */
0N/A public int getIndexAtPoint(Point p) {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null && sameWindowAncestor(pane, noteLabel)) {
0N/A // convert point from the option pane bounds
0N/A // to the note label bounds.
0N/A Point noteLabelPoint = SwingUtilities.convertPoint(pane,
0N/A p,
0N/A noteLabel);
0N/A if (noteLabelPoint != null) {
0N/A return at.getIndexAtPoint(noteLabelPoint);
0N/A }
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Determines the bounding box of the character at the given
0N/A * index into the string. The bounds are returned in local
0N/A * coordinates. If the index is invalid an empty rectangle is returned.
0N/A *
0N/A * @param i the index into the String
0N/A * @return the screen coordinates of the character's bounding box,
0N/A * if index is invalid return an empty rectangle.
0N/A */
0N/A public Rectangle getCharacterBounds(int i) {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null && sameWindowAncestor(pane, noteLabel)) {
0N/A // return rectangle in the option pane bounds
0N/A Rectangle noteLabelRect = at.getCharacterBounds(i);
0N/A if (noteLabelRect != null) {
0N/A return SwingUtilities.convertRectangle(noteLabel,
0N/A noteLabelRect,
0N/A pane);
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /*
0N/A * Returns whether source and destination components have the
0N/A * same window ancestor
0N/A */
0N/A private boolean sameWindowAncestor(Component src, Component dest) {
0N/A if (src == null || dest == null) {
0N/A return false;
0N/A }
0N/A return SwingUtilities.getWindowAncestor(src) ==
0N/A SwingUtilities.getWindowAncestor(dest);
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of characters (valid indicies)
0N/A *
0N/A * @return the number of characters
0N/A */
0N/A public int getCharCount() {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null) { // JLabel contains HTML text
0N/A return at.getCharCount();
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the zero-based offset of the caret.
0N/A *
0N/A * Note: That to the right of the caret will have the same index
0N/A * value as the offset (the caret is between two characters).
0N/A * @return the zero-based offset of the caret.
0N/A */
0N/A public int getCaretPosition() {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null) { // JLabel contains HTML text
0N/A return at.getCaretPosition();
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the String at a given index.
0N/A *
0N/A * @param part the CHARACTER, WORD, or SENTENCE to retrieve
0N/A * @param index an index within the text
0N/A * @return the letter, word, or sentence
0N/A */
0N/A public String getAtIndex(int part, int index) {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null) { // JLabel contains HTML text
0N/A return at.getAtIndex(part, index);
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the String after a given index.
0N/A *
0N/A * @param part the CHARACTER, WORD, or SENTENCE to retrieve
0N/A * @param index an index within the text
0N/A * @return the letter, word, or sentence
0N/A */
0N/A public String getAfterIndex(int part, int index) {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null) { // JLabel contains HTML text
0N/A return at.getAfterIndex(part, index);
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the String before a given index.
0N/A *
0N/A * @param part the CHARACTER, WORD, or SENTENCE to retrieve
0N/A * @param index an index within the text
0N/A * @return the letter, word, or sentence
0N/A */
0N/A public String getBeforeIndex(int part, int index) {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null) { // JLabel contains HTML text
0N/A return at.getBeforeIndex(part, index);
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the AttributeSet for a given character at a given index
0N/A *
0N/A * @param i the zero-based index into the text
0N/A * @return the AttributeSet of the character
0N/A */
0N/A public AttributeSet getCharacterAttribute(int i) {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null) { // JLabel contains HTML text
0N/A return at.getCharacterAttribute(i);
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the start offset within the selected text.
0N/A * If there is no selection, but there is
0N/A * a caret, the start and end offsets will be the same.
0N/A *
0N/A * @return the index into the text of the start of the selection
0N/A */
0N/A public int getSelectionStart() {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null) { // JLabel contains HTML text
0N/A return at.getSelectionStart();
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the end offset within the selected text.
0N/A * If there is no selection, but there is
0N/A * a caret, the start and end offsets will be the same.
0N/A *
0N/A * @return the index into teh text of the end of the selection
0N/A */
0N/A public int getSelectionEnd() {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null) { // JLabel contains HTML text
0N/A return at.getSelectionEnd();
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the portion of the text that is selected.
0N/A *
0N/A * @return the String portion of the text that is selected
0N/A */
0N/A public String getSelectedText() {
0N/A AccessibleText at = getNoteLabelAccessibleText();
0N/A if (at != null) { // JLabel contains HTML text
0N/A return at.getSelectedText();
0N/A }
0N/A return null;
0N/A }
0N/A /* ===== End AccessibleText impl ===== */
0N/A }
0N/A // inner class AccessibleProgressMonitor
0N/A
0N/A}