Kaydet (Commit) 35f8d6af authored tarafından Noel Grandin's avatar Noel Grandin

java: remove unnecessary reflection in toolkit tests

and delete a dead class

Change-Id: I7822ecff670d6036d0cf35f4b2d299b738f9061b
üst 43cc8ad3
......@@ -37,18 +37,6 @@ import com.sun.star.accessibility.XAccessibleContext;
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;
......
......@@ -22,8 +22,6 @@ import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import javax.swing.BorderFactory;
......@@ -37,20 +35,38 @@ import com.sun.star.accessibility.XAccessibleContext;
public class ObjectViewContainer
extends JPanel
{
private static interface IViewFactory {
ObjectView Create (
ObjectViewContainer aContainer,
XAccessibleContext xContext);
}
public ObjectViewContainer ()
{
maViewTemplates = new ArrayList<Class> ();
maViewTemplates = new ArrayList<IViewFactory>();
maViewBorder = BorderFactory.createBevelBorder (BevelBorder.RAISED);
setLayout (new GridBagLayout ());
System.out.println ("ObjectViewContainer");
RegisterView (ContextView.class);
RegisterView (FocusView.class);
RegisterView (TextView.class);
maViewTemplates.add(new IViewFactory() {
public ObjectView Create(ObjectViewContainer aContainer,
XAccessibleContext xContext) {
return ContextView.Create(aContainer, xContext);
}
});
maViewTemplates.add(new IViewFactory() {
public ObjectView Create(ObjectViewContainer aContainer,
XAccessibleContext xContext) {
return FocusView.Create(aContainer, xContext);
}
});
maViewTemplates.add(new IViewFactory() {
public ObjectView Create(ObjectViewContainer aContainer,
XAccessibleContext xContext) {
return TextView.Create(aContainer, xContext);
}
});
}
/** Remove all existing views and create new ones according to the
interfaces supported by the given object.
*/
......@@ -67,26 +83,9 @@ public class ObjectViewContainer
// Add new views.
for (int i=0; i<maViewTemplates.size(); i++)
{
try
{
Class<?> aViewClass = maViewTemplates.get(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);}
IViewFactory aViewFactory = maViewTemplates.get(i);
ObjectView aView = aViewFactory.Create(this, xContext);
Add (aView);
}
UpdateLayoutManager ();
......@@ -100,24 +99,6 @@ public class ObjectViewContainer
}
/** Add the given class to the list of classes which will be
instantiated the next time an accessible object is set.
*/
private void RegisterView (Class aObjectViewClass)
{
System.out.println ("registering " + aObjectViewClass);
maViewTemplates.add(aObjectViewClass);
}
/** Replace one view class with another.
*/
public void ReplaceView (Class aObjectViewClass, Class aSubstitution)
{
int nIndex = maViewTemplates.indexOf (aObjectViewClass);
if (nIndex >= 0)
maViewTemplates.set (nIndex, aSubstitution);
}
/** Add an object view and place it below all previously added views.
@param aView
This argument may be null. In this case nothing happens.
......@@ -167,5 +148,5 @@ public class ObjectViewContainer
private final Border maViewBorder;
/// List of view templates which are instantiated when new object is set.
private final ArrayList<Class> maViewTemplates;
private final ArrayList<IViewFactory> maViewTemplates;
}
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package ov;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import javax.swing.JLabel;
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 tools.NameProvider;
public class StateSetView
extends ListeningObjectView
implements MouseListener
{
/** 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)
if (mnViewMode == SHOW_ALL_STATES)
aView = StateSetAllView.Create (aContainer, xContext);
else
aView = StateSetSetView.Create (aContainer, xContext);
return aView;
}
private 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;
}
maContainer.SetObject (mxContext);
}
@Override
public String GetTitle ()
{
return ("StateSet");
}
@Override
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 final static int SHOW_SET_STATES = 0;
private final static int SHOW_ALL_STATES = 1;
private static int mnViewMode = SHOW_ALL_STATES;
private static 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;
}
private StateSetAllView (ObjectViewContainer aContainer)
{
super (aContainer);
setPreferredSize (new Dimension(300,90));
setMinimumSize (new Dimension(200,80));
}
@Override
public void paintChildren (Graphics g)
{
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.getAccessibleStateSet();
if (xStateSet != null)
{
final int nMaxStateIndex = AccessibleStateType.MANAGES_DESCENDANTS;
int nStateWidth = (aWidgetArea.width-12) / (nMaxStateIndex+1);
AffineTransform aTransform = g.getTransform ();
g.setColor (aTextColor);
int y = aWidgetArea.y+aWidgetArea.height - 12;
double nTextRotation = -0.9;//-Math.PI/2;
double nScale = 0.6;
// Create a shape for the boxes.
int nBoxWidth = nStateWidth-2;
if (nBoxWidth > 8)
nBoxWidth = 8;
Rectangle aCheckBox = new Rectangle (-nBoxWidth/2,0,nBoxWidth,nBoxWidth);
for (short i=0; i<=nMaxStateIndex; i++)
{
int x = nStateWidth + i * nStateWidth;
String sStateName = NameProvider.getStateName (i);
boolean bStateSet = xStateSet.contains (i);
g.setTransform (aTransform);
g.translate (x,y);
if (bStateSet)
{
g.setColor (Color.GREEN);
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);
}
}
}
}
private static class StateSetSetView
extends StateSetView
{
static public ObjectView Create (
ObjectViewContainer aContainer,
XAccessibleContext xContext)
{
if (xContext != null)
return new StateSetSetView (aContainer);
else
return null;
}
private StateSetSetView (ObjectViewContainer aContainer)
{
super (aContainer);
maStates = null;
setPreferredSize (new Dimension(300,90));
}
@Override
synchronized public void Update ()
{
XAccessibleStateSet xStateSet = mxContext.getAccessibleStateSet();
if (xStateSet != null)
{
String sStates = "";
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);
}
}
private final JLabel maStates;
}
}
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