java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.jorigin.swing.thumbnail.JThumbnailPanel<T>
- Type Parameters:
T- the type enclosed by the thumbnails of the list.
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
A panel dedicated to
thumbnail display.
This object works like a JList but enable more flexibility on the thumbnail interaction.- Since:
- 1.0.8
- Version:
- "1.0.14" - b202111241200L
- Author:
- Julien SEINTURIER - Université de Toulon / CNRS LIS umr 7020 - github.com/jorigin/jcommon (contact@jorigin.org)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JThumbnail<T> The first selected labelprotected ColorColor used for the coloring the background of the label where it's in focus stateprotected EventListenerListListe des ecouteurs informes des evenements du thumbnailprotected booleanThe label loading stateprotected ColorThe item presentation colorprotected intThe label count.protected intThe label height.protected intthe label margin.protected ArrayList<JThumbnail<T>> The label added to the listprotected intThe label width.protected intThe index corresponding to the last selected indexprotected ColorColor used for the coloring the background of the label where it's in standard stateprotected ColorColor used for the coloring the background of the label where it's in selected stateprotected List<JThumbnail<T>> The selected labelsprotected StringThe state description.protected doubleThe thumb ratio.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_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new empty thumbnail panel.JThumbnailPanel(int labelPerLine) Create a new thumbnail panel that display the given number of thumbnail per line. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(JThumbnail<T> label) Add an active label to the thumbnail.voidAdd a Task Listener to this objectvoidAdd an Active Thumbnail Listener to this Active ThumbnailbooleanReturns true if this thumbnail contains the specified element.booleancontains(JThumbnail<T> label) Returns true if this thumbnail contains the specified active label.protected voidFire a task event.protected voidfireThumbnailActivated(JThumbnailPanel<T> panel, JThumbnail<T> thumbnail) Fire a thumbnail activation event.protected voidfireThumbnailAdded(JThumbnailPanel<T> panel, JThumbnail<T> thumbnail) Fire a thumbnail added event.protected voidfireThumbnailEntered(JThumbnailPanel<T> panel, JThumbnail<T> thumbnail) Fire a thumbnail entered event.protected voidfireThumbnailExited(JThumbnailPanel<T> panel, JThumbnail<T> thumbnail) Fire a thumbnail exited event.protected voidfireThumbnailNeedRefresh(JThumbnailPanel<T> panel, JThumbnail<T> thumbnail) Fire a thumbnail refresh needed event.protected voidfireThumbnailRemoved(JThumbnailPanel<T> panel, JThumbnail<T> thumbnail) Fire a thumbnail removed event.protected voidfireThumbnailSelected(JThumbnailPanel<T> panel, List<JThumbnail<T>> thumbnails) Fire a thumbnail selection event.protected voidfireThumbnailSelected(JThumbnailPanel<T> panel, JThumbnail<T> thumbnail) Fire a thumbnail selection event.Get the activated thumbnail.getCellBounds(int index0, int index1) Returns the bounds of the specified range of items in JList coordinates.getLabelContaining(Object content) Get the active label displaying the content object.intGet the number of thumbnails that are attached to this panel.intGet the default height of the thumbnails displayed within this panel.intGet the default margin size of the thumbnails displayed within this panel.intGet the default width of the thumbnails displayed within this panel.intReturns the smallest selected cell index; the selection when only a single item is selected in the list.int[]Returns an array of all of the selected indices, in increasing order.Returns the first selected label, or null if the selection is empty.List<JThumbnail<T>> Returns an array of the labels for the selected cells.Object[]Returns an array of the values for the selected cells.intReturns whether single-item or multiple-item selections are allowed.getState()Get the state of this panel.doubleGet the thumb ratio.intReturns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.intindexOf(JThumbnail<T> label) Returns the index in this list of the first occurrence of the specified active label, or -1 if this list does not contain this active label.booleanGet if this panel is currently loading.protected voidProcess a MouseEvent fired by an active label.voidrefresh()Refresh the thumbnail by refreshing all the activelabels conainedbooleanremove(JThumbnail<T> label) Remove the given thumbnail from this panel.voidRemove a Task Listener from this objectvoidRemove an Active Thumbnail Listener from this Active ThumbnailvoidscrollToIndices(int[] indices) Move view rect to the component assigned the indices given in parameter.voidScroll the view to selected thumbnails.voidMove view rect to the component assigned to selected indices.voidselect(JThumbnail<T> l) Add the label given in parameter to the selected labelsvoidsetLabelCount(int count) Set the number of thumbnails that are attached to this panel.voidsetLabelHeight(int height) Set the default height of the thumbnails displayed within this panel.voidsetLabelMargin(int margin) Set the default margin size of the thumbnails displayed within this panel.voidsetLabelWidth(int width) Set the default width of the thumbnails displayed within this panel.voidsetLoading(boolean b) Set if this panel is currently loading.voidsetSelectedIndex(int index) Selects a single cell.voidsetSelectedIndices(int[] indices) Changes the selection to be the set of indices specified by the given array.voidsetSelectedThumbnail(JThumbnail<T> label, boolean shouldScroll) Selects the specified label in the list.voidsetSelectedValue(Object anObject, boolean shouldScroll) Selects the specified object from the list.voidsetSelectionMode(int selectionMode) Determines whether single-item or multiple-item selections are allowed.voidsetThumbRatio(double thumbRatio) Set the thumb ratio.voidunselect(JThumbnail<T> l) Remove the label given in parameter to the selected labelsvoidUnselect all the selected label.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, 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, updateMethods 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, validateTreeMethods 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, 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, 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 Details
-
labelWidth
protected int labelWidthThe label width. -
labelHeight
protected int labelHeightThe label height. -
thumbRatio
protected double thumbRatioThe thumb ratio. -
labelMargin
protected int labelMarginthe label margin. -
labelCount
protected int labelCountThe label count. -
labels
The label added to the list -
selectedLabels
The selected labels -
lastSelectedIndex
protected int lastSelectedIndexThe index corresponding to the last selected index -
activatedLabel
The first selected label -
isLabelLoading
protected volatile boolean isLabelLoadingThe label loading state -
idListenerList
Liste des ecouteurs informes des evenements du thumbnail -
normalColor
Color used for the coloring the background of the label where it's in standard state -
focusColor
Color used for the coloring the background of the label where it's in focus state -
selectedColor
Color used for the coloring the background of the label where it's in selected state -
itemPResentColor
The item presentation color -
state
The state description.
-
-
Constructor Details
-
JThumbnailPanel
public JThumbnailPanel()Create a new empty thumbnail panel. -
JThumbnailPanel
public JThumbnailPanel(int labelPerLine) Create a new thumbnail panel that display the given number of thumbnail per line.- Parameters:
labelPerLine- the number of thumbnail to display per line.
-
-
Method Details
-
getCellBounds
Returns the bounds of the specified range of items in JList coordinates. Returnsnullif index isn't valid.- Parameters:
index0- the index of the first JList cell in the rangeindex1- the index of the last JList cell in the range- Returns:
- the bounds of the indexed cells in pixels
-
setSelectedIndices
public void setSelectedIndices(int[] indices) Changes the selection to be the set of indices specified by the given array. Indices greater than or equal to the size are ignored.- Parameters:
indices- an array of the indices of the cells to select, non-null
-
getSelectedIndices
public int[] getSelectedIndices()Returns an array of all of the selected indices, in increasing order.- Returns:
- all of the selected indices, in increasing order, or an empty array if nothing is selected
- See Also:
-
getSelectedIndex
public int getSelectedIndex()Returns the smallest selected cell index; the selection when only a single item is selected in the list. When multiple items are selected, it is simply the smallest selected index. Returns -1 if there is no selection.- Returns:
- the smallest selected cell index
- See Also:
-
setSelectedIndex
public void setSelectedIndex(int index) Selects a single cell. Does nothing if the given index is greater than or equal to the model size.- Parameters:
index- the index of the cell to select- See Also:
-
setSelectedValue
Selects the specified object from the list.- Parameters:
anObject- the object to selectshouldScroll- true if the list should scroll to display the selected object, if one exists; otherwise false
-
setSelectedThumbnail
Selects the specified label in the list.- Parameters:
label- the label to selectshouldScroll- true if the list should scroll to display the selected label, if one exists; otherwise false
-
getSelectedThumbnail
Returns the first selected label, or null if the selection is empty.- Returns:
- the first selected label
-
getSelectedThumbnails
Returns an array of the labels for the selected cells. The returned labels are sorted in increasing index order.- Returns:
- the selected labels or an empty list if nothing is selected.
-
getSelectedValues
Returns an array of the values for the selected cells. The returned values are sorted in increasing index order.- Returns:
- the selected values or an empty list if nothing is selected.
-
setSelectionMode
public void setSelectionMode(int selectionMode) Determines whether single-item or multiple-item selections are allowed. The followingselectionModevalues are allowed:-
ListSelectionModel.SINGLE_SELECTIONOnly one list index can be selected at a time. In this mode thesetSelectionIntervalandaddSelectionIntervalmethods are equivalent, and only the second index argument is used. -
ListSelectionModel.SINGLE_INTERVAL_SELECTIONOne contiguous index interval can be selected at a time. In this modesetSelectionIntervalandaddSelectionIntervalare equivalent. -
ListSelectionModel.MULTIPLE_INTERVAL_SELECTIONIn this mode, there's no restriction on what can be selected. This is the default.
- Parameters:
selectionMode- an integer specifying the type of selections that are permissible- See Also:
-
-
getSelectionMode
public int getSelectionMode()Returns whether single-item or multiple-item selections are allowed.- Returns:
- the value of the selectionMode property
-
indexOf
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Parameters:
o- element to search for.- Returns:
- the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
-
indexOf
Returns the index in this list of the first occurrence of the specified active label, or -1 if this list does not contain this active label. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Parameters:
label- the active label to search for.- Returns:
- the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
-
contains
Returns true if this thumbnail contains the specified element. More formally, returns true if and only if this thumbnail contains at least one element e such that (o==null ? e==null : o.equals(e)).- Parameters:
o- element whose presence in this list is to be tested.- Returns:
- true if this list contains the specified element.
-
contains
Returns true if this thumbnail contains the specified active label. More formally, returns true if and only if this active thumbnail contains at least one element e such that (o==null ? e==null : o.equals(e)).- Parameters:
label- element whose presence in this thumbnail is to be tested.- Returns:
- true if this thumbnail contains the specified label.
-
getActivatedLabel
Get the activated thumbnail.- Returns:
- the activated thumbnail.
-
setThumbRatio
public void setThumbRatio(double thumbRatio) Set the thumb ratio.- Parameters:
thumbRatio- the thumb ratio.
-
getThumbRatio
public double getThumbRatio()Get the thumb ratio.- Returns:
- the thumb ratio.
-
setLabelWidth
public void setLabelWidth(int width) Set the default width of the thumbnails displayed within this panel.- Parameters:
width- the default width of the thumbnails displayed within this panel.- See Also:
-
getLabelWidth
public int getLabelWidth()Get the default width of the thumbnails displayed within this panel.- Returns:
- the default width of the thumbnails displayed within this panel.
- See Also:
-
setLabelHeight
public void setLabelHeight(int height) Set the default height of the thumbnails displayed within this panel.- Parameters:
height- the default height of the thumbnails displayed within this panel.- See Also:
-
getLabelHeight
public int getLabelHeight()Get the default height of the thumbnails displayed within this panel.- Returns:
- the default height of the thumbnails displayed within this panel.
- See Also:
-
setLabelMargin
public void setLabelMargin(int margin) Set the default margin size of the thumbnails displayed within this panel.- Parameters:
margin- the default margin size of the thumbnails displayed within this panel.- See Also:
-
getLabelMargin
public int getLabelMargin()Get the default margin size of the thumbnails displayed within this panel.- Returns:
- the default margin size of the thumbnails displayed within this panel.
- See Also:
-
setLabelCount
public void setLabelCount(int count) Set the number of thumbnails that are attached to this panel.- Parameters:
count- the number of thumbnails that are attached to this panel.- See Also:
-
getLabelCount
public int getLabelCount()Get the number of thumbnails that are attached to this panel.- Returns:
- the number of thumbnails that are attached to this panel.
- See Also:
-
getState
Get the state of this panel.- Returns:
- the state of this panel.
-
setLoading
public void setLoading(boolean b) Set if this panel is currently loading.- Parameters:
b-trueif the panel is loading andfalseotherwise.- See Also:
-
isLoading
public boolean isLoading()Get if this panel is currently loading.- Returns:
trueif the panel is loading andfalseotherwise.- See Also:
-
scrollToSelected
public void scrollToSelected()Scroll the view to selected thumbnails. -
refresh
public void refresh()Refresh the thumbnail by refreshing all the activelabels conained -
add
Add an active label to the thumbnail.- Parameters:
label- the label to add- Returns:
- true if the label is added, false otherwise
-
remove
Remove the given thumbnail from this panel.- Parameters:
label- the thumbnail to remove.- Returns:
trueif the thumbnail is removed andfalseotherwise.
-
select
Add the label given in parameter to the selected labels- Parameters:
l- ActiveLabel the label newly selected
-
unselect
Remove the label given in parameter to the selected labels- Parameters:
l- ActiveLabel the label to remove selected
-
unselectAll
public void unselectAll()Unselect all the selected label. The graphical refresh of the Active Label is called by this method -
scrollToSelectedIndices
public void scrollToSelectedIndices()Move view rect to the component assigned to selected indices. -
scrollToIndices
public void scrollToIndices(int[] indices) Move view rect to the component assigned the indices given in parameter.- Parameters:
indices- the indices to view.
-
getLabelContaining
Get the active label displaying the content object. If no label is displaying the given object, thennullis returned.- Parameters:
content- the content attached to the searched label.- Returns:
- the label.
-
fireThumbnailAdded
Fire a thumbnail added event.- Parameters:
panel- the panel that contains the added thumbnailthumbnail- the added thumbnail
-
fireThumbnailRemoved
Fire a thumbnail removed event.- Parameters:
panel- the panel that contains the removed thumbnailthumbnail- the removed thumbnail
-
fireThumbnailSelected
Fire a thumbnail selection event.- Parameters:
panel- the panel that contains the selected thumbnailthumbnail- the selected thumbnail
-
fireThumbnailSelected
Fire a thumbnail selection event.- Parameters:
panel- the panel that contains the selected thumbnailsthumbnails- the selected thumbnails
-
fireThumbnailActivated
Fire a thumbnail activation event.- Parameters:
panel- the panel that contains the activated thumbnailthumbnail- the activated thumbnail
-
fireThumbnailEntered
Fire a thumbnail entered event.- Parameters:
panel- the panel that contains the entered thumbnailthumbnail- the entered thumbnail
-
fireThumbnailExited
Fire a thumbnail exited event.- Parameters:
panel- the panel that contains the exited thumbnailthumbnail- the exited thumbnail
-
fireThumbnailNeedRefresh
Fire a thumbnail refresh needed event.- Parameters:
panel- the panel that contains the refresh needed thumbnailthumbnail- the refresh needed thumbnail
-
fireEvent
Fire a task event.- Parameters:
e- the event to fire.
-
addThumbnailPanelListener
Add an Active Thumbnail Listener to this Active Thumbnail- Parameters:
l- ActiveThumbnailListener Listener added to the Active Thumbnail
-
removeThumbnailPanelListener
Remove an Active Thumbnail Listener from this Active Thumbnail- Parameters:
l- ActiveThumbnailListener Active Listener to remove
-
addTaskListener
Add a Task Listener to this object- Parameters:
l- TaskListener Listener added to the object
-
removeTaskListener
Remove a Task Listener from this object- Parameters:
l- TaskListener listener to remove
-
processActiveLabelMouseEvent
Process a MouseEvent fired by an active label.- Parameters:
e- The event fired.
-