summaryrefslogtreecommitdiff
path: root/toolkit/test/accessibility/ov/ContextView.java
blob: 4204c5de7bac0498c3681a2364d8205512231695 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package ov;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JLabel;
import javax.swing.JTextField;

import com.sun.star.accessibility.AccessibleEventId;
import com.sun.star.accessibility.AccessibleEventObject;
import com.sun.star.accessibility.XAccessibleContext;

import tools.NameProvider;

public class ContextView
    extends ListeningObjectView
    implements ActionListener
{
    static public ObjectView Create (
        ObjectViewContainer aContainer,
        XAccessibleContext xContext)
    {
        System.out.println ("ContextView.CreateView");
        if (xContext != null)
            return new ContextView (aContainer);
        else
            return null;
    }

    public ContextView (ObjectViewContainer aContainer)
    {
        super (aContainer);
        maNameLabel = new JLabel ("Name: ");
        maName = new JLabel ("");
        maDescriptionLabel = new JLabel ("Description: ");
        maDescription = new JLabel ("");
        maRoleLabel = new JLabel ("Role: ");
        maRole = new JLabel ("");

        // Make the background of name and description white and opaque so
        // that leading and trailing spaces become visible.
        maName.setOpaque (true);
        maName.setBackground (Color.WHITE);
        maDescription.setOpaque (true);
        maDescription.setBackground (Color.WHITE);
        maRole.setOpaque (true);
        maRole.setBackground (Color.WHITE);

        GridBagLayout aLayout = new GridBagLayout();
        setLayout (aLayout);
        GridBagConstraints constraints = new GridBagConstraints ();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.weightx = 0;
        constraints.weighty = 1;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.NONE;
        add (maNameLabel, constraints);
        constraints.gridy = 1;
        add (maDescriptionLabel, constraints);
        constraints.gridy = 2;
        add (maRoleLabel, constraints);
        constraints.gridy = 0;
        constraints.gridx = 1;
        constraints.weightx = 2;
        add (maName, constraints);
        constraints.gridy = 1;
        add (maDescription, constraints);
        constraints.gridy = 2;
        add (maRole, constraints);
    }

    public void Update ()
    {
        if (mxContext == null)
        {
            maName.setText ("<null object>");
            maDescription.setText ("<null object>");
            maRole.setText ("<null object>");
        }
        else
        {
            maName.setText (mxContext.getAccessibleName());
            maDescription.setText (mxContext.getAccessibleDescription());
            maRole.setText (NameProvider.getRoleName (mxContext.getAccessibleRole()));
        }
    }

    public String GetTitle ()
    {
        return ("Context");
    }

    /** Listen for changes regarding displayed values.
    */
    public void notifyEvent (AccessibleEventObject aEvent)
    {
        switch (aEvent.EventId)
        {
            case AccessibleEventId.NAME_CHANGED :
            case AccessibleEventId.DESCRIPTION_CHANGED :
                Update ();
        }
    }

    public void actionPerformed (ActionEvent aEvent)
    {
    }


    private JLabel
        maNameLabel,
        maName,
        maDescriptionLabel,
        maDescription,
        maRoleLabel,
        maRole;
}