summaryrefslogtreecommitdiffstats
path: root/toolkit/test/accessibility/ov/ContextView.java
blob: 0dc97a67a716529e81338e0c93a0d8b119ec4270 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

package ov;

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

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

import javax.swing.JLabel;
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
{
    public static ObjectView Create (
        ObjectViewContainer aContainer,
        XAccessibleContext xContext)
    {
        System.out.println ("ContextView.CreateView");
        if (xContext != null)
            return new ContextView (aContainer);
        else
            return null;
    }

    private ContextView (ObjectViewContainer aContainer)
    {
        super (aContainer);
        JLabel aNameLabel = new JLabel ("Name: ");
        maName = new JLabel ("");
        JLabel aDescriptionLabel = new JLabel ("Description: ");
        maDescription = new JLabel ("");
        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 (aNameLabel, constraints);
        constraints.gridy = 1;
        add (aDescriptionLabel, 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);
    }

    @Override
    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()));
        }
    }

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

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

    public void actionPerformed (ActionEvent aEvent)
    {
    }


    private final JLabel
        maName,
        maDescription,
        maRole;
}