Class DynamicTabbedPane<T extends JPanel>

Type Parameters:
T - type of the component to show on the tabbed pane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants
Direct Known Subclasses:
MetersTabbedPane, StudentCourseTabbedPane

public abstract class DynamicTabbedPane<T extends JPanel> extends JTabbedPane
The DynamicTabbedPane allows to close tabs and open new tabs Provided by the broldev.core.swing project.
Since:
1.0 (Jan 8, 2009), broldev.core.swing 0.0.1-SNAPSHOT dependency
Version:
1.0 (Jan 8, 2009)
Author:
Steph GAUDRY
See Also:
Serialized Form
  • Field Details

    • DEFAULT_TITLE

      public static final String DEFAULT_TITLE
      Sign displayed on a virtual tab to add a new tab
      See Also:
      Constant Field Values
    • dynamicallyExpandable

      protected boolean dynamicallyExpandable
    • parent

      JPanel parent
  • Constructor Details

    • DynamicTabbedPane

      public DynamicTabbedPane()
      Builds an instance of tabbed pane with the ability to close tabs
    • DynamicTabbedPane

      public DynamicTabbedPane(boolean dynamicallyExpandable)
      Builds an instance of tabbed pane with the ability to close tabs and open new tabs if parameter is true
      Parameters:
      dynamicallyExpandable - true to allow the user to add tabs
  • Method Details

    • getNewTabTitle

      public abstract String getNewTabTitle()
      Returns:
      the text shown on the new tab
    • getNewTabView

      public abstract T getNewTabView()
      The implementation of getNewTabView must provides an instance of a <T> component to show when the new tab will be selected.
      Returns:
      <T> component to associate to the new tab
    • isPseudoTab

      public boolean isPseudoTab(int index)
      Determines if the index is this of the pseudo tab with the "add" feature
      Parameters:
      index - position of the tab to check
      Returns:
      true if this is the pseudo tab position
    • onOpenNewTab

      protected T onOpenNewTab()
      Override this method if you want other things to happen when opening a new tab.
      The override method may be like that :
        public StudentQuotationsPanel onOpenNewTab() {
        StudentQuotationsPanel studentQuotationsPanel = null;
        if (availableCourses == null || availableCourses.size() < 1) {
              JOptionPane.showMessageDialog(this, getLocalized("student.noCourse2Add")
                              + student.toString() + ".", getLocalized("course.add"),
                              JOptionPane.INFORMATION_MESSAGE);
        
        } else {
              Course course = (Course) JOptionPane.showInputDialog(this,
                              getLocalized("student.selectCourse2Add"), getLocalized("course.add"),
                              JOptionPane.PLAIN_MESSAGE,
                              BrolImagesEduCotation.COURSE_LOGO.getIcon(),
                              availableCourses.toArray(new Course[0]), null);
              if (course != null) {
                      startTab(course);
              }
        }
        return studentQuotationsPanel;
        }
        
      Returns:
      null if selection failed or canceled, T object otherwise
    • onCloseTab

      protected void onCloseTab(int index)
      Removes the tab at the specified index
      Parameters:
      index - position of the tab to close
    • prepareNewTab

      protected T prepareNewTab()
      Prepares the dynamic tabbed pane before adding the new tab
      Returns:
      the component to put into the new tab
    • startTab

      protected void startTab(T newTabView)
      Shows a component into a new tab
      Parameters:
      newTabView - <T> object to add
    • getTabAt

      public T getTabAt(int index)
      Returns a tab by its position
      Parameters:
      index - position of the tab
      Returns:
      <T> object found at the asked position
      Throws:
      IllegalArgumentException - if the index is out of the range
    • getToolTipForClosing

      protected String getToolTipForClosing()
    • reset

      public void reset()
      Removes all opened tabs
    • setSelectedIndex

      public void setSelectedIndex(int index)
      Overrides:
      setSelectedIndex in class JTabbedPane