|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
edu.mines.jtk.mosaic.IPanel
public class IPanel
A panel that can paint itself to fit an image. Some components in this package, such as mosaics, tiles, and tile axes, must be able to render themselves to images as well as on screen. For various reasons, those images often have resolution that is higher than that of a display screen. Simply scaling an on-screen rendering does not exploit this higher resolution, because screen coordinates are typically specified as integers. Rounding to the nearest integer screen coordinates and then scaling to a high resolution image yields visual artifacts, such as curves that appear jagged in the image.
Classes that extend this base class work differently. They paint themselves to fit any specified rectangle of a specified graphics context. When painting to a display screen, that graphics rectangle is simply the panel's rectangle, in screen coordinates. However, when painting to an image, the dimensions of that rectangle may be much larger, corresponding to the higher resolution of the image. When painting, these panels round coordinates to the nearest pixel of that graphics rectangle, not the panel's on-screen rectangle. In this way, panels can paint themselves with any desired resolution.
One complication is font size. Another is line width. Such properties are typically specified in points, which are roughly equivalant to on-screen pixels. Therefore, when drawing to a high-resolution image, font sizes and line widths must be increased. This base class provides methods that panels in this package use to properly scale font sizes, line widths, and other resolution-dependent properties.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JPanel |
|---|
javax.swing.JPanel.AccessibleJPanel |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
java.awt.Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
IPanel()
|
|
| Method Summary | |
|---|---|
protected double |
computeScale(int w,
int h)
Returns a scale factor for painting this panel to fit a rectangle. |
protected java.awt.Graphics2D |
createGraphics(java.awt.Graphics2D g2d,
int x,
int y,
int w,
int h)
Creates a graphics context for the specified graphics rectangle. |
protected float |
getLineWidth(java.awt.Graphics2D g2d)
Gets the line width for the specified graphics context. |
void |
paintToImage(java.awt.image.BufferedImage image)
Paints this panel to fit the specified image. |
java.awt.image.BufferedImage |
paintToImage(int width)
Paints this panel to fit a new image with specified width in pixels. |
void |
paintToPng(double dpi,
double win,
java.lang.String fileName)
Paints this panel to a PNG image with specified resolution and width. |
void |
paintToRect(java.awt.Graphics2D g2d,
int x,
int y,
int w,
int h)
Paints this panel to a specified rectangle of a graphics context. |
protected void |
scaleLineWidth(java.awt.Graphics2D g2d,
double scale)
Scales the line width for the specified graphics context. |
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class javax.swing.JComponent |
|---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, 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, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
| Methods inherited from class java.awt.Container |
|---|
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, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
| Methods inherited from class java.awt.Component |
|---|
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, 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, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, 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, transferFocusUpCycle |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public IPanel()
| Method Detail |
|---|
public void paintToRect(java.awt.Graphics2D g2d,
int x,
int y,
int w,
int h)
Classes that extend this base class typically override this method to draw something besides children of this panel. When appropriate, those extensions may also call this method.
g2d - the graphics context.x - the x-coordinate of the graphics rectangle.y - the y-coordinate of the graphics rectangle.w - the width of the graphics rectangle.h - the height of the graphics rectangle.public void paintToImage(java.awt.image.BufferedImage image)
image - the image.public java.awt.image.BufferedImage paintToImage(int width)
width - the image width, in pixels.
public void paintToPng(double dpi,
double win,
java.lang.String fileName)
throws java.io.IOException
dpi - the image resolution, in dots per inch.win - the image width, in inches.fileName - the name of the file to contain the PNG image.
java.io.IOException
protected double computeScale(int w,
int h)
w - the rectangle width.h - the rectangle height.
protected java.awt.Graphics2D createGraphics(java.awt.Graphics2D g2d,
int x,
int y,
int w,
int h)
Classes that extend this base class typically call this method in
their implementation of
paintToRect(java.awt.Graphics2D,int,int,int,int).
When painting to a high-resolution image, this method makes lines
and text appear as they would on screen, neither too thin nor too
small.
When the returned graphics context is no longer needed, it should be disposed.
g2d - the graphics context.x - the x-coordinate of the graphics rectangle.y - the y-coordinate of the graphics rectangle.w - the width of the graphics rectangle.h - the height of the graphics rectangle.protected float getLineWidth(java.awt.Graphics2D g2d)
g2d - the graphics context.
protected void scaleLineWidth(java.awt.Graphics2D g2d,
double scale)
createGraphics(java.awt.Graphics2D,int,int,int,int).
g2d - the graphics context.scale - the scale factor.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||