diff options
author | Andre Fischer <af@openoffice.org> | 2003-05-23 08:20:50 +0000 |
---|---|---|
committer | Andre Fischer <af@openoffice.org> | 2003-05-23 08:20:50 +0000 |
commit | e003f69e7c6a06deb9f66d2695eb52e69c93292a (patch) | |
tree | 7dea9f68f490635fdf3a80943165cbbb9a5e8829 /toolkit/test | |
parent | b2642683044021d6b1c8c833c8d0d3393e84df64 (diff) |
Changed registration of object views.
Diffstat (limited to 'toolkit/test')
-rw-r--r-- | toolkit/test/accessibility/makefile.mk | 13 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/ContextView.java | 10 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/FocusView.java | 10 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/ListeningObjectView.java | 5 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/ObjectView.java | 9 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/ObjectViewContainer.java | 77 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/StateSetView.java | 198 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/TextView.java | 10 | ||||
-rw-r--r-- | toolkit/test/accessibility/ov/makefile.mk | 2 |
9 files changed, 230 insertions, 104 deletions
diff --git a/toolkit/test/accessibility/makefile.mk b/toolkit/test/accessibility/makefile.mk index 0274fac85c96..5d0c1bc03374 100644 --- a/toolkit/test/accessibility/makefile.mk +++ b/toolkit/test/accessibility/makefile.mk @@ -16,7 +16,7 @@ JAR_PATH = $(SOLARBINDIR)$/ # The rest of this makefile should not need to be touched. -all : AccessibilityWorkBench dist +all : AccessibilityWorkBench JAR_FILES = \ unoil.jar \ @@ -94,7 +94,7 @@ JFLAGS = -deprecation -classpath $(CLASSPATH) %.class : %.java +$(JAVAC) $(JFLAGS) $< -AccessibilityWorkBench : ObjectView $(JAVA_FILES:b:+".class") +AccessibilityWorkBench : ObjectView Tools $(JAVA_FILES:b:+".class") ObjectView .SETDIR=ov : @echo "making package ObjectView" @@ -104,6 +104,15 @@ Tools .SETDIR=tools : @echo "making package Tools" dmake +# Remove all class files. +clean : ObjectView.clean Tools.clean + rm *.class + rm AccessibilityWorkBench.jar +ObjectView.clean .SETDIR=ov : + rm *.class +Tools.clean .SETDIR=tools : + rm *.class + # Create a jar file of all files neccessary to build and run the work bench. dist: AccessibilityWorkBench.jar diff --git a/toolkit/test/accessibility/ov/ContextView.java b/toolkit/test/accessibility/ov/ContextView.java index 977f8944cfd5..4204c5de7bac 100644 --- a/toolkit/test/accessibility/ov/ContextView.java +++ b/toolkit/test/accessibility/ov/ContextView.java @@ -21,16 +21,20 @@ public class ContextView extends ListeningObjectView implements ActionListener { - static public ObjectView Create (XAccessibleContext xContext) + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) { + System.out.println ("ContextView.CreateView"); if (xContext != null) - return new ContextView(); + return new ContextView (aContainer); else return null; } - public ContextView () + public ContextView (ObjectViewContainer aContainer) { + super (aContainer); maNameLabel = new JLabel ("Name: "); maName = new JLabel (""); maDescriptionLabel = new JLabel ("Description: "); diff --git a/toolkit/test/accessibility/ov/FocusView.java b/toolkit/test/accessibility/ov/FocusView.java index e05b7aae259a..665fa260e288 100644 --- a/toolkit/test/accessibility/ov/FocusView.java +++ b/toolkit/test/accessibility/ov/FocusView.java @@ -24,18 +24,22 @@ public class FocusView /** Create a FocusView when the given object supports the XAccessibleComponent interface. */ - static public ObjectView Create (XAccessibleContext xContext) + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) { XAccessibleComponent xComponent = (XAccessibleComponent)UnoRuntime.queryInterface( XAccessibleComponent.class, xContext); if (xComponent != null) - return new FocusView(); + return new FocusView (aContainer); else return null; } - public FocusView () + public FocusView (ObjectViewContainer aContainer) { + super (aContainer); + setLayout (new GridBagLayout()); GridBagConstraints aConstraints = new GridBagConstraints (); diff --git a/toolkit/test/accessibility/ov/ListeningObjectView.java b/toolkit/test/accessibility/ov/ListeningObjectView.java index c01b0e57906a..574fa989b20f 100644 --- a/toolkit/test/accessibility/ov/ListeningObjectView.java +++ b/toolkit/test/accessibility/ov/ListeningObjectView.java @@ -14,6 +14,11 @@ abstract class ListeningObjectView extends ObjectView implements XAccessibleEventListener { + public ListeningObjectView (ObjectViewContainer aContainer) + { + super (aContainer); + } + /** Add this object as event listener at the broadcasting accessible object. */ diff --git a/toolkit/test/accessibility/ov/ObjectView.java b/toolkit/test/accessibility/ov/ObjectView.java index aa09c88e31d4..0c96969e733b 100644 --- a/toolkit/test/accessibility/ov/ObjectView.java +++ b/toolkit/test/accessibility/ov/ObjectView.java @@ -24,13 +24,16 @@ abstract public class ObjectView In the ususal case this will be the support of a specific accessibility interface. */ - static public ObjectView Create (XAccessibleContext xContext) + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) { return null; } - public ObjectView () + public ObjectView (ObjectViewContainer aContainer) { + maContainer = aContainer; mxContext = null; } @@ -69,4 +72,6 @@ abstract public class ObjectView /// Reference to the current object to display information about. protected XAccessibleContext mxContext; + + protected ObjectViewContainer maContainer; } diff --git a/toolkit/test/accessibility/ov/ObjectViewContainer.java b/toolkit/test/accessibility/ov/ObjectViewContainer.java index 7bcfbabb19f3..c0bf6a86736b 100644 --- a/toolkit/test/accessibility/ov/ObjectViewContainer.java +++ b/toolkit/test/accessibility/ov/ObjectViewContainer.java @@ -6,6 +6,13 @@ 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; @@ -17,13 +24,21 @@ import com.sun.star.accessibility.XAccessibleComponent; import com.sun.star.accessibility.XAccessibleSelection; import com.sun.star.uno.UnoRuntime; + public class ObjectViewContainer extends JPanel { public ObjectViewContainer () { + maViewTemplates = new Vector (); maViewBorder = BorderFactory.createBevelBorder (BevelBorder.RAISED); setLayout (new GridBagLayout ()); + + System.out.println ("ObjectViewContainer"); + RegisterView (ContextView.class); + // RegisterView (StateSetView.class); + RegisterView (FocusView.class); + RegisterView (TextView.class); } @@ -42,11 +57,29 @@ public class ObjectViewContainer removeAll (); // Add new views. - Add (ContextView.Create(xContext)); - Add (StateSetView.Create(xContext)); - Add (FocusView.Create(xContext)); - Add (SelectionView.Create(xContext)); - Add (TextView.Create(xContext)); + 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 (); @@ -59,12 +92,29 @@ public class ObjectViewContainer } + /** 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) + { + System.out.println ("registering " + 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); + } /** Add an object view and place it below all previously added views. @param aView This argument may be null. In this case nothing happens. */ - public void Add (ObjectView aView) + private void Add (ObjectView aView) { if (aView != null) { @@ -97,15 +147,20 @@ public class ObjectViewContainer private void UpdateLayoutManager () { // Adapt the layout manager. - Component aComponent = getComponent (getComponentCount()-1); - GridBagLayout aLayout = (GridBagLayout)getLayout(); - GridBagConstraints aConstraints = aLayout.getConstraints (aComponent); - aConstraints.weighty = 1; - aLayout.setConstraints (aComponent, aConstraints); + if (getComponentCount() > 0) + { + Component aComponent = getComponent (getComponentCount()-1); + GridBagLayout aLayout = (GridBagLayout)getLayout(); + GridBagConstraints aConstraints = aLayout.getConstraints (aComponent); + aConstraints.weighty = 1; + aLayout.setConstraints (aComponent, aConstraints); + } } /// 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; } diff --git a/toolkit/test/accessibility/ov/StateSetView.java b/toolkit/test/accessibility/ov/StateSetView.java index 5e0b64ce16d9..e8997ac0c5a0 100644 --- a/toolkit/test/accessibility/ov/StateSetView.java +++ b/toolkit/test/accessibility/ov/StateSetView.java @@ -36,21 +36,103 @@ public class StateSetView /** Create a FocusView when the given object supports the XAccessibleComponent interface. */ - static public ObjectView Create (XAccessibleContext xContext) + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) { + ObjectView aView = null; if (xContext != null) - return new StateSetView(); + if (mnViewMode == SHOW_ALL_STATES) + aView = StateSetAllView.Create (aContainer, xContext); + else + aView = StateSetSetView.Create (aContainer, xContext); + return aView; + } + + public StateSetView (ObjectViewContainer aContainer) + { + super (aContainer); + + addMouseListener (this); + } + + private void SetViewMode (int nViewMode) + { + mnViewMode = nViewMode; + switch (mnViewMode) + { + case SHOW_SET_STATES : + maContainer.ReplaceView ( + getClass(), + StateSetSetView.class); + break; + case SHOW_ALL_STATES : + maContainer.ReplaceView ( + getClass(), + StateSetAllView.class); + break; + } + aContainer.SetObject (mxContext); + } + + + + public String GetTitle () + { + return ("StateSet"); + } + + public void notifyEvent (AccessibleEventObject aEvent) + { + if (aEvent.EventId == AccessibleEventId.STATE_CHANGED) + Update(); + } + + public void mouseClicked(MouseEvent e) + { + switch (mnViewMode) + { + case SHOW_SET_STATES : + SetViewMode (SHOW_ALL_STATES); + break; + case SHOW_ALL_STATES : + SetViewMode (SHOW_SET_STATES); + break; + } + } + public void mouseEntered (MouseEvent e) {} + public void mouseExited (MouseEvent e) {} + public void mousePressed (MouseEvent e) {} + public void mouseReleased(MouseEvent e) {} + + private static int mnViewMode = SHOW_ALL_STATES; + private final static int SHOW_SET_STATES = 0; + private final static int SHOW_ALL_STATES = 1; + + + +public class StateSetAllView + extends StateSetView +{ + /** Create a FocusView when the given object supports the + XAccessibleComponent interface. + */ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) + { + if (xContext != null) + return new StateSetAllView (aContainer); else return null; } - public StateSetView () + public StateSetAllView (ObjectViewContainer aContainer) { - maStates = null; - mnViewMode = SHOW_ALL_STATES; + super (aContainer); + setPreferredSize (new Dimension(300,90)); setMinimumSize (new Dimension(200,80)); - addMouseListener (this); } public void paintChildren (Graphics g) @@ -68,43 +150,10 @@ public class StateSetView aSize.width-aInsets.left-aInsets.right, aSize.height-aInsets.top-aInsets.bottom); - switch (mnViewMode) - { - case SHOW_ALL_STATES : - PaintAllStates ((Graphics2D)g, aWidgetArea); - break; - case SHOW_SET_STATES : - PaintSetStates ((Graphics2D)g, aWidgetArea); - break; - } - } - } - - private void SetViewMode (int nViewMode) - { - mnViewMode = nViewMode; - switch (mnViewMode) - { - case SHOW_SET_STATES : - maStates = new JLabel (); - add (maStates, BorderLayout.CENTER); - Update(); - break; - case SHOW_ALL_STATES : - if (maStates != null) - { - remove (maStates); - maStates = null; - } - repaint(); - break; + PaintAllStates ((Graphics2D)g, aWidgetArea); } } - private void PaintSetStates (Graphics2D g, Rectangle aWidgetArea) - { - } - private void PaintAllStates (Graphics2D g, Rectangle aWidgetArea) { Color aTextColor = g.getColor(); @@ -152,58 +201,49 @@ public class StateSetView } } } +} - synchronized public void Update () +public class StateSetSetView + extends StateSetView +{ + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) { - if (mnViewMode == SHOW_SET_STATES) - { - XAccessibleStateSet xStateSet = mxContext.getAccessibleStateSet(); - if (xStateSet != null) - { - String sStates = new String (); - short aStates[] = xStateSet.getStates(); - for (int i=0; i<aStates.length; i++) - { - if (i > 0) - sStates = sStates + ", "; - sStates = sStates + NameProvider.getStateName(aStates[i]); - } - maStates.setText (sStates); - } - } + if (xContext != null) + return new StateSetSetView (aContainer); + else + return null; } - public String GetTitle () + public StateSetSetView (ObjectViewContainer aContainer) { - return ("StateSet"); - } + super (aContainer); - public void notifyEvent (AccessibleEventObject aEvent) - { - if (aEvent.EventId == AccessibleEventId.STATE_CHANGED) - Update(); + maStates = null; + setPreferredSize (new Dimension(300,90)); } - public void mouseClicked(MouseEvent e) + + synchronized public void Update () { - switch (mnViewMode) + XAccessibleStateSet xStateSet = mxContext.getAccessibleStateSet(); + if (xStateSet != null) { - case SHOW_SET_STATES : - SetViewMode (SHOW_ALL_STATES); - break; - case SHOW_ALL_STATES : - SetViewMode (SHOW_SET_STATES); - break; + String sStates = new String (); + short aStates[] = xStateSet.getStates(); + for (int i=0; i<aStates.length; i++) + { + if (i > 0) + sStates = sStates + ", "; + sStates = sStates + NameProvider.getStateName(aStates[i]); + } + maStates.setText (sStates); } } - public void mouseEntered (MouseEvent e) {} - public void mouseExited (MouseEvent e) {} - public void mousePressed (MouseEvent e) {} - public void mouseReleased(MouseEvent e) {} private JLabel maStates; - private int mnViewMode; - private final int SHOW_SET_STATES = 0; - private final int SHOW_ALL_STATES = 1; +} + } diff --git a/toolkit/test/accessibility/ov/TextView.java b/toolkit/test/accessibility/ov/TextView.java index 6a265f6046c7..094647986e4f 100644 --- a/toolkit/test/accessibility/ov/TextView.java +++ b/toolkit/test/accessibility/ov/TextView.java @@ -23,19 +23,23 @@ public class TextView /** Create a TextView when the given object supports the XAccessibleText interface. */ - static public ObjectView Create (XAccessibleContext xContext) + static public ObjectView Create ( + ObjectViewContainer aContainer, + XAccessibleContext xContext) { XAccessibleText xText = (XAccessibleText)UnoRuntime.queryInterface( XAccessibleText.class, xContext); if (xText != null) - return new TextView(); + return new TextView (aContainer); else return null; } - public TextView () + public TextView (ObjectViewContainer aContainer) { + super (aContainer); + setLayout (new GridBagLayout()); GridBagConstraints aConstraints = new GridBagConstraints (); diff --git a/toolkit/test/accessibility/ov/makefile.mk b/toolkit/test/accessibility/ov/makefile.mk index 4dd007bb1b68..a7f272c245b9 100644 --- a/toolkit/test/accessibility/ov/makefile.mk +++ b/toolkit/test/accessibility/ov/makefile.mk @@ -33,8 +33,8 @@ JAVA_FILES = \ ov/ContextView.java \ ov/FocusView.java \ ov/SelectionView.java \ - ov/StateSetView.java \ ov/TextView.java +# ov/StateSetView.java \ JAVA_CLASSPATHS := \ |