public class JCanvas
extends javax.swing.JComponent
implements java.awt.print.Printable
This architecture allows a graphics developer to write code for a pane and a set of layers, without being concerned about whether the pane and its layers will be directly contained by a JCanvas or within some other layer. For example, it will be possible for a visualization component to be "embedded" in a larger component.
javax.swing.JComponent.AccessibleJComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
JCanvas()
Create a new canvas that contains a single GraphicsPane.
|
JCanvas(CanvasPane pane)
Create a new canvas that contains the given CanvasPane.
|
Modifier and Type | Method and Description |
---|---|
void |
exportImage(java.io.OutputStream out,
java.lang.String formatName)
Export an image of the contents of this canvas
to the specified stream.
|
CanvasPane |
getCanvasPane()
Get the canvas pane contained by this component.
|
javax.swing.BoundedRangeModel |
getHorizontalRangeModel()
Return the horizontal range model for this canvas.
|
java.lang.String |
getToolTipText(java.awt.event.MouseEvent e)
Get the toolTipText for the point in the given MouseEvent.
|
javax.swing.BoundedRangeModel |
getVerticalRangeModel()
Return the vertical range model for this canvas.
|
java.awt.geom.Rectangle2D |
getViewSize()
Return the total size of everything in the canvas, in canvas
coordinates.
|
java.awt.geom.Rectangle2D |
getVisibleSize()
Return the size of the visible part of the canvas, in canvas
coordinates.
|
boolean |
isFocusTraversable()
Return whether or not focus should be traversable across this object.
|
void |
paint(java.awt.Graphics g)
Paint the canvas.
|
int |
print(java.awt.Graphics graphics,
java.awt.print.PageFormat format,
int index)
Print the canvas to a printer, represented by the specified graphics
object.
|
int |
print(java.awt.Graphics graphics,
java.awt.print.PageFormat format,
int index,
java.awt.geom.Rectangle2D printRegion)
Print the canvas to a printer, represented by the specified graphics
object.
|
protected void |
processMouseEvent(java.awt.event.MouseEvent e)
Process a mouse event.
|
protected void |
processMouseMotionEvent(java.awt.event.MouseEvent e)
Process a mouse motion event.
|
void |
repaint(DamageRegion d)
Accept notification that a repaint has occurred on
in this canvas.
|
void |
setCanvasPane(CanvasPane pane)
Set the canvas pane contained by this JCanvas.
|
void |
setDoubleBuffered(boolean flag)
Turn double-buffering on this canvas on or off.
|
void |
setPreferredSize(java.awt.Dimension d)
Set the preferred size of this JCanvas.
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public JCanvas()
public JCanvas(CanvasPane pane)
pane
- The given CanvasPanepublic void exportImage(java.io.OutputStream out, java.lang.String formatName) throws java.awt.print.PrinterException, java.io.IOException
out
- The output stream to write to.formatName
- The format name (such as "gif" or "png").java.awt.print.PrinterException
- If printing to graphics object fails.java.io.IOException
- If conversion to the specified format fails or is not supportedpublic final CanvasPane getCanvasPane()
public java.lang.String getToolTipText(java.awt.event.MouseEvent e)
getToolTipText
in class javax.swing.JComponent
public boolean isFocusTraversable()
isFocusTraversable
in class java.awt.Component
public void paint(java.awt.Graphics g)
This method allocates an offscreen buffer if necessary, and then paints the canvas into the right buffer and blits it to the on-screen buffer.
Acknowledgment: some of this code was adapted from code posted by Jonathon Knudsen to the Java2D mailing list, May 1998.
paint
in class javax.swing.JComponent
public int print(java.awt.Graphics graphics, java.awt.print.PageFormat format, int index) throws java.awt.print.PrinterException
print
in interface java.awt.print.Printable
graphics
- The context into which the page is drawn.format
- The size and orientation of the page being drawn.index
- The zero based index of the page to be drawn.java.awt.print.PrinterException
- If the print job is terminated.public int print(java.awt.Graphics graphics, java.awt.print.PageFormat format, int index, java.awt.geom.Rectangle2D printRegion) throws java.awt.print.PrinterException
graphics
- The context into which the page is drawn.format
- The size and orientation of the page being drawn.index
- The zero based index of the page to be drawn.printRegion
- The rectangular region of the canvas, in screen
coordinates, that will be printed to the screen.java.awt.print.PrinterException
- If the print job is terminated.public void repaint(DamageRegion d)
d
- The damage region.public final void setCanvasPane(CanvasPane pane)
pane
- The canvas pane.public void setDoubleBuffered(boolean flag)
setDoubleBuffered
in class javax.swing.JComponent
public void setPreferredSize(java.awt.Dimension d)
setPreferredSize
in class javax.swing.JComponent
public javax.swing.BoundedRangeModel getHorizontalRangeModel()
public javax.swing.BoundedRangeModel getVerticalRangeModel()
public java.awt.geom.Rectangle2D getViewSize()
public java.awt.geom.Rectangle2D getVisibleSize()
protected void processMouseEvent(java.awt.event.MouseEvent e)
processMouseEvent
in class javax.swing.JComponent
protected void processMouseMotionEvent(java.awt.event.MouseEvent e)
processMouseMotionEvent
in class javax.swing.JComponent