/** This canvas displays accessible objects graphically. Each accessible objectwithgraphicalrepresentationisrepresentedbyan CanvasShapeobjectandhastobeaddedbythe <member>addAccessible</member>memberfunction.
<p>ThecanvaslistenstoselectioneventsoftheassociatedJTreeand highlightsthefirstselectednodeofthattree.</p>
*/ class Canvas extends JPanel implements MouseListener, MouseMotionListener, TreeSelectionListener//, Scrollable
{ // This constant can be passed to SetZoomMode to always show the whole screen. publicstaticfinalint WHOLE_SCREEN = -1;
public Canvas ()
{ super (true);
maObjects = new java.util.HashMap<AccTreeNode, CanvasShape> ();
maNodes = new ArrayList<AccTreeNode> ();
maObjectList = new ArrayList<CanvasShape> ();
addMouseListener (this);
addMouseMotionListener (this);
maBoundingBox = new Rectangle (0,0,100,100);
maTree = null;
mnHOffset = 0;
mnVOffset = 0;
mnScale = 1;
setShowText(false);
setShowDescriptions (true);
setShowNames (true);
setAntialiasing (true);
}
/** Tell the canvas which tree view to use to highlight accessible objects.
*/ publicvoid setTree (JTree aTree)
{ if (maTree != null)
maTree.removeTreeSelectionListener (this);
maTree = aTree; if (maTree != null)
maTree.addTreeSelectionListener (this);
}
// Draw the screen representation to give a hint of the location of the // accessible object on the screen.
Dimension aScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle2D.Double aScreen = new Rectangle2D.Double (
mnHOffset,
mnVOffset,
mnScale*aScreenSize.getWidth(),
mnScale*aScreenSize.getHeight()); // Fill the screen rectangle and draw a frame around it to increase its visibility.
g2.setColor (new Color (250,240,230));
g2.fill (aScreen);
g2.setColor (Color.BLACK);
g2.draw (aScreen);
// Paint highlighted frame around active object as the last thing. if (maActiveObject != null)
maActiveObject.paint_highlight (
g2);
}
}
/** Set up the transformation so that the graphical display can show a centeredrepresentationofthewholescreen.
*/ privatevoid setupTransformation ()
{ // Turn off scrollbars when showing the whole screen. Otherwise show them when needed.
JViewport aViewport = (JViewport)getParent();
JScrollPane aScrollPane = (JScrollPane)aViewport.getParent(); int nZoomMode = getZoomMode(); if (nZoomMode == WHOLE_SCREEN)
{ if (aScrollPane.getHorizontalScrollBarPolicy()
!= JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)
aScrollPane.setHorizontalScrollBarPolicy (JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); if (aScrollPane.getVerticalScrollBarPolicy()
!= JScrollPane.VERTICAL_SCROLLBAR_NEVER)
aScrollPane.setVerticalScrollBarPolicy (JScrollPane.VERTICAL_SCROLLBAR_NEVER);
} else
{ if (aScrollPane.getHorizontalScrollBarPolicy()
!= JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)
aScrollPane.setHorizontalScrollBarPolicy (JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); if (aScrollPane.getVerticalScrollBarPolicy()
!= JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED)
aScrollPane.setVerticalScrollBarPolicy (JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
}
Dimension aScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension aWidgetSize = aViewport.getSize();
{ if ((aScreenSize.getWidth() > 0) && (aScreenSize.getHeight() > 0))
{ if (nZoomMode == WHOLE_SCREEN)
{ // Calculate the scales that would map the screen onto the // widget in both of the coordinate axes and select the // smaller // of the two: it maps the screen onto the widget in both // axes at the same time. double nHScale = (aWidgetSize.getWidth() - 10) / aScreenSize.getWidth(); double nVScale = (aWidgetSize.getHeight() - 10) / aScreenSize.getHeight(); if (nHScale < nVScale)
mnScale = nHScale; else
mnScale = nVScale;
} else
{
mnScale = nZoomMode / 100.0;
}
// Calculate offsets that center the scaled screen inside the widget.
mnHOffset = (aWidgetSize.getWidth() - mnScale*aScreenSize.getWidth()) / 2.0;
mnVOffset = (aWidgetSize.getHeight() - mnScale*aScreenSize.getHeight()) / 2.0; if (mnHOffset < 0)
mnHOffset = 0; if (mnVOffset < 0)
mnVOffset = 0;
setPreferredSize (new Dimension (
(int)(2*mnHOffset + mnScale * aScreenSize.getWidth()),
(int)(2*mnVOffset + mnScale * aScreenSize.getHeight())));
revalidate ();
} else
{ // In case of a degenerate (not yet initialized?) screen size // use some meaningless default values.
mnScale = 1;
mnHOffset = 0;
mnVOffset = 0;
}
}
}
/** Call getAccessibleAt to determine accessible object under mouse.
*/ publicvoid mouseClicked (MouseEvent e)
{
}
/** Called when the selection of the tree changes. Highlight the correspondinggraphicalrepresentationofthefirstselectedobject.
*/ publicvoid valueChanged (javax.swing.event.TreeSelectionEvent event)
{
TreePath aPath = event.getPath();
Object aObject = aPath.getLastPathComponent(); if (aObject instanceof AccTreeNode)
{
CanvasShape aCanvasShape = maObjects.get (aObject); if (highlightObject (aCanvasShape))
repaint();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.