Class ContextManager

  • All Implemented Interfaces:
    java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener, EventListener, GameDataListener

    public class ContextManager
    extends java.awt.event.MouseAdapter
    implements GameDataListener
    A context management class for trees.
    Version:
    1.0
    Author:
    Andreas
    • Constructor Detail

      • ContextManager

        public ContextManager​(javax.swing.JTree source,
                              EventDispatcher dispatcher)
        Creates new ContextManager
    • Method Detail

      • setSelection

        public void setSelection​(SelectionEvent selection)
        Notifies this object of a selection change.
        Parameters:
        selection -
      • setFailFallback

        public void setFailFallback​(java.lang.Object failArgument,
                                    ContextFactory failFactory)
        Sets a context factory which is used in case no factory can be found based on the selected element.
        Parameters:
        failArgument - The argument which shall be passed to the factory
        failFactory - The fall-back factory
      • setSimpleObjects

        public void setSimpleObjects​(java.util.Map<java.lang.Object,​ContextFactory> simpleObjects)
        DOCUMENT-ME
      • putSimpleObject

        public void putSimpleObject​(java.lang.Object o,
                                    ContextFactory factory)
        DOCUMENT-ME
      • removeSimpleObject

        public void removeSimpleObject​(java.lang.Object o)
        DOCUMENT-ME
      • addContextListener

        public void addContextListener​(ContextListener cl)
        Registers a listener that will be notified if context menu creation fails.
        Parameters:
        cl - A new listener
      • removeContextListener

        public void removeContextListener​(ContextListener cl)
        Removes this listener
        Parameters:
        cl - This listeners will no longer be notified.
      • mouseClicked

        public void mouseClicked​(java.awt.event.MouseEvent e)
        Handles right-click actions by selecting an appropriate context menu. There are three ways to create a context menu: If the node's userObject is a Changeable, the Changeable's context factory is used. Else one of the factories registered by putSimpleObject(Object, ContextFactory) is selected. If neither of those find a suitable factory, the fallback factory set in setFailFallback(Object, ContextFactory) is used.
        Specified by:
        mouseClicked in interface java.awt.event.MouseListener
        Overrides:
        mouseClicked in class java.awt.event.MouseAdapter
        See Also:
        MouseAdapter.mouseClicked(java.awt.event.MouseEvent)
      • mousePressed

        public void mousePressed​(java.awt.event.MouseEvent e)
        Specified by:
        mousePressed in interface java.awt.event.MouseListener
        Overrides:
        mousePressed in class java.awt.event.MouseAdapter
      • mouseReleased

        public void mouseReleased​(java.awt.event.MouseEvent e)
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
        Overrides:
        mouseReleased in class java.awt.event.MouseAdapter
      • checkSimpleObjects

        protected boolean checkSimpleObjects​(java.awt.event.MouseEvent e,
                                             javax.swing.tree.DefaultMutableTreeNode node,
                                             java.lang.Object user)
      • fireContextFailed

        protected void fireContextFailed​(java.awt.Component src,
                                         java.awt.event.MouseEvent e)
      • showMenu

        public static void showMenu​(javax.swing.JPopupMenu menu,
                                    java.awt.Component c,
                                    int x,
                                    int y)
        Shows the given menu at position x,y. If there is not enough space on the screen, the menu not shown down and right from (x,y) but left or up or both of that point.
      • getSelection

        public SelectionEvent getSelection()
        Returns:
        the selection