diff options
Diffstat (limited to 'toolkit/test/accessibility/ov')
-rw-r--r-- | toolkit/test/accessibility/ov/ContextView.java | 140 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/FocusView.java | 141 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/ListeningObjectView.java | 80 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/ObjectView.java | 80 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/ObjectViewContainer.java | 152 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/TextView.java | 133 |
6 files changed, 726 insertions, 0 deletions
diff --git a/toolkit/test/accessibility/ov/ContextView.java b/toolkit/test/accessibility/ov/ContextView.java new file mode 100644 index 000000000..0dc97a67a --- /dev/null +++ b/toolkit/test/accessibility/ov/ContextView.java @@ -0,0 +1,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; +} diff --git a/toolkit/test/accessibility/ov/FocusView.java b/toolkit/test/accessibility/ov/FocusView.java new file mode 100644 index 000000000..cca1a6a0c --- /dev/null +++ b/toolkit/test/accessibility/ov/FocusView.java @@ -0,0 +1,141 @@ +/* + * 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.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +import javax.swing.JButton; +import javax.swing.JLabel; + +import com.sun.star.accessibility.AccessibleEventId; +import com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.AccessibleStateType; +import com.sun.star.accessibility.XAccessibleComponent; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleStateSet; +import com.sun.star.uno.UnoRuntime; + +public class FocusView + extends ListeningObjectView + implements ActionListener +{ + /** Create a FocusView when the given object supports the + XAccessibleComponent interface. + */ + public static ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + XAccessibleComponent xComponent = UnoRuntime.queryInterface( + XAccessibleComponent.class, xContext); + if (xComponent != null) + return new FocusView (aContainer); + else + return null; + } + + private FocusView (ObjectViewContainer aContainer) + { + super (aContainer); + + setLayout (new GridBagLayout()); + GridBagConstraints aConstraints = new GridBagConstraints (); + + maFocused = new JLabel (); + aConstraints.gridy = 0; + aConstraints.weightx = 1; + aConstraints.fill = GridBagConstraints.HORIZONTAL; + add (maFocused, aConstraints); + + maGrabFocus = new JButton ("grabFocus"); + aConstraints.gridy = 1; + aConstraints.fill = GridBagConstraints.NONE; + aConstraints.anchor = GridBagConstraints.WEST; + add (maGrabFocus, aConstraints); + + maGrabFocus.addActionListener (this); + } + + /** Additionally to the context store a reference to the + XAccessibleComponent interface. + */ + @Override + public void SetObject (XAccessibleContext xObject) + { + mxComponent = UnoRuntime.queryInterface( + XAccessibleComponent.class, xObject); + super.SetObject (xObject); + } + + @Override + synchronized public void Destroy () + { + super.Destroy(); + maGrabFocus.removeActionListener (this); + } + + @Override + synchronized public void Update () + { + if (mxContext == null) + { + maFocused.setText ("<null object>"); + maGrabFocus.setEnabled (false); + } + else + { + XAccessibleStateSet aStateSet = mxContext.getAccessibleStateSet(); + if (aStateSet.contains(AccessibleStateType.FOCUSED)) + maFocused.setText ("focused"); + else + maFocused.setText ("not focused"); + if (maGrabFocus != null) + maGrabFocus.setEnabled (true); + } + } + + @Override + public String GetTitle () + { + return "Focus"; + } + + synchronized public void actionPerformed (ActionEvent aEvent) + { + if (aEvent.getActionCommand().equals("grabFocus")) + { + mxComponent.grabFocus(); + } + } + + @Override + public void notifyEvent (AccessibleEventObject aEvent) + { + System.out.println (aEvent); + if (aEvent.EventId == AccessibleEventId.STATE_CHANGED) + Update (); + } + + private final JLabel maFocused; + private final JButton maGrabFocus; + private XAccessibleComponent mxComponent; +} diff --git a/toolkit/test/accessibility/ov/ListeningObjectView.java b/toolkit/test/accessibility/ov/ListeningObjectView.java new file mode 100644 index 000000000..63b5f8ff7 --- /dev/null +++ b/toolkit/test/accessibility/ov/ListeningObjectView.java @@ -0,0 +1,80 @@ +/* + * 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 com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleEventBroadcaster; +import com.sun.star.accessibility.XAccessibleEventListener; +import com.sun.star.lang.EventObject; +import com.sun.star.uno.UnoRuntime; + +/** Base class for object views that registers as accessibility event + listener. +*/ +abstract class ListeningObjectView + extends ObjectView + implements XAccessibleEventListener +{ + public ListeningObjectView (ObjectViewContainer aContainer) + { + super (aContainer); + } + + /** Add this object as event listener at the broadcasting + accessible object. + */ + @Override + public void SetObject (XAccessibleContext xContext) + { + super.SetObject (xContext); + XAccessibleEventBroadcaster xBroadcaster = + UnoRuntime.queryInterface( + XAccessibleEventBroadcaster.class, xContext); + if (xBroadcaster != null) + xBroadcaster.addAccessibleEventListener (this); + } + + + /** Remove this object as event listener from the broadcasting + accessible object. + */ + @Override + public void Destroy () + { + super.Destroy (); + XAccessibleEventBroadcaster xBroadcaster = + UnoRuntime.queryInterface( + XAccessibleEventBroadcaster.class, mxContext); + if (xBroadcaster != null) + xBroadcaster.removeAccessibleEventListener (this); + } + + /** Derived classes have to implement this method to handle incoming + events. + */ + abstract public void notifyEvent (AccessibleEventObject aEvent); + + /** The disposing event is ignored per default. If a derived class is + interested it can overwrite this method. + */ + public void disposing (EventObject aEvent) + { + } +} diff --git a/toolkit/test/accessibility/ov/ObjectView.java b/toolkit/test/accessibility/ov/ObjectView.java new file mode 100644 index 000000000..7e1570b62 --- /dev/null +++ b/toolkit/test/accessibility/ov/ObjectView.java @@ -0,0 +1,80 @@ +/* + * 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 javax.swing.JPanel; + +import com.sun.star.accessibility.XAccessibleContext; + +/** This is the base class for all object views that can be placed inside an + object view container. + + <p>When provided with a new accessible object the container will call + the Create method to create a new instance when certain conditions are + met. It then calls SetObject to pass the object to the instance. + Finally it calls Update.</p> + + <p>The SetObject and Update methods may be called for a new object + without calling Create first. In this way an existing instance is + recycled.</p> +*/ +abstract public class ObjectView + extends JPanel +{ + public ObjectView (ObjectViewContainer aContainer) + { + mxContext = null; + } + + /** Call this when you want the object to be destroyed. Release all + resources when called. + */ + public void Destroy () + { + } + + /** Tell the view to display information for a new accessible object. + @param xContext + The given object may be null. A typical behaviour in this case + would be to display a blank area. But is also possible to show + information about the last object. + */ + public void SetObject (XAccessibleContext xContext) + { + mxContext = xContext; + Update (); + } + + + /** This is a request of a repaint with the current state of the current + object. The current object may or may not be the same as the one + when Update() was called the last time. + */ + public void Update () + { + } + + + /** Return a string that is used as a title of an enclosing frame. + */ + abstract public String GetTitle (); + + /// Reference to the current object to display information about. + protected XAccessibleContext mxContext; +} diff --git a/toolkit/test/accessibility/ov/ObjectViewContainer.java b/toolkit/test/accessibility/ov/ObjectViewContainer.java new file mode 100644 index 000000000..c7e647d67 --- /dev/null +++ b/toolkit/test/accessibility/ov/ObjectViewContainer.java @@ -0,0 +1,152 @@ +/* + * 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.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.util.ArrayList; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.border.BevelBorder; +import javax.swing.border.Border; + +import com.sun.star.accessibility.XAccessibleContext; + + +public class ObjectViewContainer + extends JPanel +{ + private static interface IViewFactory { + ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext); + } + + public ObjectViewContainer () + { + maViewTemplates = new ArrayList<IViewFactory>(); + maViewBorder = BorderFactory.createBevelBorder (BevelBorder.RAISED); + setLayout (new GridBagLayout ()); + + maViewTemplates.add(new IViewFactory() { + public ObjectView Create(ObjectViewContainer aContainer, + XAccessibleContext xContext) { + return ContextView.Create(aContainer, xContext); + } + }); + maViewTemplates.add(new IViewFactory() { + public ObjectView Create(ObjectViewContainer aContainer, + XAccessibleContext xContext) { + return FocusView.Create(aContainer, xContext); + } + }); + maViewTemplates.add(new IViewFactory() { + public ObjectView Create(ObjectViewContainer aContainer, + XAccessibleContext xContext) { + return TextView.Create(aContainer, xContext); + } + }); + } + + /** Remove all existing views and create new ones according to the + interfaces supported by the given object. + */ + public void SetObject (XAccessibleContext xContext) + { + // Call Destroy at all views to give them a chance to release their + // resources. + int n = getComponentCount(); + for (int i=0; i<n; i++) + ((ObjectView)getComponent(i)).Destroy(); + // Remove existing views. + removeAll (); + + // Add new views. + for (int i=0; i<maViewTemplates.size(); i++) + { + IViewFactory aViewFactory = maViewTemplates.get(i); + ObjectView aView = aViewFactory.Create(this, xContext); + Add (aView); + } + + UpdateLayoutManager (); + + // Now set the object at all views. + n = getComponentCount(); + for (int i=0; i<n; i++) + ((ObjectView)getComponent(i)).SetObject (xContext); + + setPreferredSize (getLayout().preferredLayoutSize (this)); + } + + + /** Add an object view and place it below all previously added views. + @param aView + This argument may be null. In this case nothing happens. + */ + private void Add (ObjectView aView) + { + if (aView != null) + { + GridBagConstraints constraints = new GridBagConstraints (); + constraints.gridx = 0; + constraints.gridy = getComponentCount(); + constraints.gridwidth = 1; + constraints.gridheight = 1; + constraints.weightx = 1; + constraints.weighty = 0; + constraints.ipadx = 2; + constraints.ipady = 5; + constraints.insets = new Insets (5,5,5,5); + constraints.anchor = GridBagConstraints.NORTH; + constraints.fill = GridBagConstraints.HORIZONTAL; + + aView.setBorder ( + BorderFactory.createTitledBorder ( + maViewBorder, aView.GetTitle())); + + add (aView, constraints); + } + } + + /** Update the layout manager by setting the vertical weight of the + bottom entry to 1 and so make it stretch to over the available + space. + + */ + private void UpdateLayoutManager () + { + // Adapt the layout manager. + if (getComponentCount() > 0) + { + Component aComponent = getComponent (getComponentCount()-1); + GridBagLayout aLayout = (GridBagLayout)getLayout(); + GridBagConstraints aConstraints = aLayout.getConstraints (aComponent); + aConstraints.weighty = 1; + aLayout.setConstraints (aComponent, aConstraints); + } + } + + private final Border maViewBorder; + /// List of view templates which are instantiated when new object is set. + private final ArrayList<IViewFactory> maViewTemplates; +} diff --git a/toolkit/test/accessibility/ov/TextView.java b/toolkit/test/accessibility/ov/TextView.java new file mode 100644 index 000000000..518d5ff50 --- /dev/null +++ b/toolkit/test/accessibility/ov/TextView.java @@ -0,0 +1,133 @@ +/* + * 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.GridBagConstraints; +import java.awt.GridBagLayout; +import javax.swing.JLabel; + +import com.sun.star.accessibility.AccessibleEventId; +import com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.XAccessibleText; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.uno.UnoRuntime; + +public class TextView + extends ListeningObjectView +{ + /** Create a TextView when the given object supports the + XAccessibleText interface. + */ + public static ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + XAccessibleText xText = UnoRuntime.queryInterface( + XAccessibleText.class, xContext); + if (xText != null) + return new TextView (aContainer); + else + return null; + } + + + private TextView (ObjectViewContainer aContainer) + { + super (aContainer); + + setLayout (new GridBagLayout()); + GridBagConstraints aConstraints = new GridBagConstraints (); + + JLabel aLabel = new JLabel ("Text:"); + aConstraints.gridy = 0; + aConstraints.weightx = 1; + aConstraints.fill = GridBagConstraints.HORIZONTAL; + add (aLabel, aConstraints); + + maTextLabel = new JLabel (""); + aConstraints.gridx = 1; + aConstraints.fill = GridBagConstraints.NONE; + aConstraints.anchor = GridBagConstraints.WEST; + add (maTextLabel, aConstraints); + + aLabel = new JLabel ("Caret position:"); + aConstraints.gridx = 0; + aConstraints.gridy = 1; + aConstraints.weightx = 1; + aConstraints.fill = GridBagConstraints.HORIZONTAL; + add (aLabel, aConstraints); + + maCaretPositionLabel = new JLabel (""); + aConstraints.gridx = 1; + aConstraints.fill = GridBagConstraints.NONE; + aConstraints.anchor = GridBagConstraints.WEST; + add (maCaretPositionLabel, aConstraints); + } + + + /** Additionally to the context store a reference to the + XAccessibleText interface. + */ + @Override + public void SetObject (XAccessibleContext xObject) + { + mxText = UnoRuntime.queryInterface( + XAccessibleText.class, xObject); + super.SetObject (xObject); + } + + @Override + synchronized public void Update () + { + if (mxText == null) + { + maTextLabel.setText ("<null object>"); + maCaretPositionLabel.setText ("<null object>"); + } + else + { + maTextLabel.setText (mxText.getText()); + maCaretPositionLabel.setText (Integer.toString(mxText.getCaretPosition())); + } + } + + @Override + public String GetTitle () + { + return "Text"; + } + + @Override + public void notifyEvent (AccessibleEventObject aEvent) + { + System.out.println (aEvent); + switch (aEvent.EventId) + { + case AccessibleEventId.TEXT_CHANGED : + case AccessibleEventId.CARET_CHANGED : + Update (); + break; + } + } + + private final JLabel + maTextLabel, + maCaretPositionLabel; + private XAccessibleText mxText; +} |