Class MultiPagePane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class MultiPagePane extends BasePanel
Manages multiple pages, like JTabbedPane manages multiple tabs. Uses a JList for listing the page titles.
Author:
FracPete (fracpete at waikato dot ac dot nz)
See Also:
  • Field Details

    • m_SplitPane

      protected JSplitPane m_SplitPane
      the split pane.
    • m_LeftPanel

      protected BasePanel m_LeftPanel
      the panel with the list and buttons.
    • m_PageList

      protected com.googlecode.jfilechooserbookmarks.gui.BaseList m_PageList
      the page list.
    • m_PageListModel

      protected DefaultListModel<MultiPagePane.PageContainer> m_PageListModel
      the list model.
    • m_PanelListButtons

      protected BasePanel m_PanelListButtons
      the panel for the list buttons.
    • m_ButtonUp

      protected BaseFlatButton m_ButtonUp
      the move up button.
    • m_ButtonDown

      protected BaseFlatButton m_ButtonDown
      the move down button.
    • m_ButtonRemove

      protected BaseFlatButton m_ButtonRemove
      the remove button.
    • m_ButtonRemoveAll

      protected BaseFlatButton m_ButtonRemoveAll
      the remove all button.
    • m_ButtonUndo

      protected BaseFlatButton m_ButtonUndo
      the undo button.
    • m_ButtonAction

      protected BaseSplitButton m_ButtonAction
      the action button.
    • m_PanelContent

      protected BasePanel m_PanelContent
      the content pane for the pages.
    • m_ChangeListeners

      protected HashSet<ChangeListener> m_ChangeListeners
      the listeners when pages get selected.
    • m_IgnoreUpdates

      protected boolean m_IgnoreUpdates
      whether to ignore updates.
    • m_PageCloseApprover

      protected MultiPagePane.PageCloseApprover m_PageCloseApprover
      for approving page closing.
    • m_PopupCustomizer

      protected MultiPagePane.PopupCustomizer m_PopupCustomizer
      an optional customizer for the popup on the JList.
    • m_ToolTipCustomizer

      protected MultiPagePane.ToolTipCustomizer m_ToolTipCustomizer
      an optional customizer for the tooltips of the JList.
    • m_ReadOnly

      protected boolean m_ReadOnly
      whether the page list is readonly.
    • m_MaxPageCloseUndo

      protected int m_MaxPageCloseUndo
      the maximum number of tabs to keep for undo.
    • m_PageUndoList

      protected transient List<MultiPagePane.PageUndo> m_PageUndoList
      the list of tabs to undo.
    • m_SkipPageUndo

      protected boolean m_SkipPageUndo
      whether to skip tab undo.
  • Constructor Details

    • MultiPagePane

      public MultiPagePane()
  • Method Details

    • initialize

      protected void initialize()
      For initializing members.
      Overrides:
      initialize in class BasePanel
    • initGUI

      protected void initGUI()
      For initializing the GUI.
      Overrides:
      initGUI in class BasePanel
    • finishInit

      protected void finishInit()
      finishes the initialization.
      Overrides:
      finishInit in class BasePanel
    • newRenderer

      protected MultiPagePane.TitleRenderer newRenderer()
      Returns the renderer to use.
      Returns:
      the renderer
    • setReadOnly

      public void setReadOnly(boolean value)
      Sets whether the pages are readonly or can be manipulated.
      Parameters:
      value - true if no manipulation possible
    • isReadOnly

      public boolean isReadOnly()
      Returns whether the pages are readonly or can be manipulated.
      Returns:
      true if no manipulation possible
    • getButtonPanel

      public BasePanel getButtonPanel()
      Returns the panel with the buttons.
      Returns:
      the panel
    • setDividerLocation

      public void setDividerLocation(int value)
      Sets the location for the divider between page titles and content.
      Parameters:
      value - the location in pixels
    • getDividerLocation

      public int getDividerLocation()
      Returns the current location of the divider between page titles and content.
      Returns:
      the location in pixels
    • setTitleRenderer

      public void setTitleRenderer(ListCellRenderer renderer)
      Sets the renderer for the titles.
      Parameters:
      renderer - the renderer to use
    • getTitleRenderer

      public ListCellRenderer getTitleRenderer()
      Returns the renderer for the titles.
      Returns:
      the renderer to use
    • getPageCount

      public int getPageCount()
      Returns the number of pages.
      Returns:
      the number of pages
    • getSelectedIndex

      public int getSelectedIndex()
      Returns the currently selected page index.
      Returns:
      the index, -1 if none selected
    • setSelectedIndex

      public void setSelectedIndex(int index)
      Selects the specified page index.
      Parameters:
      index - the index of the page to select
    • getSelectedIndices

      public int[] getSelectedIndices()
      Returns the currently selected page indices.
      Returns:
      the indices, 0-length array if none selected
    • setSelectedIndices

      public void setSelectedIndices(int[] indices)
      Sets the currently selected page indices.
      Parameters:
      indices - the indices
    • setSelectedPage

      public void setSelectedPage(Component page)
      Selects the specified page component as active page.
      Parameters:
      page - the component to select
    • setPageAt

      public void setPageAt(int index, MultiPagePane.PageContainer cont)
      Sets the container at the specified index.
      Parameters:
      index - the page index
      cont - the new container
    • getPageContainerAt

      public MultiPagePane.PageContainer getPageContainerAt(int index)
      Returns the page container at the specified index.
      Parameters:
      index - the page index
      Returns:
      the associated page container
    • getSelectedPageContainer

      public MultiPagePane.PageContainer getSelectedPageContainer()
      Returns the currently selected page container.
      Returns:
      the page container, null if none selected
    • setPageAt

      public void setPageAt(int index, Component page)
      Sets the page at the specified index.
      Parameters:
      index - the page index
      page - the new page
    • getPageAt

      public Component getPageAt(int index)
      Returns the page component at the specified index.
      Parameters:
      index - the page index
      Returns:
      the associated page component
    • getDetachablePageAt

      public MultiPagePane.DetachablePage getDetachablePageAt(int index)
      Returns the detachable page component at the specified index.
      Parameters:
      index - the page index
      Returns:
      the associated detachable page component
    • indexOfPage

      public int indexOfPage(Component page)
      Returns the page index for the page component.
      Parameters:
      page - the page component to look up
      Returns:
      the associated page index, -1 if not found
    • indexOfPage

      public int indexOfPage(MultiPagePane.PageContainer cont)
      Returns the page index for the page container.
      Parameters:
      cont - the page component to look up
      Returns:
      the associated page index, -1 if not found
    • getSelectedPage

      public Component getSelectedPage()
      Returns the currently selected page.
      Returns:
      the page, null if none selected
    • getSelectedDetachablePage

      public MultiPagePane.DetachablePage getSelectedDetachablePage()
      Returns the currently selected detachable page.
      Returns:
      the detachable page, null if none selected
    • setTitleAt

      public void setTitleAt(int index, String title)
      Sets the title at the specified index.
      Parameters:
      index - the page index
      title - the new title
    • getTitleAt

      public String getTitleAt(int index)
      Returns the title at the specified index.
      Parameters:
      index - the page index
      Returns:
      the associated title
    • getSelectedTitle

      public String getSelectedTitle()
      Returns the title of the currently selected page.
      Returns:
      the title, null if none selected
    • setIconAt

      public void setIconAt(int index, ImageIcon icon)
      Sets the icon at the specified index.
      Parameters:
      index - the page index
      icon - the new icon
    • getIconAt

      public ImageIcon getIconAt(int index)
      Returns the icon at the specified index.
      Parameters:
      index - the page index
      Returns:
      the associated icon
    • getSelectedIcon

      public ImageIcon getSelectedIcon()
      Returns the icon of the currently selected page.
      Returns:
      the icon, null if none selected
    • isPageClosingApproved

      protected boolean isPageClosingApproved(int index)
      Approves the closing of the specified page.
      Parameters:
      index - the page index
      Returns:
      true if can be closed
      See Also:
    • isPageClosingApproved

      protected boolean isPageClosingApproved(int[] indices)
      Approves the closing of the specified pages.
      Parameters:
      indices - the page indices
      Returns:
      true if can be closed
      See Also:
    • checkedRemoveSelectedPage

      public MultiPagePane.PageContainer checkedRemoveSelectedPage()
      Removes the currently selected page container, if approved.
      Returns:
      the removed container, if any
    • removeSelectedPage

      public MultiPagePane.PageContainer removeSelectedPage()
      Removes the currently selected page container.
      Returns:
      the removed container
    • checkedRemoveSelectedPages

      public void checkedRemoveSelectedPages()
      Removes the currently selected page containers, if approved.
    • removeSelectedPages

      public void removeSelectedPages()
      Removes the currently selected page containers.
    • checkedRemovePageAt

      public MultiPagePane.PageContainer checkedRemovePageAt(int index)
      Removes the page container at the specified index, if approved.
      Parameters:
      index - the page index
      Returns:
      the removed container, null if not removed
      See Also:
    • removePageAt

      public MultiPagePane.PageContainer removePageAt(int index)
      Removes the page container at the specified index.
      Parameters:
      index - the page index
      Returns:
      the removed container
    • checkedRemoveAllPages

      public void checkedRemoveAllPages()
      Removes all pages. Does not stored them in undo.
    • removeAllPages

      public void removeAllPages()
      Removes all pages. Does not stored them in undo.
    • addPage

      public void addPage(String title, Component page)
      Adds the page at the end.
      Parameters:
      title - the title
      page - the page component
    • addPage

      public void addPage(MultiPagePane.PageContainer cont)
      Adds the page at the end.
      Parameters:
      cont - the page container
    • addPage

      public void addPage(int index, String title, Component page)
      Adds the page at the specified index.
      Parameters:
      index - the page index to insert the page at
      title - the title
      page - the page component
    • addPage

      public void addPage(int index, MultiPagePane.PageContainer cont)
      Adds the page at the specified index.
      Parameters:
      index - the page index to insert the page at
      cont - the page container
    • moveUp

      public void moveUp()
      moves the selected items up by 1.
    • moveDown

      public void moveDown()
      moves the selected item down by 1.
    • moveTop

      public void moveTop()
      moves the selected items to the top.
    • moveBottom

      public void moveBottom()
      moves the selected items to the end.
    • canMoveUp

      public boolean canMoveUp()
      checks whether the selected items can be moved up.
      Returns:
      true if the selected items can be moved
    • canMoveDown

      public boolean canMoveDown()
      checks whether the selected items can be moved down.
      Returns:
      true if the selected items can be moved
    • addRemoveItemsListener

      public void addRemoveItemsListener(com.googlecode.jfilechooserbookmarks.event.RemoveItemsListener l)
      Adds the remove items listener to its internal list.
      Parameters:
      l - the listener to add
    • removeRemoveItemsListener

      public void removeRemoveItemsListener(com.googlecode.jfilechooserbookmarks.event.RemoveItemsListener l)
      Removes the remove items listener from its internal list.
      Parameters:
      l - the listener to remove
    • addChangeListener

      public void addChangeListener(ChangeListener l)
      Adds the change listener to its internal list.
      Parameters:
      l - the listener to add
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
      Removes the change listener from its internal list.
      Parameters:
      l - the listener to remove
    • notifyChangeListeners

      protected void notifyChangeListeners()
      Notifies the change listeners.
    • update

      protected void update()
      Updates the content panel.
    • updateButtons

      protected void updateButtons()
      Updates the enabled state of the buttons.
    • addAction

      public void addAction(Action action)
      Adds the action to the action button.
      Parameters:
      action - the action to add
    • addAction

      public void addAction(JMenuItem action)
      Adds the menu item to the action button.
      Parameters:
      action - the item to add
    • processListKey

      protected boolean processListKey(KeyEvent e)
      Handles the key event from the page list.
      Parameters:
      e - the event
      Returns:
      true if processed
    • setPageCloseApprover

      public void setPageCloseApprover(MultiPagePane.PageCloseApprover value)
      Sets the approver for closing pages.
      Parameters:
      value - the approver, null to remove
    • getPageCloseApprover

      public MultiPagePane.PageCloseApprover getPageCloseApprover()
      Returns the approver for closing pages.
      Returns:
      the approver, null if none set
    • createPopup

      protected JPopupMenu createPopup(MouseEvent e)
      Generates the right-click menu for the JList.

      Derived classes should override this method instead of making use of the PopupCustomizer.
      Parameters:
      e - the event that triggered the popup
      Returns:
      the generated menu
      See Also:
    • updateTitle

      protected void updateTitle(String title, MultiPagePane.DetachablePage detach)
      Hook method for updating the title.
      Parameters:
      title - the entry title
      detach - the detachable page
    • showPopup

      protected void showPopup(MouseEvent e)
      Generates and pops up the right-click menu on the JList.
      Parameters:
      e - the event that triggered the popup
      See Also:
    • setPopupCustomizer

      public void setPopupCustomizer(MultiPagePane.PopupCustomizer value)
      Sets the popup customizer to use.
      Parameters:
      value - the customizer, use null to turn off
    • getPopupCustomizer

      public MultiPagePane.PopupCustomizer getPopupCustomizer()
      Returns the currently set popup customizer.
      Returns:
      the customizer, can be null if none set
    • setToolTipCustomizer

      public void setToolTipCustomizer(MultiPagePane.ToolTipCustomizer value)
      Sets the tool tip customizer to use.
      Parameters:
      value - the customizer, use null to turn off
    • getToolTipCustomizer

      public MultiPagePane.ToolTipCustomizer getToolTipCustomizer()
      Returns the currently set tool tip customizer.
      Returns:
      the customizer, can be null if none set
    • generateToolTip

      protected String generateToolTip(int index)
      Generates the tool tip for the index.
      Parameters:
      index - the index, can be outside range
      Returns:
      the tool tip, null if none available
    • setMaxPageCloseUndo

      public void setMaxPageCloseUndo(int value)
      Sets the maximum pages to keep around for undoing closing.
      Parameters:
      value - the maximum, <1 turned off
    • getMaxPageCloseUndo

      public int getMaxPageCloseUndo()
      Returns the maximum pages to keep around for undoing closing.
      Returns:
      the maximum, <1 turned off
    • getPageUndoList

      protected List<MultiPagePane.PageUndo> getPageUndoList()
      Returns the page undo list.
      Returns:
      the list
    • addPageUndo

      protected void addPageUndo(int index)
      Adds the page to its undo list, if enabled.
      Parameters:
      index - the position of the tab
    • canUndoPageClose

      public boolean canUndoPageClose()
      Returns whether a tab close can be undone.
      Returns:
      true if possible
    • undoPageClose

      public boolean undoPageClose()
      Performs an undo of a page close.
      Returns:
      true if successfully restored
    • clearPageUndo

      protected void clearPageUndo()
      Clears the page undo list.
    • cleanUp

      public void cleanUp()
      Cleans up data structures, frees up memory.