|
||||||||||
| 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
net.luniks.jtvd.ImagePanel
This class provides the drawing area used to design the menu. It can have a plain color or an image as background and text items that can be selected and moved around with the arrow keys or by dragging them with the mouse. Any of these items have individual properties such as colors and font style. This class also provides methods to generate the background, highlight and select images for the menu.
| Nested Class Summary | |
(package private) class |
ImagePanel.Item
This class provides a text item that can be drawn on for example a JPanel and selected and moved around with the arrow keys or by dragging it with the mouse. |
(package private) class |
ImagePanel.MenuItem
This class is a special type of Item that can draw a shape
or change its text color when it is clicked or "mouseovered".
|
| Nested classes inherited from class javax.swing.JPanel |
javax.swing.JPanel.AccessibleJPanel |
| Nested classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary | |
private java.awt.Color |
backgroundColor
|
private java.awt.image.BufferedImage |
backgroundImage
|
private java.awt.Rectangle |
borderRect
|
private java.awt.BasicStroke |
borderStroke
|
static java.lang.String |
EFFECT_NONE
|
static java.lang.String |
EFFECT_SHAPE
|
static java.lang.String |
EFFECT_TEXT
|
private java.lang.String |
highlightEffect
|
static int |
IMAGE_BACKGROUND
|
static int |
IMAGE_HIGHLIGHT
|
static int |
IMAGE_SELECT
|
private java.util.ArrayList |
items
|
private java.awt.image.BufferedImage |
scaledBackgroundImage
|
private java.lang.String |
selectEffect
|
private boolean |
showBackgroundImage
|
| Fields inherited from class javax.swing.JPanel |
|
| 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.Container |
|
| 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 | |
ImagePanel()
Sets the background color to white and focusable to true |
|
| Method Summary | |
void |
addItem(ImagePanel.Item item)
Adds the item given as argument to the drawing and draws it which implicitly makes it calculate its bounds. |
void |
arrangeMenuItems()
Arranges all items of type MenuItem in columns.
|
void |
check()
Performs some checks to (try to) ensure that the menu will work, such as: - If the menu contains no menu items at all - If no menu effect has been assigned - If menu items are (partially) outside the menu - If menu items are too close to each other If one of these checks fails, an exception with a descriptive message is thrown. |
void |
deleteItem(ImagePanel.Item item)
Removes the item given as argument from the drawing, deletes it and repaints the drawing. |
java.awt.Color |
getBackgroundColor()
Returns the current background color |
java.awt.image.IndexColorModel |
getColorModel(java.util.Set colors,
int max)
Returns an instance of IndexColorModel with a colormap
created from the Set of colors given as argument. |
java.lang.String |
getHighlightEffect()
Returns the type of effect used for highlighting menu buttons |
java.awt.image.BufferedImage |
getImage(int type,
int width,
int height)
Returns a BufferedImage created from the drawing of the type
given as argument type with the size given as arguments
width and height.
|
ImagePanel.Item[] |
getItems()
Returns all items of the drawing |
ImagePanel.MenuItem[] |
getMenuItems()
Returns all items of type MenuItem of the drawing |
ImagePanel.Item[] |
getSelectedItems()
Returns all items of the drawing which are currently selected |
java.lang.String |
getSelectEffect()
Returns the type of effect used for selecting menu buttons |
boolean |
getShowBackgroundImage()
Returns true if the background image is shown or not |
void |
paintComponent(java.awt.Graphics g)
Draws the background and items |
void |
removeAllMenuItems()
Removes all items of type MenuItem from the drawing
and repaints it. |
java.awt.image.BufferedImage |
scale(java.awt.image.BufferedImage image,
int width,
int height)
Scales the BufferedImage given as first argument to the size given as the remaining arguments. |
void |
setBackgroundColor(java.awt.Color color)
Sets the background color and repaints the drawing |
void |
setBackgroundImage(java.awt.image.BufferedImage image)
Sets the image given as argument as background image, scales it and repaints the drawing |
void |
setHighlightEffect(java.lang.String effect)
Sets the type of effect used for highlighting menu buttons and repaints the drawing. |
void |
setPanelSize(java.awt.Dimension size)
Sets the size of the drawing to the dimensions given as argument and scales the background image to this size |
void |
setSelectEffect(java.lang.String effect)
Sets the type of effect used for selecting menu buttons and repaints the drawing. |
void |
setShowBackgroundImage(boolean show)
Sets if the background image should be shown or not and repaints the drawing |
void |
validateItemLocations()
Calls validateLocation() on each item to make
sure that no item's location is outside the drawing area |
| Methods inherited from class javax.swing.JPanel |
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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 |
| Field Detail |
public static final int IMAGE_BACKGROUND
public static final int IMAGE_HIGHLIGHT
public static final int IMAGE_SELECT
public static final java.lang.String EFFECT_SHAPE
public static final java.lang.String EFFECT_TEXT
public static final java.lang.String EFFECT_NONE
private java.awt.image.BufferedImage backgroundImage
private java.awt.image.BufferedImage scaledBackgroundImage
private java.awt.Color backgroundColor
private boolean showBackgroundImage
private java.lang.String highlightEffect
private java.lang.String selectEffect
private java.util.ArrayList items
private java.awt.Rectangle borderRect
private java.awt.BasicStroke borderStroke
| Constructor Detail |
public ImagePanel()
| Method Detail |
public boolean getShowBackgroundImage()
public java.awt.Color getBackgroundColor()
public java.lang.String getHighlightEffect()
public java.lang.String getSelectEffect()
public void addItem(ImagePanel.Item item)
item - the item to be added to the drawingpublic void deleteItem(ImagePanel.Item item)
item - the item to be removed from the drawingpublic void removeAllMenuItems()
MenuItem from the drawing
and repaints it. Unregisteres all items as Mouse-, MouseMotion-
and KeyListener.
public ImagePanel.Item[] getItems()
public ImagePanel.MenuItem[] getMenuItems()
MenuItem of the drawing
public ImagePanel.Item[] getSelectedItems()
public void arrangeMenuItems()
MenuItem in columns.
This is probably a very clumsy implementation, if somebody could
show me how to do this a bit smarter I would be grateful.
public void validateItemLocations()
validateLocation() on each item to make
sure that no item's location is outside the drawing area
public void setPanelSize(java.awt.Dimension size)
size - the new size of the drawingpublic void setBackgroundImage(java.awt.image.BufferedImage image)
image - the new background imagepublic void setShowBackgroundImage(boolean show)
show - the background image or notpublic void setBackgroundColor(java.awt.Color color)
color - the new background colorpublic void setHighlightEffect(java.lang.String effect)
effect - for highlightingpublic void setSelectEffect(java.lang.String effect)
effect - for selecting
public java.awt.image.BufferedImage scale(java.awt.image.BufferedImage image,
int width,
int height)
Image.getScaledInstance
with Image.SCALE_AREA_AVERAGING as hint. This gives a
nicer quality than AffineTransformOp.filter with
TYPE_BILINEAR.
image - the image to be scaledwidth - the width to be scaled toheight - the height to be scaled to
public java.awt.image.IndexColorModel getColorModel(java.util.Set colors,
int max)
IndexColorModel with a colormap
created from the Set of colors given as argument. The
colormap includes transparency (color black with an alpha component
of 0) and the first max - 1 colors from the set.
public java.awt.image.BufferedImage getImage(int type,
int width,
int height)
throws java.lang.Exception
BufferedImage created from the drawing of the type
given as argument type with the size given as arguments
width and height.
Possible types are IMAGE_BACKGROUND, IMAGE_HIGHLIGHT
and IMAGE_SELECT
java.lang.Exceptionpublic void paintComponent(java.awt.Graphics g)
public void check()
throws java.lang.Exception
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||