diff options
Diffstat (limited to 'accessibility/workben/org/openoffice/accessibility/awb/view')
27 files changed, 3780 insertions, 0 deletions
diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/ComponentView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/ComponentView.java new file mode 100644 index 000000000000..d4c0e102b7a9 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/ComponentView.java @@ -0,0 +1,195 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.Color; +import java.awt.Dimension; + +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.XAccessible; +import com.sun.star.accessibility.XAccessibleComponent; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.uno.UnoRuntime; + +import org.openoffice.accessibility.misc.NameProvider; + +/** The <type>ContextView</type> class displays information accessible over + the <type>XAccessibleContext</type> interface. This includes name, + description, and role. +*/ +public class ComponentView + extends ObjectView +{ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + if (UnoRuntime.queryInterface( + XAccessibleComponent.class, xContext) != null) + return new ComponentView (aContainer); + else + return null; + } + + public ComponentView (ObjectViewContainer aContainer) + { + super (aContainer); + + ViewGridLayout aLayout = new ViewGridLayout (this); + + maRelativeLocationLabel = aLayout.AddLabeledEntry ("Relative Location: "); + maAbsoluteLocationLabel = aLayout.AddLabeledEntry ("Location on Screen: "); + maSizeLabel = aLayout.AddLabeledEntry ("Size"); + maBoundingBoxLabel = aLayout.AddLabeledEntry ("Bounding Box: "); + maConsistencyLabel = aLayout.AddLabeledEntry ("Consistent: "); + maForegroundColorLabel = aLayout.AddLabeledEntry ("Foreground Color: "); + maBackgroundColorLabel = aLayout.AddLabeledEntry ("Background Color: "); + } + + + public void SetObject (XAccessibleContext xContext) + { + mxComponent = (XAccessibleComponent)UnoRuntime.queryInterface( + XAccessibleComponent.class, xContext); + super.SetObject (xContext); + } + + public void Update () + { + if (mxContext == null) + { + maRelativeLocationLabel.setText ("<null object>"); + maAbsoluteLocationLabel.setText ("<null object>"); + maSizeLabel.setText ("<null object>"); + maBoundingBoxLabel.setText ("<null object>"); + maConsistencyLabel.setText ("<null object>"); + maForegroundColorLabel.setText ("<null object>"); + maBackgroundColorLabel.setText ("<null object>"); + } + else + { + com.sun.star.awt.Point aLocation = mxComponent.getLocation(); + maRelativeLocationLabel.setText ( + aLocation.X + ", " + aLocation.Y); + com.sun.star.awt.Point aLocationOnScreen = + mxComponent.getLocationOnScreen(); + maAbsoluteLocationLabel.setText ( + aLocationOnScreen.X + ", " + aLocationOnScreen.Y); + com.sun.star.awt.Size aSize = mxComponent.getSize(); + maSizeLabel.setText ( + aSize.Width + ", " + aSize.Height); + com.sun.star.awt.Rectangle aBBox = mxComponent.getBounds(); + maBoundingBoxLabel.setText ( + aBBox.X + ", " + aBBox.Y + "," + + aBBox.Width + ", " + aBBox.Height); + int nColor = mxComponent.getForeground(); + maForegroundColorLabel.setText ( + "R"+ (nColor>>16&0xff) + + "G" + (nColor>>8&0xff) + + "B" + (nColor>>0&0xff) + + "A" + (nColor>>24&0xff)); + nColor = mxComponent.getBackground(); + maBackgroundColorLabel.setText ( + "R"+ (nColor>>16&0xff) + + "G" + (nColor>>8&0xff) + + "B" + (nColor>>0&0xff) + + "A" + (nColor>>24&0xff)); + + // Check consistency of coordinates. + String sConsistency = new String (); + if (aBBox.X!=aLocation.X || aBBox.Y!=aLocation.Y) + sConsistency += (sConsistency.length()!=0?", ":"") + + "Bounding box conflicts with relative location"; + if (aBBox.Width!=aSize.Width || aBBox.Height!=aSize.Height) + sConsistency += (sConsistency.length()!=0?", ":"") + + "Bounding box conflicts with size"; + XAccessible xParent = mxContext.getAccessibleParent(); + XAccessibleComponent xParentComponent = + (XAccessibleComponent)UnoRuntime.queryInterface( + XAccessibleComponent.class, xParent); + if (xParentComponent == null) + { + if (aLocation.X != aLocationOnScreen.X + || aLocation.Y != aLocationOnScreen.Y) + sConsistency += (sConsistency.length()!=0?", ":"") + + "location on screen does not equal " + + "relative location without parent"; + } + else + { + com.sun.star.awt.Point aParentLocationOnScreen = + xParentComponent.getLocationOnScreen(); + if (aLocation.X+aParentLocationOnScreen.X + != aLocationOnScreen.X + || aLocation.Y+aParentLocationOnScreen.Y + != aLocationOnScreen.Y) + sConsistency += (sConsistency.length()!=0?", ":"") + + "location on screen does not match " + + "relative location"; + } + if (sConsistency.length() == 0) + sConsistency += "yes"; + else + maConsistencyLabel.setBackground (GetContainer().GetErrorColor()); + maConsistencyLabel.setText (sConsistency); + } + } + + public String GetTitle () + { + return ("Component"); + } + + /** Listen for changes regarding displayed values. + */ + public void notifyEvent (AccessibleEventObject aEvent) + { + switch (aEvent.EventId) + { + case AccessibleEventId.BOUNDRECT_CHANGED : + case AccessibleEventId.VISIBLE_DATA_CHANGED : + Update (); + } + } + + private XAccessibleComponent mxComponent; + private JLabel + maRelativeLocationLabel, + maAbsoluteLocationLabel, + maSizeLabel, + maBoundingBoxLabel, + maConsistencyLabel, + maForegroundColorLabel, + maBackgroundColorLabel; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/ContextView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/ContextView.java new file mode 100644 index 000000000000..a8588cd18ca6 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/ContextView.java @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.Color; +import java.awt.Dimension; + +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 org.openoffice.accessibility.misc.NameProvider; + +/** The <type>ContextView</type> class displays information accessible over + the <type>XAccessibleContext</type> interface. This includes name, + description, and role. +*/ +public class ContextView + extends ObjectView + implements ActionListener +{ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + if (xContext != null) + return new ContextView (aContainer); + else + return null; + } + + public ContextView (ObjectViewContainer aContainer) + { + super (aContainer); + + ViewGridLayout aLayout = new ViewGridLayout (this); + maNameLabel = aLayout.AddLabeledString ("Name:"); + maDescriptionLabel = aLayout.AddLabeledString ("Description:"); + maRoleLabel = aLayout.AddLabeledEntry ("Role:"); + } + + public void Update () + { + if (mxContext == null) + { + maNameLabel.setText ("<null object>"); + maDescriptionLabel.setText ("<null object>"); + maRoleLabel.setText ("<null object>"); + } + else + { + maNameLabel.setText (mxContext.getAccessibleName()); + maDescriptionLabel.setText (mxContext.getAccessibleDescription()); + maRoleLabel.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, + maDescriptionLabel, + maRoleLabel; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/EditableTextView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/EditableTextView.java new file mode 100644 index 000000000000..2e39f117f62e --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/EditableTextView.java @@ -0,0 +1,119 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JButton; + +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleEditableText; +import com.sun.star.uno.UnoRuntime; + +import org.openoffice.accessibility.awb.view.text.TextDialogFactory; + + +public class EditableTextView + extends ObjectView + implements ActionListener +{ + /** Create a EditableTextView when the given object supports the + XAccessibleEditableText interface. + */ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + XAccessibleEditableText xEditableText = + (XAccessibleEditableText)UnoRuntime.queryInterface( + XAccessibleEditableText.class, xContext); + if (xEditableText != null) + return new EditableTextView (aContainer); + else + return null; + } + + public EditableTextView (ObjectViewContainer aContainer) + { + super (aContainer); + + JButton aButton = new JButton ("cut..."); + aButton.setFont (ViewGridLayout.GetFont()); + aButton.addActionListener (this); + add (aButton); + aButton = new JButton ("paste..."); + aButton.setFont (ViewGridLayout.GetFont()); + aButton.addActionListener (this); + add (aButton); + aButton = new JButton ("edit..."); + aButton.setFont (ViewGridLayout.GetFont()); + aButton.addActionListener (this); + add (aButton); + aButton = new JButton ("format..."); + aButton.setFont (ViewGridLayout.GetFont()); + aButton.addActionListener (this); + add (aButton); + } + + + /** Additionally to the context store a reference to the + XAccessibleEditableText interface. + */ + public void SetObject (XAccessibleContext xObject) + { + mxEditableText = (XAccessibleEditableText)UnoRuntime.queryInterface( + XAccessibleEditableText.class, xObject); + super.SetObject (xObject); + } + + public String GetTitle () + { + return ("Editable Text"); + } + + synchronized public void Destroy () + { + mxEditableText = null; + super.Destroy(); + } + + public void actionPerformed (ActionEvent aEvent) + { + String sCommand = aEvent.getActionCommand(); + if (sCommand.equals ("cut...")) + TextDialogFactory.CreateCutDialog (mxContext); + else if (sCommand.equals ("past...")) + TextDialogFactory.CreatePasteDialog (mxContext); + else if (sCommand.equals ("edit...")) + TextDialogFactory.CreateEditDialog (mxContext); + else if (sCommand.equals ("format...")) + TextDialogFactory.CreateFormatDialog (mxContext); + } + + private XAccessibleEditableText mxEditableText; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/EventMonitorView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/EventMonitorView.java new file mode 100644 index 000000000000..67e8091e027f --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/EventMonitorView.java @@ -0,0 +1,126 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.BorderLayout; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import javax.swing.JScrollBar; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import com.sun.star.accessibility.AccessibleEventId; +import com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.XAccessibleContext; + +import org.openoffice.accessibility.misc.NameProvider; + + +/** A simple event monitor that shows all events sent to one accessible + object. +*/ +class EventMonitorView + extends ObjectView +{ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + if (xContext != null) + return new EventMonitorView (aContainer); + else + return null; + } + + public EventMonitorView (ObjectViewContainer aContainer) + { + super (aContainer); + mnLineNo = 0; + Layout(); + } + + public String GetTitle () + { + return "Event Monitor"; + } + + /** Create and arrange the widgets for this view. + */ + private void Layout () + { + setLayout (new GridBagLayout ()); + + maText = new JTextArea(); + maText.setBackground (new Color (255,250,240)); + maText.setFont (new Font ("Helvetica", Font.PLAIN, 9)); + + maScrollPane = new JScrollPane (maText, + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + maScrollPane.setPreferredSize (new Dimension (300,200)); + + GridBagConstraints aConstraints = new GridBagConstraints (); + aConstraints.weightx = 1; + aConstraints.fill = GridBagConstraints.HORIZONTAL; + add (maScrollPane, aConstraints); + } + + + public void Update () + { + } + + + private void UpdateVerticalScrollBar () + { + JScrollBar sb = maScrollPane.getVerticalScrollBar(); + if (sb != null) + { + int nScrollBarValue = sb.getMaximum() - sb.getVisibleAmount() - 1; + sb.setValue (nScrollBarValue); + } + } + + + public void notifyEvent (AccessibleEventObject aEvent) + { + maText.append ((mnLineNo++) + ". " + NameProvider.getEventName (aEvent.EventId) + " : " + + aEvent.OldValue.toString() + + " -> " + + aEvent.NewValue.toString() + "\n"); + UpdateVerticalScrollBar(); + } + + private JTextArea maText; + private int mnLineNo; + private JScrollPane maScrollPane; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/FocusView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/FocusView.java new file mode 100644 index 000000000000..4dec27958d71 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/FocusView.java @@ -0,0 +1,148 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.Font; +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 ObjectView + implements ActionListener +{ + /** Create a FocusView when the given object supports the + XAccessibleComponent interface. + */ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + XAccessibleComponent xComponent = (XAccessibleComponent)UnoRuntime.queryInterface( + XAccessibleComponent.class, xContext); + if (xComponent != null) + return new FocusView (aContainer); + else + return null; + } + + public FocusView (ObjectViewContainer aContainer) + { + super (aContainer); + + setLayout (new GridBagLayout()); + GridBagConstraints aConstraints = new GridBagConstraints (); + + maFocused = new JLabel (); + maFocused.setFont (GetContainer().GetViewFont()); + aConstraints.gridy = 0; + aConstraints.weightx = 1; + aConstraints.fill = GridBagConstraints.HORIZONTAL; + add (maFocused, aConstraints); + + maGrabFocus = new JButton ("grabFocus"); + maGrabFocus.setFont (GetContainer().GetViewFont()); + 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. + */ + public void SetObject (XAccessibleContext xObject) + { + mxComponent = (XAccessibleComponent)UnoRuntime.queryInterface( + XAccessibleComponent.class, xObject); + super.SetObject (xObject); + } + + synchronized public void Destroy () + { + super.Destroy(); + maGrabFocus.removeActionListener (this); + } + + 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); + } + } + + public String GetTitle () + { + return ("Focus"); + } + + synchronized public void actionPerformed (ActionEvent aEvent) + { + if (aEvent.getActionCommand().equals("grabFocus")) + { + mxComponent.grabFocus(); + } + } + + public void notifyEvent (AccessibleEventObject aEvent) + { + System.out.println (aEvent); + if (aEvent.EventId == AccessibleEventId.STATE_CHANGED) + Update (); + } + + private JLabel maFocused; + private JButton maGrabFocus; + private XAccessibleComponent mxComponent; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/LayoutManager.java b/accessibility/workben/org/openoffice/accessibility/awb/view/LayoutManager.java new file mode 100644 index 000000000000..728b3dc426d7 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/LayoutManager.java @@ -0,0 +1,160 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.Component; +import java.awt.Cursor; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Point; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseEvent; +import javax.swing.JComponent; + +class LayoutManager + implements MouseListener, + MouseMotionListener +{ + public LayoutManager (JComponent aLayoutedComponent) + { + maLayoutedComponent = aLayoutedComponent; + maDraggedView = null; + mbInsertionPending = false; + } + + public void mouseClicked (MouseEvent aEvent) + { + System.out.println (aEvent); + } + public void mousePressed (MouseEvent aEvent) + { + mnOldY = aEvent.getPoint().y; + } + public void mouseReleased (MouseEvent aEvent) + { + if (mbInsertionPending) + { + InsertView (maDraggedView, aEvent.getPoint().y); + mbInsertionPending = false; + maDraggedView = null; + } + } + public void mouseEntered (MouseEvent aEvent) + { + } + public void mouseExited (MouseEvent aEvent) + { + if (mbInsertionPending) + { + InsertView (maDraggedView, mnOldY); + mbInsertionPending = false; + maDraggedView = null; + } + } + public void mouseDragged (MouseEvent aEvent) + { + int dy = mnOldY - aEvent.getPoint().y; + GridBagLayout aLayout = (GridBagLayout)maLayoutedComponent.getLayout(); + if ( ! mbInsertionPending && dy != 0) + { + maDraggedView = RemoveView (mnOldY); + if (maDraggedView != null) + mbInsertionPending = true; + } + } + public void mouseMoved (MouseEvent aEvent) + { + } + + + + + private ObjectView RemoveView (int y) + { + ObjectView aView = null; + GridBagLayout aLayout = (GridBagLayout)maLayoutedComponent.getLayout(); + + Point aGridLocation = aLayout.location (10,y); + Component[] aComponentList = maLayoutedComponent.getComponents(); + System.out.println ("removing view at " + aGridLocation); + for (int i=0; i<aComponentList.length && aView==null; i++) + { + GridBagConstraints aConstraints = aLayout.getConstraints ( + aComponentList[i]); + if (aConstraints.gridy == aGridLocation.y) + aView = (ObjectView)aComponentList[i]; + } + maNormalCursor = maLayoutedComponent.getCursor(); + if (aView != null) + { + System.out.println ("removing view at " + aGridLocation.y); + maLayoutedComponent.setCursor (new Cursor (Cursor.MOVE_CURSOR)); + maLayoutedComponent.remove (aView); + maLayoutedComponent.validate(); + maLayoutedComponent.repaint(); + } + + return aView; + } + + private void InsertView (ObjectView aView, int y) + { + if (aView != null) + { + GridBagLayout aLayout = (GridBagLayout)maLayoutedComponent.getLayout(); + Point aGridLocation = aLayout.location (0,y); + Component[] aComponentList = maLayoutedComponent.getComponents(); + System.out.println ("new position is " + aGridLocation.y); + for (int i=0; i<aComponentList.length; i++) + { + GridBagConstraints aConstraints = aLayout.getConstraints ( + aComponentList[i]); + if (aConstraints.gridy >= aGridLocation.y) + { + if (aConstraints.gridy == aGridLocation.y) + maLayoutedComponent.add (maDraggedView, aConstraints); + aConstraints.gridy += 1; + aLayout.setConstraints (aComponentList[i], aConstraints); + } + } + maLayoutedComponent.validate(); + maLayoutedComponent.repaint(); + } + maLayoutedComponent.setCursor (maNormalCursor); + } + + + + + private JComponent maLayoutedComponent; + private ObjectView maDraggedView; + private int mnOldY; + private boolean mbInsertionPending; + private Cursor maNormalCursor; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/Makefile b/accessibility/workben/org/openoffice/accessibility/awb/view/Makefile new file mode 100644 index 000000000000..2e4eb1566afd --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/Makefile @@ -0,0 +1,13 @@ +# $Id: Makefile,v 1.1 2003/06/13 16:30:34 af Exp $ + +all : package + +ROOT=../../../../.. +PACKAGE = org.openoffice.accessibility.awb.view +SUBDIRS = text +include makefile.common + +include $(ROOT)/makefile.in + + +package : $(CLASS_FILES) diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/ObjectView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/ObjectView.java new file mode 100644 index 000000000000..3c1b8e90ff26 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/ObjectView.java @@ -0,0 +1,90 @@ +package org.openoffice.accessibility.awb.view; + +import javax.swing.JPanel; + +import com.sun.star.accessibility.AccessibleEventObject; +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 +{ + /** This factory method creates a new instance of the (derived) class + when the given accessible object supports all necessary features. + In the ususal case this will be the support of a specific + accessibility interface. + */ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + return null; + } + + public ObjectView (ObjectViewContainer aContainer) + { + maContainer = 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 xObject + 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 (); + + + public ObjectViewContainer GetContainer () + { + return maContainer; + } + + + /** Implement this method if you are interested in accessible events. + */ + public void notifyEvent (AccessibleEventObject aEvent) + {} + + /// Reference to the current object to display information about. + protected XAccessibleContext mxContext; + + protected ObjectViewContainer maContainer; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/ObjectViewContainer.java b/accessibility/workben/org/openoffice/accessibility/awb/view/ObjectViewContainer.java new file mode 100644 index 000000000000..54855cbaf885 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/ObjectViewContainer.java @@ -0,0 +1,310 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Insets; + +import java.util.Vector; + +import java.lang.reflect.Method; +import java.lang.NoSuchMethodException; +import java.lang.IllegalAccessException; +import java.lang.reflect.InvocationTargetException; + +import javax.swing.JPanel; +import javax.swing.JTree; +import javax.swing.BorderFactory; +import javax.swing.border.Border; +import javax.swing.border.BevelBorder; +import javax.swing.SwingUtilities; + +import com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleComponent; +import com.sun.star.accessibility.XAccessibleEventBroadcaster; +import com.sun.star.accessibility.XAccessibleEventListener; +import com.sun.star.accessibility.XAccessibleSelection; +import com.sun.star.lang.EventObject; +import com.sun.star.uno.UnoRuntime; + +import org.openoffice.accessibility.awb.view.ObjectView; + + + +/** This container of specialized object views displays information about + one accessible object. + In this it plays several roles: + 1. Object container. + 2. Accessibility event dispatcher. + 3. Object view class registration manager. + 4. Swing widget. +*/ +public class ObjectViewContainer + extends JPanel + implements XAccessibleEventListener +{ + public ObjectViewContainer () + { + maFont = new Font ("Dialog", Font.PLAIN, 11); + maViewTemplates = new Vector (); + maViewBorder = BorderFactory.createBevelBorder (BevelBorder.RAISED); + GridBagLayout aLayout = new GridBagLayout (); + setLayout (aLayout); + // maLayoutManager = new LayoutManager (this); + maLayoutManager = null; + + RegisterView (ContextView.class); + RegisterView (ComponentView.class); + RegisterView (ParentView.class); + RegisterView (StateSetView.class); + RegisterView (FocusView.class); + RegisterView (TextView.class); + RegisterView (EditableTextView.class); + RegisterView (TableView.class); + RegisterView (SelectionView.class); + RegisterView (ServiceInterfaceView.class); + RegisterView (EventMonitorView.class); + + mxContext = null; + + // addMouseListener (maLayoutManager); + // addMouseMotionListener (maLayoutManager); + } + + + + /** Remove all existing views and create new ones according to the + interfaces supported by the given object. + */ + public synchronized 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 (); + + mxContext = xContext; + + // Add new views. + for (int i=0; i<maViewTemplates.size(); i++) + { + try + { + Class aViewClass = (Class)maViewTemplates.elementAt (i); + Method aCreateMethod = aViewClass.getDeclaredMethod ( + "Create", new Class[] { + ObjectViewContainer.class, + XAccessibleContext.class}); + if (aCreateMethod != null) + { + ObjectView aView = (ObjectView) + aCreateMethod.invoke ( + null, new Object[] {this, xContext}); + Add (aView); + } + } + catch (NoSuchMethodException e) + {System.err.println ("Caught exception while creating view " + + i + " : " + e);} + catch (IllegalAccessException e) + {System.err.println ("Caught exception while creating view " + + i + " : " + e);} + catch (InvocationTargetException e) + {System.err.println ("Caught exception while creating view " + + i + " : " + e);} + } + + 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)); + ((GridBagLayout) getLayout()).invalidateLayout(this); + validate(); + } + + + + + /** Add the given class to the list of classes which will be + instantiated the next time an accessible object is set. + */ + public void RegisterView (Class aObjectViewClass) + { + maViewTemplates.addElement (aObjectViewClass); + } + + + + + /** Replace one view class with another. + */ + public void ReplaceView (Class aObjectViewClass, Class aSubstitution) + { + int nIndex = maViewTemplates.indexOf (aObjectViewClass); + if (nIndex >= 0) + maViewTemplates.setElementAt (aSubstitution, nIndex); + } + + + /** Return a font that should be used for widgets in the views. + */ + public Font GetViewFont () + { + return maFont; + } + + public Color GetErrorColor () + { + return new Color (255,80,50); + } + + /** 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 strech to over the available + space. + + */ + private void UpdateLayoutManager () + { + // Adapt the layout manager. + if (getComponentCount() > 1000) + { + Component aComponent = getComponent (getComponentCount()-1); + GridBagLayout aLayout = (GridBagLayout)getLayout(); + GridBagConstraints aConstraints = aLayout.getConstraints (aComponent); + aConstraints.weighty = 1; + aLayout.setConstraints (aComponent, aConstraints); + } + } + + + + + /** Put the event just received into the event queue which will deliver + it soon asynchronuously to the DispatchEvent method. + */ + public void notifyEvent (final AccessibleEventObject aEvent) + { + SwingUtilities.invokeLater( + new Runnable() + { + public void run() + { + DispatchEvent (aEvent); + } + } + ); + } + + + + + /** Forward accessibility events to all views without them being + registered as event listeners each on their own. + */ + private void DispatchEvent (AccessibleEventObject aEvent) + { + int n = getComponentCount(); + for (int i=0; i<n; i++) + ((ObjectView)getComponent(i)).notifyEvent (aEvent); + } + + + + /** When the object is disposed that is displayed by the views of this + container then tell all views about this. + */ + public void disposing (EventObject aEvent) + { + mxContext = null; + SwingUtilities.invokeLater( + new Runnable() + { + public void run() + { + SetObject (null); + } + } + ); + } + + + + + /// The current accessible context display by the views. + private XAccessibleContext mxContext; + + /// Observe this tree for selection changes and notify them to all + /// children. + private JTree maTree; + private Border maViewBorder; + /// List of view templates which are instantiated when new object is set. + private Vector maViewTemplates; + private Font maFont; + private LayoutManager maLayoutManager; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/ObjectViewContainerWindow.java b/accessibility/workben/org/openoffice/accessibility/awb/view/ObjectViewContainerWindow.java new file mode 100644 index 000000000000..8db9af4f46ca --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/ObjectViewContainerWindow.java @@ -0,0 +1,35 @@ +package org.openoffice.accessibility.awb.view; + +import java.awt.BorderLayout; +import javax.swing.JFrame; +import com.sun.star.accessibility.XAccessibleContext; + + +/** Top level window that creates a single object view container. This + container shows information about a specific accessible object and is + not affected by the selection of the accessbility tree widget. +*/ +public class ObjectViewContainerWindow + extends JFrame +{ + public ObjectViewContainerWindow (XAccessibleContext xContext) + { + setSize (new java.awt.Dimension (300,600)); + + maContainer = new ObjectViewContainer (); + maContainer.SetObject (xContext); + getContentPane().add (maContainer, BorderLayout.CENTER); + + pack (); + setVisible (true); + } + + /** Set the object that is displayed in this window. + */ + public void SetObject (XAccessibleContext xContext) + { + maContainer.SetObject (xContext); + } + + private ObjectViewContainer maContainer; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/ParentView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/ParentView.java new file mode 100644 index 000000000000..216bc3a82bfc --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/ParentView.java @@ -0,0 +1,147 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.lang.Integer; +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.XAccessible; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.lang.IndexOutOfBoundsException; + +import org.openoffice.accessibility.misc.NameProvider; + + +/** Show informations related to the parent/child relationship. +*/ +public class ParentView + extends ObjectView +{ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + if (xContext != null) + return new ParentView (aContainer); + else + return null; + } + + public ParentView (ObjectViewContainer aContainer) + { + super (aContainer); + + ViewGridLayout aLayout = new ViewGridLayout (this); + maParentLabel = aLayout.AddLabeledEntry ("Has parent: "); + maIndexLabel = aLayout.AddLabeledEntry ("Index in parent: "); + maValidLabel = aLayout.AddLabeledEntry ("Parent/Child relationship valid: "); + maChildrenLabel = aLayout.AddLabeledEntry ("Child count: "); + } + + public void Update () + { + if (mxContext == null) + { + maParentLabel.setText ("<null object>"); + maIndexLabel.setText ("<null object>"); + maValidLabel.setText ("<null object>"); + maChildrenLabel.setText ("<null object>"); + } + else + { + XAccessible xParent = mxContext.getAccessibleParent(); + int nIndex = mxContext.getAccessibleIndexInParent(); + maIndexLabel.setText (Integer.toString(nIndex)); + if (xParent != null) + { + maParentLabel.setText ("yes"); + XAccessibleContext xParentContext = + xParent.getAccessibleContext(); + if (xParentContext != null) + { + try + { + XAccessible xChild = + xParentContext.getAccessibleChild(nIndex); + if (xChild != mxContext) + maValidLabel.setText ("yes"); + else + { + maValidLabel.setText ("no"); + maValidLabel.setBackground (GetContainer().GetErrorColor()); + } + } + catch (IndexOutOfBoundsException e) + { + maValidLabel.setText ("no: invalid index in parent"); + maValidLabel.setBackground (GetContainer().GetErrorColor()); + } + } + else + { + maValidLabel.setText ("no: parent has no context"); + maValidLabel.setBackground (GetContainer().GetErrorColor()); + } + } + else + maParentLabel.setText ("no"); + maChildrenLabel.setText (Integer.toString(mxContext.getAccessibleChildCount())); + } + } + + public String GetTitle () + { + return ("Parent"); + } + + + /** Listen for changes regarding displayed values. + */ + public void notifyEvent (AccessibleEventObject aEvent) + { + switch (aEvent.EventId) + { + default: + Update (); + } + } + + + private JLabel + maParentLabel, + maIndexLabel, + maValidLabel, + maChildrenLabel; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/SelectionView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/SelectionView.java new file mode 100644 index 000000000000..ad5a83467372 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/SelectionView.java @@ -0,0 +1,267 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.util.Vector; + +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; + +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JOptionPane; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JToggleButton; +import javax.swing.ListSelectionModel; + + +import com.sun.star.accessibility.AccessibleEventId; +import com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.AccessibleRole; +import com.sun.star.accessibility.AccessibleStateType; +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleSelection; +import com.sun.star.accessibility.XAccessibleStateSet; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.IndexOutOfBoundsException; + + +/** Display a list of children and select/deselect buttons +*/ +class SelectionView + extends ObjectView + implements ActionListener +{ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + XAccessibleSelection xSelection = (XAccessibleSelection)UnoRuntime.queryInterface( + XAccessibleSelection.class, xContext); + if (xSelection != null) + return new SelectionView(aContainer); + else + return null; + } + + public SelectionView (ObjectViewContainer aContainer) + { + super (aContainer); + Layout(); + } + + public String GetTitle () + { + return "Selection"; + } + + /** Create and arrange the widgets for this view. + */ + private void Layout () + { + setLayout (new GridBagLayout()); + + GridBagConstraints aConstraints = new GridBagConstraints(); + + // Label that shows whether the selection is multi selectable. + aConstraints.gridx = 0; + aConstraints.gridy = 0; + aConstraints.anchor = GridBagConstraints.WEST; + maTypeLabel = new JLabel (); + maTypeLabel.setFont (maContainer.GetViewFont()); + add (maTypeLabel, aConstraints); + + // the JListBox + maChildrenSelector = new JPanel (); + maChildrenSelector.setPreferredSize (new Dimension (100,100)); + maChildrenSelector.setLayout ( + new BoxLayout (maChildrenSelector, BoxLayout.Y_AXIS)); + + aConstraints.gridx = 0; + aConstraints.gridwidth = 4; + aConstraints.gridy = 1; + aConstraints.fill = GridBagConstraints.HORIZONTAL; + add (new JScrollPane (maChildrenSelector, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), + aConstraints); + + JButton aButton; + aButton = new JButton( "Select all" ); + aButton.setFont (maContainer.GetViewFont()); + aButton.setActionCommand( "Select all" ); + aButton.addActionListener( this ); + aConstraints.gridx = 0; + aConstraints.gridwidth = 1; + aConstraints.gridy = 2; + aConstraints.fill = GridBagConstraints.NONE; + aConstraints.anchor = GridBagConstraints.WEST; + add (aButton, aConstraints); + + aButton = new JButton( "Clear Selection" ); + aButton.setFont (maContainer.GetViewFont()); + aButton.setActionCommand( "Clear Selection" ); + aButton.addActionListener( this ); + aConstraints.gridx = 1; + aConstraints.gridy = 2; + aConstraints.weightx = 1; + add (aButton, aConstraints); + + setSize (getPreferredSize()); + } + + + public void SetObject (XAccessibleContext xContext) + { + mxSelection = (XAccessibleSelection)UnoRuntime.queryInterface( + XAccessibleSelection.class, xContext); + super.SetObject (xContext); + } + + + public void Update () + { + maChildrenSelector.removeAll (); + + // Determine whether multi selection is possible. + XAccessibleStateSet aStateSet = mxContext.getAccessibleStateSet(); + boolean bMultiSelectable = false; + if (aStateSet!=null && aStateSet.contains( + AccessibleStateType.MULTI_SELECTABLE)) + { + bMultiSelectable = true; + maTypeLabel.setText ("multi selectable"); + } + else + { + maTypeLabel.setText ("single selectable"); + } + + if (mxContext.getAccessibleRole() != AccessibleRole.TABLE) + { + int nCount = mxContext.getAccessibleChildCount(); + for (int i=0; i<nCount; i++) + { + try + { + XAccessible xChild = mxContext.getAccessibleChild(i); + XAccessibleContext xChildContext = xChild.getAccessibleContext(); + + String sName = i + " " + xChildContext.getAccessibleName(); + JToggleButton aChild; + aChild = new JCheckBox (sName); + aChild.setFont (maContainer.GetViewFont()); + + XAccessibleStateSet aChildStateSet = + mxContext.getAccessibleStateSet(); + aChild.setSelected (aChildStateSet!=null + && aChildStateSet.contains(AccessibleStateType.SELECTED)); + + aChild.addActionListener (this); + maChildrenSelector.add (aChild); + + } + catch (IndexOutOfBoundsException e) + { + } + } + } + } + + + void SelectAll() + { + mxSelection.selectAllAccessibleChildren(); + } + + void ClearSelection() + { + mxSelection.clearAccessibleSelection(); + } + + + + /** Call the function associated with the pressed button. + */ + public void actionPerformed (ActionEvent aEvent) + { + String sCommand = aEvent.getActionCommand(); + + if (sCommand.equals ("Clear Selection")) + ClearSelection(); + else if (sCommand.equals ("Select all")) + SelectAll(); + else + { + // Extract the child index from the widget text. + String[] aWords = sCommand.split (" "); + int nIndex = Integer.parseInt(aWords[0]); + try + { + if (((JToggleButton)aEvent.getSource()).isSelected()) + mxSelection.selectAccessibleChild (nIndex); + else + mxSelection.deselectAccessibleChild (nIndex); + } + catch (IndexOutOfBoundsException e) + { + System.err.println ( + "caught exception while changing selection: " + e); + } + } + } + + + public void notifyEvent (AccessibleEventObject aEvent) + { + switch (aEvent.EventId) + { + case AccessibleEventId.SELECTION_CHANGED: + case AccessibleEventId.STATE_CHANGED: + case AccessibleEventId.CHILD: + Update (); + } + } + + private JPanel maChildrenSelector; + private XAccessibleSelection mxSelection; + private JLabel maTypeLabel; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/ServiceInterfaceView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/ServiceInterfaceView.java new file mode 100644 index 000000000000..7c41ff01c97e --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/ServiceInterfaceView.java @@ -0,0 +1,150 @@ +package org.openoffice.accessibility.awb.view; + +import java.awt.GridLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.lang.Integer; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; + +import com.sun.star.accessibility.AccessibleEventId; +import com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; + +import org.openoffice.accessibility.misc.NameProvider; + + +/** Show all supported services and interfaces. +*/ +public class ServiceInterfaceView + extends ObjectView +{ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + if (xContext != null) + return new ServiceInterfaceView (aContainer); + else + return null; + } + + + + + public ServiceInterfaceView (ObjectViewContainer aContainer) + { + super (aContainer); + + maImplementationNameRoot = new DefaultMutableTreeNode ("Implementation Name"); + maServiceRoot = new DefaultMutableTreeNode ("Supported Services"); + maInterfaceRoot = new DefaultMutableTreeNode ("Supported Interfaces"); + maTree = new JTree (new DefaultMutableTreeNode[] + {maServiceRoot,maInterfaceRoot}); + JScrollPane aScrollPane = new JScrollPane ( + maTree, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + + setMinimumSize (new Dimension(300,200)); + setLayout (new GridLayout (1,1)); + add (aScrollPane); + } + + + + + public void Update () + { + DefaultTreeModel aModel = (DefaultTreeModel)maTree.getModel(); + + // Clear old tree. + DefaultMutableTreeNode aRoot =(DefaultMutableTreeNode)aModel.getRoot(); + aRoot.removeAllChildren(); + + // Create the new tree. + CreateImplementationNameTree (); + CreateServiceTree (); + CreateInterfaceTree (); + aRoot.add (maImplementationNameRoot); + aRoot.add (maServiceRoot); + aRoot.add (maInterfaceRoot); + aModel.setRoot (aRoot); + + // Expand whole tree. + for (int i=0; i<maTree.getRowCount(); i++) + maTree.expandRow (i); + } + + private void CreateImplementationNameTree () + { + XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface( + XServiceInfo.class, mxContext); + maImplementationNameRoot.removeAllChildren(); + if (xServiceInfo != null) + { + maImplementationNameRoot.add ( + new DefaultMutableTreeNode ( + (xServiceInfo!=null + ? xServiceInfo.getImplementationName() + : "<XServiceInfo not supported>"))); + } + } + + private void CreateServiceTree () + { + XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface( + XServiceInfo.class, mxContext); + maServiceRoot.removeAllChildren(); + if (xServiceInfo != null) + { + String[] aServiceNames = xServiceInfo.getSupportedServiceNames(); + int nCount = aServiceNames.length; + for (int i=0; i<nCount; i++) + maServiceRoot.add ( + new DefaultMutableTreeNode (aServiceNames[i])); + } + else + maServiceRoot.add ( + new DefaultMutableTreeNode("XServiceInfo not supported")); + } + + private void CreateInterfaceTree () + { + XTypeProvider xTypeProvider = (XTypeProvider)UnoRuntime.queryInterface( + XTypeProvider.class, mxContext); + maInterfaceRoot.removeAllChildren(); + if (xTypeProvider != null) + { + Type[] aTypes = xTypeProvider.getTypes(); + int nCount = aTypes.length; + for (int i=0; i<nCount; i++) + maInterfaceRoot.add ( + new DefaultMutableTreeNode (aTypes[i].getTypeName())); + } + else + maInterfaceRoot.add ( + new DefaultMutableTreeNode("XTypeProvider not supported")); + } + + public String GetTitle () + { + return ("Supported Services and Interfaces"); + } + + + private JTree maTree; + private DefaultMutableTreeNode maImplementationNameRoot; + private DefaultMutableTreeNode maServiceRoot; + private DefaultMutableTreeNode maInterfaceRoot; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/StateSetView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/StateSetView.java new file mode 100644 index 000000000000..44638b099edc --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/StateSetView.java @@ -0,0 +1,199 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; + + + +import com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.AccessibleEventId; +import com.sun.star.accessibility.AccessibleStateType; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleStateSet; + +import org.openoffice.accessibility.misc.NameProvider; + +public class StateSetView + extends ObjectView +{ + /** Create a FocusView when the given object supports the + XAccessibleComponent interface. + */ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + ObjectView aView = null; + if (xContext != null) + aView = new StateSetView (aContainer); + + return aView; + } + + public StateSetView (ObjectViewContainer aContainer) + { + super (aContainer); + setPreferredSize (new Dimension(300,110)); + setMinimumSize (new Dimension(200,80)); + } + + public String GetTitle () + { + return ("StateSet"); + } + + public void notifyEvent (AccessibleEventObject aEvent) + { + if (aEvent.EventId == AccessibleEventId.STATE_CHANGED) + Update(); + } + + + public void Update () + { + repaint (); + } + + public void paintChildren (Graphics g) + { + if (g != null) + synchronized (g) + { + super.paintChildren (g); + + // Calculcate the are inside the border. + Insets aInsets = getInsets (); + Dimension aSize = getSize(); + Rectangle aWidgetArea = new Rectangle ( + aInsets.left, + aInsets.top, + aSize.width-aInsets.left-aInsets.right, + aSize.height-aInsets.top-aInsets.bottom); + + PaintAllStates ((Graphics2D)g, aWidgetArea); + } + } + + private void PaintAllStates (Graphics2D g, Rectangle aWidgetArea) + { + Color aTextColor = g.getColor(); + + g.setRenderingHint ( + RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + XAccessibleStateSet xStateSet = ( mxContext != null ) ? mxContext.getAccessibleStateSet() : null; + if (xStateSet != null) + { + short aStates[] = xStateSet.getStates (); + final int nMaxStateIndex = AccessibleStateType.VISIBLE;//MANAGES_DESCENDANTS; + int nStateWidth = (aWidgetArea.width-12) / (nMaxStateIndex+1); + AffineTransform aTransform = g.getTransform (); + g.setColor (aTextColor); + int y = aWidgetArea.y+aWidgetArea.height - 25; + double nTextRotation = -0.9;//-java.lang.Math.PI/2; + double nScale = 0.6; + + // Create a shape for the boxes. + int nBoxWidth = 8; + Rectangle aCheckBox = new Rectangle (-nBoxWidth/2,0,nBoxWidth,nBoxWidth); + + // For each state draw a box, fill it appropriately, and draw + // thre states name. + for (short i=0; i<=nMaxStateIndex; i++) + { + int x = nStateWidth + i * nStateWidth; + String sStateName = NameProvider.getStateName (i); + if (sStateName == null) + sStateName = new String ("<unknown state " + i + ">"); + boolean bStateSet = xStateSet.contains (i); + g.setTransform (aTransform); + g.translate (x,y); + if (bStateSet) + { + switch (i) + { + case AccessibleStateType.INVALID: + case AccessibleStateType.DEFUNC: + g.setColor (saInvalidColor); + break; + case AccessibleStateType.FOCUSED: + g.setColor (saFocusColor); + break; + case AccessibleStateType.SELECTED: + g.setColor (saSelectionColor); + break; + case AccessibleStateType.EDITABLE: + g.setColor (saEditColor); + break; + default: + g.setColor (saDefaultColor); + break; + } + g.fill (aCheckBox); + g.setColor (aTextColor); + } + g.draw (aCheckBox); + g.rotate (nTextRotation); + g.scale (nScale, nScale); + g.translate (2,-2); + g.drawString (sStateName, 0,0); + } + + // Draw string of set states. + String sStates = new String (); + for (int i=0; i<aStates.length; i++) + { + if (i > 0) + sStates = sStates + ", "; + sStates = sStates + NameProvider.getStateName(aStates[i]); + } + g.setTransform (aTransform); + g.translate (10,aWidgetArea.y+aWidgetArea.height-3); + g.scale (0.9,0.9); + g.drawString (sStates,0,0); + } + } + + static private Color + saInvalidColor = new Color (255,0,255), + saFocusColor = new Color (100,100,255), + saSelectionColor = Color.GREEN, + saDefaultColor = new Color (90,90,90), + saEditColor = new Color (240,240,0); +} + + diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/TableView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/TableView.java new file mode 100644 index 000000000000..07b5d2bb9b78 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/TableView.java @@ -0,0 +1,161 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.lang.Integer; +import java.lang.StringBuffer; + +import javax.swing.JLabel; + +import com.sun.star.accessibility.AccessibleEventId; +import com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleTable; +import com.sun.star.uno.UnoRuntime; + + + +/** The <type>ContextView</type> class displays information accessible over + the <type>XAccessibleContext</type> interface. This includes name, + description, and role. +*/ +public class TableView + extends ObjectView +{ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + if (UnoRuntime.queryInterface( + XAccessibleTable.class, xContext) != null) + return new TableView (aContainer); + else + return null; + } + + public TableView (ObjectViewContainer aContainer) + { + super (aContainer); + + ViewGridLayout aLayout = new ViewGridLayout (this); + + maRowCountLabel = aLayout.AddLabeledEntry ("Row Count: "); + maColumnCountLabel = aLayout.AddLabeledEntry ("Column Count: "); + maCellCountLabel = aLayout.AddLabeledEntry ("Cell Count: "); + maSelectedRowsLabel = aLayout.AddLabeledEntry ("Selected Rows: "); + maSelectedColumnsLabel = aLayout.AddLabeledEntry ("Selected Columns: "); + } + + + public void SetObject (XAccessibleContext xContext) + { + mxTable = (XAccessibleTable)UnoRuntime.queryInterface( + XAccessibleTable.class, xContext); + super.SetObject (xContext); + } + + + public void Update () + { + if (mxTable == null) + { + maRowCountLabel.setText ("<null object>"); + maColumnCountLabel.setText ("<null object>"); + maCellCountLabel.setText ("<null object>"); + maSelectedRowsLabel.setText ("<null object>"); + maSelectedColumnsLabel.setText ("<null object>"); + } + else + { + int nRowCount = mxTable.getAccessibleRowCount(); + int nColumnCount = mxTable.getAccessibleColumnCount(); + maRowCountLabel.setText (Integer.toString (nRowCount)); + maColumnCountLabel.setText (Integer.toString (nColumnCount)); + maCellCountLabel.setText (Integer.toString (nRowCount*nColumnCount)); + + StringBuffer sList = new StringBuffer(); + int[] aSelected = mxTable.getSelectedAccessibleRows(); + boolean bFirst = true; + for (int i=0; i<aSelected.length; i++) + { + if ( ! bFirst) + { + sList.append (", "); + bFirst = false; + } + sList.append (Integer.toString(aSelected[i])); + } + maSelectedRowsLabel.setText (sList.toString()); + sList = new StringBuffer(); + aSelected = mxTable.getSelectedAccessibleColumns(); + bFirst = true; + for (int i=0; i<aSelected.length; i++) + { + if ( ! bFirst) + { + sList.append (", "); + bFirst = false; + } + sList.append (Integer.toString(aSelected[i])); + } + maSelectedColumnsLabel.setText (sList.toString()); + } + } + + + + + public String GetTitle () + { + return ("Table"); + } + + + + + /** Listen for changes regarding displayed values. + */ + public void notifyEvent (AccessibleEventObject aEvent) + { + switch (aEvent.EventId) + { + case AccessibleEventId.TABLE_MODEL_CHANGED : + case AccessibleEventId.SELECTION_CHANGED: + Update (); + } + } + + private XAccessibleTable mxTable; + private JLabel + maRowCountLabel, + maColumnCountLabel, + maCellCountLabel, + maSelectedRowsLabel, + maSelectedColumnsLabel; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/TextView.java b/accessibility/workben/org/openoffice/accessibility/awb/view/TextView.java new file mode 100644 index 000000000000..4a838aa85884 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/TextView.java @@ -0,0 +1,467 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.Color; +import java.awt.Dimension; +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.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSpinner; +import javax.swing.JTree; +import javax.swing.tree.TreeNode; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.MutableTreeNode; + +import com.sun.star.accessibility.AccessibleEventId; +import com.sun.star.accessibility.AccessibleEventObject; +import com.sun.star.accessibility.AccessibleTextType; +import com.sun.star.accessibility.AccessibleStateType; +import com.sun.star.accessibility.TextSegment; +import com.sun.star.accessibility.XAccessibleText; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleMultiLineText; +import com.sun.star.accessibility.XAccessibleStateSet; +import com.sun.star.awt.Point; +import com.sun.star.awt.Rectangle; +import com.sun.star.beans.PropertyValue; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.uno.UnoRuntime; + +import org.openoffice.accessibility.awb.view.text.CaretSpinnerModel; +import org.openoffice.accessibility.awb.view.text.TextDialogFactory; + + +public class TextView + extends ObjectView + implements ActionListener +{ + + /** Create a TextView when the given object supports the + XAccessibleText interface. + */ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + XAccessibleText xText = (XAccessibleText)UnoRuntime.queryInterface( + XAccessibleText.class, xContext); + if (xText != null) + return new TextView (aContainer); + else + return null; + } + + + public TextView (ObjectViewContainer aContainer) + { + super (aContainer); + + ViewGridLayout aLayout = new ViewGridLayout (this); + + maTextLabel = aLayout.AddLabeledString ("Text: "); + maCharacterArrayLabel = aLayout.AddLabeledEntry ("Characters: "); + maCharacterCountLabel = aLayout.AddLabeledEntry ("Character Count: "); + maSelectionLabel = aLayout.AddLabeledEntry ("Selection: "); + maBoundsLabel = aLayout.AddLabeledEntry ("Bounds Test: "); + maCaretPositionSpinner = (JSpinner)aLayout.AddLabeledComponent ( + "Caret position:", new JSpinner()); + Dimension aSize = maCaretPositionSpinner.getSize(); + maCaretPositionSpinner.setPreferredSize (new Dimension (100,20)); + maCaretLineNoLabel = aLayout.AddLabeledEntry ("Line number at caret: "); + maCaretLineTextLabel = aLayout.AddLabeledEntry ("Text of line at caret: "); + maLineNoFromCaretPosLabel = aLayout.AddLabeledEntry ("Line number at index of caret: "); + maLineTextFromCaretPosLabel = aLayout.AddLabeledEntry ("Text of line at index of caret: "); + + JPanel aButtonPanel = new JPanel (); + aLayout.AddComponent (aButtonPanel); + + JButton aButton = new JButton ("select..."); + aButton.setFont (aLayout.GetFont()); + aButton.addActionListener (this); + aButtonPanel.add (aButton); + + aButton = new JButton ("copy..."); + aButton.setFont (aLayout.GetFont()); + aButton.addActionListener (this); + aButtonPanel.add (aButton); + + // A tree that holds the text broken down into various segments. + maTree = new JTree (); + aLayout.AddComponent (new JScrollPane ( + maTree, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); + } + + + /** Additionally to the context store a reference to the + XAccessibleText interface. + */ + public void SetObject (XAccessibleContext xObject) + { + mxText = (XAccessibleText)UnoRuntime.queryInterface( + XAccessibleText.class, xObject); + maCaretSpinnerModel = new CaretSpinnerModel(mxText); + maCaretPositionSpinner.setModel (maCaretSpinnerModel); + super.SetObject (xObject); + } + + synchronized public void Destroy () + { + mxText = null; + super.Destroy(); + } + + synchronized public void Update () + { + maCaretPositionSpinner.setEnabled (mxText != null); + DefaultMutableTreeNode aRoot = new DefaultMutableTreeNode ("Text Segments"); + if (mxText == null) + { + maTextLabel.setText ("<null object>"); + maCharacterArrayLabel.setText ("<null object>"); + maCharacterCountLabel.setText ("<null object>"); + maSelectionLabel.setText ("<null object>"); + maBoundsLabel.setText ("<null object>"); + maCaretLineNoLabel.setText ("<null object>"); + maCaretLineTextLabel.setText ("<null object>"); + maLineNoFromCaretPosLabel.setText ("<null object>"); + maLineTextFromCaretPosLabel.setText ("<null object>"); + } + else + { + maTextLabel.setText (mxText.getText()); + maCharacterArrayLabel.setText (GetCharacterArray()); + maCharacterCountLabel.setText ( + Integer.toString(mxText.getCharacterCount())); + // Selection. + maSelectionLabel.setText ( + "[" + mxText.getSelectionStart() + + "," + mxText.getSelectionEnd() + + "] \"" + mxText.getSelectedText() + "\""); + + // Character bounds. + maBoundsLabel.setText (GetTextBoundsString()); + + // Caret position. + maCaretPositionSpinner.setValue (new Integer (mxText.getCaretPosition())); + + // Multi line methods. + XAccessibleMultiLineText xMultiText = (XAccessibleMultiLineText) + UnoRuntime.queryInterface( XAccessibleMultiLineText.class, mxText ); + + if( null != xMultiText ) { + try { + maCaretLineNoLabel.setText ( Integer.toString( xMultiText.getNumberOfLineWithCaret() ) ); + TextSegment ts = xMultiText.getTextAtLineWithCaret(); + maCaretLineTextLabel.setText ( "[" + ts.SegmentStart + + "," + ts.SegmentEnd + + "] \"" + ts.SegmentText + "\""); + maLineNoFromCaretPosLabel.setText ( Integer.toString( xMultiText.getLineNumberAtIndex( mxText.getCaretPosition() ) ) ); + ts = xMultiText.getTextAtLineNumber(xMultiText.getLineNumberAtIndex( mxText.getCaretPosition() ) ); + maLineTextFromCaretPosLabel.setText ( "[" + ts.SegmentStart + + "," + ts.SegmentEnd + + "] \"" + ts.SegmentText + "\""); + } catch( IndexOutOfBoundsException e) { + } + } + + // Text segments. + aRoot.add (CreateNode ("Character", AccessibleTextType.CHARACTER)); + aRoot.add (CreateNode ("Word", AccessibleTextType.WORD)); + aRoot.add (CreateNode ("Sentence", AccessibleTextType.SENTENCE)); + aRoot.add (CreateNode ("Paragraph", AccessibleTextType.PARAGRAPH)); + aRoot.add (CreateNode ("Line", AccessibleTextType.LINE)); + aRoot.add (CreateNode ("Attribute", AccessibleTextType.ATTRIBUTE_RUN)); + aRoot.add (CreateNode ("Glyph", AccessibleTextType.GLYPH)); + } + ((DefaultTreeModel)maTree.getModel()).setRoot (aRoot); + } + + public String GetTitle () + { + return ("Text"); + } + + public void notifyEvent (AccessibleEventObject aEvent) + { + System.out.println (aEvent); + switch (aEvent.EventId) + { + case AccessibleEventId.CARET_CHANGED : + maCaretSpinnerModel.Update(); + Update (); + break; + + case AccessibleEventId.TEXT_CHANGED : + case AccessibleEventId.TEXT_SELECTION_CHANGED: + Update (); + break; + } + } + + public void actionPerformed (ActionEvent aEvent) + { + String sCommand = aEvent.getActionCommand(); + if (sCommand.equals ("select...")) + TextDialogFactory.CreateSelectionDialog (mxContext); + else if (sCommand.equals ("copy...")) + TextDialogFactory.CreateCopyDialog (mxContext); + } + + + + /** Create a string that is a list of all characters returned by the + getCharacter() method. + */ + private String GetCharacterArray () + { + // Do not show more than 30 characters. + int nCharacterCount = mxText.getCharacterCount(); + int nMaxDisplayCount = 30; + + // build up string + StringBuffer aCharacterArray = new StringBuffer(); + int nIndex = 0; + try + { + while (nIndex<nCharacterCount && nIndex<nMaxDisplayCount) + { + aCharacterArray.append (mxText.getCharacter (nIndex)); + if (nIndex < nCharacterCount-1) + aCharacterArray.append (","); + nIndex ++; + } + if (nMaxDisplayCount < nCharacterCount) + aCharacterArray.append (", ..."); + } + catch (IndexOutOfBoundsException e) + { + aCharacterArray.append ("; Index Out Of Bounds at index " + nIndex); + } + + return aCharacterArray.toString(); + } + + + + /** Iterate over all characters and translate their positions + back and forth. + */ + private String GetTextBoundsString () + { + StringBuffer aBuffer = new StringBuffer (); + try + { + // Iterate over all characters in the text. + int nCount = mxText.getCharacterCount(); + for (int i=0; i<nCount; i++) + { + // Get bounds for this character. + Rectangle aBBox = mxText.getCharacterBounds (i); + + // get the character by 'clicking' into the middle of + // the bounds + Point aMiddle = new Point(); + aMiddle.X = aBBox.X + (aBBox.Width / 2) - 1; + aMiddle.Y = aBBox.Y + (aBBox.Height / 2) - 1; + int nIndex = mxText.getIndexAtPoint (aMiddle); + + // get the character, or a '#' for an illegal index + if ((nIndex >= 0) && (nIndex < mxText.getCharacter(i))) + aBuffer.append (mxText.getCharacter(nIndex)); + else + aBuffer.append ('#'); + } + } + catch (IndexOutOfBoundsException aEvent) + { + // Ignore errors. + } + + return aBuffer.toString(); + } + + + + + private final static int BEFORE = -1; + private final static int AT = 0; + private final static int BEHIND = +1; + + private MutableTreeNode CreateNode (String sTitle, short nTextType) + { + DefaultMutableTreeNode aNode = new DefaultMutableTreeNode (sTitle); + + aNode.add (CreateSegmentNode ("Before", nTextType, BEFORE)); + aNode.add (CreateSegmentNode ("At", nTextType, AT)); + aNode.add (CreateSegmentNode ("Behind", nTextType, BEHIND)); + + return aNode; + } + + private MutableTreeNode CreateSegmentNode (String sTitle, short nTextType, int nWhere) + { + TextSegment aSegment; + int nTextLength = mxText.getCharacterCount(); + DefaultMutableTreeNode aNode = new DefaultMutableTreeNode (sTitle); + for (int nIndex=0; nIndex<=nTextLength; /* empty */) + { + aSegment = GetTextSegment (nIndex, nTextType, nWhere); + DefaultMutableTreeNode aSegmentNode = new DefaultMutableTreeNode ( + new StringBuffer ( + Integer.toString (nIndex) + " -> " + + Integer.toString (aSegment.SegmentStart) + " - " + + Integer.toString (aSegment.SegmentEnd) + " : " + + aSegment.SegmentText.toString())); + aNode.add (aSegmentNode); + if (nTextType == AccessibleTextType.ATTRIBUTE_RUN) + AddAttributeNodes (aSegmentNode, aSegment); + if (aSegment.SegmentEnd > nIndex) + nIndex = aSegment.SegmentEnd; + else + nIndex ++; + } + + return aNode; + } + + + private TextSegment GetTextSegment (int nIndex, short nTextType, int nWhere) + { + TextSegment aSegment; + + try + { + switch (nWhere) + { + case BEFORE: + aSegment = mxText.getTextBeforeIndex (nIndex, nTextType); + break; + + case AT: + aSegment = mxText.getTextAtIndex (nIndex, nTextType); + break; + + case BEHIND: + aSegment = mxText.getTextBehindIndex (nIndex, nTextType); + break; + + default: + aSegment = new TextSegment(); + aSegment.SegmentText = new String ("unknown position " + nWhere); + aSegment.SegmentStart = nIndex; + aSegment.SegmentStart = nIndex+1; + break; + } + } + catch (IndexOutOfBoundsException aException) + { + aSegment = new TextSegment (); + aSegment.SegmentText = new String ("Invalid index at ") + nIndex + " : " + + aException.toString(); + aSegment.SegmentStart = nIndex; + aSegment.SegmentEnd = nIndex+1; + } + catch (IllegalArgumentException aException) + { + aSegment = new TextSegment (); + aSegment.SegmentText = new String ("Illegal argument at ") + nIndex + " : " + + aException.toString(); + aSegment.SegmentStart = nIndex; + aSegment.SegmentEnd = nIndex+1; + } + + return aSegment; + } + + + /** Add to the given node one node for every attribute of the given segment. + */ + private void AddAttributeNodes ( + DefaultMutableTreeNode aNode, + TextSegment aSegment) + { + try + { + PropertyValue[] aValues = mxText.getCharacterAttributes ( + aSegment.SegmentStart, aAttributeList); + for (int i=0; i<aValues.length; i++) + aNode.add (new DefaultMutableTreeNode ( + aValues[i].Name + ": " + aValues[i].Value)); + } + catch (IndexOutOfBoundsException aException) + { + aNode.add (new DefaultMutableTreeNode ( + "caught IndexOutOfBoundsException while retrieveing attributes")); + } + } + + private XAccessibleText mxText; + private JLabel + maTextLabel, + maCharacterArrayLabel, + maCharacterCountLabel, + maSelectionLabel, + maBoundsLabel, + maCaretLineNoLabel, + maCaretLineTextLabel, + maLineNoFromCaretPosLabel, + maLineTextFromCaretPosLabel; + + private JSpinner maCaretPositionSpinner; + private JTree maTree; + private CaretSpinnerModel maCaretSpinnerModel; + + private static String[] aAttributeList = new String[] { + "CharBackColor", + "CharColor", + "CharEscapement", + "CharHeight", + "CharPosture", + "CharStrikeout", + "CharUnderline", + "CharWeight", + "ParaAdjust", + "ParaBottomMargin", + "ParaFirstLineIndent", + "ParaLeftMargin", + "ParaLineSpacing", + "ParaRightMargin", + "ParaTabStops"}; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/ViewGridLayout.java b/accessibility/workben/org/openoffice/accessibility/awb/view/ViewGridLayout.java new file mode 100644 index 000000000000..bc598dcaf2fa --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/ViewGridLayout.java @@ -0,0 +1,117 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import javax.swing.JComponent; +import javax.swing.JLabel; + + +/** This class is a convenience class for views to use the GridBagLayout. +*/ +class ViewGridLayout +{ + public ViewGridLayout (JComponent aComponent) + { + maComponent = aComponent; + maComponent.setLayout (new GridBagLayout()); + maComponent.setMinimumSize (new Dimension (300,30)); + maComponent.setMaximumSize (new Dimension (300,1000)); + mnCurrentLine = 0; + } + + public JLabel AddLabeledEntry (String sTitle) + { + return (JLabel)AddLabeledComponent (sTitle, new JLabel ("")); + } + + public JLabel AddLabeledString (String sTitle) + { + JLabel aLabel = AddLabeledEntry (sTitle); + aLabel.setBackground (new Color(220,220,220)); + aLabel.setOpaque (true); + return aLabel; + } + + public JComponent AddLabeledComponent (String sTitle, JComponent aComponent) + { + GridBagConstraints constraints = new GridBagConstraints (); + constraints.gridx = 0; + constraints.anchor = GridBagConstraints.WEST; + constraints.fill = GridBagConstraints.NONE; + constraints.gridy = mnCurrentLine; + + JLabel aLabel = new JLabel(sTitle); + aLabel.setFont (saFont); + maComponent.add (aLabel, constraints); + constraints.gridx = 1; + constraints.weightx = 1; + constraints.fill = GridBagConstraints.NONE; + aComponent.setFont (saFont); + maComponent.add (aComponent, constraints); + + mnCurrentLine += 1; + + return aComponent; + } + + public JComponent AddComponent (JComponent aComponent) + { + GridBagConstraints constraints = new GridBagConstraints (); + constraints.gridx = 0; + constraints.gridwidth = 2; + constraints.weightx = 1; + constraints.anchor = GridBagConstraints.WEST; + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.gridy = mnCurrentLine; + + maComponent.add (aComponent, constraints); + + mnCurrentLine += 1; + + return aComponent; + } + + static public Font GetFont () + { + return saFont; + } + + static private Font saFont; + private int mnCurrentLine; + private JComponent maComponent; + + static + { + saFont = new Font ("Dialog", Font.PLAIN, 11); + } +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/makefile.common b/accessibility/workben/org/openoffice/accessibility/awb/view/makefile.common new file mode 100644 index 000000000000..38033b3ab658 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/makefile.common @@ -0,0 +1,45 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +JARFILES = jurt.jar unoil.jar ridl.jar +JAVAFILES = \ + ComponentView.java \ + ContextView.java \ + EditableTextView.java \ + EventMonitorView.java \ + FocusView.java \ + LayoutManager.java \ + ObjectView.java \ + ObjectViewContainer.java \ + ObjectViewContainerWindow.java \ + ParentView.java \ + SelectionView.java \ + ServiceInterfaceView.java \ + StateSetView.java \ + TableView.java \ + TextView.java \ + ViewGridLayout.java diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/makefile.mk b/accessibility/workben/org/openoffice/accessibility/awb/view/makefile.mk new file mode 100644 index 000000000000..0bfa48537ea2 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/makefile.mk @@ -0,0 +1,51 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJNAME = awb +PRJ = ..$/..$/..$/..$/..$/.. +TARGET = awb_view +PACKAGE = org$/openoffice$/accessibility$/awb$/view + +USE_JAVAVER:=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.IF "$(JAVAVER:s/.//)" >= "140" + +.INCLUDE : makefile.common + +JAVACLASSFILES= $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +.ENDIF + +# --- Targets ------------------------------------------------------ + + +.INCLUDE : target.mk + diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/text/CaretSpinnerModel.java b/accessibility/workben/org/openoffice/accessibility/awb/view/text/CaretSpinnerModel.java new file mode 100644 index 000000000000..c210b0eff086 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/text/CaretSpinnerModel.java @@ -0,0 +1,122 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view.text; + +import java.lang.Integer; +import java.util.Vector; +import javax.swing.SpinnerModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.sun.star.accessibility.XAccessibleText; +import com.sun.star.lang.IndexOutOfBoundsException; + + +/** A simple model for JSpinner objects that clips the spinner values to valid + text indices. +*/ +public class CaretSpinnerModel + implements SpinnerModel +{ + public CaretSpinnerModel (XAccessibleText xText) + { + mxText = xText; + maListeners = new Vector (); + } + + public void addChangeListener (ChangeListener aListener) + { + if (aListener != null) + maListeners.add (aListener); + } + + public void removeChangeListener (ChangeListener aListener) + { + maListeners.removeElement (aListener); + } + + public Object getNextValue () + { + if (mxText != null) + { + int nPosition = mxText.getCaretPosition(); + if (nPosition+1 <= mxText.getCharacterCount()) + return new Integer (nPosition+1); + } + return null; + } + + public Object getPreviousValue () + { + if (mxText != null) + { + int nPosition = mxText.getCaretPosition(); + if (nPosition > 0) + return new Integer (nPosition-1); + } + return null; + } + + public Object getValue () + { + if (mxText != null) + return new Integer (mxText.getCaretPosition()); + else + return null; + } + + public void setValue (Object aValue) + { + if (mxText != null) + if (aValue instanceof Integer) + { + try + { + if( ((Integer)aValue).intValue() != mxText.getCaretPosition() ) + mxText.setCaretPosition (((Integer)aValue).intValue()); + } + catch (IndexOutOfBoundsException aException) + { + } + } + } + + /** Call this method when the caret position has changes so that the model + can inform its listeners about it. + */ + public void Update () + { + ChangeEvent aEvent = new ChangeEvent (this); + for (int i=0; i<maListeners.size(); i++) + ((ChangeListener)maListeners.elementAt(i)).stateChanged (aEvent); + } + + private XAccessibleText mxText; + private Integer maValue; + private Vector maListeners; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/text/Makefile b/accessibility/workben/org/openoffice/accessibility/awb/view/text/Makefile new file mode 100644 index 000000000000..c58899a09f6e --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/text/Makefile @@ -0,0 +1,13 @@ +# $Id: Makefile,v 1.1 2003/06/13 16:30:41 af Exp $ + +all : package + +ROOT=../../../../.. +PACKAGE = org.openoffice.accessibility.awb.view.text +SUBDIRS = +include makefile.common + +include $(ROOT)/makefile.in + + +package : $(CLASS_FILES) diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextActionDialog.java b/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextActionDialog.java new file mode 100644 index 000000000000..f37969d5ee59 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextActionDialog.java @@ -0,0 +1,208 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view.text; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.FlowLayout; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.text.JTextComponent; + +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleText; +import com.sun.star.accessibility.XAccessibleEditableText; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.uno.UnoRuntime; + + +/** + * Display a dialog with a text field and a pair of cancel/do-it buttons + */ +class TextActionDialog + extends JDialog + implements ActionListener +{ + public TextActionDialog ( + XAccessibleContext xContext, + String sExplanation, + String sTitle) + { + super();// AccessibilityWorkBench.Instance() ); + + mxContext = xContext; + msTitle = sTitle; + msExplanation = sExplanation; + Layout (); + setSize (350, 225); + + } + + + /** build dialog */ + protected void Layout() + { + setTitle (msTitle); + + // vertical stacking of the elements + Container aContent = getContentPane(); + // aContent.setLayout( new BorderLayout() ); + + // Label with explanation. + if (msExplanation.length() > 0) + aContent.add (new JLabel (msExplanation), BorderLayout.NORTH); + + // the text field + maText = new JTextArea(); + maText.setLineWrap (true); + maText.setEditable (false); + aContent.add (maText, BorderLayout.CENTER); + + XAccessibleText xText = (XAccessibleText)UnoRuntime.queryInterface( + XAccessibleText.class, mxContext); + String sText = xText.getText(); + maText.setText (sText); + maText.setRows (sText.length() / 40 + 1); + maText.setColumns (Math.min (Math.max (40, sText.length()), 20)); + + JPanel aButtons = new JPanel(); + aButtons.setLayout (new FlowLayout()); + maIndexToggle = new JCheckBox ("reverse selection"); + aButtons.add (maIndexToggle); + + JButton aActionButton = new JButton (msTitle); + aActionButton.setActionCommand ("Action"); + aActionButton.addActionListener (this); + aButtons.add (aActionButton); + + JButton aCancelButton = new JButton ("cancel"); + aCancelButton.setActionCommand ("Cancel"); + aCancelButton.addActionListener (this); + aButtons.add (aCancelButton); + + // add Panel with buttons + aContent.add (aButtons, BorderLayout.SOUTH); + } + + protected void Cancel() + { + hide(); + dispose(); + } + + public void actionPerformed(ActionEvent e) + { + String sCommand = e.getActionCommand(); + + if( "Cancel".equals( sCommand ) ) + Cancel(); + else if( "Action".equals( sCommand ) ) + Action(); + } + + + protected int GetSelectionStart() + { + return GetSelection(true); + } + protected int GetSelectionEnd() + { + return GetSelection(false); + } + private int GetSelection (boolean bStart) + { + if (bStart ^ maIndexToggle.isSelected()) + return maText.getSelectionStart(); + else + return maText.getSelectionEnd(); + } + + + + protected void Action () + { + String sError = null; + boolean bSuccess = true; + try + { + XAccessibleText xText = + (XAccessibleText)UnoRuntime.queryInterface( + XAccessibleText.class, mxContext); + if (xText != null) + bSuccess = bSuccess && TextAction (xText); + + XAccessibleEditableText xEditableText = + (XAccessibleEditableText)UnoRuntime.queryInterface( + XAccessibleEditableText.class, mxContext); + if (xEditableText != null) + bSuccess = bSuccess && EditableTextAction (xEditableText); + + if ( ! bSuccess) + sError = "Can't execute"; + } + catch (IndexOutOfBoundsException e) + { + sError = "Index out of bounds"; + } + + if (sError != null) + JOptionPane.showMessageDialog ( + this,// AccessibilityWorkBench.Instance(), + sError, + msTitle, + JOptionPane.ERROR_MESSAGE); + + Cancel(); + } + + /** override this for dialog-specific action */ + boolean TextAction (XAccessibleText xText) + throws IndexOutOfBoundsException + { + return true; + } + + boolean EditableTextAction (XAccessibleEditableText xText) + throws IndexOutOfBoundsException + { + return true; + } + + private XAccessibleContext mxContext; + protected JTextArea maText; + private String msTitle; + private String msExplanation; + private JCheckBox maIndexToggle; +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextAttributeDialog.java b/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextAttributeDialog.java new file mode 100644 index 000000000000..dad548ca730e --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextAttributeDialog.java @@ -0,0 +1,179 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view.text; + +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.BoxLayout; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JColorChooser; +import javax.swing.JPanel; +import javax.swing.text.JTextComponent; + +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleEditableText; +import com.sun.star.beans.PropertyValue; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.uno.UnoRuntime; + + +class TextAttributeDialog + extends TextActionDialog +{ + public TextAttributeDialog (XAccessibleContext xContext) + { + super (xContext, + "Choose attributes, select text, and press 'Set':", + "set"); + } + + protected void Layout () + { + super.Layout (); + + maForeground = Color.black; + maBackground = Color.white; + + JPanel aPanel = new JPanel(); + aPanel.setLayout (new BoxLayout (aPanel, BoxLayout.Y_AXIS)); + + maBoldCheckBox = new JCheckBox ("bold"); + maUnderlineCheckBox = new JCheckBox ("underline"); + maItalicsCheckBox = new JCheckBox ("italics"); + + JButton aForegroundButton = new JButton ("Foreground", + new TextAttributeDialog.ColorIcon(true)); + aForegroundButton.addActionListener (new ActionListener() + { + public void actionPerformed (ActionEvent aEvent) + { + maForeground = JColorChooser.showDialog ( + TextAttributeDialog.this, + "Select Foreground Color", + maForeground); + } + } ); + + JButton aBackgroundButton = new JButton("Background", + new TextAttributeDialog.ColorIcon(false)); + aBackgroundButton.addActionListener (new ActionListener() + { + public void actionPerformed (ActionEvent eEvent) + { + maBackground = JColorChooser.showDialog( + TextAttributeDialog.this, + "Select Background Color", + maBackground); + } + } ); + + aPanel.add (maBoldCheckBox); + aPanel.add (maUnderlineCheckBox); + aPanel.add (maItalicsCheckBox); + aPanel.add (aForegroundButton); + aPanel.add (aBackgroundButton); + + getContentPane().add (aPanel, BorderLayout.WEST); + } + + + /** edit the text */ + boolean EditableTextAction (XAccessibleEditableText xText) + throws IndexOutOfBoundsException + { + PropertyValue[] aSequence = new PropertyValue[6]; + aSequence[0] = new PropertyValue(); + aSequence[0].Name = "CharWeight"; + aSequence[0].Value = new Integer (maBoldCheckBox.isSelected() ? 150 : 100); + aSequence[1] = new PropertyValue(); + aSequence[1].Name = "CharUnderline"; + aSequence[1].Value = new Integer (maUnderlineCheckBox.isSelected() ? 1 : 0); + aSequence[2] = new PropertyValue(); + aSequence[2].Name = "CharBackColor"; + aSequence[2].Value = new Integer (maBackground.getRGB()); + aSequence[3] = new PropertyValue(); + aSequence[3].Name = "CharColor"; + aSequence[3].Value = new Integer (maForeground.getRGB()); + aSequence[4] = new PropertyValue(); + aSequence[4].Name = "CharPosture"; + aSequence[4].Value = new Integer (maItalicsCheckBox.isSelected() ? 1 : 0); + aSequence[5] = new PropertyValue(); + aSequence[5].Name = "CharBackTransparent"; + aSequence[5].Value = new Boolean (false); + + return xText.setAttributes ( + GetSelectionStart(), + GetSelectionEnd(), + aSequence); + } + + class ColorIcon + implements Icon + { + public ColorIcon(boolean bWhich) { bForeground = bWhich; } + public int getIconHeight() { return nHeight; } + public int getIconWidth() { return nWidth; } + public void paintIcon (Component c, Graphics g, int x, int y) + { + g.setColor( getColor() ); + g.fillRect( x, y, nHeight, nWidth ); + g.setColor( c.getForeground() ); + g.drawRect( x, y, nHeight, nWidth ); + } + Color getColor() + { + if (bForeground) + return maForeground; + else + return maBackground; + } + + private static final int nHeight = 16; + private static final int nWidth = 16; + private boolean bForeground; + } + + + + + private JCheckBox + maBoldCheckBox, + maUnderlineCheckBox, + maItalicsCheckBox; + private Color + maForeground, + maBackground; + +} + diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextDialogFactory.java b/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextDialogFactory.java new file mode 100644 index 000000000000..cdb3f26b5e55 --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextDialogFactory.java @@ -0,0 +1,136 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view.text; + +import javax.swing.JDialog; +import javax.swing.text.JTextComponent; + +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleEditableText; +import com.sun.star.accessibility.XAccessibleText; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.uno.UnoRuntime; + + +/** Factory for dialogs of the text views. +*/ +public class TextDialogFactory +{ + static public JDialog CreateSelectionDialog (XAccessibleContext xContext) + { + JDialog aDialog = new TextActionDialog( + xContext, + "Select range:", + "select") + { + boolean TextAction (XAccessibleText xText) + throws IndexOutOfBoundsException + { + return xText.setSelection( + GetSelectionStart(), + GetSelectionEnd() ); + } + }; + if (aDialog != null) + aDialog.show(); + return aDialog; + } + + static public JDialog CreateCopyDialog (XAccessibleContext xContext) + { + JDialog aDialog = new TextActionDialog( + xContext, + "Select range and copy:", + "copy") + { + boolean TextAction (XAccessibleText xText) + throws IndexOutOfBoundsException + { + return xText.copyText( + GetSelectionStart(), + GetSelectionEnd()); + } + }; + if (aDialog != null) + aDialog.show(); + return aDialog; + } + static public JDialog CreateCutDialog (XAccessibleContext xContext) + { + JDialog aDialog = new TextActionDialog( + xContext, + "Select range and cut:", + "cut") + { + boolean EditableTextAction (XAccessibleEditableText xText) + throws IndexOutOfBoundsException + { + return xText.cutText( + GetSelectionStart(), + GetSelectionEnd() ); + } + }; + if (aDialog != null) + aDialog.show(); + return aDialog; + } + static public JDialog CreatePasteDialog (XAccessibleContext xContext) + { + JDialog aDialog = new TextActionDialog ( + xContext, + "Place Caret and paste:", + "paste") + { + boolean EditableTextAction (XAccessibleEditableText xText) + throws IndexOutOfBoundsException + { + return xText.pasteText(maText.getCaretPosition()); + } + }; + if (aDialog != null) + aDialog.show(); + return aDialog; + } + static public JDialog CreateEditDialog (XAccessibleContext xContext) + { + JDialog aDialog = new TextEditDialog ( + xContext, + "Edit text:", + "edit"); + if (aDialog != null) + aDialog.show(); + return aDialog; + } + static public JDialog CreateFormatDialog (XAccessibleContext xContext) + { + JDialog aDialog = new TextAttributeDialog (xContext); + if (aDialog != null) + aDialog.show(); + return aDialog; + } +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextEditDialog.java b/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextEditDialog.java new file mode 100644 index 000000000000..a8710cbad7cc --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/text/TextEditDialog.java @@ -0,0 +1,122 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.accessibility.awb.view.text; + +import javax.swing.text.JTextComponent; + +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleEditableText; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.uno.UnoRuntime; + + +class TextEditDialog + extends TextActionDialog +{ + public TextEditDialog ( + XAccessibleContext xContext, + String sExplanation, + String sTitle ) + { + super (xContext, sExplanation, sTitle); + } + + protected void Layout() + { + super.Layout(); + maText.setEditable (true); + } + + + /** edit the text */ + boolean EditableTextAction (XAccessibleEditableText xText) + { + return UpdateText (xText, maText.getText()); + } + + + /** update the text */ + boolean UpdateText (XAccessibleEditableText xText, String sNew) + { + boolean bResult = false; + + String sOld = xText.getText(); + + // false alarm? Early out if no change was done! + if ( ! sOld.equals (sNew)) + { + + // Get the minimum length of both strings. + int nMinLength = sOld.length(); + if (sNew.length() < nMinLength) + nMinLength = sNew.length(); + + // Count equal characters from front and end. + int nFront = 0; + while ((nFront < nMinLength) && + (sNew.charAt(nFront) == sOld.charAt(nFront))) + nFront++; + int nBack = 0; + while ((nBack < nMinLength) && + (sNew.charAt(sNew.length()-nBack-1) == + sOld.charAt(sOld.length()-nBack-1) )) + nBack++; + if (nFront + nBack > nMinLength) + nBack = nMinLength - nFront; + + // so... the first nFront and the last nBack characters are the + // same. Change the others! + String sDel = sOld.substring (nFront, sOld.length() - nBack); + String sIns = sNew.substring (nFront, sNew.length() - nBack); + + System.out.println ("edit text: " + + sOld.substring(0, nFront) + + " [ " + sDel + " -> " + sIns + " ] " + + sOld.substring(sOld.length() - nBack)); + + try + { + // edit the text, and use + // (set|insert|delete|replace)Text as needed + if( nFront+nBack == 0 ) + bResult = xText.setText( sIns ); + else if( sDel.length() == 0 ) + bResult = xText.insertText( sIns, nFront ); + else if( sIns.length() == 0 ) + bResult = xText.deleteText( nFront, sOld.length()-nBack ); + else + bResult = xText.replaceText(nFront, sOld.length()-nBack,sIns); + } + catch( IndexOutOfBoundsException aException) + { + } + } + + return bResult; + } +} diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/text/makefile.common b/accessibility/workben/org/openoffice/accessibility/awb/view/text/makefile.common new file mode 100644 index 000000000000..7d9a5e8febfa --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/text/makefile.common @@ -0,0 +1,34 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +JARFILES = jurt.jar unoil.jar ridl.jar +JAVAFILES = \ + CaretSpinnerModel.java \ + TextActionDialog.java \ + TextEditDialog.java \ + TextAttributeDialog.java \ + TextDialogFactory.java diff --git a/accessibility/workben/org/openoffice/accessibility/awb/view/text/makefile.mk b/accessibility/workben/org/openoffice/accessibility/awb/view/text/makefile.mk new file mode 100644 index 000000000000..1ec7da26619b --- /dev/null +++ b/accessibility/workben/org/openoffice/accessibility/awb/view/text/makefile.mk @@ -0,0 +1,51 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJNAME = awb +PRJ = ..$/..$/..$/..$/..$/..$/.. +TARGET = awb_view_text +PACKAGE = org$/openoffice$/accessibility$/awb$/view$/text + +USE_JAVAVER:=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.IF "$(JAVAVER:s/.//)" >= "140" + +.INCLUDE : makefile.common + +JAVACLASSFILES= $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +.ENDIF + +# --- Targets ------------------------------------------------------ + + +.INCLUDE : target.mk + |