Class ItemOrderingMenu

All Implemented Interfaces:
ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, MenuElement, SwingConstants

public class ItemOrderingMenu extends JMenu implements ActionListener
A JMenu that exposes the four z-order operations for a single AItem: move to front, move to back, move forward one step, and move backward one step.

Usage

Obtain a configured menu via the factory method forItem(AItem, boolean), which creates a fresh JMenu instance bound to the given item. The returned menu can be added to any popup or main menu.


 JPopupMenu popup = new JPopupMenu();
 popup.add(ItemOrderingMenu.forItem(myItem, true));
 

Thread safety

Each menu instance carries its own targetItem reference rather than sharing a static field. Multiple views can therefore display ordering menus simultaneously without racing over a shared hotItem.

See Also:
  • Method Details

    • forItem

      public static JMenu forItem(AItem item, boolean insertItemName)
      Create and return a fully configured ItemOrderingMenu for the given item.

      Each call returns a new menu instance, ensuring that simultaneous menus in different views do not share mutable state.

      Parameters:
      item - the item whose z-order the menu will control; must not be null
      insertItemName - unused parameter retained for API compatibility with the previous implementation; the layer name is always embedded in the menu labels
      Returns:
      a new, ready-to-use JMenu; never null
      Throws:
      NullPointerException - if item is null
    • forItem

      public static JMenu forItem(AItem item)
      Convenience overload — equivalent to forItem(item, true).
      Parameters:
      item - the item whose z-order the menu will control; must not be null
      Returns:
      a new, ready-to-use JMenu
    • getItemOrderingMenu

      @Deprecated public static JMenu getItemOrderingMenu(AItem item, boolean insertItemName)
      Deprecated.
      Legacy factory method retained for source compatibility.

      Deprecated. The old API stored the target item in a static field, which is unsafe in multi-view MDI applications because a right-click in one view can overwrite the field before the menu action fires in another view. Use forItem(AItem, boolean) instead, which creates a dedicated menu instance per invocation.

      Parameters:
      item - the item whose z-order the menu will control
      insertItemName - unused; see forItem(AItem, boolean)
      Returns:
      a new ordering menu
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Handle a z-order menu-item selection.

      The action is applied to targetItem using the layer it belongs to at the time of the click. If the layer is null (e.g. the item was deleted between right-click and menu selection) the method returns silently.

      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      e - the action event from one of the four menu items