Module org.jcommon

Class JThumbnailPanel<T>

  • Type Parameters:
    T - the type enclosed by the thumbnails of the list.
    All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible

    public class JThumbnailPanel<T>
    extends JPanel
    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.8
    Author:
    Julien Seinturier - COMEX SA
    See Also:
    Serialized Form
    • Field Detail

      • labelWidth

        protected int labelWidth
      • labelHeight

        protected int labelHeight
      • thumbRatio

        protected double thumbRatio
      • labelMargin

        protected int labelMargin
      • labelCount

        protected int labelCount
      • selectedLabels

        protected List<JThumbnail<T>> selectedLabels
        The selected labels
      • lastSelectedIndex

        protected int lastSelectedIndex
        The index corresponding to the last selected index
      • activatedLabel

        protected JThumbnail<T> activatedLabel
        The first selected label
      • isLabelLoading

        protected volatile boolean isLabelLoading
      • idListenerList

        protected EventListenerList idListenerList
        Liste des ecouteurs informes des evenements du thumbnail
      • normalColor

        protected Color normalColor
        Color used for the coloring the background of the label where it's in standard state
      • focusColor

        protected Color focusColor
        Color used for the coloring the background of the label where it's in focus state
      • selectedColor

        protected Color selectedColor
        Color used for the coloring the background of the label where it's in selected state
      • itemPResentColor

        protected Color itemPResentColor
      • state

        protected String state
    • Constructor Detail

      • 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 Detail

      • getCellBounds

        public Rectangle getCellBounds​(int index0,
                                       int index1)
        Returns the bounds of the specified range of items in JList coordinates. Returns null if index isn't valid.
        Parameters:
        index0 - the index of the first JList cell in the range
        index1 - 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:
        setSelectedIndices(int[])
      • 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(int)
      • 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:
        getSelectedIndex()
      • setSelectedValue

        public void setSelectedValue​(Object anObject,
                                     boolean shouldScroll)
        Selects the specified object from the list.
        Parameters:
        anObject - the object to select
        shouldScroll - true if the list should scroll to display the selected object, if one exists; otherwise false
      • setSelectedThumbnail

        public void setSelectedThumbnail​(JThumbnail<T> label,
                                         boolean shouldScroll)
        Selects the specified label in the list.
        Parameters:
        label - the label to select
        shouldScroll - true if the list should scroll to display the selected label, if one exists; otherwise false
      • getSelectedThumbnail

        public JThumbnail<T> getSelectedThumbnail()
        Returns the first selected label, or null if the selection is empty.
        Returns:
        the first selected label
      • getSelectedThumbnails

        public List<JThumbnail<T>> 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

        public Object[] 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 following selectionMode values are allowed:
        • ListSelectionModel.SINGLE_SELECTION Only one list index can be selected at a time. In this mode the setSelectionInterval and addSelectionInterval methods are equivalent, and only the second index argument is used.
        • ListSelectionModel.SINGLE_INTERVAL_SELECTION One contiguous index interval can be selected at a time. In this mode setSelectionInterval and addSelectionInterval are equivalent.
        • ListSelectionModel.MULTIPLE_INTERVAL_SELECTION In 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()
      • getSelectionMode

        public int getSelectionMode()
        Returns whether single-item or multiple-item selections are allowed.
        Returns:
        the value of the selectionMode property
      • indexOf

        public int indexOf​(Object o)
        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

        public int indexOf​(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. 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

        public boolean contains​(Object o)
        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

        public boolean contains​(JThumbnail<T> label)
        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

        public JThumbnail<T> 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()
      • 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:
        setLabelWidth(int)
      • 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()
      • 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:
        setLabelHeight(int)
      • 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()
      • 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:
        setLabelMargin(int)
      • 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()
      • 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:
        setLabelCount(int)
      • getState

        public String 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 - true if the panel is loading and false otherwise.
        See Also:
        isLoading()
      • isLoading

        public boolean isLoading()
        Get if this panel is currently loading.
        Returns:
        true if the panel is loading and false otherwise.
        See Also:
        setLoading(boolean)
      • scrollToSelected

        public void scrollToSelected()
        Scroll the view to selected thumbnails.
      • refresh

        public void refresh()
        Refresh the thumbnail by refreshing all the activelabels conained
      • add

        public boolean add​(JThumbnail<T> label)
        Add an active label to the thumbnail.
        Parameters:
        label - the label to add
        Returns:
        true if the label is added, false otherwise
      • remove

        public boolean remove​(JThumbnail<T> label)
        Remove the given thumbnail from this panel.
        Parameters:
        label - the thumbnail to remove.
        Returns:
        true if the thumbnail is removed and false otherwise.
      • select

        public void select​(JThumbnail<T> l)
        Add the label given in parameter to the selected labels
        Parameters:
        l - ActiveLabel the label newly selected
      • unselect

        public void unselect​(JThumbnail<T> l)
        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

        public JThumbnail<T> getLabelContaining​(Object content)
        Get the active label displaying the content object. If no label is displaying the given object, then null is returned.
        Parameters:
        content - the content attached to the searched label.
        Returns:
        the label.
      • fireEvent

        protected void fireEvent​(TaskEvent e)
      • addThumbnailPanelListener

        public void addThumbnailPanelListener​(JThumbnailPanelListener<T> l)
        Add an Active Thumbnail Listener to this Active Thumbnail
        Parameters:
        l - ActiveThumbnailListener Listener added to the Active Thumbnail
      • removeThumbnailPanelListener

        public void removeThumbnailPanelListener​(JThumbnailPanelListener<T> l)
        Remove an Active Thumbnail Listener from this Active Thumbnail
        Parameters:
        l - ActiveThumbnailListener Active Listener to remove
      • addTaskListener

        public void addTaskListener​(TaskListener l)
        Add a Task Listener to this object
        Parameters:
        l - TaskListener Listener added to the object
      • removeTaskListener

        public void removeTaskListener​(TaskListener l)
        Remove a Task Listener from this object
        Parameters:
        l - TaskListener listener to remove
      • processActiveLabelMouseEvent

        protected void processActiveLabelMouseEvent​(MouseEvent e)
        Process a MouseEvent fired by an active label.
        Parameters:
        e - The event fired.