<commit_before>
import drafts.com.sun.star.accessibility.XAccessibleContext;
import drafts.com.sun.star.accessibility.XAccessibleText;
import drafts.com.sun.star.accessibility.XAccessibleEditableText;
import drafts.com.sun.star.accessibility.AccessibleTextType;

import com.sun.star.awt.Rectangle;
import com.sun.star.awt.Point;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.beans.PropertyValue;

import java.util.Vector;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.Icon;
import javax.swing.JTextArea;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.BoxLayout;
import javax.swing.text.JTextComponent;


class AccessibleTextHandler extends NodeHandler
{
    public NodeHandler createHandler (XAccessibleContext xContext)
    {
        XAccessibleText xText = (XAccessibleText) UnoRuntime.queryInterface (
            XAccessibleText.class, xContext);
        if (xText != null)
            return new AccessibleTextHandler (xText);
        else
            return null;
    }

    public AccessibleTextHandler ()
    {
    }

    public AccessibleTextHandler (XAccessibleText xText)
    {
        if (xText != null)
            maChildList.setSize (13);
    }

    public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex)
    {
        AccessibleTreeNode aChild = null;
        XAccessibleText xText = null;
        if (aParent instanceof AccTreeNode)
            xText = ((AccTreeNode)aParent).getText();

        try
        {
            if( xText != null )
            {
                switch( nIndex )
                {
                    case 0:
                        aChild = new StringNode (xText.getText(), aParent);
                        break;
                    case 1:
                        aChild = new StringNode ("# chars: " + xText.getCharacterCount(), aParent);
                        break;
                    case 2:
                        aChild = new StringNode (characters( xText ), aParent);
                        break;
                    case 3:
                        aChild = new StringNode ("selection: "
                            + "[" + xText.getSelectionStart()
                            + "," + xText.getSelectionEnd()
                            + "] \"" + xText.getSelectedText() + "\"",
                            aParent);
                        break;
                    case 4:
                        aChild = new StringNode ("getCaretPosition: " + xText.getCaretPosition(), aParent);
                        break;
                    case 5:
                        aChild = textAtIndexNode( xText, "Character",
                            AccessibleTextType.CHARACTER,
                            aParent);
                        break;
                    case 6:
                        aChild = textAtIndexNode( xText, "Word",
                            AccessibleTextType.WORD,
                            aParent);
                        break;
                    case 7:
                        aChild = textAtIndexNode( xText, "Sentence",
                            AccessibleTextType.SENTENCE,
                            aParent);
                        break;
                    case 8:
                        aChild = textAtIndexNode( xText, "Paragraph",
                            AccessibleTextType.PARAGRAPH,
                            aParent);
                        break;
                    case 9:
                        aChild = textAtIndexNode( xText, "Line",
                            AccessibleTextType.LINE,
                            aParent);
                        break;
                    case 10:
                        aChild = textAtIndexNode( xText, "Attribute",
                            (short)6/*AccessibleTextType.ATTRIBUTE*/,
                            aParent);
                        break;
                    case 11:
                        aChild = new StringNode (bounds( xText ), aParent);
                        break;
                    case 12:
                        aChild = getAttributes( xText, aParent );
                        break;
                    default:
                        aChild = new StringNode ("unknown child index " + nIndex, aParent);
                }
            }
        }
        catch (Exception e)
        {
            // Return empty child.
        }

        return aChild;
    }


    private String textAtIndexNodeString(
        int nStart, int nEnd,
        String sWord, String sBefore, String sBehind)
    {
        return "[" + nStart + "," + nEnd + "] "
            + "\"" + sWord + "\"     \t"
            + "(" + sBefore + ","
            + "" + sBehind + ")";
    }

    /** Create a text node that lists all strings of a particular text type
     */
    private AccessibleTreeNode textAtIndexNode(
        XAccessibleText xText,<commit_msg>added support for AccessibleTextType::GLYPH and ATTRIBUTE_RUN<commit_after>
import drafts.com.sun.star.accessibility.XAccessibleContext;
import drafts.com.sun.star.accessibility.XAccessibleText;
import drafts.com.sun.star.accessibility.XAccessibleEditableText;
import drafts.com.sun.star.accessibility.AccessibleTextType;

import com.sun.star.awt.Rectangle;
import com.sun.star.awt.Point;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.beans.PropertyValue;

import java.util.Vector;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.Icon;
import javax.swing.JTextArea;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.BoxLayout;
import javax.swing.text.JTextComponent;


class AccessibleTextHandler extends NodeHandler
{
    public NodeHandler createHandler (XAccessibleContext xContext)
    {
        XAccessibleText xText = (XAccessibleText) UnoRuntime.queryInterface (
            XAccessibleText.class, xContext);
        if (xText != null)
            return new AccessibleTextHandler (xText);
        else
            return null;
    }

    public AccessibleTextHandler ()
    {
    }

    public AccessibleTextHandler (XAccessibleText xText)
    {
        if (xText != null)
            maChildList.setSize (8);
    }

    public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex)
    {
        AccessibleTreeNode aChild = null;
        XAccessibleText xText = null;
        if (aParent instanceof AccTreeNode)
            xText = ((AccTreeNode)aParent).getText();

        try
        {
            if( xText != null )
            {
                switch( nIndex )
                {
                    case 0:
                        aChild = new StringNode (xText.getText(), aParent);
                        break;
                    case 1:
                        aChild = new StringNode ("# chars: " + xText.getCharacterCount(), aParent);
                        break;
                    case 2:
                        aChild = new StringNode (characters( xText ), aParent);
                        break;
                    case 3:
                        aChild = new StringNode ("selection: "
                            + "[" + xText.getSelectionStart()
                            + "," + xText.getSelectionEnd()
                            + "] \"" + xText.getSelectedText() + "\"",
                            aParent);
                        break;
                    case 4:
                        aChild = new StringNode ("getCaretPosition: " + xText.getCaretPosition(), aParent);
                        break;
                    case 5:
                    {
                        VectorNode aVec = new VectorNode("portions", aParent);
                        aChild = aVec;
                        aVec.addChild(
                             textAtIndexNode( xText, "Character",
                                              AccessibleTextType.CHARACTER,
                                              aParent ) );
                        aVec.addChild(
                            textAtIndexNode( xText, "Word",
                                             AccessibleTextType.WORD,
                                             aParent ) );
                        aVec.addChild(
                            textAtIndexNode( xText, "Sentence",
                                             AccessibleTextType.SENTENCE,
                                             aParent ) );
                        aVec.addChild(
                            textAtIndexNode( xText, "Paragraph",
                                             AccessibleTextType.PARAGRAPH,
                                             aParent ) );
                        aVec.addChild(
                            textAtIndexNode( xText, "Line",
                                             AccessibleTextType.LINE,
                                             aParent ) );
                        aVec.addChild(
                            textAtIndexNode( xText, "Attribute",
                                             AccessibleTextType.ATTRIBUTE_RUN,
                                             aParent ) );
                        aVec.addChild(
                            textAtIndexNode( xText, "Glyph",
                                             AccessibleTextType.GLYPH,
                                             aParent ) );
                    }
                    break;
                    case 6:
                        aChild = new StringNode (bounds( xText ), aParent);
                        break;
                    case 7:
                        aChild = getAttributes( xText, aParent );
                        break;
                    default:
                        aChild = new StringNode ("unknown child index " + nIndex, aParent);
                }
            }
        }
        catch (Exception e)
        {
            // Return empty child.
        }

        return aChild;
    }


    private String textAtIndexNodeString(
        int nStart, int nEnd,
        String sWord, String sBefore, String sBehind)
    {
        return "[" + nStart + "," + nEnd + "] "
            + "\"" + sWord + "\"     \t"
            + "(" + sBefore + ","
            + "" + sBehind + ")";
    }

    /** Create a text node that lists all strings of a particular text type
     */
    private AccessibleTreeNode textAtIndexNode(
        XAccessibleText xText,
{'fraction_non_alphanumeric': 0.08130883012102197, 'fraction_numerical': 0.002510085163603765, 'mean_word_length': 1.2343280592829962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4735814', 'n_tokens_mistral': 2776, 'n_tokens_neox': 2624, 'n_words': 584}