Kaydet (Commit) e003f69e authored tarafından Andre Fischer's avatar Andre Fischer

Changed registration of object views.

üst b2642683
...@@ -16,7 +16,7 @@ JAR_PATH = $(SOLARBINDIR)$/ ...@@ -16,7 +16,7 @@ JAR_PATH = $(SOLARBINDIR)$/
# The rest of this makefile should not need to be touched. # The rest of this makefile should not need to be touched.
all : AccessibilityWorkBench dist all : AccessibilityWorkBench
JAR_FILES = \ JAR_FILES = \
unoil.jar \ unoil.jar \
...@@ -94,7 +94,7 @@ JFLAGS = -deprecation -classpath $(CLASSPATH) ...@@ -94,7 +94,7 @@ JFLAGS = -deprecation -classpath $(CLASSPATH)
%.class : %.java %.class : %.java
+$(JAVAC) $(JFLAGS) $< +$(JAVAC) $(JFLAGS) $<
AccessibilityWorkBench : ObjectView $(JAVA_FILES:b:+".class") AccessibilityWorkBench : ObjectView Tools $(JAVA_FILES:b:+".class")
ObjectView .SETDIR=ov : ObjectView .SETDIR=ov :
@echo "making package ObjectView" @echo "making package ObjectView"
...@@ -104,6 +104,15 @@ Tools .SETDIR=tools : ...@@ -104,6 +104,15 @@ Tools .SETDIR=tools :
@echo "making package Tools" @echo "making package Tools"
dmake 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. # Create a jar file of all files neccessary to build and run the work bench.
dist: AccessibilityWorkBench.jar dist: AccessibilityWorkBench.jar
......
...@@ -21,16 +21,20 @@ public class ContextView ...@@ -21,16 +21,20 @@ public class ContextView
extends ListeningObjectView extends ListeningObjectView
implements ActionListener implements ActionListener
{ {
static public ObjectView Create (XAccessibleContext xContext) static public ObjectView Create (
ObjectViewContainer aContainer,
XAccessibleContext xContext)
{ {
System.out.println ("ContextView.CreateView");
if (xContext != null) if (xContext != null)
return new ContextView(); return new ContextView (aContainer);
else else
return null; return null;
} }
public ContextView () public ContextView (ObjectViewContainer aContainer)
{ {
super (aContainer);
maNameLabel = new JLabel ("Name: "); maNameLabel = new JLabel ("Name: ");
maName = new JLabel (""); maName = new JLabel ("");
maDescriptionLabel = new JLabel ("Description: "); maDescriptionLabel = new JLabel ("Description: ");
......
...@@ -24,18 +24,22 @@ public class FocusView ...@@ -24,18 +24,22 @@ public class FocusView
/** Create a FocusView when the given object supports the /** Create a FocusView when the given object supports the
XAccessibleComponent interface. XAccessibleComponent interface.
*/ */
static public ObjectView Create (XAccessibleContext xContext) static public ObjectView Create (
ObjectViewContainer aContainer,
XAccessibleContext xContext)
{ {
XAccessibleComponent xComponent = (XAccessibleComponent)UnoRuntime.queryInterface( XAccessibleComponent xComponent = (XAccessibleComponent)UnoRuntime.queryInterface(
XAccessibleComponent.class, xContext); XAccessibleComponent.class, xContext);
if (xComponent != null) if (xComponent != null)
return new FocusView(); return new FocusView (aContainer);
else else
return null; return null;
} }
public FocusView () public FocusView (ObjectViewContainer aContainer)
{ {
super (aContainer);
setLayout (new GridBagLayout()); setLayout (new GridBagLayout());
GridBagConstraints aConstraints = new GridBagConstraints (); GridBagConstraints aConstraints = new GridBagConstraints ();
......
...@@ -14,6 +14,11 @@ abstract class ListeningObjectView ...@@ -14,6 +14,11 @@ abstract class ListeningObjectView
extends ObjectView extends ObjectView
implements XAccessibleEventListener implements XAccessibleEventListener
{ {
public ListeningObjectView (ObjectViewContainer aContainer)
{
super (aContainer);
}
/** Add this object as event listener at the broadcasting /** Add this object as event listener at the broadcasting
accessible object. accessible object.
*/ */
......
...@@ -24,13 +24,16 @@ abstract public class ObjectView ...@@ -24,13 +24,16 @@ abstract public class ObjectView
In the ususal case this will be the support of a specific In the ususal case this will be the support of a specific
accessibility interface. accessibility interface.
*/ */
static public ObjectView Create (XAccessibleContext xContext) static public ObjectView Create (
ObjectViewContainer aContainer,
XAccessibleContext xContext)
{ {
return null; return null;
} }
public ObjectView () public ObjectView (ObjectViewContainer aContainer)
{ {
maContainer = aContainer;
mxContext = null; mxContext = null;
} }
...@@ -69,4 +72,6 @@ abstract public class ObjectView ...@@ -69,4 +72,6 @@ abstract public class ObjectView
/// Reference to the current object to display information about. /// Reference to the current object to display information about.
protected XAccessibleContext mxContext; protected XAccessibleContext mxContext;
protected ObjectViewContainer maContainer;
} }
...@@ -6,6 +6,13 @@ import java.awt.GridBagLayout; ...@@ -6,6 +6,13 @@ import java.awt.GridBagLayout;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.Insets; 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.JPanel;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
...@@ -17,13 +24,21 @@ import com.sun.star.accessibility.XAccessibleComponent; ...@@ -17,13 +24,21 @@ import com.sun.star.accessibility.XAccessibleComponent;
import com.sun.star.accessibility.XAccessibleSelection; import com.sun.star.accessibility.XAccessibleSelection;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
public class ObjectViewContainer public class ObjectViewContainer
extends JPanel extends JPanel
{ {
public ObjectViewContainer () public ObjectViewContainer ()
{ {
maViewTemplates = new Vector ();
maViewBorder = BorderFactory.createBevelBorder (BevelBorder.RAISED); maViewBorder = BorderFactory.createBevelBorder (BevelBorder.RAISED);
setLayout (new GridBagLayout ()); 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 ...@@ -42,11 +57,29 @@ public class ObjectViewContainer
removeAll (); removeAll ();
// Add new views. // Add new views.
Add (ContextView.Create(xContext)); for (int i=0; i<maViewTemplates.size(); i++)
Add (StateSetView.Create(xContext)); {
Add (FocusView.Create(xContext)); try
Add (SelectionView.Create(xContext)); {
Add (TextView.Create(xContext)); 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 (); UpdateLayoutManager ();
...@@ -59,12 +92,29 @@ public class ObjectViewContainer ...@@ -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. /** Add an object view and place it below all previously added views.
@param aView @param aView
This argument may be null. In this case nothing happens. This argument may be null. In this case nothing happens.
*/ */
public void Add (ObjectView aView) private void Add (ObjectView aView)
{ {
if (aView != null) if (aView != null)
{ {
...@@ -97,15 +147,20 @@ public class ObjectViewContainer ...@@ -97,15 +147,20 @@ public class ObjectViewContainer
private void UpdateLayoutManager () private void UpdateLayoutManager ()
{ {
// Adapt the layout manager. // Adapt the layout manager.
Component aComponent = getComponent (getComponentCount()-1); if (getComponentCount() > 0)
GridBagLayout aLayout = (GridBagLayout)getLayout(); {
GridBagConstraints aConstraints = aLayout.getConstraints (aComponent); Component aComponent = getComponent (getComponentCount()-1);
aConstraints.weighty = 1; GridBagLayout aLayout = (GridBagLayout)getLayout();
aLayout.setConstraints (aComponent, aConstraints); GridBagConstraints aConstraints = aLayout.getConstraints (aComponent);
aConstraints.weighty = 1;
aLayout.setConstraints (aComponent, aConstraints);
}
} }
/// Observe this tree for selection changes and notify them to all /// Observe this tree for selection changes and notify them to all
/// children. /// children.
private JTree maTree; private JTree maTree;
private Border maViewBorder; private Border maViewBorder;
/// List of view templates which are instantiated when new object is set.
private Vector maViewTemplates;
} }
...@@ -36,21 +36,103 @@ public class StateSetView ...@@ -36,21 +36,103 @@ public class StateSetView
/** Create a FocusView when the given object supports the /** Create a FocusView when the given object supports the
XAccessibleComponent interface. XAccessibleComponent interface.
*/ */
static public ObjectView Create (XAccessibleContext xContext) static public ObjectView Create (
ObjectViewContainer aContainer,
XAccessibleContext xContext)
{ {
ObjectView aView = null;
if (xContext != 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 else
return null; return null;
} }
public StateSetView () public StateSetAllView (ObjectViewContainer aContainer)
{ {
maStates = null; super (aContainer);
mnViewMode = SHOW_ALL_STATES;
setPreferredSize (new Dimension(300,90)); setPreferredSize (new Dimension(300,90));
setMinimumSize (new Dimension(200,80)); setMinimumSize (new Dimension(200,80));
addMouseListener (this);
} }
public void paintChildren (Graphics g) public void paintChildren (Graphics g)
...@@ -68,43 +150,10 @@ public class StateSetView ...@@ -68,43 +150,10 @@ public class StateSetView
aSize.width-aInsets.left-aInsets.right, aSize.width-aInsets.left-aInsets.right,
aSize.height-aInsets.top-aInsets.bottom); aSize.height-aInsets.top-aInsets.bottom);
switch (mnViewMode) PaintAllStates ((Graphics2D)g, aWidgetArea);
{
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;
} }
} }
private void PaintSetStates (Graphics2D g, Rectangle aWidgetArea)
{
}
private void PaintAllStates (Graphics2D g, Rectangle aWidgetArea) private void PaintAllStates (Graphics2D g, Rectangle aWidgetArea)
{ {
Color aTextColor = g.getColor(); Color aTextColor = g.getColor();
...@@ -152,58 +201,49 @@ public class StateSetView ...@@ -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) if (xContext != null)
{ return new StateSetSetView (aContainer);
XAccessibleStateSet xStateSet = mxContext.getAccessibleStateSet(); else
if (xStateSet != null) return 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);
}
}
} }
public String GetTitle () public StateSetSetView (ObjectViewContainer aContainer)
{ {
return ("StateSet"); super (aContainer);
}
public void notifyEvent (AccessibleEventObject aEvent) maStates = null;
{ setPreferredSize (new Dimension(300,90));
if (aEvent.EventId == AccessibleEventId.STATE_CHANGED)
Update();
} }
public void mouseClicked(MouseEvent e)
synchronized public void Update ()
{ {
switch (mnViewMode) XAccessibleStateSet xStateSet = mxContext.getAccessibleStateSet();
if (xStateSet != null)
{ {
case SHOW_SET_STATES : String sStates = new String ();
SetViewMode (SHOW_ALL_STATES); short aStates[] = xStateSet.getStates();
break; for (int i=0; i<aStates.length; i++)
case SHOW_ALL_STATES : {
SetViewMode (SHOW_SET_STATES); if (i > 0)
break; 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 JLabel maStates;
private int mnViewMode; }
private final int SHOW_SET_STATES = 0;
private final int SHOW_ALL_STATES = 1;
} }
...@@ -23,19 +23,23 @@ public class TextView ...@@ -23,19 +23,23 @@ public class TextView
/** Create a TextView when the given object supports the /** Create a TextView when the given object supports the
XAccessibleText interface. XAccessibleText interface.
*/ */
static public ObjectView Create (XAccessibleContext xContext) static public ObjectView Create (
ObjectViewContainer aContainer,
XAccessibleContext xContext)
{ {
XAccessibleText xText = (XAccessibleText)UnoRuntime.queryInterface( XAccessibleText xText = (XAccessibleText)UnoRuntime.queryInterface(
XAccessibleText.class, xContext); XAccessibleText.class, xContext);
if (xText != null) if (xText != null)
return new TextView(); return new TextView (aContainer);
else else
return null; return null;
} }
public TextView () public TextView (ObjectViewContainer aContainer)
{ {
super (aContainer);
setLayout (new GridBagLayout()); setLayout (new GridBagLayout());
GridBagConstraints aConstraints = new GridBagConstraints (); GridBagConstraints aConstraints = new GridBagConstraints ();
......
...@@ -33,8 +33,8 @@ JAVA_FILES = \ ...@@ -33,8 +33,8 @@ JAVA_FILES = \
ov/ContextView.java \ ov/ContextView.java \
ov/FocusView.java \ ov/FocusView.java \
ov/SelectionView.java \ ov/SelectionView.java \
ov/StateSetView.java \
ov/TextView.java ov/TextView.java
# ov/StateSetView.java \
JAVA_CLASSPATHS := \ JAVA_CLASSPATHS := \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment