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)$/
# 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
......
......@@ -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: ");
......
......@@ -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 ();
......
......@@ -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.
*/
......
......@@ -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;
}
......@@ -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;
}
......@@ -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;
}
}
......@@ -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 ();
......
......@@ -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 := \
......
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