下面列出了javax.swing.JComponent#isEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private int getComponentState(JComponent c) {
int state;
if (!c.isEnabled()) {
return DISABLED;
}
if (menuItem.isArmed()) {
state = MOUSE_OVER;
} else {
state = SeaGlassLookAndFeel.getComponentState(c);
}
if (menuItem.isSelected()) {
state |= SELECTED;
}
return state;
}
@Override
protected Color getForeground( JComponent c ) {
if( c.isEnabled() && ((AbstractButton)c).isSelected() && !isToolBarButton( c ) )
return selectedForeground;
return super.getForeground( c );
}
private int getComponentState(JComponent c) {
int state;
if (!c.isEnabled()) {
state = DISABLED;
} else if (menuItem.isArmed()) {
state = MOUSE_OVER;
} else {
state = SeaGlassLookAndFeel.getComponentState(c);
}
if (menuItem.isSelected()) {
state |= SELECTED;
}
return state;
}
/**
* DOCUMENT ME!
*
* @param c DOCUMENT ME!
* @param region DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
private int getComponentState(JComponent c, Region region) {
if (region == SeaGlassRegion.SEARCH_FIELD_CANCEL_BUTTON && c.isEnabled()) {
if (((JTextComponent) c).getText().length() == 0) {
return DISABLED;
} else if (isCancelArmed) {
return PRESSED;
}
return ENABLED;
}
return SeaGlassLookAndFeel.getComponentState(c);
}
/**
* Get the state for the specified tab's close button.
*
* @param c the tabbed pane.
* @param tabIndex the index of the tab.
* @param tabIsMousedOver TODO
*
* @return the close button state.
*/
public int getCloseButtonState(JComponent c, int tabIndex, boolean tabIsMousedOver) {
if (!c.isEnabled()) {
return DISABLED;
} else if (tabIndex == closeButtonArmedIndex) {
return PRESSED;
} else if (tabIndex == closeButtonHoverIndex) {
return FOCUSED;
} else if (tabIsMousedOver) {
return MOUSE_OVER;
}
return ENABLED;
}
@Override
public boolean canImport(JComponent c, DataFlavor[] dataFlavors) {
if (c.isEnabled() && (c instanceof JTable)) {
for (DataFlavor dataFlavor : dataFlavors) {
if (dataFlavor.equals(this.dataFlavor)) {
return true;
}
}
}
return false;
}
/**
* Invoked when the <code>JComponent</code> associated with the
* <code>JToolTip</code> has changed, or at initialization time. This
* should update any state dependant upon the <code>JComponent</code>.
*
* @param c the JToolTip the JComponent has changed on.
*/
private void componentChanged(JComponent c) {
JComponent comp = ((JToolTip)c).getComponent();
if (comp != null && !(comp.isEnabled())) {
// For better backward compatibility, only install inactive
// properties if they are defined.
if (UIManager.getBorder("ToolTip.borderInactive") != null) {
LookAndFeel.installBorder(c, "ToolTip.borderInactive");
}
else {
LookAndFeel.installBorder(c, "ToolTip.border");
}
if (UIManager.getColor("ToolTip.backgroundInactive") != null) {
LookAndFeel.installColors(c,"ToolTip.backgroundInactive",
"ToolTip.foregroundInactive");
}
else {
LookAndFeel.installColors(c,"ToolTip.background",
"ToolTip.foreground");
}
} else {
LookAndFeel.installBorder(c, "ToolTip.border");
LookAndFeel.installColors(c, "ToolTip.background",
"ToolTip.foreground");
}
}
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds )
{
if (!c.isEnabled()) {
return;
}
if (MetalLookAndFeel.usingOcean()) {
oceanPaintThumb(g, c, thumbBounds);
return;
}
boolean leftToRight = MetalUtils.isLeftToRight(c);
g.translate( thumbBounds.x, thumbBounds.y );
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
{
if ( !isFreeStanding ) {
thumbBounds.width += 2;
if ( !leftToRight ) {
g.translate( -1, 0 );
}
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 2);
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
bumps.paintIcon( c, g, 3, 4 );
if ( !isFreeStanding ) {
thumbBounds.width -= 2;
if ( !leftToRight ) {
g.translate( 1, 0 );
}
}
}
else // HORIZONTAL
{
if ( !isFreeStanding ) {
thumbBounds.height += 2;
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 3);
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
bumps.paintIcon( c, g, 4, 3 );
if ( !isFreeStanding ) {
thumbBounds.height -= 2;
}
}
g.translate( -thumbBounds.x, -thumbBounds.y );
}
@Override
public void update( Graphics g, JComponent c ) {
// fill background if opaque to avoid garbage if user sets opaque to true
if( c.isOpaque() )
FlatUIUtils.paintParentBackground( g, c );
Graphics2D g2 = (Graphics2D) g;
FlatUIUtils.setRenderingHints( g2 );
int width = c.getWidth();
int height = c.getHeight();
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
float arc = FlatUIUtils.getBorderArc( c );
int arrowX = popupButton.getX();
int arrowWidth = popupButton.getWidth();
boolean enabled = c.isEnabled();
boolean isLeftToRight = c.getComponentOrientation().isLeftToRight();
// paint background
g2.setColor( enabled ? c.getBackground() : disabledBackground );
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
// paint arrow button background
if( enabled ) {
g2.setColor( buttonBackground );
Shape oldClip = g2.getClip();
if( isLeftToRight )
g2.clipRect( arrowX, 0, width - arrowX, height );
else
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
g2.setClip( oldClip );
}
// paint vertical line between value and arrow button
g2.setColor( enabled ? borderColor : disabledBorderColor );
float lw = scale( 1f );
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2) ) );
paint( g, c );
}
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds )
{
if (!c.isEnabled()) {
return;
}
if (MetalLookAndFeel.usingOcean()) {
oceanPaintThumb(g, c, thumbBounds);
return;
}
boolean leftToRight = MetalUtils.isLeftToRight(c);
g.translate( thumbBounds.x, thumbBounds.y );
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
{
if ( !isFreeStanding ) {
thumbBounds.width += 2;
if ( !leftToRight ) {
g.translate( -1, 0 );
}
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 2);
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
bumps.paintIcon( c, g, 3, 4 );
if ( !isFreeStanding ) {
thumbBounds.width -= 2;
if ( !leftToRight ) {
g.translate( 1, 0 );
}
}
}
else // HORIZONTAL
{
if ( !isFreeStanding ) {
thumbBounds.height += 2;
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 3);
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
bumps.paintIcon( c, g, 4, 3 );
if ( !isFreeStanding ) {
thumbBounds.height -= 2;
}
}
g.translate( -thumbBounds.x, -thumbBounds.y );
}
protected State getState(final JComponent c) {
if (!AquaFocusHandler.isActive(c)) return State.INACTIVE;
if (!c.isEnabled()) return State.DISABLED;
return State.ACTIVE;
}
protected State getState(final JComponent c) {
if (!AquaFocusHandler.isActive(c)) return State.INACTIVE;
if (!c.isEnabled()) return State.DISABLED;
return State.ACTIVE;
}
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds )
{
if (!c.isEnabled()) {
return;
}
if (MetalLookAndFeel.usingOcean()) {
oceanPaintThumb(g, c, thumbBounds);
return;
}
boolean leftToRight = MetalUtils.isLeftToRight(c);
g.translate( thumbBounds.x, thumbBounds.y );
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
{
if ( !isFreeStanding ) {
thumbBounds.width += 2;
if ( !leftToRight ) {
g.translate( -1, 0 );
}
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 2);
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
bumps.paintIcon( c, g, 3, 4 );
if ( !isFreeStanding ) {
thumbBounds.width -= 2;
if ( !leftToRight ) {
g.translate( 1, 0 );
}
}
}
else // HORIZONTAL
{
if ( !isFreeStanding ) {
thumbBounds.height += 2;
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 3);
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
bumps.paintIcon( c, g, 4, 3 );
if ( !isFreeStanding ) {
thumbBounds.height -= 2;
}
}
g.translate( -thumbBounds.x, -thumbBounds.y );
}
/**
* Returns the current state of the passed in <code>AbstractButton</code>.
*
* @param c the button component.
*
* @return the button's state.
*/
private int getComponentState(JComponent c) {
int state = ENABLED;
if (!c.isEnabled()) {
state = DISABLED;
}
if (SeaGlassLookAndFeel.selectedUI == this) {
return SeaGlassLookAndFeel.selectedUIState | SynthConstants.ENABLED;
}
AbstractButton button = (AbstractButton) c;
ButtonModel model = button.getModel();
if (model.isPressed()) {
if (model.isArmed()) {
state = PRESSED;
} else {
state = MOUSE_OVER;
}
}
if (model.isRollover()) {
state |= MOUSE_OVER;
}
if (model.isSelected()) {
state |= SELECTED;
}
if (c.isFocusOwner() && button.isFocusPainted()) {
state |= FOCUSED;
}
if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) {
state |= DEFAULT;
}
return state;
}
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds )
{
if (!c.isEnabled()) {
return;
}
if (MetalLookAndFeel.usingOcean()) {
oceanPaintThumb(g, c, thumbBounds);
return;
}
boolean leftToRight = MetalUtils.isLeftToRight(c);
g.translate( thumbBounds.x, thumbBounds.y );
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
{
if ( !isFreeStanding ) {
thumbBounds.width += 2;
if ( !leftToRight ) {
g.translate( -1, 0 );
}
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 2);
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
bumps.paintIcon( c, g, 3, 4 );
if ( !isFreeStanding ) {
thumbBounds.width -= 2;
if ( !leftToRight ) {
g.translate( 1, 0 );
}
}
}
else // HORIZONTAL
{
if ( !isFreeStanding ) {
thumbBounds.height += 2;
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 3);
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
bumps.paintIcon( c, g, 4, 3 );
if ( !isFreeStanding ) {
thumbBounds.height -= 2;
}
}
g.translate( -thumbBounds.x, -thumbBounds.y );
}
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds )
{
if (!c.isEnabled()) {
return;
}
if (MetalLookAndFeel.usingOcean()) {
oceanPaintThumb(g, c, thumbBounds);
return;
}
boolean leftToRight = MetalUtils.isLeftToRight(c);
g.translate( thumbBounds.x, thumbBounds.y );
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
{
if ( !isFreeStanding ) {
thumbBounds.width += 2;
if ( !leftToRight ) {
g.translate( -1, 0 );
}
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 2);
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
bumps.paintIcon( c, g, 3, 4 );
if ( !isFreeStanding ) {
thumbBounds.width -= 2;
if ( !leftToRight ) {
g.translate( 1, 0 );
}
}
}
else // HORIZONTAL
{
if ( !isFreeStanding ) {
thumbBounds.height += 2;
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 3);
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
bumps.paintIcon( c, g, 4, 3 );
if ( !isFreeStanding ) {
thumbBounds.height -= 2;
}
}
g.translate( -thumbBounds.x, -thumbBounds.y );
}
private boolean isAvailable(JComponent c) {
return c.isVisible() && c.isEnabled();
}
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds )
{
if (!c.isEnabled()) {
return;
}
if (MetalLookAndFeel.usingOcean()) {
oceanPaintThumb(g, c, thumbBounds);
return;
}
boolean leftToRight = MetalUtils.isLeftToRight(c);
g.translate( thumbBounds.x, thumbBounds.y );
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
{
if ( !isFreeStanding ) {
thumbBounds.width += 2;
if ( !leftToRight ) {
g.translate( -1, 0 );
}
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 2);
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
bumps.paintIcon( c, g, 3, 4 );
if ( !isFreeStanding ) {
thumbBounds.width -= 2;
if ( !leftToRight ) {
g.translate( 1, 0 );
}
}
}
else // HORIZONTAL
{
if ( !isFreeStanding ) {
thumbBounds.height += 2;
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 3);
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
bumps.paintIcon( c, g, 4, 3 );
if ( !isFreeStanding ) {
thumbBounds.height -= 2;
}
}
g.translate( -thumbBounds.x, -thumbBounds.y );
}
protected State getState(final JComponent c) {
if (!AquaFocusHandler.isActive(c)) return State.INACTIVE;
if (!c.isEnabled()) return State.DISABLED;
return State.ACTIVE;
}
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds )
{
if (!c.isEnabled()) {
return;
}
if (MetalLookAndFeel.usingOcean()) {
oceanPaintThumb(g, c, thumbBounds);
return;
}
boolean leftToRight = MetalUtils.isLeftToRight(c);
g.translate( thumbBounds.x, thumbBounds.y );
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
{
if ( !isFreeStanding ) {
thumbBounds.width += 2;
if ( !leftToRight ) {
g.translate( -1, 0 );
}
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 2);
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
bumps.paintIcon( c, g, 3, 4 );
if ( !isFreeStanding ) {
thumbBounds.width -= 2;
if ( !leftToRight ) {
g.translate( 1, 0 );
}
}
}
else // HORIZONTAL
{
if ( !isFreeStanding ) {
thumbBounds.height += 2;
}
g.setColor( thumbColor );
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
g.setColor( thumbShadow );
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
g.setColor( thumbHighlightColor );
drawHLine(g, 1, thumbBounds.width - 3, 1);
drawVLine(g, 1, 1, thumbBounds.height - 3);
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
bumps.paintIcon( c, g, 4, 3 );
if ( !isFreeStanding ) {
thumbBounds.height -= 2;
}
}
g.translate( -thumbBounds.x, -thumbBounds.y );
}