ActionButton.java revision d25372dc8e65a9ed019a88fdf659ca61313f1b31
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
*/
/**
* A basic extension of a button that changes its rendering so that the looks
* are more similar to a row in a list. It is used in the actions on the left
* of the main Control Center dialog (in actions like 'Manage Entries...',
* 'Import from LDIF...' etc.
*
*/
public class ActionButton extends JButton
{
private static final long serialVersionUID = -1898192406268037714L;
private boolean isBeingPressed;
private boolean hasMouseOver;
private static Border buttonBorder;
private static Border focusBorder;
static
{
//Calculate border based on category settings
};
private static final Color defaultBackground =
private static final Color defaultForeground =
private static final Color mouseOverBackground =
private static final Color mouseOverForeground =
private static final Color pressedBackground =
private static final Color pressedForeground =
/**
* Creates a button associated with the provided action.
* @param action the action.
*/
super();
setIconTextGap(0);
setOpaque(true);
setFocusPainted(true);
setContentAreaFilled(false);
setRolloverEnabled(false);
}
/**
* {@inheritDoc}
*/
{
isBeingPressed = true;
final boolean[] hadMouseOver = {hasMouseOver};
hasMouseOver = true;
repaint();
{
public void run()
{
isBeingPressed = false;
repaint();
}
});
}
/**
* {@inheritDoc}
*/
public void mousePressed(MouseEvent e)
{
isBeingPressed = true;
}
/**
* {@inheritDoc}
*/
public void mouseReleased(MouseEvent e)
{
isBeingPressed = false;
}
/**
* {@inheritDoc}
*/
public void mouseExited(MouseEvent e)
{
hasMouseOver = false;
repaint();
}
/**
* {@inheritDoc}
*/
public void mouseEntered(MouseEvent e)
{
hasMouseOver = true;
repaint();
}
/**
* {@inheritDoc}
*/
public void updateUI() {
super.updateUI();
// some look and feels replace our border, so take it back
}
/**
* {@inheritDoc}
*/
protected void paintComponent(Graphics g) {
if (isBeingPressed && hasMouseOver)
{
}
else if (hasMouseOver)
{
}
else {
}
super.paintComponent(g);
}
/**
* Returns the action associated with this button.
* @return the action associated with this button.
*/
public Action getActionObject() {
return action;
}
}