JIDE 3.5.15

com.jidesoft.paging
Class PageNavigationBar

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JToolBar
                  extended by com.jidesoft.paging.PageNavigationBar
All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, SwingConstants
Direct Known Subclasses:
PagedTablePaneNavigationBar

public class PageNavigationBar
extends JToolBar
implements PropertyChangeListener

PageNavigationBar provides a quick way to paginate a JTable, a TableScrollPane or a JList. All you need to do is to call new PageNavigationBar(table) or new PageNavigationBar(list) and add the PageNavigationBar below or above the table or the list. PageNavigationBar will automatically paginate the table or the list. PageNavigationBar provides a page index field and buttons to navigate the pages. If the table or the list doesn't have a model that implementing PageNavigationSupport, it will automatically create a DefaultPageTableModel or DefaultPageListModel to provide the paging support. Otherwise it will use the existing mode that implements PageNavigationSupport.

PageNavigationBar uses methods provided by PageNavigationSupport to navigate the pages. It has four buttons and one field. The four buttons are for the first page, the previous page, the next page and the last page. The field displays the current page index and the total page count. It also allows user to type in the page index in it and press enter to jump to that page. It has a context menu where allows user to switch from the default page index mode to the row index mode. In the row index mode, instead of displaying the current page, it displays the current row index and the total row count. Typing the row index and enter will jump to the row. User can also press UP, DOWN, PAGE_UP, PAGE_DOWN, CTRL + PAGE_UP, CTRL + PAGE_DOWN, CTRL + HOME, and CTRL + END to navigate the pages when the focus is in the field. It will also beep when users try to navigate to a page that is not available. For example user presses page up when it is already on the first page, or try to jump to 100 page when there are only 99 pages.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JToolBar
JToolBar.AccessibleJToolBar, JToolBar.Separator
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  PageNavigationField _pageNavigationField
           
protected  PageNavigationSupport _pageNavigationSupport
           
 String CLIENT_PROPERTY_ALWAYS_DISABLED
           
static String COMMAND_FIRST
           
static String COMMAND_GOTO
           
static String COMMAND_LAST
           
static String COMMAND_NEXT
           
static String COMMAND_PREVIOUS
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected PageNavigationBar()
           
  PageNavigationBar(JList list)
          The constructor to install a PageNavigationBar over a JList.
  PageNavigationBar(JTable table)
          The constructor to install a PageNavigationBar over a JTable.
  PageNavigationBar(TableScrollPane pane)
          The constructor to install a PageNavigationBar over a TableScrollPane.
 
Method Summary
protected  void changeCurrentPage(int newPageIndex)
           
protected  AbstractButton createButton(Action action)
          Creates the button.
protected  ChangeListener createChangeListener()
          Creates a ChangeListener that will be added to the NavigationField.
protected  FocusListener createFocusListener()
          Creates a FocusListener that will be added to the NavigationField.
protected  MouseWheelListener createMouseWheelListener()
          Creates a MouseWheelListener that will be added to the table or the list.
protected  PageNavigationField createNavigationField()
          Creates the navigation field.
protected  PageNavigationListener createPageNavigationListener()
          Creates a PageNavigationListener that will be added to the PageNavigationSupport.
protected  PageNavigationSupport createPageTableModel(TableModel model, int pageSize)
          Creates the page table model.
protected  ListSelectionListener createSelectionListener()
          Creates a ListSelectionListener that will be added to the table or the list.
 void firstPage()
          Navigates to the first page.
 void firstRecord()
          Navigates to the first record/row.
 void firstRecordInPage()
          Navigates to the first record/row in the current page.
 int getCurrentRecord()
          Gets the current record.
 PageNavigationField getNavigationField()
          Gets the navigation field.
 PageNavigationSupport getPageNavigationSupport()
          Gets the PageNavigationSupport used by this PageNavigationBar.
protected  int getPageSize()
          Gets the page size to change the current record while previous or next page is requested.
protected  int getRecordCountInPage()
          Gets the record/row count in the current page.
protected  String getResourceString(String key)
          Gets the localized string from resource bundle.
protected  int getSelectedRecordIndex()
          Gets the selected record/row index.
protected  void gotoPage()
          Navigates to the page as shown in the PageNavigationField.
 void gotoPage(int page)
          Navigates to the specified page.
protected  void gotoRecord()
          Navigates to the record/row as shown in the PageNavigationField.
 int gotoRecord(int record)
          Navigates to the specified record/row.
protected  void initComponents()
           
protected  boolean isAtFirstPage()
          Checks if right now it's the first possible page.
protected  boolean isAtLastPage()
          Checks if right now it's the last possible page.
 boolean isButtonEnabled(String command)
          Checks if the button is always disabled.
 boolean isButtonVisible(String command)
          Checks if the button is visible.
 boolean isSelectViewIndex()
          Gets the flag indicating if PageNavigationBar will automatically select the same view index as previous page while changing pages.
 void lastPage()
          Navigates to the last page.
 void lastRecord()
          Navigates to the last record/row.
 void lastRecordInPage()
          Navigates to the last record/row in the current page.
 void nextPage()
          Navigates to the next page.
 void nextRecord()
          Navigates to the next record/row, changes the current page if necessary.
protected  void notifyUser()
           
 void previousPage()
          Navigates to the previous page.
 void previousRecord()
          Navigates to the previous record/row, changes the current page if necessary.
 void propertyChange(PropertyChangeEvent evt)
          The property change listener to handle the model change of JList/JTable/TableScrollPane.
protected  void registerKeyboardActions(JComponent component)
          Registers the navigation keystrokes.
 void selectRecord(int record)
          Navigates to and select the specified record/row.
 void setButtonEnabled(String command, boolean enabled)
          Sets the button to always disabled.
 void setButtonVisible(String command, boolean visible)
          Sets the button visible or invisible.
 void setEnabled(boolean enabled)
           
 void setListModel(ListModel model)
          Sets the list model of the page navigation bar if the wrapped component is a JList.
protected  void setSelectedRecordIndex(int row)
          Sets the selected record/row.
 void setSelectViewIndex(boolean selectViewIndex)
          Sets the flag indicating if PageNavigationBar will automatically select the same view index as previous page while changing pages.
 void setTableModel(TableModel model)
          Sets the table model of the page navigation bar if the wrapped component is a JTable.
protected  void updateButtonPanel()
           
protected  void updateNavigationField()
          Updates the navigation field.
protected  void updateTooltipText(String key, Action action)
          Update the tooltip text of navigation buttons according to the navigation type
 
Methods inherited from class javax.swing.JToolBar
add, addImpl, addSeparator, addSeparator, createActionChangeListener, createActionComponent, getAccessibleContext, getComponentAtIndex, getComponentIndex, getMargin, getOrientation, getUI, getUIClassID, isBorderPainted, isFloatable, isRollover, paintBorder, paramString, setBorderPainted, setFloatable, setLayout, setMargin, setOrientation, setRollover, setUI, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, 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, 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, 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, transferFocusBackward, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_pageNavigationSupport

protected PageNavigationSupport _pageNavigationSupport

COMMAND_FIRST

public static final String COMMAND_FIRST
See Also:
Constant Field Values

COMMAND_PREVIOUS

public static final String COMMAND_PREVIOUS
See Also:
Constant Field Values

COMMAND_NEXT

public static final String COMMAND_NEXT
See Also:
Constant Field Values

COMMAND_LAST

public static final String COMMAND_LAST
See Also:
Constant Field Values

COMMAND_GOTO

public static final String COMMAND_GOTO
See Also:
Constant Field Values

CLIENT_PROPERTY_ALWAYS_DISABLED

public final String CLIENT_PROPERTY_ALWAYS_DISABLED
See Also:
Constant Field Values

_pageNavigationField

protected PageNavigationField _pageNavigationField
Constructor Detail

PageNavigationBar

protected PageNavigationBar()

PageNavigationBar

public PageNavigationBar(TableScrollPane pane)
The constructor to install a PageNavigationBar over a TableScrollPane.

Parameters:
pane - the table scroll pane
Since:
3.1.1

PageNavigationBar

public PageNavigationBar(JTable table)
The constructor to install a PageNavigationBar over a JTable.

Parameters:
table - the table

PageNavigationBar

public PageNavigationBar(JList list)
The constructor to install a PageNavigationBar over a JList.

Parameters:
list - the list
Method Detail

createPageTableModel

protected PageNavigationSupport createPageTableModel(TableModel model,
                                                     int pageSize)
Creates the page table model.

By default, it creates a DefaultPageTableModel.

Parameters:
model - the target table's model
pageSize - the row size of each page
Returns:
the installed table model to support page navigation.

propertyChange

public void propertyChange(PropertyChangeEvent evt)
The property change listener to handle the model change of JList/JTable/TableScrollPane.

Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
evt - the property change event
Since:
3.4.4

initComponents

protected void initComponents()

createChangeListener

protected ChangeListener createChangeListener()
Creates a ChangeListener that will be added to the NavigationField.

Returns:
a ChangeListener

updateTooltipText

protected void updateTooltipText(String key,
                                 Action action)
Update the tooltip text of navigation buttons according to the navigation type

Parameters:
key -
action -
Since:
3.4.2

createFocusListener

protected FocusListener createFocusListener()
Creates a FocusListener that will be added to the NavigationField.

Returns:
a FocusListener

createPageNavigationListener

protected PageNavigationListener createPageNavigationListener()
Creates a PageNavigationListener that will be added to the PageNavigationSupport.

Returns:
a PageNavigationListener

createSelectionListener

protected ListSelectionListener createSelectionListener()
Creates a ListSelectionListener that will be added to the table or the list.

Returns:
a ListSelectionListener

createMouseWheelListener

protected MouseWheelListener createMouseWheelListener()
Creates a MouseWheelListener that will be added to the table or the list.

Returns:
a MouseWheelListener

registerKeyboardActions

protected void registerKeyboardActions(JComponent component)
Registers the navigation keystrokes. The keystrokes are Those keystrokes are supported in both the table/list as well as in the PageNavigationField on the PageNavigationBar.

Parameters:
component - the component to register actions

getCurrentRecord

public int getCurrentRecord()
Gets the current record. It is the selected row as in the whole table or list model. If the table or the list is not selected, we treat it as the first row is selected.

Returns:
the current record.

setTableModel

public void setTableModel(TableModel model)
Sets the table model of the page navigation bar if the wrapped component is a JTable.

Parameters:
model - the original table model
Since:
3.4.2

setListModel

public void setListModel(ListModel model)
Sets the list model of the page navigation bar if the wrapped component is a JList.

Parameters:
model - the original list model
Since:
3.4.2

createNavigationField

protected PageNavigationField createNavigationField()
Creates the navigation field.

Returns:
the navigation field.
Since:
3.1.1

getNavigationField

public PageNavigationField getNavigationField()
Gets the navigation field.

Returns:
the navigation field.
Since:
3.1.1

updateNavigationField

protected void updateNavigationField()
Updates the navigation field.

Since:
3.1.1

createButton

protected AbstractButton createButton(Action action)
Creates the button. Our default code is
 protected AbstractButton createButton(Action action) {
     AbstractButton button = new JideButton(action);
     button.setName("" + action.getValue(Action.ACTION_COMMAND_KEY));
     button.setDisabledIcon((Icon) action.getValue("disabledIcon"));
     button.setRequestFocusEnabled(false);
     AutoRepeatButtonUtils.install(button, 50, 200);
     return button;
 }
 

Parameters:
action - the action for the button.
Returns:
a button.

getResourceString

protected String getResourceString(String key)
Gets the localized string from resource bundle. Subclass can override it to provide its own string. For example, you can customize the icons by overriding this method. The key for the icons will be in the format of "PageNavigationBar.moveLeft.icon" and "PageNavigationBar.moveLeft.disabledIcon" for the move left button. There are a total of eight buttons. Once you override, you can return a full qualified path to the icon resource such as "/com/yourcompany/icons/moveLeft.png". Note that the icon must be in the class path so that we can access it as resource.

Parameters:
key - the key
Returns:
the localized string.

isSelectViewIndex

public boolean isSelectViewIndex()
Gets the flag indicating if PageNavigationBar will automatically select the same view index as previous page while changing pages.

Returns:
true if view index will be selected. Otherwise false.
See Also:
setSelectViewIndex(boolean)

setSelectViewIndex

public void setSelectViewIndex(boolean selectViewIndex)
Sets the flag indicating if PageNavigationBar will automatically select the same view index as previous page while changing pages.

By default, the flag is true to keep original behavior. You could set it to false if you want the actual selected row index be kept while you navigate back to the previous page.

Parameters:
selectViewIndex - the flag

firstPage

public void firstPage()
Navigates to the first page.


lastPage

public void lastPage()
Navigates to the last page.


getPageSize

protected int getPageSize()
Gets the page size to change the current record while previous or next page is requested.

Returns:
the page size.

previousPage

public void previousPage()
Navigates to the previous page.


nextPage

public void nextPage()
Navigates to the next page.


firstRecord

public void firstRecord()
Navigates to the first record/row.


lastRecord

public void lastRecord()
Navigates to the last record/row.


firstRecordInPage

public void firstRecordInPage()
Navigates to the first record/row in the current page.


lastRecordInPage

public void lastRecordInPage()
Navigates to the last record/row in the current page.


previousRecord

public void previousRecord()
Navigates to the previous record/row, changes the current page if necessary.


nextRecord

public void nextRecord()
Navigates to the next record/row, changes the current page if necessary.


gotoPage

protected void gotoPage()
Navigates to the page as shown in the PageNavigationField.


gotoRecord

protected void gotoRecord()
Navigates to the record/row as shown in the PageNavigationField.


getRecordCountInPage

protected int getRecordCountInPage()
Gets the record/row count in the current page.

Returns:
the record/row count in the current page.

getSelectedRecordIndex

protected int getSelectedRecordIndex()
Gets the selected record/row index.

Returns:
the selected record/row index.

setSelectedRecordIndex

protected void setSelectedRecordIndex(int row)
Sets the selected record/row.

Parameters:
row - the new selected record/row index.

gotoPage

public void gotoPage(int page)
Navigates to the specified page. It will beep if the page is invalid.

Parameters:
page - the new page index.

changeCurrentPage

protected void changeCurrentPage(int newPageIndex)

gotoRecord

public int gotoRecord(int record)
Navigates to the specified record/row. It will beep if the record/row is invalid.

Parameters:
record - the new record/row index.
Returns:
the actual record number that goes to.

selectRecord

public void selectRecord(int record)
Navigates to and select the specified record/row. It will beep if the record/row is invalid.

Parameters:
record - the new record/row index.
Since:
3.4.1

notifyUser

protected void notifyUser()

updateButtonPanel

protected void updateButtonPanel()

isAtLastPage

protected boolean isAtLastPage()
Checks if right now it's the last possible page.

Returns:
true if current page is the last page. Otherwise false.

isAtFirstPage

protected boolean isAtFirstPage()
Checks if right now it's the first possible page.

Returns:
true if current page is the first page. Otherwise false.

setEnabled

public void setEnabled(boolean enabled)
Overrides:
setEnabled in class JComponent

setButtonVisible

public void setButtonVisible(String command,
                             boolean visible)
Sets the button visible or invisible.

Parameters:
command - the name defined in DualList. They are constants starting with "COMMAND_" such as COMMAND_FIRST.
visible - true to show the button and false to hide.

isButtonVisible

public boolean isButtonVisible(String command)
Checks if the button is visible.

Parameters:
command - the name defined in DualList. They are constants starting with "COMMAND_" such as COMMAND_FIRST.
Returns:
true or false.

setButtonEnabled

public void setButtonEnabled(String command,
                             boolean enabled)
Sets the button to always disabled.

Parameters:
command - the name defined in DualList. They are constants starting with "COMMAND_" such as COMMAND_FIRST.
enabled - false to always disable the button.

isButtonEnabled

public boolean isButtonEnabled(String command)
Checks if the button is always disabled.

Parameters:
command - the name defined in DualList. They are constants starting with "COMMAND_" such as COMMAND_FIRST.
Returns:
false if the button is always disabled. Otherwise true. Note that this method still could return true when the button isEnabled() return false.

getPageNavigationSupport

public PageNavigationSupport getPageNavigationSupport()
Gets the PageNavigationSupport used by this PageNavigationBar.

Returns:
the PageNavigationSupport used by this PageNavigationBar.

JIDE 3.5.15