public class ColumnControlButton extends JButton
JXTable
's
columns.
It's main purpose is to allow toggling of table columns' visibility.
Additionally, arbitrary configuration actions can be exposed.
This component is installed in the JXTable
's
trailing corner, if enabled:
table.setColumnControlVisible(true);
From the perspective of a JXTable
, the component's behaviour is
opaque. Typically, the button's action is to popup a component for user
interaction.
This class is responsible for handling/providing/updating the lists of
actions and to keep each Action's state in synch with Table-/Column state.
The visible behaviour of the popup is delegated to a
ColumnControlPopup
.
Default support for adding table (configuration or other) Action
s is
informal, driven by convention:
ColumnControlButton.COLUMN_CONTROL_MARKER
Modifier and Type | Class and Description |
---|---|
class |
ColumnControlButton.ColumnVisibilityAction
A specialized
Action which takes care of keeping in synch with
TableColumn state. |
class |
ColumnControlButton.DefaultColumnControlPopup
A default implementation of ColumnControlPopup.
|
JButton.AccessibleJButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
private boolean |
additionalActionsVisible |
static String |
COLUMN_CONTROL_BUTTON_ICON_KEY
the key for looking up the control's icon in the UIManager.
|
static String |
COLUMN_CONTROL_BUTTON_MARGIN_KEY
the key for looking up the control's margin in the UIManager.
|
static String |
COLUMN_CONTROL_MARKER
Marker to auto-recognize actions which should be added to the popup.
|
(package private) TableColumnModelListener |
columnModelListener
Listener for table's columnModel.
|
private List<ColumnControlButton.ColumnVisibilityAction> |
columnVisibilityActions
the list of actions for column menuitems.
|
protected ColumnControlPopup |
popup
exposed for testing.
|
private JXTable |
table
The table which is controlled by this.
|
private PropertyChangeListener |
tablePropertyChangeListener
Listener for table property changes.
|
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
ColumnControlButton(JXTable table)
Creates a column control button for the table.
|
ColumnControlButton(JXTable table,
Icon icon)
Creates a column control button for the table.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addAdditionalActionItems()
Adds additional actions to the popup, if additionalActionsVisible is true,
does nothing otherwise.
|
protected void |
addVisibilityActionItems()
Adds visibility actions into the popup view.
|
void |
applyComponentOrientation(ComponentOrientation o) |
protected boolean |
canControl()
Method to check if we can control column visibility POST: if true we can
be sure to have an extended TableColumnModel
|
protected void |
clearAll()
removes all components from the popup, making sure to release all
columnVisibility actions.
|
protected void |
clearColumnVisibilityActions()
Releases actions and clears list of actions.
|
protected ColumnControlPopup |
createColumnControlPopup()
Factory method to return a
ColumnControlPopup . |
protected TableColumnModelListener |
createColumnModelListener()
Creates the listener to columnModel.
|
protected ColumnControlButton.ColumnVisibilityAction |
createColumnVisibilityAction(TableColumn column)
Creates and returns a
ColumnVisibilityAction for the given
TableColumn . |
private Action |
createControlAction(Icon icon)
Creates and returns the default action for this button.
|
protected PropertyChangeListener |
createTablePropertyChangeListener()
Creates the listener to table's property changes.
|
protected void |
createVisibilityActions()
Creates and adds a ColumnVisiblityAction for every column that should be
togglable via the column control.
|
protected List<Action> |
getAdditionalActions()
creates and returns a list of additional Actions to add to the popup.
|
boolean |
getAdditionalActionsVisible()
Returns the actionsVisible property which controls whether or not
additional table Actions should be included into the popup.
|
protected List |
getColumnControlActionKeys()
Looks up and returns action keys to access actions in the
table's actionMap which should be included into the popup.
|
protected ColumnControlPopup |
getColumnControlPopup()
Returns to popup component for user interaction.
|
protected TableColumnModelListener |
getColumnModelListener()
Returns the listener to table's column model.
|
protected List<ColumnControlButton.ColumnVisibilityAction> |
getColumnVisibilityActions()
Lazyly creates and returns the List of visibility actions.
|
protected PropertyChangeListener |
getTablePropertyChangeListener()
Returns the listener to table's property changes.
|
private void |
init()
Initialize the column control button's gui
|
private void |
installTable(JXTable table) |
protected boolean |
isColumnControlActionKey(Object actionKey)
Here: true if a String key starts with #COLUMN_CONTROL_MARKER.
|
protected void |
populatePopup()
Populates the popup from scratch.
|
void |
setActionGrouper(ColumnControlPopup.ActionGrouper grouper)
Sets the grouper to use for grouping the additional actions.
|
void |
setAdditionalActionsVisible(boolean additionalActionsVisible)
Sets the additonalActionsVisible property.
|
void |
togglePopup()
Toggles the popup component's visibility.
|
protected void |
updateActionUI()
Updates the action properties provided by the LAF.
|
protected void |
updateButtonUI()
Updates this button's properties provided by the LAF.
|
protected void |
updateFromColumnModelChange(TableColumnModel oldModel)
Adjusts internal state after table's column model property has changed.
|
protected void |
updateFromTableEnabledChanged()
Synchs this button's enabled with table's enabled.
|
void |
updateUI() |
getAccessibleContext, getUIClassID, isDefaultButton, isDefaultCapable, paramString, removeNotify, setDefaultCapable
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, 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
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, 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, transferFocusDownCycle, validate, validateTree
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, 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, transferFocusBackward, transferFocusUpCycle
public static final String COLUMN_CONTROL_MARKER
public static final String COLUMN_CONTROL_BUTTON_ICON_KEY
public static final String COLUMN_CONTROL_BUTTON_MARGIN_KEY
protected ColumnControlPopup popup
private PropertyChangeListener tablePropertyChangeListener
TableColumnModelListener columnModelListener
private List<ColumnControlButton.ColumnVisibilityAction> columnVisibilityActions
private boolean additionalActionsVisible
public ColumnControlButton(JXTable table)
table
- the JXTable
controlled by this componentpublic ColumnControlButton(JXTable table, Icon icon)
table
- the JXTable
controlled by this componenticon
- the Icon
to showprotected void updateButtonUI()
protected void updateActionUI()
public void togglePopup()
Here: delegates to getControlPopup().
public boolean getAdditionalActionsVisible()
public void setAdditionalActionsVisible(boolean additionalActionsVisible)
The default value is true
.
additionalActionsVisible
- the additionalActionsVisible to setpublic void setActionGrouper(ColumnControlPopup.ActionGrouper grouper)
grouper
- public void applyComponentOrientation(ComponentOrientation o)
applyComponentOrientation
in class Container
protected ColumnControlPopup getColumnControlPopup()
null
.createColumnControlPopup()
protected ColumnControlPopup createColumnControlPopup()
ColumnControlPopup
.
Subclasses can override to hook custom implementations.ColumnControlPopup
used.protected void updateFromColumnModelChange(TableColumnModel oldModel)
oldModel
- the old TableColumnModel
we had been listening to.protected void updateFromTableEnabledChanged()
protected boolean canControl()
protected void populatePopup()
protected void clearAll()
protected void clearColumnVisibilityActions()
protected void addVisibilityActionItems()
PRE: columnVisibilityActions populated before calling this.
protected void addAdditionalActionItems()
Here: delegates the list of actions as returned by #getAdditionalActions() to the DefaultColumnControlPopup. Does nothing if #getColumnActions() is empty.
protected void createVisibilityActions()
Here: all table columns contained in the TableColumnModel
-
visible and invisible columns - to createColumnVisibilityAction
and
adds all not null
return values.
PRE: canControl()
protected ColumnControlButton.ColumnVisibilityAction createColumnVisibilityAction(TableColumn column)
ColumnVisibilityAction
for the given
TableColumn
. The return value might be null, f.i. if the
column should not be allowed to be toggled.column
- the TableColumn
to use for the actionnull
.protected List<ColumnControlButton.ColumnVisibilityAction> getColumnVisibilityActions()
protected List<Action> getAdditionalActions()
protected List getColumnControlActionKeys()
protected boolean isColumnControlActionKey(Object actionKey)
actionKey
- a key in the table's actionMap.private void installTable(JXTable table)
private void init()
private Action createControlAction(Icon icon)
icon
- icon
- the Icon to use in the action.protected PropertyChangeListener getTablePropertyChangeListener()
PropertyChangeListener
for use with the
table, guaranteed to be not null
.protected PropertyChangeListener createTablePropertyChangeListener()
Implementation note: this listener reacts to table's enabled
and
columnModel
properties and calls the respective
updateFromXX
methodes.
PropertyChangeListener
for use with the table.protected TableColumnModelListener getColumnModelListener()
TableColumnModelListener
for use with the
table's column model, guaranteed to be not null
.protected TableColumnModelListener createColumnModelListener()
Implementation note: this listener reacts to "real" columnRemoved/-Added by populating the popups content from scratch.
TableColumnModelListener
for use with the
table's columnModel.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses