bump product version to 7.2.5.1
[LibreOffice.git] / toolkit / test / accessibility / ov / ContextView.java
blob0dc97a67a716529e81338e0c93a0d8b119ec4270
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ov;
21 import java.awt.Color;
22 import java.awt.GridBagLayout;
23 import java.awt.GridBagConstraints;
25 import java.awt.event.ActionListener;
26 import java.awt.event.ActionEvent;
28 import javax.swing.JLabel;
29 import com.sun.star.accessibility.AccessibleEventId;
30 import com.sun.star.accessibility.AccessibleEventObject;
31 import com.sun.star.accessibility.XAccessibleContext;
33 import tools.NameProvider;
35 public class ContextView
36 extends ListeningObjectView
37 implements ActionListener
39 public static ObjectView Create (
40 ObjectViewContainer aContainer,
41 XAccessibleContext xContext)
43 System.out.println ("ContextView.CreateView");
44 if (xContext != null)
45 return new ContextView (aContainer);
46 else
47 return null;
50 private ContextView (ObjectViewContainer aContainer)
52 super (aContainer);
53 JLabel aNameLabel = new JLabel ("Name: ");
54 maName = new JLabel ("");
55 JLabel aDescriptionLabel = new JLabel ("Description: ");
56 maDescription = new JLabel ("");
57 JLabel maRoleLabel = new JLabel ("Role: ");
58 maRole = new JLabel ("");
60 // Make the background of name and description white and opaque so
61 // that leading and trailing spaces become visible.
62 maName.setOpaque (true);
63 maName.setBackground (Color.WHITE);
64 maDescription.setOpaque (true);
65 maDescription.setBackground (Color.WHITE);
66 maRole.setOpaque (true);
67 maRole.setBackground (Color.WHITE);
69 GridBagLayout aLayout = new GridBagLayout();
70 setLayout (aLayout);
71 GridBagConstraints constraints = new GridBagConstraints ();
72 constraints.gridx = 0;
73 constraints.gridy = 0;
74 constraints.gridwidth = 1;
75 constraints.gridheight = 1;
76 constraints.weightx = 0;
77 constraints.weighty = 1;
78 constraints.anchor = GridBagConstraints.WEST;
79 constraints.fill = GridBagConstraints.NONE;
80 add (aNameLabel, constraints);
81 constraints.gridy = 1;
82 add (aDescriptionLabel, constraints);
83 constraints.gridy = 2;
84 add (maRoleLabel, constraints);
85 constraints.gridy = 0;
86 constraints.gridx = 1;
87 constraints.weightx = 2;
88 add (maName, constraints);
89 constraints.gridy = 1;
90 add (maDescription, constraints);
91 constraints.gridy = 2;
92 add (maRole, constraints);
95 @Override
96 public void Update ()
98 if (mxContext == null)
100 maName.setText ("<null object>");
101 maDescription.setText ("<null object>");
102 maRole.setText ("<null object>");
104 else
106 maName.setText (mxContext.getAccessibleName());
107 maDescription.setText (mxContext.getAccessibleDescription());
108 maRole.setText (NameProvider.getRoleName (mxContext.getAccessibleRole()));
112 @Override
113 public String GetTitle ()
115 return "Context";
118 /** Listen for changes regarding displayed values.
120 @Override
121 public void notifyEvent (AccessibleEventObject aEvent)
123 switch (aEvent.EventId)
125 case AccessibleEventId.NAME_CHANGED :
126 case AccessibleEventId.DESCRIPTION_CHANGED :
127 Update ();
131 public void actionPerformed (ActionEvent aEvent)
136 private final JLabel
137 maName,
138 maDescription,
139 maRole;