public class IPanel
extends javax.swing.JPanel
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.
javax.swing.JPanel.AccessibleJPanel
javax.swing.JComponent.AccessibleJComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
IPanel() |
Modifier and Type | Method and Description |
---|---|
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.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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
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, 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, 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, transferFocusBackward, transferFocusUpCycle
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.