Package ca.cgjennings.ui
Class JIconDrop
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JLabel
-
- ca.cgjennings.ui.JIconDrop
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible,javax.swing.SwingConstants
public class JIconDrop extends javax.swing.JLabelA box to drop image files on in order to fetch the image or image file. The selected image can be changed by callingsetFile(java.io.File)orsetImage(java.awt.image.BufferedImage). Changes to the selected image can be detected by registering a property change listener and listening for changes to the propertySELECTED_IMAGE_CHANGED_PROPERTY.- Since:
- 3.0
- Author:
- Chris Jennings
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSELECTED_IMAGE_CHANGED_PROPERTY-
Fields inherited from class javax.swing.JComponent
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
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
-
Constructor Summary
Constructors Constructor Description JIconDrop()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.swing.IconcreateIconForImage()java.awt.ColorgetBackColor()Returns the background paint, if it is a color.java.awt.PaintgetBackgroundPaint()java.io.FilegetFile()Returns the file that was the source of the current image, ornullif no image is set or if the image did not come from a file.intgetIdealDropBoxSize()java.awt.image.BufferedImagegetImage()Returns the currently selected image, ornullif no image is selected.java.awt.image.BufferedImagegetImageAtSize(int size)java.awt.image.BufferedImagegetImageAtSize(int width, int height)protected voidpaintComponent(java.awt.Graphics g1)voidsetBackground(java.awt.Color c)This call is rerouted tosetBackgroundPaint(java.awt.Paint).voidsetBackgroundPaint(java.awt.Paint p)Sets the paint used to draw the backdrop behind the image.voidsetFile(java.io.File file)Sets the current image by loading it from a file.voidsetIdealDropBoxSize(int idealSize)voidsetImage(java.awt.image.BufferedImage image)Sets the selected image, or clears the selection if the image isnull.-
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, 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, 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, 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, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
SELECTED_IMAGE_CHANGED_PROPERTY
public static final java.lang.String SELECTED_IMAGE_CHANGED_PROPERTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
paintComponent
protected void paintComponent(java.awt.Graphics g1)
- Overrides:
paintComponentin classjavax.swing.JComponent
-
setBackgroundPaint
public void setBackgroundPaint(java.awt.Paint p)
Sets the paint used to draw the backdrop behind the image. Ifnull, a default paint will be used.- Parameters:
p-
-
getBackgroundPaint
public java.awt.Paint getBackgroundPaint()
-
setBackground
public void setBackground(java.awt.Color c)
This call is rerouted tosetBackgroundPaint(java.awt.Paint).- Overrides:
setBackgroundin classjavax.swing.JComponent- Parameters:
c- the background color to set
-
getBackColor
public java.awt.Color getBackColor()
Returns the background paint, if it is a color. Otherwise, returns the background color of the parent. It is preferable to callgetBackgroundPaint()instead.- Returns:
- the background paint, if a color, or the parent's background
-
getFile
public java.io.File getFile()
Returns the file that was the source of the current image, ornullif no image is set or if the image did not come from a file.- Returns:
- the file that the current image came from, or
null
-
setFile
public void setFile(java.io.File file)
Sets the current image by loading it from a file.- Parameters:
file- the file containing the selected image
-
getImage
public java.awt.image.BufferedImage getImage()
Returns the currently selected image, ornullif no image is selected.- Returns:
- the selected image
-
setImage
public void setImage(java.awt.image.BufferedImage image)
Sets the selected image, or clears the selection if the image isnull. Setting the image directly will also set the current file tonull. Ifimageis not in an integer RGB format, the component will create a copy of the image in such a format, using the converted image in place of the original.- Parameters:
image- the image to select
-
createIconForImage
protected javax.swing.Icon createIconForImage()
-
getIdealDropBoxSize
public int getIdealDropBoxSize()
-
setIdealDropBoxSize
public void setIdealDropBoxSize(int idealSize)
-
getImageAtSize
public java.awt.image.BufferedImage getImageAtSize(int size)
-
getImageAtSize
public java.awt.image.BufferedImage getImageAtSize(int width, int height)
-
-