com.limegroup.gnutella.gui.tables
Class AbstractTableMediator

java.lang.Object
  extended bycom.limegroup.gnutella.gui.tables.AbstractTableMediator
All Implemented Interfaces:
ComponentMediator, HeaderMouseObserver, RefreshListener, ThemeObserver
Direct Known Subclasses:
ConnectionMediator, DownloadMediator, UploadMediator

public abstract class AbstractTableMediator
extends java.lang.Object
implements ComponentMediator, HeaderMouseObserver, ThemeObserver

The basics of a ComponentMediator for a Table. Used for: Associating a LimeJTable (TABLE) with a DataLineModel (DATA_MODEL). Associating a JPopupMenu & ButtonRow (BUTTON_ROW) with the DATA_MODEL. Holding common Action/Mouse/ListSelection listeners. (REMOVE_LISTENER, DEFAULT_LISTENER, HEADER_LISTENER, SELECTION_LISTENER) Holding common TableCellRenderers. [static] (PROGRESS_BAR_RENDERER, CHAT_RENDERER) Building a JPanel (MAIN_PANEL) of the LimeJTable, ButtonRow & JPopupMenu. Handling mouse interactions and displaying the appropriate menus. A popup menu if right-click over table. ColumnSelectionMenu if right-click over the header. Sorting the DATA_MODEL if left-click over the header. Refreshing the DATA_MODEL from the RefreshListener's call.


Nested Class Summary
protected  class AbstractTableMediator.Resorter
           
 
Field Summary
protected  ButtonRow BUTTON_ROW
          Variable to the ButtonRow for this table.
protected static javax.swing.table.TableCellRenderer CHAT_RENDERER
          Variable for the ChatRenderer for all components.
protected static javax.swing.table.TableCellRenderer COLOR_RENDERER
          Variable for the ColorRenderer for all components.
protected  DataLineModel DATA_MODEL
          Variable to the DataLineList containg the underlying data for this table.
 java.awt.event.MouseListener DEFAULT_LISTENER
          Variable for the DefaultMouseListener for this component.
 javax.swing.event.MouseInputListener HEADER_LISTENER
          Variable for the HeaderMouseListener for this component.
protected  java.lang.String ID
          The ID that uniquely defines this table.
protected  PaddedPanel MAIN_PANEL
          Variable to the main component displaying this Table.
protected static javax.swing.table.TableCellRenderer PROGRESS_BAR_RENDERER
          Variable for the ProgressBarRenderer for all components.
 java.awt.event.ActionListener REMOVE_LISTENER
          Variable for the RemoveListener for this component.
protected  AbstractTableMediator.Resorter RESORTER
          Resorter -- for doing real-time resorts.
protected  javax.swing.JScrollPane SCROLL_PANE
          The JScrollPane instance for scrolling through the table.
 javax.swing.event.ListSelectionListener SELECTION_LISTENER
          Variable for the ListSelectionListener for this component.
 TableSettings SETTINGS
          Variable for the TableSettings for this component.
protected  LimeJTable TABLE
          Variable to the LimeJTable for this table.
protected  java.awt.Component TABLE_PANE
          The Component containing the JScrollPane for the table.
protected static java.awt.Dimension ZERO_DIMENSION
          A zero dimension to be used in all tables.
 
Constructor Summary
protected AbstractTableMediator(java.lang.String id)
          Basic constructor that uses a Template Pattern to delegate the setup functions to individual methods.
 
Method Summary
 void add(java.lang.Object o)
          Add a new DataLine initialized by Object o to the list, tell the dataModel there was a row inserted, and unselect the first row (to address the java bug)
protected  void addListeners()
          Adds the listeners to the table.
 void addUnsorted(java.lang.Object o)
          Forces the object to be added unsorted.
protected  void buildListeners()
          Assigns the listeners to their slots.
protected  void buildSettings()
          Retrieves or builds the correct settings.
protected  void clearSelection()
          Helper-function to clear selected items.
 void clearTable()
          Clear the table of all items
protected  javax.swing.JPopupMenu createColumnSelectionMenu()
          Creates a new ColumnSelectionMenu JPopupMenu.
protected  ColumnPreferenceHandler createDefaultColumnPreferencesHandler()
           
protected abstract  javax.swing.JPopupMenu createPopupMenu()
          Abstract method for creating a right-click popup menu for the table.
protected  void doRefresh()
          Exists for extending classes to overwrite.
 void forceResort()
          Resorts the underlying data, regardless of if the column is dynamic.
 javax.swing.JComponent getComponent()
          Returns the underlying component that this Mediator handles
protected  java.awt.Component getScrolledTablePane()
          Sets up & gets the table inside a JScrollPanel inside a JPanel.
 int getSize()
          Gets the size of the underlying model.
 void handleHeaderColumnLeftClick(java.awt.Point p)
          Sorts the column whose header maps to the given point
 void handleHeaderColumnPressed(java.awt.Point p)
          Tell the table something is pressed.
 void handleHeaderColumnReleased(java.awt.Point p)
          Tell the table something is not pressed.
 void handleHeaderPopupMenu(java.awt.Point p)
          Show the column selection menu.
 void handlePopupMenu(java.awt.Point p)
          Shows the popup menu at Point p
 void handleRightMouseClick(java.awt.Point p)
          Changes the selection in the table in response to a right-mouse click.
 void refresh()
          Implements RefreshListener Wraps the doRefresh call so that extending classes can maintain the resort & isShowing checks.
 void remove(java.lang.Object o)
          Removes the row associated with the Object o Delegates to removeRow(int) If no matching row is found, nothing is done.
 void removeRow(int row)
          Removes the row.
 void removeSelection()
          Removes all selected rows from the list and fires deletions through the dataModel
 void resort()
          Resorts the underlying data.
 void setButtonEnabled(int buttonIdx, boolean enabled)
          Delegates the setButtonEnabled call to the ButtonRow
protected  void setDefaultEditors()
          Intended for setting up default editors.
protected  void setDefaultRenderers()
          Intended for adding default renderers to the table.
protected abstract  void setupConstants()
          Intended for setting the DATA_MODEL and TABLE constants.
protected  void setupMainPanel()
          Sets up the MAIN_PANEL to have a uniform look among all tables.
protected  void setupTable()
          Sets row heights a little larger than normal, turns off the display of the grid and disallows column selections.
protected  void setupTableHeaders()
          Organizes the table headers so that they're sized correctly, in the correct order, and are either visible or not visible, depending on the user's preferences.
protected  void sortAndMaintainSelection(int columnToSort)
          Sorts the DATA_MODEL and maintains selections in the TABLE.
 void update(java.lang.Object o)
          Tells the model to update a specific DataLine
protected abstract  void updateSplashScreen()
          Intended for updating the splash screen while this component loads.
 void updateTheme()
          Update any required theme settings, such as colors or images.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.limegroup.gnutella.gui.tables.ComponentMediator
handleMouseDoubleClick, handleNoSelection, handleSelection
 

Field Detail

ID

protected final java.lang.String ID
The ID that uniquely defines this table.


MAIN_PANEL

protected PaddedPanel MAIN_PANEL
Variable to the main component displaying this Table. MUST be initialize in setupConstants()


DATA_MODEL

protected DataLineModel DATA_MODEL
Variable to the DataLineList containg the underlying data for this table. MUST be initialized in setupConstants()


TABLE

protected LimeJTable TABLE
Variable to the LimeJTable for this table. MUST be initialize in setupConstants()


BUTTON_ROW

protected ButtonRow BUTTON_ROW
Variable to the ButtonRow for this table.


REMOVE_LISTENER

public java.awt.event.ActionListener REMOVE_LISTENER
Variable for the RemoveListener for this component.


DEFAULT_LISTENER

public java.awt.event.MouseListener DEFAULT_LISTENER
Variable for the DefaultMouseListener for this component.


HEADER_LISTENER

public javax.swing.event.MouseInputListener HEADER_LISTENER
Variable for the HeaderMouseListener for this component.


SELECTION_LISTENER

public javax.swing.event.ListSelectionListener SELECTION_LISTENER
Variable for the ListSelectionListener for this component.


SETTINGS

public TableSettings SETTINGS
Variable for the TableSettings for this component.


PROGRESS_BAR_RENDERER

protected static final javax.swing.table.TableCellRenderer PROGRESS_BAR_RENDERER
Variable for the ProgressBarRenderer for all components.


CHAT_RENDERER

protected static final javax.swing.table.TableCellRenderer CHAT_RENDERER
Variable for the ChatRenderer for all components.


COLOR_RENDERER

protected static final javax.swing.table.TableCellRenderer COLOR_RENDERER
Variable for the ColorRenderer for all components.


ZERO_DIMENSION

protected static final java.awt.Dimension ZERO_DIMENSION
A zero dimension to be used in all tables.


RESORTER

protected AbstractTableMediator.Resorter RESORTER
Resorter -- for doing real-time resorts.


TABLE_PANE

protected java.awt.Component TABLE_PANE
The Component containing the JScrollPane for the table.


SCROLL_PANE

protected javax.swing.JScrollPane SCROLL_PANE
The JScrollPane instance for scrolling through the table.

Constructor Detail

AbstractTableMediator

protected AbstractTableMediator(java.lang.String id)
Basic constructor that uses a Template Pattern to delegate the setup functions to individual methods. The following methods are called in the order they are listed.

Of these, some have are already written as default implementions. The extending class should call GUIMediator.addRefreshListener(this) if they want to be a refreshListener.

Method Detail

updateSplashScreen

protected abstract void updateSplashScreen()
Intended for updating the splash screen while this component loads.


buildSettings

protected void buildSettings()
Retrieves or builds the correct settings.


setupConstants

protected abstract void setupConstants()
Intended for setting the DATA_MODEL and TABLE constants. Optionally, MAIN_PANEL, BUTTON_ROW, and POPUP_MENU can also be set.


buildListeners

protected void buildListeners()
Assigns the listeners to their slots. This must be done _before_ the individual components are created, incase any of them want to use a listener. Extending components that want to build extra listeners should call super.buildListeners and then build their own. DEFAULT_LISTENER, SELECTION_LISTENER, HEADER_LISTENER, and REMOVE_LISTENER are created by default.


addListeners

protected void addListeners()
Adds the listeners to the table. Extending components that want to add extra listeners should call super.addListeners and then add their own. DEFAULT_LISTENER, SELECTION_LISTENER and HEADER_LISTENER are added by default.


setupTable

protected void setupTable()
Sets row heights a little larger than normal, turns off the display of the grid and disallows column selections.


setDefaultRenderers

protected void setDefaultRenderers()
Intended for adding default renderers to the table. Extending components that want to add extra default renderers should call super.setDefaultRenderers and then add their own. By default, PROGRESS_BAR_RENDERER is assigned to ProgressBarHolder.class, CHAT_RENDERER is assigned to ChatHolder.class, and COLOR_RENDERER is assigned to ColoredCell.class.


setDefaultEditors

protected void setDefaultEditors()
Intended for setting up default editors. By default, no editors are added.


setupMainPanel

protected void setupMainPanel()
Sets up the MAIN_PANEL to have a uniform look among all tables. If the MAIN_PANEL is not created, nothing will happen.


setupTableHeaders

protected void setupTableHeaders()
Organizes the table headers so that they're sized correctly, in the correct order, and are either visible or not visible, depending on the user's preferences.


createDefaultColumnPreferencesHandler

protected ColumnPreferenceHandler createDefaultColumnPreferencesHandler()

getScrolledTablePane

protected java.awt.Component getScrolledTablePane()
Sets up & gets the table inside a JScrollPanel inside a JPanel.


updateTheme

public void updateTheme()
Description copied from interface: ThemeObserver
Update any required theme settings, such as colors or images.

Specified by:
updateTheme in interface ThemeObserver

add

public void add(java.lang.Object o)
Add a new DataLine initialized by Object o to the list, tell the dataModel there was a row inserted, and unselect the first row (to address the java bug)

Specified by:
add in interface ComponentMediator

addUnsorted

public void addUnsorted(java.lang.Object o)
Forces the object to be added unsorted.


remove

public void remove(java.lang.Object o)
Removes the row associated with the Object o Delegates to removeRow(int) If no matching row is found, nothing is done.

Specified by:
remove in interface ComponentMediator

removeRow

public void removeRow(int row)
Removes the row.


refresh

public void refresh()
Implements RefreshListener Wraps the doRefresh call so that extending classes can maintain the resort & isShowing checks. Extending classes should NOT override this. Instead, they should override doRefresh.

Specified by:
refresh in interface RefreshListener

doRefresh

protected void doRefresh()
Exists for extending classes to overwrite. Mostly used for updating the values of buttons/menu-items With the return value of the DATA_MODEL's refresh.


update

public void update(java.lang.Object o)
Tells the model to update a specific DataLine

Specified by:
update in interface ComponentMediator

resort

public void resort()
Resorts the underlying data. Maintains highlighted rows.


forceResort

public void forceResort()
Resorts the underlying data, regardless of if the column is dynamic.


getComponent

public javax.swing.JComponent getComponent()
Description copied from interface: ComponentMediator
Returns the underlying component that this Mediator handles

Specified by:
getComponent in interface ComponentMediator
Returns:
The main component which has all components

removeSelection

public void removeSelection()
Removes all selected rows from the list and fires deletions through the dataModel

Specified by:
removeSelection in interface ComponentMediator

createColumnSelectionMenu

protected javax.swing.JPopupMenu createColumnSelectionMenu()
Creates a new ColumnSelectionMenu JPopupMenu. If the table wants to use a custom popup menu, override this method and do something different.


handleRightMouseClick

public void handleRightMouseClick(java.awt.Point p)
Changes the selection in the table in response to a right-mouse click. This was contributed by Chance Moore originally for the search package.

Specified by:
handleRightMouseClick in interface ComponentMediator

handlePopupMenu

public void handlePopupMenu(java.awt.Point p)
Shows the popup menu at Point p

Specified by:
handlePopupMenu in interface ComponentMediator

handleHeaderColumnLeftClick

public void handleHeaderColumnLeftClick(java.awt.Point p)
Sorts the column whose header maps to the given point

Specified by:
handleHeaderColumnLeftClick in interface HeaderMouseObserver

handleHeaderPopupMenu

public void handleHeaderPopupMenu(java.awt.Point p)
Show the column selection menu.

Specified by:
handleHeaderPopupMenu in interface HeaderMouseObserver

handleHeaderColumnPressed

public void handleHeaderColumnPressed(java.awt.Point p)
Tell the table something is pressed.

Specified by:
handleHeaderColumnPressed in interface HeaderMouseObserver

handleHeaderColumnReleased

public void handleHeaderColumnReleased(java.awt.Point p)
Tell the table something is not pressed.

Specified by:
handleHeaderColumnReleased in interface HeaderMouseObserver

setButtonEnabled

public void setButtonEnabled(int buttonIdx,
                             boolean enabled)
Delegates the setButtonEnabled call to the ButtonRow

Specified by:
setButtonEnabled in interface ComponentMediator

getSize

public int getSize()
Gets the size of the underlying model.


clearTable

public void clearTable()
Clear the table of all items


clearSelection

protected void clearSelection()
Helper-function to clear selected items.


sortAndMaintainSelection

protected void sortAndMaintainSelection(int columnToSort)
Sorts the DATA_MODEL and maintains selections in the TABLE. If columnToSort is -1, it will resort the current column. Otherwise it will sort columnToSort.


createPopupMenu

protected abstract javax.swing.JPopupMenu createPopupMenu()
Abstract method for creating a right-click popup menu for the table. If an implemention does not support a right-click popup menu, it should return null.

Returns:
a new JPopupMenu to display on right-click