站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

AbstractTabCellRenderer (Tab Control) - NetBeans API Javadoc (Current Development Version)

org.netbeans.swing.tabcontrol 1.8

org.netbeans.swing.tabcontrol.plaf
Class AbstractTabCellRenderer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by org.netbeans.swing.tabcontrol.plaf.AbstractTabCellRenderer
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, TabCellRenderer

public abstract class AbstractTabCellRenderer
extends JLabel
implements TabCellRenderer

Base class for tab renderers for the tab control. This is a support class which will allow authors who want to provide a different look or behavior for tabbed controls with a minimum of coding. The main methods of interest are

.

Typical usage is to pass one or more TabPainter objects to the constructor which will be responsible for doing the actual painting, calling the convenience getters in this class (such as isSelected) to determine how to paint.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JLabel
labelFor
 
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
AbstractTabCellRenderer(TabPainter painter, Dimension padding)
           
AbstractTabCellRenderer(TabPainter leftClip, TabPainter noClip, TabPainter rightClip, Dimension padding)
          Creates a new instance of AbstractTabCellRenderer
 
Method Summary
 void addContainerListener(ContainerListener cl)
          Overridden to be a no-op for performance reasons
 void addHierarchyBoundsListener(HierarchyBoundsListener hbl)
          Overridden to be a no-op for performance reasons
 void addHierarchyListener(HierarchyListener hl)
          Overridden to be a no-op for performance reasons
protected  void firePropertyChange(String s, Object a, Object b)
          Overridden to be a no-op for performance reasons
protected  int getCaptionYAdjustment()
          Return non-zero to shift the text up or down by the specified number of pixels when painting.
 String getCommandAtPoint(Point p, int tabState, Rectangle bounds)
          Get a command string which is identified with a region of the tab cell renderer, such as TabbedContainer.COMMAND_CLOSE if the point is inside the close button, or TabbedContainer.COMMAND_SELECT if the point is over the tab title.
 String getCommandAtPoint(Point p, int tabState, Rectangle bounds, int mouseButton, int eventType, int modifiers)
          Get a command string which is identified with a region of the tab cell renderer, such as TabbedContainer.COMMAND_CLOSE if the point is inside the close button, or TabbedContainer.COMMAND_SELECT if the point is over the tab title.
protected  int getIconYAdjustment()
          Return non-zero to shift the icon up or down by the specified number of pixels when painting.
 Dimension getPadding()
          Returns the number of pixels this renderer wants added to the base width and height of the icon and text to fit decorations such as close butons, drag indicators, etc.
 int getPixelsToAddToSelection()
          Subclasses which want to make the selected tab wider than it would otherwise be should return a value greater than 0 here.
 JComponent getRendererComponent(TabData data, Rectangle bounds, int state)
          Implementation of getRendererComponent from TabCellRenderer.
 Color getSelectedActivatedBackground()
           
 Color getSelectedActivatedForeground()
           
 Color getSelectedBackground()
           
 Color getSelectedForeground()
           
 int getState()
          Returns the state as set up in getRendererComponent
 Polygon getTabShape(int tabState, Rectangle bounds)
          Get the shape of the tab.
protected  boolean inCloseButton()
           
protected  boolean isActive()
          Convenience getter to determine if the current state includes the active state (a component in the container or the container itself has keyboard focus)
protected  boolean isArmed()
          Convenience getter to determine if the current state includes the armed state (the mouse is in the tab the component is currently configured to render).
protected  boolean isAttention()
           
protected  boolean isClipLeft()
          Convenience getter to determine if the current state includes the left-clipped state (the right hand side of the tab is not visible).
protected  boolean isClipRight()
          Convenience getter to determine if the current state includes the right-clipped state (the right hand side of the tab is not visible).
protected  boolean isLeftmost()
          Convenience getter to determine if the current state indicates that the renderer is currently configured as the leftmost (non-clipped).
protected  boolean isNextTabArmed()
          Convenience getter to determine if the current state indicates that the renderer is currently configured appears to the left of the armed tab.
protected  boolean isNextTabSelected()
          Convenience getter to determine if the current state indicates that the renderer is currently configured appears to the left of the selected tab.
protected  boolean isPressed()
          Convenience getter to determine if the current state includes the pressed state (the mouse is in the tab this component is currently configured to render, and the mouse button is currently down)
protected  boolean isPreviousTabSelected()
          Convenience getter to determine if the current state indicates that the renderer is currently configured appears to the right of the selected tab.
protected  boolean isRightmost()
          Convenience getter to determine if the current state indicates that the renderer is currently configured as the rightmost (non-clipped).
protected  boolean isSelected()
          Convenience getter to determine if the current state includes the selected state (the tab this component is currently configured to render is the selected tab in a container)
 boolean isShowCloseButton()
           
 void paintComponent(Graphics g)
          Overridden to paint the interior of the polygon if the border is an instance of TabPainter.
protected  void paintIconAndText(Graphics g)
          Actually paints the icon and text (using the lightweight HTML renderer)
 void repaint()
          Overridden to be a no-op for performance reasons
 void repaint(long tm)
          Overridden to be a no-op for performance reasons
 void repaint(long tm, int x, int y, int w, int h)
          Overridden to be a no-op for performance reasons
 void revalidate()
          Overridden to be a no-op for performance reasons
 void setShowCloseButton(boolean b)
           
protected  void setState(int state)
          Set the state of the renderer, in preparation for painting it or evaluating a condition (such as the position of the close button) for which it must be correctly configured).
protected  int stateChanged(int oldState, int newState)
           
 void validate()
          Overridden to be a no-op for performance reasons
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, 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, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, 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, addImpl, 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, setLayout, transferFocusBackward, transferFocusDownCycle, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, 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, 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, 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
 

Constructor Detail

AbstractTabCellRenderer

public AbstractTabCellRenderer(TabPainter leftClip,
                               TabPainter noClip,
                               TabPainter rightClip,
                               Dimension padding)
Creates a new instance of AbstractTabCellRenderer


AbstractTabCellRenderer

public AbstractTabCellRenderer(TabPainter painter,
                               Dimension padding)
Method Detail

setShowCloseButton

public final void setShowCloseButton(boolean b)
Specified by:
setShowCloseButton in interface TabCellRenderer

isShowCloseButton

public final boolean isShowCloseButton()
Specified by:
isShowCloseButton in interface TabCellRenderer

getCommandAtPoint

public String getCommandAtPoint(Point p,
                                int tabState,
                                Rectangle bounds)
Description copied from interface: TabCellRenderer
Get a command string which is identified with a region of the tab cell renderer, such as TabbedContainer.COMMAND_CLOSE if the point is inside the close button, or TabbedContainer.COMMAND_SELECT if the point is over the tab title. The command returned should be the one that would be executed were the default mouse button to be pressed. Primarily this method is used to determine what, if any, visual feedback to show to the user as the mouse is moved over tabs.

Specified by:
getCommandAtPoint in interface TabCellRenderer
Parameters:
p - A point (presumably) within the bounds of the passed rectangle
tabState - The state of the tab, such as selected, clip right, etc.
bounds - The bounds of the tab, defining the coordinate space in which the point parameter should be evaluated
Returns:
A command string. TabDisplayer/TabbedContainer define a small number, but other UIs can define whatever private contract they want. If the action is performed, an action event with this string will be fired from the tabbed container, so client code can handle the actual work of the action as needed

getCommandAtPoint

public String getCommandAtPoint(Point p,
                                int tabState,
                                Rectangle bounds,
                                int mouseButton,
                                int eventType,
                                int modifiers)
Description copied from interface: TabCellRenderer
Get a command string which is identified with a region of the tab cell renderer, such as TabbedContainer.COMMAND_CLOSE if the point is inside the close button, or TabbedContainer.COMMAND_SELECT if the point is over the tab title. Note that this method may return a different result than getCommandAtPoint (Point p, int tabState, Rectangle bounds) - that method is primarily used for painting logic (such as whether to draw a rectangle around a close button); this one is to determine the actual action, if any to perform. So it is free to return null, some other action, etc.

Specified by:
getCommandAtPoint in interface TabCellRenderer
Parameters:
p - A point (presumably) within the bounds of the passed rectangle
tabState - The state of the tab, such as selected, clip right, etc.
bounds - The bounds of the tab, defining the coordinate space in which the point parameter should be evaluated
mouseButton - The mouse button used to produce the event, as defined in MouseEvent
eventType - The event type, as defined in MouseEvent
modifiers - The modifiers mask, as defined in MouseEvent
Returns:
A command string or null

isArmed

protected final boolean isArmed()
Convenience getter to determine if the current state includes the armed state (the mouse is in the tab the component is currently configured to render).


isActive

protected final boolean isActive()
Convenience getter to determine if the current state includes the active state (a component in the container or the container itself has keyboard focus)


isPressed

protected final boolean isPressed()
Convenience getter to determine if the current state includes the pressed state (the mouse is in the tab this component is currently configured to render, and the mouse button is currently down)


isSelected

protected final boolean isSelected()
Convenience getter to determine if the current state includes the selected state (the tab this component is currently configured to render is the selected tab in a container)


isClipRight

protected final boolean isClipRight()
Convenience getter to determine if the current state includes the right-clipped state (the right hand side of the tab is not visible).


isClipLeft

protected final boolean isClipLeft()
Convenience getter to determine if the current state includes the left-clipped state (the right hand side of the tab is not visible).


isLeftmost

protected final boolean isLeftmost()
Convenience getter to determine if the current state indicates that the renderer is currently configured as the leftmost (non-clipped).


isRightmost

protected final boolean isRightmost()
Convenience getter to determine if the current state indicates that the renderer is currently configured as the rightmost (non-clipped).


isAttention

protected final boolean isAttention()

isNextTabSelected

protected final boolean isNextTabSelected()
Convenience getter to determine if the current state indicates that the renderer is currently configured appears to the left of the selected tab.


isNextTabArmed

protected final boolean isNextTabArmed()
Convenience getter to determine if the current state indicates that the renderer is currently configured appears to the left of the armed tab.


isPreviousTabSelected

protected final boolean isPreviousTabSelected()
Convenience getter to determine if the current state indicates that the renderer is currently configured appears to the right of the selected tab.


getPadding

public Dimension getPadding()
Description copied from interface: TabCellRenderer
Returns the number of pixels this renderer wants added to the base width and height of the icon and text to fit decorations such as close butons, drag indicators, etc. This method is called only once, during initialization, if this renderer is the default renderer created by TabsUI.createDefaultRenderer(). The values it returns cannot be changed dynamically. The result will be passed as padX/padY arguments to the constructor of DefaultTabLayoutModel (unless createLayoutModel is overridden with some custom model - then all bets are off).

Specified by:
getPadding in interface TabCellRenderer

setState

protected final void setState(int state)
Set the state of the renderer, in preparation for painting it or evaluating a condition (such as the position of the close button) for which it must be correctly configured). This method will call stateChanged(), allowing the renderer to reconfigure itself if necessary, when the state changes.

Parameters:
state -

getState

public final int getState()
Returns the state as set up in getRendererComponent


getRendererComponent

public final JComponent getRendererComponent(TabData data,
                                             Rectangle bounds,
                                             int state)
Implementation of getRendererComponent from TabCellRenderer. This method is final, and will configure the text, bounds and icon correctly according to the passed values, and call setState to set the state of the tab. Implementers must implement stateChanged() to handle any changes (background color, border, etc) necessary to reflect the current state as returned by getState().

Specified by:
getRendererComponent in interface TabCellRenderer

stateChanged

protected int stateChanged(int oldState,
                           int newState)

revalidate

public void revalidate()
Overridden to be a no-op for performance reasons

Overrides:
revalidate in class JComponent

repaint

public void repaint()
Overridden to be a no-op for performance reasons

Overrides:
repaint in class Component

validate

public void validate()
Overridden to be a no-op for performance reasons

Overrides:
validate in class Container

repaint

public void repaint(long tm)
Overridden to be a no-op for performance reasons

Overrides:
repaint in class Component

repaint

public void repaint(long tm,
                    int x,
                    int y,
                    int w,
                    int h)
Overridden to be a no-op for performance reasons

Overrides:
repaint in class JComponent

firePropertyChange

protected final void firePropertyChange(String s,
                                        Object a,
                                        Object b)
Overridden to be a no-op for performance reasons

Overrides:
firePropertyChange in class Component

addHierarchyBoundsListener

public final void addHierarchyBoundsListener(HierarchyBoundsListener hbl)
Overridden to be a no-op for performance reasons

Overrides:
addHierarchyBoundsListener in class Component

addHierarchyListener

public final void addHierarchyListener(HierarchyListener hl)
Overridden to be a no-op for performance reasons

Overrides:
addHierarchyListener in class Component

addContainerListener

public final void addContainerListener(ContainerListener cl)
Overridden to be a no-op for performance reasons

Overrides:
addContainerListener in class Container

paintComponent

public void paintComponent(Graphics g)
Overridden to paint the interior of the polygon if the border is an instance of TabPainter.

Overrides:
paintComponent in class JComponent

getCaptionYAdjustment

protected int getCaptionYAdjustment()
Return non-zero to shift the text up or down by the specified number of pixels when painting.

Returns:
A positive or negative number of pixels

getIconYAdjustment

protected int getIconYAdjustment()
Return non-zero to shift the icon up or down by the specified number of pixels when painting.

Returns:
A positive or negative number of pixels

paintIconAndText

protected void paintIconAndText(Graphics g)
Actually paints the icon and text (using the lightweight HTML renderer)

Parameters:
g - The graphics context

getTabShape

public Polygon getTabShape(int tabState,
                           Rectangle bounds)
Get the shape of the tab. The implementation here will check if the border is an instance of TabPainter, and if so, use the polygon it returns, translating it to the position of the passed-in rectangle. If you are subclassing but do not intend to use TabPainter, you need to override this method

Specified by:
getTabShape in interface TabCellRenderer

getSelectedBackground

public Color getSelectedBackground()
Specified by:
getSelectedBackground in interface TabCellRenderer

getSelectedActivatedBackground

public Color getSelectedActivatedBackground()
Specified by:
getSelectedActivatedBackground in interface TabCellRenderer

getSelectedActivatedForeground

public Color getSelectedActivatedForeground()

getSelectedForeground

public Color getSelectedForeground()

inCloseButton

protected boolean inCloseButton()

getPixelsToAddToSelection

public int getPixelsToAddToSelection()
Subclasses which want to make the selected tab wider than it would otherwise be should return a value greater than 0 here. The default implementation returns 0.

Specified by:
getPixelsToAddToSelection in interface TabCellRenderer

org.netbeans.swing.tabcontrol 1.8

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.