Class ControlPanelEditor

  • All Implemented Interfaces:
    java.awt.datatransfer.ClipboardOwner, java.awt.dnd.DropTargetListener, java.awt.event.ActionListener, java.awt.event.ComponentListener, java.awt.event.KeyListener, java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.beans.VetoableChangeListener, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants, BeanInterface, ModifiedFlag, JmriMouseListener, JmriMouseMotionListener, WindowInterface

    public class ControlPanelEditor
    extends Editor
    implements java.awt.dnd.DropTargetListener, java.awt.datatransfer.ClipboardOwner
    Provides a simple editor for adding jmri.jmrit.display items to a captive JFrame.

    GUI is structured as a band of common parameters across the top, then a series of things you can add.

    All created objects are put specific levels depending on their type (higher levels are in front):

    • BKG background
    • ICONS icons and other drawing symbols
    • LABELS text labels
    • TURNOUTS turnouts and other variable track items
    • SENSORS sensors and other independently modified objects
    Note that higher numbers appear behind lower numbers.

    The "contents" List keeps track of all the objects added to the target frame for later manipulation. Extends the behavior it shares with PanelPro DnD implemented at JDK 1.2 for backward compatibility

    See Also:
    Serialized Form
    • Method Detail

      • init

        protected void init​(java.lang.String name)
        Specified by:
        init in class Editor
      • makeWarrantMenu

        protected void makeWarrantMenu​(boolean edit,
                                       boolean addMenu)
      • makeEditMenu

        protected void makeEditMenu()
        Create an Edit menu to support cut/copy/paste. An incredible hack to get some semblance of CCP between panels. The hack works for one of two problems. 1. Invoking a copy to the system clipboard causes a delayed repaint placed on the EventQueue whenever ScrollBars are invoked. This repaint ends with a null pointer exception at javax.swing.plaf.basic.BasicScrollPaneUI.paint(BasicScrollPaneUI.java:90) This error occurs regardless of the method used to put the copy in the clipboard - JDK 1.2 style or 1.4 TransferHandler Fixed! Get the plaf glue (BasicScrollPaneUI) and call installUI(_panelScrollPane) See copyToClipboard() below, line 527 (something the Java code should have done) No scrollbars - no problem. Hack does not fix this problem. 2. The clipboard provides a shallow copy of what was placed there. For things that have an icon Map (ArrayLists) the Tranferable data is shallow. The Hack to work around this is: Place a reference to the panel copying to the clipboard in the clipboard and let the pasting panel callback to the copying panel to get the data. See public ArrayList<Positionable> getClipGroup() {} below.
      • lostOwnership

        public void lostOwnership​(java.awt.datatransfer.Clipboard clipboard,
                                  java.awt.datatransfer.Transferable contents)
        Specified by:
        lostOwnership in interface java.awt.datatransfer.ClipboardOwner
      • setAllEditable

        public void setAllEditable​(boolean edit)
        Description copied from class: Editor
        Control whether target panel items are editable. Does this by invoke the Positionable.setEditable(boolean) function of each item on the target panel. This also controls the relevant pop-up menu items (which are the primary way that items are edited).
        Overrides:
        setAllEditable in class Editor
        Parameters:
        edit - true for editable.
      • setUseGlobalFlag

        public void setUseGlobalFlag​(boolean set)
        Description copied from class: Editor
        Set which flag should be used, global or local for Positioning and Control of individual items. Items call getFlag() to return the appropriate flag it should use.
        Overrides:
        setUseGlobalFlag in class Editor
        Parameters:
        set - True if global flags should be used for positioning.
      • initView

        public void initView()
        After construction, initialize all the widgets to their saved config settings.
        Specified by:
        initView in class Editor
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent e)
        Capture key events.
        Specified by:
        keyPressed in interface java.awt.event.KeyListener
        Overrides:
        keyPressed in class Editor
        Parameters:
        e - the event
      • mouseDragged

        public void mouseDragged​(JmriMouseEvent event)
        Description copied from interface: JmriMouseMotionListener
        Invoked when a mouse button is pressed on a component and then dragged. MOUSE_DRAGGED events will continue to be delivered to the component where the drag originated until the mouse button is released (regardless of whether the mouse position is within the bounds of the component).

        Due to platform-dependent Drag&Drop implementations, MOUSE_DRAGGED events may not be delivered during a native Drag&Drop operation.

        Specified by:
        mouseDragged in interface JmriMouseMotionListener
        Specified by:
        mouseDragged in class Editor
        Parameters:
        event - the event to be processed
      • targetWindowClosingEvent

        protected void targetWindowClosingEvent​(java.awt.event.WindowEvent e)
        The target window has been requested to close, don't delete it at this time. Deletion must be accomplished via the Delete this panel menu item.
        Specified by:
        targetWindowClosingEvent in class Editor
        Parameters:
        e - the triggering event
      • paintTargetPanel

        protected void paintTargetPanel​(java.awt.Graphics g)
        Description copied from class: Editor
        Called from TargetPanel's paint method for additional drawing by editor view.
        Specified by:
        paintTargetPanel in class Editor
        Parameters:
        g - the context to paint within
      • copyItem

        protected void copyItem​(Positionable p)
        Set up selections for a paste. Note a copy of _selectionGroup is made that is NOT in the _contents. This disconnected ArrayList is added to the _contents when (if) a paste is made. The disconnected _selectionGroup can be dragged to a new location.
        Specified by:
        copyItem in class Editor
        Parameters:
        p - the item to copy
      • abortPasteItems

        void abortPasteItems()
        Showing the popup of a member of _selectionGroup causes an image to be placed in to the _targetPanel. If the objects are not put into _contents (putItem(p)) the image will persist. Thus set these transitory object invisible.
      • setCopyMenu

        public void setCopyMenu​(Positionable p,
                                javax.swing.JPopupMenu popup)
        Add an action to copy the Positionable item and the group to which is may belong.
        Parameters:
        p - the copyable item
        popup - the menu to add it to
      • showPopUp

        protected void showPopUp​(Positionable p,
                                 JmriMouseEvent event)
        Create popup for a Positionable object. Popup items common to all positionable objects are done before and after the items that pertain only to specific Positionable types.
        Parameters:
        p - the item containing or requiring the context menu
        event - the event triggering the menu
      • setColorMenu

        public void setColorMenu​(javax.swing.JPopupMenu popup,
                                 javax.swing.JComponent pos,
                                 int type)
      • disableMenus

        protected void disableMenus()
        ******************* Circuitbuilder ***********************************
      • highlight

        protected void highlight​(Positionable pos)
        Highlight an item.
        Parameters:
        pos - the item to hightlight
      • makeDataFlavors

        protected void makeDataFlavors()
        ************************** DnD *************************************
      • dragExit

        public void dragExit​(java.awt.dnd.DropTargetEvent evt)
        ************************* DropTargetListener ***********************
        Specified by:
        dragExit in interface java.awt.dnd.DropTargetListener
      • dragEnter

        public void dragEnter​(java.awt.dnd.DropTargetDragEvent evt)
        Specified by:
        dragEnter in interface java.awt.dnd.DropTargetListener
      • dragOver

        public void dragOver​(java.awt.dnd.DropTargetDragEvent evt)
        Specified by:
        dragOver in interface java.awt.dnd.DropTargetListener
      • dropActionChanged

        public void dropActionChanged​(java.awt.dnd.DropTargetDragEvent evt)
        Specified by:
        dropActionChanged in interface java.awt.dnd.DropTargetListener
      • drop

        public void drop​(java.awt.dnd.DropTargetDropEvent evt)
        Specified by:
        drop in interface java.awt.dnd.DropTargetListener