jdk/src/share/classes/javax/swing/text/html/AccessibleHTML.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 1299 027d966d5658
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 2000-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.text.html;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.text.BreakIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The AccessibleHTML class provide information about the contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * of a HTML document to assistive technologies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author  Lynn Monsanto
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class AccessibleHTML implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * The editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private JEditorPane editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Current model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private Document model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * DocumentListener installed on the current model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private DocumentListener docListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * PropertyChangeListener installed on the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private PropertyChangeListener propChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * The root ElementInfo for the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private ElementInfo rootElementInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * The root accessible context for the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private RootHTMLAccessibleContext rootHTMLAccessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public AccessibleHTML(JEditorPane pane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        editor = pane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        propChangeListener = new PropertyChangeHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        setDocument(editor.getDocument());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        docListener = new DocumentHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Sets the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private void setDocument(Document document) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            model.removeDocumentListener(docListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            editor.removePropertyChangeListener(propChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        this.model = document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            if (rootElementInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                rootElementInfo.invalidate(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            buildInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            model.addDocumentListener(docListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            rootElementInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            editor.addPropertyChangeListener(propChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Returns the Document currently presenting information for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private Document getDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Returns the JEditorPane providing information for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private JEditorPane getTextComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Returns the ElementInfo representing the root Element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private ElementInfo getRootInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return rootElementInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Returns the root <code>View</code> associated with the current text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private View getRootView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return getTextComponent().getUI().getRootView(getTextComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns the bounds the root View will be rendered in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private Rectangle getRootEditorRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        Rectangle alloc = getTextComponent().getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if ((alloc.width > 0) && (alloc.height > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            alloc.x = alloc.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            Insets insets = editor.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            alloc.x += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            alloc.y += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            alloc.width -= insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            alloc.height -= insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return alloc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * If possible acquires a lock on the Document.  If a lock has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * obtained a key will be retured that should be passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * <code>unlock</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private Object lock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        Document document = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (document instanceof AbstractDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            ((AbstractDocument)document).readLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Releases a lock previously obtained via <code>lock</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private void unlock(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (key != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            ((AbstractDocument)key).readUnlock();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Rebuilds the information from the current info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private void buildInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        Object lock = lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            Element root = doc.getDefaultRootElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            rootElementInfo = new ElementInfo(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            rootElementInfo.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            unlock(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Create an ElementInfo subclass based on the passed in Element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    ElementInfo createElementInfo(Element e, ElementInfo parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        AttributeSet attrs = e.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (attrs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            Object name = attrs.getAttribute(StyleConstants.NameAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            if (name == HTML.Tag.IMG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                return new IconElementInfo(e, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            else if (name == HTML.Tag.CONTENT || name == HTML.Tag.CAPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                return new TextElementInfo(e, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            else if (name == HTML.Tag.TABLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                return new TableElementInfo(e, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return null;
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
     * Returns the root AccessibleContext for the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (rootHTMLAccessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            rootHTMLAccessibleContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                new RootHTMLAccessibleContext(rootElementInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return rootHTMLAccessibleContext;
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
     * The roow AccessibleContext for the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private class RootHTMLAccessibleContext extends HTMLAccessibleContext {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        public RootHTMLAccessibleContext(ElementInfo elementInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            super(elementInfo);
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 accessibleName property of this object.  The accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         * property of an object is a localized String that designates the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         * of the object.  For example, the accessibleName property of a label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         * or button might be the text of the label or button itself.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         * case of an object that doesn't display its name, the accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
         * should still be set.  For example, in the case of a text field used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         * to enter the name of a city, the accessibleName for the en_US locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         * could be 'city.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
         * @return the localized name of the object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                return (String)model.getProperty(Document.TitleProperty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * Gets the accessibleDescription property of this object.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * property isn't set, returns the content type of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         * <code>JEditorPane</code> instead (e.g. "plain/text", "html/text").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
         * @return the localized description of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         *      if this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return editor.getContentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         * Gets the role of this object.  The role of the object is the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         * purpose or use of the class of this object.  For example, the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         * of a push button is AccessibleRole.PUSH_BUTTON.  The roles in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
         * AccessibleRole are provided so component developers can pick from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
         * a set of predefined roles.  This enables assistive technologies to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         * provide a consistent interface to various tweaked subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
         * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
         * that act like a push button) as well as distinguish between sublasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
         * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
         * and AccessibleRole.RADIO_BUTTON for radio buttons).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
         * <p>Note that the AccessibleRole class is also extensible, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
         * custom component developers can define their own AccessibleRole's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
         * if the set of predefined roles is inadequate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
         * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return AccessibleRole.TEXT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Base AccessibleContext class for HTML elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    protected abstract class HTMLAccessibleContext extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        implements Accessible, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        protected ElementInfo elementInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        public HTMLAccessibleContext(ElementInfo elementInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            this.elementInfo = elementInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // begin AccessibleContext implementation ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         * @return an instance of AccessibleStateSet describing the states
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            AccessibleStateSet states = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            Component comp = getTextComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (comp.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                states.add(AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            if (comp instanceof JTextComponent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                ((JTextComponent)comp).isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                states.add(AccessibleState.EDITABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                states.add(AccessibleState.FOCUSABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (comp.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                states.add(AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (comp.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                states.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * Gets the 0-based index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * @return the 0-based index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         * object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * @see #getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            return elementInfo.getIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
         * Returns the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         * @return the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return elementInfo.getChildCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         * Returns the specified Accessible child of the object.  The Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * children of an Accessible object are zero-based, so the first child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * of an Accessible child is at index 0, the second child is at index 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         * @return the Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            ElementInfo childInfo = elementInfo.getChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (childInfo != null && childInfo instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                return (Accessible)childInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
         * Gets the locale of the component. If the component does not have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
         * locale, then the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
         * @return this component's locale.  If this component does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
         * a locale, the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
         * @exception IllegalComponentStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         * If the Component does not have its own locale and has not yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         * added to a containment hierarchy such that the locale can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         * determined from the containing parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        public Locale getLocale() throws IllegalComponentStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            return editor.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        // ... end AccessibleContext implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        // begin AccessibleComponent implementation ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         * Gets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            return getTextComponent().getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
         * Sets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
         * @param c the new Color for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
         * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            getTextComponent().setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
         * Gets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
         * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
         * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            return getTextComponent().getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         * Sets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
         * @param c the new Color for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
         * @see #getForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            getTextComponent().setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
         * Gets the Cursor of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
         * @return the Cursor, if supported, of the object; otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
         * @see #setCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            return getTextComponent().getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
         * Sets the Cursor of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
         * @param c the new Cursor for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         * @see #getCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        public void setCursor(Cursor cursor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            getTextComponent().setCursor(cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
         * Gets the Font of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
         * @return the Font,if supported, for the object; otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
         * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            return getTextComponent().getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
         * Sets the Font of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         * @param f the new Font for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            getTextComponent().setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
         * Gets the FontMetrics of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
         * @param f the Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
         * @return the FontMetrics, if supported, the object; otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
         * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return getTextComponent().getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
         * Determines if the object is enabled.  Objects that are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
         * will also have the AccessibleState.ENABLED state set in their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
         * AccessibleStateSets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         * @return true if object is enabled; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         * @see #setEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         * @see AccessibleContext#getAccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         * @see AccessibleState#ENABLED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return getTextComponent().isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         * Sets the enabled state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         * @param b if true, enables this object; otherwise, disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         * @see #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            getTextComponent().setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         * Determines if the object is visible.  Note: this means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         * object intends to be visible; however, it may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         * showing on the screen because one of the objects that this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         * is contained by is currently not visible.  To determine if an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         * is showing on the screen, use isShowing().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         * <p>Objects that are visible will also have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
         * AccessibleState.VISIBLE state set in their AccessibleStateSets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         * @return true if object is visible; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
         * @see #setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
         * @see AccessibleContext#getAccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
         * @see AccessibleState#VISIBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
         * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            return getTextComponent().isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         * Sets the visible state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
         * @param b if true, shows this object; otherwise, hides it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
         * @see #isVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            getTextComponent().setVisible(b);
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
         * Determines if the object is showing.  This is determined by checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
         * the visibility of the object and its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
         * Note: this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
         * will return true even if the object is obscured by another (for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
         * example, it is underneath a menu that was pulled down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
         * @return true if object is showing; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            return getTextComponent().isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
         * Checks whether the specified point is within this object's bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
         * where the point's x and y coordinates are defined to be relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         * to the coordinate system of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
         * @param p the Point relative to the coordinate system of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
         * @return true if object contains Point; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
         * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                return r.contains(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         * Returns the location of the object on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
         * @return the location of the object on screen; null if this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
         * is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
         * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
         * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            Point editorLocation = getTextComponent().getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                return new Point(editorLocation.x + r.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                 editorLocation.y + r.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
         * Gets the location of the object relative to the parent in the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
         * of a point specifying the object's top-left corner in the screen's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
         * coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
         * @return An instance of Point representing the top-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
         * object's bounds in the coordinate space of the screen; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
         * this object or its parent are not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
         * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         * @see #getLocationOnScreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                return new Point(r.x, r.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         * Sets the location of the object relative to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
         * @param p the new position for the top-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
         * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         * Gets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         * @return A rectangle indicating this component's bounds; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
         * this object is not on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
         * @see #contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            return elementInfo.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
         * Sets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
         * @param r rectangle indicating this component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
         * Returns the size of this object in the form of a Dimension object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
         * The height field of the Dimension object contains this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
         * height, and the width field of the Dimension object contains this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         * object's width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
         * @return A Dimension object that indicates the size of this component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
         * null if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
         * @see #setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                return new Dimension(r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
         * Resizes this object so that it has width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
         * @param d The dimension specifying the new size of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
         * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        public void setSize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            Component comp = getTextComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            comp.setSize(d);
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
         * Returns the Accessible child, if one exists, contained at the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
         * coordinate Point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
         * @param p The point relative to the coordinate system of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
         * @return the Accessible, if it exists, at the specified location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
         * otherwise null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            ElementInfo innerMostElement = getElementInfoAt(rootElementInfo, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            if (innerMostElement instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                return (Accessible)innerMostElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        private ElementInfo getElementInfoAt(ElementInfo elementInfo, Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            if (elementInfo.getBounds() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            if (elementInfo.getChildCount() == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                elementInfo.getBounds().contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                return elementInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                if (elementInfo instanceof TableElementInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                    // Handle table caption as a special case since it's the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    // only table child that is not a table row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    ElementInfo captionInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                        ((TableElementInfo)elementInfo).getCaptionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    if (captionInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                        Rectangle bounds = captionInfo.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                        if (bounds != null && bounds.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                            return captionInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                for (int i = 0; i < elementInfo.getChildCount(); i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    ElementInfo childInfo = elementInfo.getChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                    ElementInfo retValue = getElementInfoAt(childInfo, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                    if (retValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
         * Returns whether this object can accept focus or not.   Objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
         * can accept focus will also have the AccessibleState.FOCUSABLE state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
         * set in their AccessibleStateSets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
         * @return true if object can accept focus; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
         * @see AccessibleContext#getAccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
         * @see AccessibleState#FOCUSABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
         * @see AccessibleState#FOCUSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            Component comp = getTextComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            if (comp instanceof JTextComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                if (((JTextComponent)comp).isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
         * Requests focus for this object.  If this object cannot accept focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
         * nothing will happen.  Otherwise, the object will attempt to take
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
         * focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
         * @see #isFocusTraversable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            // TIGER - 4856191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if (! isFocusTraversable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            Component comp = getTextComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            if (comp instanceof JTextComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                comp.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    if (elementInfo.validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                        // set the caret position to the start of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                        Element elem = elementInfo.getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                        ((JTextComponent)comp).setCaretPosition(elem.getStartOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                        // fire a AccessibleState.FOCUSED property change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                        AccessibleContext ac = editor.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                        PropertyChangeEvent pce = new PropertyChangeEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                            null, AccessibleState.FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                        ac.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                            null, pce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    // don't fire property change event
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         * Adds the specified focus listener to receive focus events from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
         * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
         * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
         * @see #removeFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            getTextComponent().addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
         * Removes the specified focus listener so it no longer receives focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
         * events from this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
         * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
         * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            getTextComponent().removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        // ... end AccessibleComponent implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    } // ... end HTMLAccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * ElementInfo for text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    class TextElementInfo extends ElementInfo implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        TextElementInfo(Element element, ElementInfo parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            super(element, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        // begin AccessibleText implementation ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        private AccessibleContext accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                accessibleContext = new TextAccessibleContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
         * AccessibleContext for text elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        public class TextAccessibleContext extends HTMLAccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            implements AccessibleText {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            public TextAccessibleContext(ElementInfo elementInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                super(elementInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
             * Gets the accessibleName property of this object.  The accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
             * property of an object is a localized String that designates the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
             * of the object.  For example, the accessibleName property of a label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
             * or button might be the text of the label or button itself.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
             * case of an object that doesn't display its name, the accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
             * should still be set.  For example, in the case of a text field used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
             * to enter the name of a city, the accessibleName for the en_US locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
             * could be 'city.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
             * @return the localized name of the object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
             * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
             * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                    return (String)model.getProperty(Document.TitleProperty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
             * Gets the accessibleDescription property of this object.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
             * property isn't set, returns the content type of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
             * <code>JEditorPane</code> instead (e.g. "plain/text", "html/text").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
             * @return the localized description of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
             *  if this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
             * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                return editor.getContentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
             * Gets the role of this object.  The role of the object is the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
             * purpose or use of the class of this object.  For example, the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
             * of a push button is AccessibleRole.PUSH_BUTTON.  The roles in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
             * AccessibleRole are provided so component developers can pick from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
             * a set of predefined roles.  This enables assistive technologies to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
             * provide a consistent interface to various tweaked subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
             * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
             * that act like a push button) as well as distinguish between sublasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
             * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
             * and AccessibleRole.RADIO_BUTTON for radio buttons).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
             * <p>Note that the AccessibleRole class is also extensible, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
             * custom component developers can define their own AccessibleRole's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
             * if the set of predefined roles is inadequate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
             * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                return AccessibleRole.TEXT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
             * Given a point in local coordinates, return the zero-based index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
             * of the character under that Point.  If the point is invalid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
             * this method returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
             * @param p the Point in local coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
             * @return the zero-based index of the character under Point p; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
             * Point is invalid returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            public int getIndexAtPoint(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                View v = getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                    return v.viewToModel(p.x, p.y, getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
             * Determine the bounding box of the character at the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
             * index into the string.  The bounds are returned in local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
             * coordinates.  If the index is invalid an empty rectangle is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
             * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
             * @param i the index into the String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
             * @return the screen coordinates of the character's the bounding box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
             * if index is invalid returns an empty rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            public Rectangle getCharacterBounds(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                    return editor.getUI().modelToView(editor, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
             * Return the number of characters (valid indicies)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
             * @return the number of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            public int getCharCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                    Element elem = elementInfo.getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                    return elem.getEndOffset() - elem.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
             * Return the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
             * Note: That to the right of the caret will have the same index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
             * value as the offset (the caret is between two characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
             * @return the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            public int getCaretPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                View v = getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                if (v == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                Container c = v.getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                if (c instanceof JTextComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                    return ((JTextComponent)c).getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
             * IndexedSegment extends Segment adding the offset into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
             * the model the <code>Segment</code> was asked for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            private class IndexedSegment extends Segment {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                 * Offset into the model that the position represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                public int modelOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            public String getAtIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                return getAtIndex(part, index, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            public String getAfterIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                return getAtIndex(part, index, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            public String getBeforeIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                return getAtIndex(part, index, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
             * Gets the word, sentence, or character at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
             * If <code>direction</code> is non-null this will find the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
             * next/previous word/sentence/character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            private String getAtIndex(int part, int index, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                if (model instanceof AbstractDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                    ((AbstractDocument)model).readLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                    if (index < 0 || index >= model.getLength()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                    switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                    case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                        if (index + direction < model.getLength() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                            index + direction >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                            return model.getText(index + direction, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                    case AccessibleText.WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                    case AccessibleText.SENTENCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                        IndexedSegment seg = getSegmentAt(part, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                        if (seg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                            if (direction != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                                int next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                                if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                                    next = seg.modelOffset - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                                    next = seg.modelOffset + direction * seg.count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                                if (next >= 0 && next <= model.getLength()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                                    seg = getSegmentAt(part, next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                                    seg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                            if (seg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                                return new String(seg.array, seg.offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                                                  seg.count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                    if (model instanceof AbstractDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                        ((AbstractDocument)model).readUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
             * Returns the paragraph element for the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            private Element getParagraphElement(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                if (model instanceof PlainDocument ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                    PlainDocument sdoc = (PlainDocument)model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                    return sdoc.getParagraphElement(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                } else if (model instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                    StyledDocument sdoc = (StyledDocument)model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                    return sdoc.getParagraphElement(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    Element para = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                    for (para = model.getDefaultRootElement(); ! para.isLeaf(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                        int pos = para.getElementIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                        para = para.getElement(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                    if (para == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                    return para.getParentElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
             * Returns a <code>Segment</code> containing the paragraph text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
             * at <code>index</code>, or null if <code>index</code> isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
             * valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            private IndexedSegment getParagraphElementText(int index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                Element para = getParagraphElement(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                if (para != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                    IndexedSegment segment = new IndexedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                        int length = para.getEndOffset() - para.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                        model.getText(para.getStartOffset(), length, segment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                    } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    segment.modelOffset = para.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                    return segment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
             * Returns the Segment at <code>index</code> representing either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
             * the paragraph or sentence as identified by <code>part</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
             * null if a valid paragraph/sentence can't be found. The offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
             * will point to the start of the word/sentence in the array, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
             * the modelOffset will point to the location of the word/sentence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
             * in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            private IndexedSegment getSegmentAt(int part, int index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                IndexedSegment seg = getParagraphElementText(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                if (seg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                BreakIterator iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                case AccessibleText.WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                    iterator = BreakIterator.getWordInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                case AccessibleText.SENTENCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                    iterator = BreakIterator.getSentenceInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                seg.first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                iterator.setText(seg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                int end = iterator.following(index - seg.modelOffset + seg.offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                if (end == BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                if (end > seg.offset + seg.count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                int begin = iterator.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                if (begin == BreakIterator.DONE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                    begin >= seg.offset + seg.count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                seg.modelOffset = seg.modelOffset + begin - seg.offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                seg.offset = begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                seg.count = end - begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                return seg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
             * Return the AttributeSet for a given character at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
             * @param i the zero-based index into the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
             * @return the AttributeSet of the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            public AttributeSet getCharacterAttribute(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                if (model instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                    StyledDocument doc = (StyledDocument)model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                    Element elem = doc.getCharacterElement(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                    if (elem != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                        return elem.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
             * Returns the start offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
             * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
             * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
             * @return the index into the text of the start of the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            public int getSelectionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                return editor.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
             * Returns the end offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
             * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
             * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
             * @return the index into teh text of the end of the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            public int getSelectionEnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                return editor.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
             * Returns the portion of the text that is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
             * @return the String portion of the text that is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            public String getSelectedText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                return editor.getSelectedText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
             * Returns the text substring starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
             * offset with the specified length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            private String getText(int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                if (model != null && model instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                    StyledDocument doc = (StyledDocument)model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                    return model.getText(offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * ElementInfo for images
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    private class IconElementInfo extends ElementInfo implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        private int width = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        private int height = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        IconElementInfo(Element element, ElementInfo parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            super(element, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        protected void invalidate(boolean first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            super.invalidate(first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            width = height = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        private int getImageSize(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                int size = getIntAttr(getAttributes(), key, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                if (size == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                    View v = getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                    size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                    if (v instanceof ImageView) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                        Image img = ((ImageView)v).getImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                        if (img != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                            if (key == HTML.Attribute.WIDTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                                size = img.getWidth(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                                size = img.getHeight(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        // begin AccessibleIcon implementation ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        private AccessibleContext accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                accessibleContext = new IconAccessibleContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
         * AccessibleContext for images
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        protected class IconAccessibleContext extends HTMLAccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            implements AccessibleIcon  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            public IconAccessibleContext(ElementInfo elementInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                super(elementInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
             * Gets the accessibleName property of this object.  The accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
             * property of an object is a localized String that designates the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
             * of the object.  For example, the accessibleName property of a label
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
             * or button might be the text of the label or button itself.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
             * case of an object that doesn't display its name, the accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
             * should still be set.  For example, in the case of a text field used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
             * to enter the name of a city, the accessibleName for the en_US locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
             * could be 'city.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
             * @return the localized name of the object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
             * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
             * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                return getAccessibleIconDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
             * Gets the accessibleDescription property of this object.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
             * property isn't set, returns the content type of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
             * <code>JEditorPane</code> instead (e.g. "plain/text", "html/text").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
             * @return the localized description of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
             *  if this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
             * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                return editor.getContentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
             * Gets the role of this object.  The role of the object is the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
             * purpose or use of the class of this object.  For example, the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
             * of a push button is AccessibleRole.PUSH_BUTTON.  The roles in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
             * AccessibleRole are provided so component developers can pick from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
             * a set of predefined roles.  This enables assistive technologies to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
             * provide a consistent interface to various tweaked subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
             * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
             * that act like a push button) as well as distinguish between sublasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
             * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
             * and AccessibleRole.RADIO_BUTTON for radio buttons).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
             * <p>Note that the AccessibleRole class is also extensible, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
             * custom component developers can define their own AccessibleRole's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
             * if the set of predefined roles is inadequate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
             * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                return AccessibleRole.ICON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            public AccessibleIcon [] getAccessibleIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                AccessibleIcon [] icons = new AccessibleIcon[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                icons[0] = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                return icons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
             * Gets the description of the icon.  This is meant to be a brief
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
             * textual description of the object.  For example, it might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
             * presented to a blind user to give an indication of the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
             * of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
             * @return the description of the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            public String getAccessibleIconDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                return ((ImageView)getView()).getAltText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
             * Sets the description of the icon.  This is meant to be a brief
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
             * textual description of the object.  For example, it might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
             * presented to a blind user to give an indication of the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
             * of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
             * @param description the description of the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            public void setAccessibleIconDescription(String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
             * Gets the width of the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
             * @return the width of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            public int getAccessibleIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                if (width == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                    width = getImageSize(HTML.Attribute.WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
             * Gets the height of the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
             * @return the height of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            public int getAccessibleIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                if (height == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                    height = getImageSize(HTML.Attribute.HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        // ... end AccessibleIconImplementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * TableElementInfo encapsulates information about a HTML.Tag.TABLE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * To make access fast it crates a grid containing the children to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * allow for access by row, column. TableElementInfo will contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * TableRowElementInfos, which will contain TableCellElementInfos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * Any time one of the rows or columns becomes invalid the table is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * invalidated.  This is because any time one of the child attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * changes the size of the grid may have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    private class TableElementInfo extends ElementInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        protected ElementInfo caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
         * Allocation of the table by row x column. There may be holes (eg
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
         * nulls) depending upon the html, any cell that has a rowspan/colspan
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
         * > 1 will be contained multiple times in the grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        private TableCellElementInfo[][] grid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        TableElementInfo(Element e, ElementInfo parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            super(e, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        public ElementInfo getCaptionInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            return caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
         * Overriden to update the grid when validating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        protected void validate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
            super.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            updateGrid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
         * Overriden to only alloc instances of TableRowElementInfos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        protected void loadChildren(Element e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            for (int counter = 0; counter < e.getElementCount(); counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                Element child = e.getElement(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                AttributeSet attrs = child.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                if (attrs.getAttribute(StyleConstants.NameAttribute) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                                       HTML.Tag.TR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                    addChild(new TableRowElementInfo(child, this, counter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                } else if (attrs.getAttribute(StyleConstants.NameAttribute) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                                       HTML.Tag.CAPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                    // Handle captions as a special case since all other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                    // children are table rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                    caption = createElementInfo(child, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
         * Updates the grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        private void updateGrid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            // Determine the max row/col count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            int delta = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            int maxCols = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            int rows = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            for (int counter = 0; counter < getChildCount(); counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                TableRowElementInfo row = getRow(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                int prev = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                for (int y = 0; y < delta; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                    prev = Math.max(prev, getRow(counter - y - 1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                                    getColumnCount(y + 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                delta = Math.max(row.getRowCount(), delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                delta--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                maxCols = Math.max(maxCols, row.getColumnCount() + prev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            rows = getChildCount() + delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            // Alloc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            grid = new TableCellElementInfo[rows][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            for (int counter = 0; counter < rows; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                grid[counter] = new TableCellElementInfo[maxCols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            // Update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            for (int counter = 0; counter < rows; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                getRow(counter).updateGrid(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
         * Returns the TableCellElementInfo at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        public TableRowElementInfo getRow(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            return (TableRowElementInfo)getChild(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
         * Returns the TableCellElementInfo by row and column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        public TableCellElementInfo getCell(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            if (validateIfNecessary() && r < grid.length &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                                         c < grid[0].length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                return grid[r][c];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
         * Returns the rowspan of the specified entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        public int getRowExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            TableCellElementInfo cell = getCell(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            if (cell != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                int rows = cell.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                int delta = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                while ((r - delta) >= 0 && grid[r - delta][c] == cell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                    delta++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                return rows - delta + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
         * Returns the colspan of the specified entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        public int getColumnExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            TableCellElementInfo cell = getCell(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
            if (cell != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                int cols = cell.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                int delta = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                while ((c - delta) >= 0 && grid[r][c - delta] == cell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                    delta++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                return cols - delta + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
         * Returns the number of rows in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                return grid.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
         * Returns the number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            if (validateIfNecessary() && grid.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                return grid[0].length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        // begin AccessibleTable implementation ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        private AccessibleContext accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                accessibleContext = new TableAccessibleContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
         * AccessibleContext for tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        public class TableAccessibleContext extends HTMLAccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            implements AccessibleTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
            private AccessibleHeadersTable rowHeadersTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
            public TableAccessibleContext(ElementInfo elementInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                super(elementInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
             * Gets the accessibleName property of this object.  The accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
             * property of an object is a localized String that designates the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
             * of the object.  For example, the accessibleName property of a label
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
             * or button might be the text of the label or button itself.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
             * case of an object that doesn't display its name, the accessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
             * should still be set.  For example, in the case of a text field used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
             * to enter the name of a city, the accessibleName for the en_US locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
             * could be 'city.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
             * @return the localized name of the object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
             * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
             * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                // return the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                return getAccessibleRole().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
             * Gets the accessibleDescription property of this object.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
             * property isn't set, returns the content type of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
             * <code>JEditorPane</code> instead (e.g. "plain/text", "html/text").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
             * @return the localized description of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
             *  if this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
             * @see #setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                return editor.getContentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
             * Gets the role of this object.  The role of the object is the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
             * purpose or use of the class of this object.  For example, the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
             * of a push button is AccessibleRole.PUSH_BUTTON.  The roles in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
             * AccessibleRole are provided so component developers can pick from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
             * a set of predefined roles.  This enables assistive technologies to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
             * provide a consistent interface to various tweaked subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
             * components (e.g., use AccessibleRole.PUSH_BUTTON for all components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
             * that act like a push button) as well as distinguish between sublasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
             * that behave differently (e.g., AccessibleRole.CHECK_BOX for check boxes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
             * and AccessibleRole.RADIO_BUTTON for radio buttons).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
             * <p>Note that the AccessibleRole class is also extensible, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
             * custom component developers can define their own AccessibleRole's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
             * if the set of predefined roles is inadequate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
             * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                return AccessibleRole.TABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
             * Gets the 0-based index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
             * @return the 0-based index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
             * object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
             * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
             * @gsee #getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                return elementInfo.getIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
             * Returns the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
             * @return the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                return ((TableElementInfo)elementInfo).getRowCount() *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                    ((TableElementInfo)elementInfo).getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
             * Returns the specified Accessible child of the object.  The Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
             * children of an Accessible object are zero-based, so the first child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
             * of an Accessible child is at index 0, the second child is at index 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
             * and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
             * @return the Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
             * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                int rowCount = ((TableElementInfo)elementInfo).getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                int columnCount = ((TableElementInfo)elementInfo).getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                int r = i / rowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                int c = i % columnCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                if (r < 0 || r >= rowCount || c < 0 || c >= columnCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                    return getAccessibleAt(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            public AccessibleTable getAccessibleTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
             * Returns the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
             * @return the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
            public Accessible getAccessibleCaption() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                ElementInfo captionInfo = getCaptionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                if (captionInfo instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                    return (Accessible)caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
             * Sets the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
             * @param a the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            public void setAccessibleCaption(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
             * Returns the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
             * @return the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
            public Accessible getAccessibleSummary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
             * Sets the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
             * @param a the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
            public void setAccessibleSummary(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
             * Returns the number of rows in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
             * @return the number of rows in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            public int getAccessibleRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                return ((TableElementInfo)elementInfo).getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
             * Returns the number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
             * @return the number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            public int getAccessibleColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                return ((TableElementInfo)elementInfo).getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
             * Returns the Accessible at a specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
             * in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
             * @return the Accessible at the specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
            public Accessible getAccessibleAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                TableCellElementInfo cellInfo = getCell(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                if (cellInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                    return cellInfo.getAccessible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
             * Returns the number of rows occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
             * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
             * @return the number of rows occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
             * given specified (row, column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
            public int getAccessibleRowExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                return ((TableElementInfo)elementInfo).getRowExtentAt(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
             * Returns the number of columns occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
             * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
             * @return the number of columns occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
             * given specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            public int getAccessibleColumnExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                return ((TableElementInfo)elementInfo).getColumnExtentAt(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
             * Returns the row headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
             * @return an AccessibleTable representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
             * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            public AccessibleTable getAccessibleRowHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                return rowHeadersTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
             * Sets the row headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
             * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
             * row headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
            public void setAccessibleRowHeader(AccessibleTable table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
             * Returns the column headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
             * @return an AccessibleTable representing the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
             * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            public AccessibleTable getAccessibleColumnHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
             * Sets the column headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
             * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
             * column headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            public void setAccessibleColumnHeader(AccessibleTable table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
             * Returns the description of the specified row in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
             * @return the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            public Accessible getAccessibleRowDescription(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
             * Sets the description text of the specified row of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
             * @param a the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            public void setAccessibleRowDescription(int r, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
             * Returns the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
             * @return the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            public Accessible getAccessibleColumnDescription(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
             * Sets the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
             * @param a the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
            public void setAccessibleColumnDescription(int c, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
             * Returns a boolean value indicating whether the accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
             * a specified row and column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
             * @return the boolean value true if the accessible at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
             * row and column is selected. Otherwise, the boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
             * false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            public boolean isAccessibleSelected(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                    if (r < 0 || r >= getAccessibleRowCount() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                        c < 0 || c >= getAccessibleColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                    TableCellElementInfo cell = getCell(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                    if (cell != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                        Element elem = cell.getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                        int start = elem.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                        int end = elem.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                        return start >= editor.getSelectionStart() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                            end <= editor.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
             * Returns a boolean value indicating whether the specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
             * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
             * @return the boolean value true if the specified row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
             * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            public boolean isAccessibleRowSelected(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                    if (r < 0 || r >= getAccessibleRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                    int nColumns = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                    TableCellElementInfo startCell = getCell(r, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                    if (startCell == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                    int start = startCell.getElement().getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                    TableCellElementInfo endCell = getCell(r, nColumns-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                    if (endCell == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                    int end = endCell.getElement().getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                    return start >= editor.getSelectionStart() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                        end <= editor.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
             * Returns a boolean value indicating whether the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
             * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
             * @param r zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
             * @return the boolean value true if the specified column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
             * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            public boolean isAccessibleColumnSelected(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                    if (c < 0 || c >= getAccessibleColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                    int nRows = getAccessibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                    TableCellElementInfo startCell = getCell(0, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                    if (startCell == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                    int start = startCell.getElement().getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                    TableCellElementInfo endCell = getCell(nRows-1, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                    if (endCell == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                    int end = endCell.getElement().getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                    return start >= editor.getSelectionStart() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                        end <= editor.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
             * Returns the selected rows in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
             * @return an array of selected rows where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
             * zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            public int [] getSelectedAccessibleRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                    int nRows = getAccessibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                    Vector vec = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                    for (int i = 0; i < nRows; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
                        if (isAccessibleRowSelected(i)) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1973
                            vec.addElement(Integer.valueOf(i));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                    int retval[] = new int[vec.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
                    for (int i = 0; i < retval.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                        retval[i] = ((Integer)vec.elementAt(i)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                    return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                return new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
             * Returns the selected columns in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
             * @return an array of selected columns where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
             * zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
            public int [] getSelectedAccessibleColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                    int nColumns = getAccessibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                    Vector vec = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                    for (int i = 0; i < nColumns; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                        if (isAccessibleColumnSelected(i)) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1998
                            vec.addElement(Integer.valueOf(i));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                    int retval[] = new int[vec.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                    for (int i = 0; i < retval.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                        retval[i] = ((Integer)vec.elementAt(i)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                    return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                return new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            // begin AccessibleExtendedTable implementation -------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
             * Returns the row number of an index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
             * @param index the zero-based index in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
             * @return the zero-based row of the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
             * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            public int getAccessibleRow(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                    int numCells = getAccessibleColumnCount() *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                        getAccessibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                    if (index >= numCells) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                        return index / getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
             * Returns the column number of an index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
             * @param index the zero-based index in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
             * @return the zero-based column of the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
             * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            public int getAccessibleColumn(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                    int numCells = getAccessibleColumnCount() *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                        getAccessibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                    if (index >= numCells) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                        return index % getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
             * Returns the index at a row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
             * @return the zero-based index in the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
             * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
            public int getAccessibleIndex(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                    if (r >= getAccessibleRowCount() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                        c >= getAccessibleColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                        return r * getAccessibleColumnCount() + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
             * Returns the row header at a row in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
             * @return a String representing the row header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
             * if one exists; otherwise null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
            public String getAccessibleRowHeader(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
                    TableCellElementInfo cellInfo = getCell(r, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                    if (cellInfo.isHeaderCell()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                        View v = cellInfo.getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                        if (v != null && model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                                return model.getText(v.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                                                     v.getEndOffset() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                                                     v.getStartOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
                            } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
             * Returns the column header at a column in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
             * @return a String representing the column header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
             * if one exists; otherwise null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            public String getAccessibleColumnHeader(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                    TableCellElementInfo cellInfo = getCell(0, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                    if (cellInfo.isHeaderCell()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                        View v = cellInfo.getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                        if (v != null && model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
                                return model.getText(v.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                                                     v.getEndOffset() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                                                     v.getStartOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                            } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
            public void addRowHeader(TableCellElementInfo cellInfo, int rowNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                if (rowHeadersTable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                    rowHeadersTable = new AccessibleHeadersTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                rowHeadersTable.addHeader(cellInfo, rowNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
            // end of AccessibleExtendedTable implementation ------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
            protected class AccessibleHeadersTable implements AccessibleTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                // Header information is modeled as a Hashtable of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                // ArrayLists where each Hashtable entry represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                // a row containing one or more headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                private Hashtable headers = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                private int rowCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
                private int columnCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
                public void addHeader(TableCellElementInfo cellInfo, int rowNumber) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  2142
                    Integer rowInteger = Integer.valueOf(rowNumber);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
                    ArrayList list = (ArrayList)headers.get(rowInteger);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                    if (list == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
                        list = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
                        headers.put(rowInteger, list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                    list.add(cellInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                 * Returns the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
                 * @return the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
                public Accessible getAccessibleCaption() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
                 * Sets the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
                 * @param a the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                public void setAccessibleCaption(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
                 * Returns the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
                 * @return the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                public Accessible getAccessibleSummary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
                 * Sets the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
                 * @param a the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                public void setAccessibleSummary(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                 * Returns the number of rows in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                 * @return the number of rows in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                public int getAccessibleRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
                    return rowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                 * Returns the number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
                 * @return the number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
                public int getAccessibleColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                    return columnCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                private TableCellElementInfo getElementInfoAt(int r, int c) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  2204
                    ArrayList list = (ArrayList)headers.get(Integer.valueOf(r));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                    if (list != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                        return (TableCellElementInfo)list.get(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                 * Returns the Accessible at a specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                 * in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
                 * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                 * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
                 * @return the Accessible at the specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
                public Accessible getAccessibleAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
                    ElementInfo elementInfo = getElementInfoAt(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
                    if (elementInfo instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
                        return (Accessible)elementInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                 * Returns the number of rows occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                 * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
                 * @return the number of rows occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
                 * given specified (row, column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                public int getAccessibleRowExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
                    TableCellElementInfo elementInfo = getElementInfoAt(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
                    if (elementInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
                        return elementInfo.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
                 * Returns the number of columns occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
                 * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
                 * @return the number of columns occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
                 * given specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
                public int getAccessibleColumnExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
                    TableCellElementInfo elementInfo = getElementInfoAt(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
                    if (elementInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
                        return elementInfo.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
                        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
                 * Returns the row headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
                 * @return an AccessibleTable representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
                 * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
                public AccessibleTable getAccessibleRowHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
                 * Sets the row headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                 * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                 * row headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
                public void setAccessibleRowHeader(AccessibleTable table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
                 * Returns the column headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
                 * @return an AccessibleTable representing the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                 * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
                public AccessibleTable getAccessibleColumnHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                 * Sets the column headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
                 * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
                 * column headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
                public void setAccessibleColumnHeader(AccessibleTable table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
                 * Returns the description of the specified row in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
                 * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
                 * @return the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
                public Accessible getAccessibleRowDescription(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
                 * Sets the description text of the specified row of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
                 * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
                 * @param a the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
                public void setAccessibleRowDescription(int r, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
                 * Returns the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
                 * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
                 * @return the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
                public Accessible getAccessibleColumnDescription(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
                 * Sets the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                 * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
                 * @param a the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
                public void setAccessibleColumnDescription(int c, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
                 * Returns a boolean value indicating whether the accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
                 * a specified row and column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
                 * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
                 * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
                 * @return the boolean value true if the accessible at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
                 * row and column is selected. Otherwise, the boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
                 * false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
                public boolean isAccessibleSelected(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
                 * Returns a boolean value indicating whether the specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
                 * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
                 * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
                 * @return the boolean value true if the specified row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
                 * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
                public boolean isAccessibleRowSelected(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                 * Returns a boolean value indicating whether the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                 * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
                 * @param r zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
                 * @return the boolean value true if the specified column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
                 * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
                public boolean isAccessibleColumnSelected(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                 * Returns the selected rows in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
                 * @return an array of selected rows where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
                 * zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
                public int [] getSelectedAccessibleRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
                    return new int [0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
                 * Returns the selected columns in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
                 * @return an array of selected columns where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
                 * zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
                public int [] getSelectedAccessibleColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
                    return new int [0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
        } // ... end AccessibleHeadersTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
         * ElementInfo for table rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
        private class TableRowElementInfo extends ElementInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
            private TableElementInfo parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
            private int rowNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
            TableRowElementInfo(Element e, TableElementInfo parent, int rowNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                super(e, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
                this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
                this.rowNumber = rowNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
            protected void loadChildren(Element e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
                for (int x = 0; x < e.getElementCount(); x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
                    AttributeSet attrs = e.getElement(x).getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
                    if (attrs.getAttribute(StyleConstants.NameAttribute) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
                            HTML.Tag.TH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
                        TableCellElementInfo headerElementInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
                            new TableCellElementInfo(e.getElement(x), this, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                        addChild(headerElementInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
                        AccessibleTable at =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
                            parent.getAccessibleContext().getAccessibleTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
                        TableAccessibleContext tableElement =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
                            (TableAccessibleContext)at;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
                        tableElement.addRowHeader(headerElementInfo, rowNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
                    } else if (attrs.getAttribute(StyleConstants.NameAttribute) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                            HTML.Tag.TD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
                        addChild(new TableCellElementInfo(e.getElement(x), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                                                          false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
             * Returns the max of the rowspans of the cells in this row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
            public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
                int rowCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
                    for (int counter = 0; counter < getChildCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
                         counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
                        TableCellElementInfo cell = (TableCellElementInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
                                                    getChild(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
                        if (cell.validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
                            rowCount = Math.max(rowCount, cell.getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
                return rowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
             * Returns the sum of the column spans of the individual
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
             * cells in this row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
                int colCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
                    for (int counter = 0; counter < getChildCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
                         counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
                        TableCellElementInfo cell = (TableCellElementInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
                                                    getChild(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
                        if (cell.validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
                            colCount += cell.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
                return colCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
             * Overriden to invalidate the table as well as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
             * TableRowElementInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
            protected void invalidate(boolean first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
                super.invalidate(first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
                getParent().invalidate(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
             * Places the TableCellElementInfos for this element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
             * the grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
            private void updateGrid(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
                    boolean emptyRow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
                    while (!emptyRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
                        for (int counter = 0; counter < grid[row].length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
                                 counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
                            if (grid[row][counter] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
                                emptyRow = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
                        if (!emptyRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
                            row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                    for (int col = 0, counter = 0; counter < getChildCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                             counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                        TableCellElementInfo cell = (TableCellElementInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                                                    getChild(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
                        while (grid[row][col] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
                            col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
                        for (int rowCount = cell.getRowCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
                             rowCount >= 0; rowCount--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
                            for (int colCount = cell.getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
                                 colCount >= 0; colCount--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
                                grid[row + rowCount][col + colCount] = cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
                        col += cell.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
             * Returns the column count of the number of columns that have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
             * a rowcount >= rowspan.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
            private int getColumnCount(int rowspan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
                    int cols = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
                    for (int counter = 0; counter < getChildCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
                         counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
                        TableCellElementInfo cell = (TableCellElementInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
                                                    getChild(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
                        if (cell.getRowCount() >= rowspan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
                            cols += cell.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
                    return cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
         * TableCellElementInfo is used to represents the cells of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
         * the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
        private class TableCellElementInfo extends ElementInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
            private Accessible accessible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            private boolean isHeaderCell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
            TableCellElementInfo(Element e, ElementInfo parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
                super(e, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
                this.isHeaderCell = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
            TableCellElementInfo(Element e, ElementInfo parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
                                 boolean isHeaderCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
                super(e, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
                this.isHeaderCell = isHeaderCell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
             * Returns whether this table cell is a header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
            public boolean isHeaderCell() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
                return this.isHeaderCell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
             * Returns the Accessible representing this table cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
            public Accessible getAccessible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
                accessible = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
                getAccessible(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
                return accessible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
             * Gets the outermost Accessible in the table cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
            private void getAccessible(ElementInfo elementInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
                if (elementInfo instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
                    accessible = (Accessible)elementInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
                    for (int i = 0; i < elementInfo.getChildCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
                        getAccessible(elementInfo.getChild(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
             * Returns the rowspan attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
                    return Math.max(1, getIntAttr(getAttributes(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
                                                  HTML.Attribute.ROWSPAN, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
             * Returns the colspan attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
            public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
                if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
                    return Math.max(1, getIntAttr(getAttributes(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
                                                  HTML.Attribute.COLSPAN, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
             * Overriden to invalidate the TableRowElementInfo as well as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
             * the TableCellElementInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
            protected void invalidate(boolean first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
                super.invalidate(first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
                getParent().invalidate(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
     * ElementInfo provides a slim down view of an Element.  Each ElementInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
     * can have any number of child ElementInfos that are not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
     * direct children of the Element. As the Document changes various
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
     * ElementInfos become invalidated. Before accessing a particular portion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     * of an ElementInfo you should make sure it is valid by invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     * <code>validateIfNecessary</code>, this will return true if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     * successful, on the other hand a false return value indicates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     * ElementInfo is not valid and can never become valid again (usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     * the result of the Element the ElementInfo encapsulates being removed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
    private class ElementInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
         * The children of this ElementInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
        private ArrayList children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
         * The Element this ElementInfo is providing information for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
        private Element element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
         * The parent ElementInfo, will be null for the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
        private ElementInfo parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
         * Indicates the validity of the ElementInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
        private boolean isValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
         * Indicates if the ElementInfo can become valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
        private boolean canBeValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
         * Creates the root ElementInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
        ElementInfo(Element element) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
            this(element, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
         * Creates an ElementInfo representing <code>element</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
         * the specified parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
        ElementInfo(Element element, ElementInfo parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
            this.element = element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
            this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
            isValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
            canBeValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
         * Validates the receiver. This recreates the children as well. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
         * will be invoked within a <code>readLock</code>. If this is overriden
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
         * it MUST invoke supers implementation first!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
        protected void validate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
            isValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
            loadChildren(getElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
         * Recreates the direct children of <code>info</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
        protected void loadChildren(Element parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
            if (!parent.isLeaf()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
                for (int counter = 0, maxCounter = parent.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
                    counter < maxCounter; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
                    Element e = parent.getElement(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
                    ElementInfo childInfo = createElementInfo(e, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
                    if (childInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
                        addChild(childInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
                        loadChildren(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
         * Returns the index of the child in the parent, or -1 for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
         * root or if the parent isn't valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
        public int getIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
            if (parent == null || !parent.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
            return parent.indexOf(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
         * Returns the Element this <code>ElementInfo</code> represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
        public Element getElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
            return element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
         * Returns the parent of this Element, or null for the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
        public ElementInfo getParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
            return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
         * Returns the index of the specified child, or -1 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
         * <code>child</code> isn't a valid child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
        public int indexOf(ElementInfo child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
            ArrayList children = this.children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
            if (children != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
                return children.indexOf(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
         * Returns the child ElementInfo at <code>index</code>, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
         * if <code>index</code> isn't a valid index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        public ElementInfo getChild(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
            if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
                ArrayList children = this.children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
                if (children != null && index >= 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
                                        index < children.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
                    return (ElementInfo)children.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
         * Returns the number of children the ElementInfo contains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
        public int getChildCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            validateIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
            return (children == null) ? 0 : children.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
         * Adds a new child to this ElementInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
        protected void addChild(ElementInfo child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
            if (children == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
                children = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
            children.add(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
         * Returns the View corresponding to this ElementInfo, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
         * if the ElementInfo can't be validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
        protected View getView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            if (!validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
            Object lock = lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
                View rootView = getRootView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
                Element e = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
                int start = e.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
                if (rootView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
                    return getView(rootView, e, start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
                unlock(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
         * Returns the Bounds for this ElementInfo, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
         * if the ElementInfo can't be validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
        public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
            if (!validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
            Object lock = lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
                Rectangle bounds = getRootEditorRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
                View rootView = getRootView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
                Element e = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
                if (bounds != null && rootView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
                        return rootView.modelToView(e.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
                                                    Position.Bias.Forward,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
                                                    e.getEndOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
                                                    Position.Bias.Backward,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
                                                    bounds).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
                    } catch (BadLocationException ble) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
                unlock(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
         * Returns true if this ElementInfo is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
        protected boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
            return isValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
         * Returns the AttributeSet associated with the Element, this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
         * return null if the ElementInfo can't be validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
        protected AttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
                return getElement().getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
         * Returns the AttributeSet associated with the View that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
         * representing this Element, this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
         * return null if the ElementInfo can't be validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
        protected AttributeSet getViewAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
            if (validateIfNecessary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
                View view = getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
                if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
                    return view.getElement().getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
                return getElement().getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
         * Convenience method for getting an integer attribute from the passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
         * in AttributeSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
        protected int getIntAttr(AttributeSet attrs, Object key, int deflt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
            if (attrs != null && attrs.isDefined(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                String val = (String)attrs.getAttribute(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
                if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
                    i = deflt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
                        i = Math.max(0, Integer.parseInt(val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
                    } catch (NumberFormatException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
                        i = deflt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
            return deflt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
         * Validates the ElementInfo if necessary.  Some ElementInfos may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
         * never be valid again.  You should check <code>isValid</code> before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
         * using one.  This will reload the children and invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
         * <code>validate</code> if the ElementInfo is invalid and can become
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
         * valid again. This will return true if the receiver is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
        protected boolean validateIfNecessary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
            if (!isValid() && canBeValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
                children = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
                Object lock = lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
                    validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
                    unlock(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
            return isValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
         * Invalidates the ElementInfo. Subclasses should override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
         * if they need to reset state once invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
        protected void invalidate(boolean first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
            if (!isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
                if (canBeValid && !first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
                    canBeValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
            isValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
            canBeValid = first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
            if (children != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
                for (int counter = 0; counter < children.size(); counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
                    ((ElementInfo)children.get(counter)).invalidate(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
                children = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
        private View getView(View parent, Element e, int start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
            if (parent.getElement() == e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
                return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
            int index = parent.getViewIndex(start, Position.Bias.Forward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
            if (index != -1 && index < parent.getViewCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
                return getView(parent.getView(index), e, start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
        private int getClosestInfoIndex(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
            for (int counter = 0; counter < getChildCount(); counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
                ElementInfo info = getChild(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
                if (index < info.getElement().getEndOffset() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
                    index == info.getElement().getStartOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
                    return counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
        private void update(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
            if (!isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
            ElementInfo parent = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
            Element element = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
                DocumentEvent.ElementChange ec = e.getChange(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
                if (ec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
                    if (element == getElement()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
                        // One of our children changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
                        invalidate(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
                    else if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
                        parent.invalidate(parent == getRootInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
                element = element.getParentElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
            } while (parent != null && element != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
                     element != parent.getElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
            if (getChildCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                Element elem = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
                int pos = e.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
                int index0 = getClosestInfoIndex(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
                if (index0 == -1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
                    e.getType() == DocumentEvent.EventType.REMOVE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
                    pos >= elem.getEndOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
                    // Event beyond our offsets. We may have represented this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
                    // that is the remove may have removed one of our child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
                    // Elements that represented this, so, we should foward
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
                    // to last element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
                    index0 = getChildCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
                ElementInfo info = (index0 >= 0) ? getChild(index0) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
                if (info != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
                    (info.getElement().getStartOffset() == pos) && (pos > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
                    // If at a boundary, forward the event to the previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
                    // ElementInfo too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
                    index0 = Math.max(index0 - 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
                int index1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
                if (e.getType() != DocumentEvent.EventType.REMOVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
                    index1 = getClosestInfoIndex(pos + e.getLength());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
                    if (index1 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
                        index1 = getChildCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
                    index1 = index0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
                    // A remove may result in empty elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
                    while ((index1 + 1) < getChildCount() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
                           getChild(index1 + 1).getElement().getEndOffset() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
                           getChild(index1 + 1).getElement().getStartOffset()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
                        index1++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
                index0 = Math.max(index0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
                // The check for isValid is here as in the process of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
                // forwarding update our child may invalidate us.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
                for (int i = index0; i <= index1 && isValid(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
                    getChild(i).update(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
     * DocumentListener installed on the current Document.  Will invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
     * <code>update</code> on the <code>RootInfo</code> in response to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
     * any event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
    private class DocumentHandler implements DocumentListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
        public void insertUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
            getRootInfo().update(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
        public void removeUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
            getRootInfo().update(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
        public void changedUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
            getRootInfo().update(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
     * PropertyChangeListener installed on the editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
    private class PropertyChangeHandler implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
        public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
            if (evt.getPropertyName().equals("document")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
                // handle the document change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
                setDocument(editor.getDocument());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
}