More widening.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2516 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -44,15 +44,14 @@ import com.samskivert.util.ObserverList;
|
||||
import com.samskivert.util.RunAnywhere;
|
||||
|
||||
/**
|
||||
* Provides a radial menu with iconic menu items that expand to include
|
||||
* textual descriptions when moused over.
|
||||
* Provides a radial menu with iconic menu items that expand to include textual descriptions when
|
||||
* moused over.
|
||||
*/
|
||||
public class RadialMenu
|
||||
implements MouseMotionListener, MouseListener
|
||||
{
|
||||
/**
|
||||
* The interface used to communicate back to the component that hosts
|
||||
* this menu.
|
||||
* The interface used to communicate back to the component that hosts this menu.
|
||||
*/
|
||||
public static interface Host
|
||||
{
|
||||
@@ -62,10 +61,9 @@ public class RadialMenu
|
||||
public Component getComponent ();
|
||||
|
||||
/**
|
||||
* Requests the bounds of the visible region in which we'll be
|
||||
* rendering the menu. The menu will be constrained to fit within
|
||||
* these bounds starting with a natural position around the
|
||||
* supplied target bounds and adjusting minimally to fit.
|
||||
* Requests the bounds of the visible region in which we'll be rendering the menu. The menu
|
||||
* will be constrained to fit within these bounds starting with a natural position around
|
||||
* the supplied target bounds and adjusting minimally to fit.
|
||||
*/
|
||||
public Rectangle getViewBounds ();
|
||||
|
||||
@@ -75,34 +73,30 @@ public class RadialMenu
|
||||
public void repaintRect (int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Instructs the host component to stop rendering this menu
|
||||
* because it has been popped down.
|
||||
* Instructs the host component to stop rendering this menu because it has been popped
|
||||
* down.
|
||||
*/
|
||||
public void menuDeactivated (RadialMenu menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine at the time that a menu is shown, whether its
|
||||
* items should be included and/or enabled. Predicate methods are
|
||||
* called immediately before showing a radial menu and thus should not
|
||||
* perform complicated computations. They generally will check some
|
||||
* simple model to determine a menu item's status.
|
||||
* Used to determine at the time that a menu is shown, whether its items should be included
|
||||
* and/or enabled. Predicate methods are called immediately before showing a radial menu and
|
||||
* thus should not perform complicated computations. They generally will check some simple
|
||||
* model to determine a menu item's status.
|
||||
*/
|
||||
public static interface Predicate
|
||||
{
|
||||
/**
|
||||
* If true, the menu will be included in the character menu when
|
||||
* it is displayed.
|
||||
* If true, the menu will be included in the character menu when it is displayed.
|
||||
*
|
||||
* @param menu the menu that will include or not include the item
|
||||
* in question.
|
||||
* @param menu the menu that will include or not include the item in question.
|
||||
* @param item the menu item that will or will not be included.
|
||||
*/
|
||||
public boolean isIncluded (RadialMenu menu, RadialMenuItem item);
|
||||
|
||||
/**
|
||||
* If true, the menu will be enabled when displayed in a
|
||||
* character's menu.
|
||||
* If true, the menu will be enabled when displayed in a character's menu.
|
||||
*
|
||||
* @param menu the menu that contains the item in question.
|
||||
* @param item the menu item that will or will not be enabled.
|
||||
@@ -111,8 +105,7 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* An additional interface that can be implemented by the predicate
|
||||
* to display extra status.
|
||||
* An additional interface that can be implemented by the predicate to display extra status.
|
||||
*/
|
||||
public static interface IconPredicate extends Predicate
|
||||
{
|
||||
@@ -130,32 +123,27 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a menu item to the menu. The menu should not currently be
|
||||
* active.
|
||||
* Adds a menu item to the menu. The menu should not currently be active.
|
||||
*
|
||||
* @param command the command to be issued when the item is selected.
|
||||
* @param label the textual label to be displayed with the menu item.
|
||||
* @param icon the icon to display next to the menu text or null if no
|
||||
* icon is desired.
|
||||
* @param predicate a predicate that will be used to determine whether
|
||||
* or not this menu item should be included in the menu and enabled
|
||||
* when it is shown.
|
||||
* @param predicate a predicate that will be used to determine whether or not this menu item
|
||||
* should be included in the menu and enabled when it is shown.
|
||||
*
|
||||
* @return the item that was added to the menu. It can be modified
|
||||
* while the menu is not being displayed.
|
||||
* @return the item that was added to the menu. It can be modified while the menu is not being
|
||||
* displayed.
|
||||
*/
|
||||
public RadialMenuItem addMenuItem (String command, String label,
|
||||
Image icon, Predicate predicate)
|
||||
public RadialMenuItem addMenuItem (String command, String label, Image icon, Predicate predicate)
|
||||
{
|
||||
RadialMenuItem item = new RadialMenuItem(
|
||||
command, label, new ImageIcon(icon), predicate);
|
||||
RadialMenuItem item = new RadialMenuItem(command, label, new ImageIcon(icon), predicate);
|
||||
addMenuItem(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an already constructed menu item to the menu. The menu should
|
||||
* not currently be active.
|
||||
* Adds an already constructed menu item to the menu. The menu should not currently be active.
|
||||
*
|
||||
* @param item the menu item instance to be added.
|
||||
*/
|
||||
@@ -168,8 +156,7 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an already constructed menu item to the menu. The menu should
|
||||
* not currently be active.
|
||||
* Adds an already constructed menu item to the menu. The menu should not currently be active.
|
||||
*
|
||||
* @param item the menu item instance to be added.
|
||||
*/
|
||||
@@ -187,8 +174,7 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the first menu item that matches the specified command from
|
||||
* this menu.
|
||||
* Removes the first menu item that matches the specified command from this menu.
|
||||
*
|
||||
* @return true if a matching menu item was removed, false if not.
|
||||
*/
|
||||
@@ -218,9 +204,8 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener that will be notified when a menu item is
|
||||
* selected. When the the menu is popped down, all listeners will be
|
||||
* cleared.
|
||||
* Adds a listener that will be notified when a menu item is selected. When the the menu is
|
||||
* popped down, all listeners will be cleared.
|
||||
*/
|
||||
public void addActionListener (ActionListener listener)
|
||||
{
|
||||
@@ -228,8 +213,7 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the optional centerpiece icon to be displayed in the center of
|
||||
* the menu.
|
||||
* Sets the optional centerpiece icon to be displayed in the center of the menu.
|
||||
*/
|
||||
public void setCenterIcon (Icon icon)
|
||||
{
|
||||
@@ -237,19 +221,15 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the radial menu, rendering a menu around the prescribed
|
||||
* bounds. It is expected that the host component will subsequently
|
||||
* call {@link #render} if the menu invalidates the region of the
|
||||
* component occupied by the menu and requests it to repaint.
|
||||
* Activates the radial menu, rendering a menu around the prescribed bounds. It is expected
|
||||
* that the host component will subsequently call {@link #render} if the menu invalidates the
|
||||
* region of the component occupied by the menu and requests it to repaint.
|
||||
*
|
||||
* @param host the host component within which the radial menu is
|
||||
* displayed.
|
||||
* @param bounds the bounds of the object that was clicked to activate
|
||||
* the menu.
|
||||
* @param argument a reference to an object that will be provided
|
||||
* along with the command that is issued if the user selects a menu
|
||||
* item (unless that item has an overriding argument, in which case
|
||||
* the overriding argument will be used).
|
||||
* @param host the host component within which the radial menu is displayed.
|
||||
* @param bounds the bounds of the object that was clicked to activate the menu.
|
||||
* @param argument a reference to an object that will be provided along with the command that
|
||||
* is issued if the user selects a menu item (unless that item has an overriding argument, in
|
||||
* which case the overriding argument will be used).
|
||||
*/
|
||||
public void activate (Host host, Rectangle bounds, Object argument)
|
||||
{
|
||||
@@ -258,15 +238,12 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the radial menu, rendering a menu around the prescribed
|
||||
* bounds. It is expected that the host component will subsequently
|
||||
* call {@link #render} if the menu invalidates the region of the
|
||||
* component occupied by the menu and requests it to repaint.
|
||||
* Activates the radial menu, rendering a menu around the prescribed bounds. It is expected
|
||||
* that the host component will subsequently call {@link #render} if the menu invalidates the
|
||||
* region of the component occupied by the menu and requests it to repaint.
|
||||
*
|
||||
* @param host the host component within which the radial menu is
|
||||
* displayed.
|
||||
* @param bounds the bounds of the object that was clicked to activate
|
||||
* the menu.
|
||||
* @param host the host component within which the radial menu is displayed.
|
||||
* @param bounds the bounds of the object that was clicked to activate the menu.
|
||||
*/
|
||||
public void activate (Host host, Rectangle bounds)
|
||||
{
|
||||
@@ -296,10 +273,9 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument provided to this menu when {@link #activate}
|
||||
* was called. This will only be non-null while the menu is active and
|
||||
* only then if an argument was provided in the call to {@link
|
||||
* #activate}.
|
||||
* Returns the argument provided to this menu when {@link #activate} was called. This will only
|
||||
* be non-null while the menu is active and only then if an argument was provided in the call
|
||||
* to {@link #activate}.
|
||||
*/
|
||||
public Object getActivationArgument ()
|
||||
{
|
||||
@@ -363,8 +339,7 @@ public class RadialMenu
|
||||
}
|
||||
// we have to wait and render the active item last
|
||||
if (item != _activeItem) {
|
||||
item.render(host, this, gfx, x + item.closedBounds.x,
|
||||
y + item.closedBounds.y);
|
||||
item.render(host, this, gfx, x + item.closedBounds.x, y + item.closedBounds.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,8 +394,8 @@ public class RadialMenu
|
||||
_activeItem.setActive(true);
|
||||
repaint = true;
|
||||
|
||||
// if we got here with a mouse moved, we've definately
|
||||
// made the decision to be in non drag mode
|
||||
// if we got here with a mouse moved, we've definately made the decision to be
|
||||
// in non drag mode
|
||||
if (event.getID() == MouseEvent.MOUSE_MOVED) {
|
||||
_msMode = true;
|
||||
}
|
||||
@@ -462,9 +437,8 @@ public class RadialMenu
|
||||
long when = RunAnywhere.getWhen(event);
|
||||
if (!_msMode &&
|
||||
(when < _poptime + DRAGMODE_DELAY)) {
|
||||
// if the dragmode delay time hasn't passed, then we're
|
||||
// going to leave the menu up because the user wants it
|
||||
// to behave like a MS Windows menu.
|
||||
// if the dragmode delay time hasn't passed, then we're going to leave the menu up
|
||||
// because the user wants it to behave like a MS Windows menu.
|
||||
_msMode = true;
|
||||
return;
|
||||
|
||||
@@ -501,8 +475,7 @@ public class RadialMenu
|
||||
}
|
||||
|
||||
/**
|
||||
* Lays the radial menu items out based on the currently configured
|
||||
* bounds information.
|
||||
* Lays the radial menu items out based on the currently configured bounds information.
|
||||
*/
|
||||
protected void layout ()
|
||||
{
|
||||
@@ -537,16 +510,14 @@ public class RadialMenu
|
||||
}
|
||||
gfx.dispose();
|
||||
|
||||
// use the maximum of either width or height and make a circle
|
||||
// around that
|
||||
// use the maximum of either width or height and make a circle around that
|
||||
double radius = Math.max(_tbounds.height, _tbounds.width) / 2;
|
||||
|
||||
// be sure to add a gap and space for the menu item itself
|
||||
radius += (5 + maxwid/2);
|
||||
|
||||
// compute the angle between menu items (we use the diameter of
|
||||
// the menu items as an approximate measure of the distance along
|
||||
// the circumference)
|
||||
// compute the angle between menu items (we use the diameter of the menu items as an
|
||||
// approximate measure of the distance along the circumference)
|
||||
double theta = (maxwid + 10) / radius ;
|
||||
|
||||
// now position each item accordingly
|
||||
@@ -586,8 +557,8 @@ public class RadialMenu
|
||||
_bounds.add(item.openBounds);
|
||||
}
|
||||
|
||||
// now translate everything from the center of the target bounds
|
||||
// to the upper left of the menu bounds
|
||||
// now translate everything from the center of the target bounds to the upper left of the
|
||||
// menu bounds
|
||||
if (_centerLabel != null) {
|
||||
_centerLabel.openBounds.translate(-_bounds.x, -_bounds.y);
|
||||
_centerLabel.closedBounds.translate(-_bounds.x, -_bounds.y);
|
||||
@@ -598,28 +569,25 @@ public class RadialMenu
|
||||
item.closedBounds.translate(-_bounds.x, -_bounds.y);
|
||||
}
|
||||
|
||||
// the origin was at the center of the encircled rectangle; we
|
||||
// need to translate it such that the origin of our bounds are in
|
||||
// screen coordinates and at the upper left rather than the center
|
||||
// the origin was at the center of the encircled rectangle; we need to translate it such
|
||||
// that the origin of our bounds are in screen coordinates and at the upper left rather
|
||||
// than the center
|
||||
_bounds.x += (_tbounds.x + _tbounds.width/2);
|
||||
_bounds.y += (_tbounds.y + _tbounds.height/2);
|
||||
|
||||
// now make sure the whole shebang is fully visible within the
|
||||
// host component
|
||||
// now make sure the whole shebang is fully visible within the host component
|
||||
Rectangle hbounds = _host.getViewBounds();
|
||||
Point pos = SwingUtil.fitRectInRect(_bounds, hbounds);
|
||||
_bounds.setLocation(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that our host component repaint the part of itself that we
|
||||
* occupy.
|
||||
* Requests that our host component repaint the part of itself that we occupy.
|
||||
*/
|
||||
protected void repaint ()
|
||||
{
|
||||
// only repaint the area that we overlap
|
||||
_host.repaintRect(_bounds.x, _bounds.y,
|
||||
_bounds.width+1, _bounds.height+1);
|
||||
_host.repaintRect(_bounds.x, _bounds.y, _bounds.width+1, _bounds.height+1);
|
||||
}
|
||||
|
||||
/** Our host component. */
|
||||
@@ -631,8 +599,8 @@ public class RadialMenu
|
||||
/** The bounds that all of our menu items occupy. */
|
||||
protected Rectangle _bounds;
|
||||
|
||||
/** The argument object, which will be delivered along with a posted
|
||||
* command when a menu item is selected. */
|
||||
/** The argument object, which will be delivered along with a posted command when a menu item
|
||||
* is selected. */
|
||||
protected Object _argument;
|
||||
|
||||
/** The centerpiece icon or null if there is none. */
|
||||
@@ -642,31 +610,28 @@ public class RadialMenu
|
||||
protected RadialLabelSausage _centerLabel;
|
||||
|
||||
/** Our menu items. */
|
||||
protected ArrayList<RadialMenuItem> _items =
|
||||
new ArrayList<RadialMenuItem>();
|
||||
protected ArrayList<RadialMenuItem> _items = new ArrayList<RadialMenuItem>();
|
||||
|
||||
/** The item that has the mouse over it presently, and the default item
|
||||
* if we're double clicked. */
|
||||
/** The item that has the mouse over it presently, and the default item if we're double
|
||||
* clicked. */
|
||||
protected RadialMenuItem _activeItem, _defaultItem;
|
||||
|
||||
/** The amount of time the user must hold down the mouse in order
|
||||
* to put it in drag mode, after which the first mouse-up will pop
|
||||
* down the menu. */
|
||||
/** The amount of time the user must hold down the mouse in order to put it in drag mode, after
|
||||
* which the first mouse-up will pop down the menu. */
|
||||
protected static final long DRAGMODE_DELAY = 1000L;
|
||||
|
||||
/** The amount of time after the menu has been popped up before we
|
||||
* accept selections. */
|
||||
/** The amount of time after the menu has been popped up before we accept selections. */
|
||||
protected static final long DEBOUNCE_DELAY = 200L;
|
||||
|
||||
/** How quickly a second click must arrive for us to count it as a double
|
||||
* click and not two single clicks. */
|
||||
/** How quickly a second click must arrive for us to count it as a double click and not two
|
||||
* single clicks. */
|
||||
protected static final long DOUBLECLICK_DELAY = 400L;
|
||||
|
||||
/** The time at which the menu was popped up. */
|
||||
protected long _poptime;
|
||||
|
||||
/** Whether we're popping the menu up in microsoft mode, where the
|
||||
* user does not need to drag to the item they want to select. */
|
||||
/** Whether we're popping the menu up in microsoft mode, where the user does not need to drag
|
||||
* to the item they want to select. */
|
||||
protected boolean _msMode = false;
|
||||
|
||||
/** This hijacks and holds onto the previous mouse listeners. */
|
||||
|
||||
Reference in New Issue
Block a user