Class SwitchboardEditor

  • All Implemented Interfaces:
    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 SwitchboardEditor
    extends Editor
    Provides a simple editor for adding jmri.jmrit.display.switchBoard items to a JLayeredPane inside a captive JFrame. Primary use is for new users.

    GUI is structured as a separate setup panel to set the visible range and type plus menus.

    All created objects are placed in a GridLayout grid. No special use of the LayeredPane layers. Inspired by Oracle JLayeredPane demo.

    The "switchesOnBoard" LinkedHashMap keeps track of all the objects added to the target frame for later manipulation. May be used in an update to store mixed switchboards with more than 1 connection and more than 1 bean type/range.
    The 'ready' flag protects the map during regeneration.

    No DnD as panels will be automatically populated in order of the DCC address. New beans may be created from the Switchboard by right clicking an unconnected switch. TODO allow user entry of connection specific starting name, validated in manager using hardwareAddressValidator

    See Also:
    Serialized Form
    • Constructor Detail

      • SwitchboardEditor

        public SwitchboardEditor​(java.lang.String name)
        Ctor by a given name.
        Parameters:
        name - title to assign to the new SwitchBoard
    • Method Detail

      • init

        protected final void init​(java.lang.String name)
        Initialize the newly created Switchboard.
        Specified by:
        init in class Editor
        Parameters:
        name - the title of the switchboard content frame
      • updatePressed

        public void updatePressed()
        Create a new set of switches after removing the current array.

        Called by Update button click, and automatically after loading a panel from XML (with all saved options set). Switchboard JPanel WindowResize() event is handled by resizeInFrame()

      • setDefaultBackgroundColor

        public void setDefaultBackgroundColor​(java.awt.Color color)
        Load from xml and set bg color of _targetpanel as well as variable.
        Parameters:
        color - RGB Color for switchboard background and beanSwitches
      • getDefaultBackgroundColor

        public java.awt.Color getDefaultBackgroundColor()
        Get current default background color.
        Returns:
        background color of this Switchboard
      • 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.
      • setHideUnconnected

        public void setHideUnconnected​(boolean state)
        Control whether target panel items without a connection to the layout are displayed.
        Parameters:
        state - true to hide all in range
      • setAutoItemRange

        public void setAutoItemRange​(boolean state)
        Control whether range of items is automatically preserved.
        Parameters:
        state - true to calculate upper limit from lowest value range value set (default)
      • resetDirty

        public void resetDirty()
        Allow external reset of dirty bit.
      • setDirty

        public void setDirty​(boolean val)
        Allow external set of dirty bit.
        Parameters:
        val - new dirty flag value, true dirty, false clean.
      • isDirty

        public boolean isDirty()
        Check the dirty state.
        Returns:
        true if panel changed, else false.
      • setPanelMenuRangeMin

        public void setPanelMenuRangeMin​(int rangemin)
        Load Range minimum.
        Parameters:
        rangemin - lowest address to show
      • setPanelMenuRangeMax

        public void setPanelMenuRangeMax​(int rangemax)
        Load Range maximum.
        Parameters:
        rangemax - highest address to show
      • getPanelMenuRangeMin

        public int getPanelMenuRangeMin()
        Store Range minimum.
        Returns:
        lowest address shown
      • getPanelMenuRangeMax

        public int getPanelMenuRangeMax()
        Store Range maximum.
        Returns:
        highest address shown
      • getSwitchType

        public java.lang.String getSwitchType()
        Store bean type.
        Returns:
        bean type prefix as set for Switchboard
      • getSwitchTypeName

        public java.lang.String getSwitchTypeName()
        Get bean type name.
        Returns:
        bean type name
      • setSwitchType

        public void setSwitchType​(java.lang.String prefix)
        Load bean type from xml.
        Parameters:
        prefix - the bean type prefix
      • getSwitchManu

        public java.lang.String getSwitchManu()
        Store connection type.
        Returns:
        active bean connection prefix
      • setSwitchManu

        public void setSwitchManu​(java.lang.String manuPrefix)
        Load connection type.
        Parameters:
        manuPrefix - connection prefix
      • getSwitchShape

        public java.lang.String getSwitchShape()
        Store switch shape.
        Returns:
        bean shape prefix
      • setSwitchShape

        public void setSwitchShape​(java.lang.String switchShape)
        Load switch shape.
        Parameters:
        switchShape - name of switch shape
      • getRows

        public int getRows()
        Store Switchboard rowsNum JSpinner or turn on autoRows option.
        Returns:
        the number of switches to display per row or 0 if autoRowsBox (menu-setting) is selected
      • setRows

        public void setRows​(int rws)
        Load Switchboard rowsNum JSpinner.
        Parameters:
        rws - the number of switches displayed per row (as text) or 0 te activate autoRowsBox setting
      • getTotal

        public int getTotal()
        Store total number of switches displayed (unconnected/hidden excluded).
        Returns:
        the total number of switches displayed
      • setShowUserName

        @Deprecated
        public void setShowUserName​(java.lang.Boolean on)
        Deprecated.
        Initial, simple boolean label option
        Parameters:
        on - true to show both system and user name on the switch label
      • initView

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

        protected Manager<?> getManager()
        Get the currently active manager.
        Returns:
        manager in use for the currently selected bean type and connection
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent e)
        KeyListener of Editor.
        Specified by:
        keyPressed in interface java.awt.event.KeyListener
        Overrides:
        keyPressed in class Editor
        Parameters:
        e - the key event heard
      • 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
      • windowClosing

        public void windowClosing​(java.awt.event.WindowEvent e)
        Handle close of Editor window.

        Overload/override method in JmriJFrame parent, which by default is permanently closing the window. Here, we just want to make it invisible, so we don't dispose it (yet).

        Specified by:
        windowClosing in interface java.awt.event.WindowListener
        Overrides:
        windowClosing in class JmriJFrame
      • windowOpened

        public void windowOpened​(java.awt.event.WindowEvent e)
        Handle opening of Editor window.

        Overload/override method in JmriJFrame parent to reset _menuBar.

        Specified by:
        windowOpened in interface java.awt.event.WindowListener
        Overrides:
        windowOpened in class JmriJFrame
      • 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
      • makeFrame

        public JmriJFrame makeFrame​(java.lang.String name)
        Create sequence of panels, etc. for switches: JFrame contains its ContentPane which contains a JPanel with BoxLayout (p1) which contains a JScrollPane (js) which contains the targetPane. Note this is a private menuBar, looking identical to the Editor's _menuBar
        Parameters:
        name - title for the Switchboard.
        Returns:
        frame containing the switchboard editor.
      • 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
      • getSwitch

        protected BeanSwitch getSwitch​(java.lang.String sName)
        Get a beanSwitch object from this SwitchBoard panel by a given name.
        Parameters:
        sName - name of switch label/connected bean
        Returns:
        BeanSwitch switch object with the given name
      • getSwitches

        public java.util.List<BeanSwitchgetSwitches()
        Get a list with copies of BeanSwitch objects currently displayed to transfer to Web Server for display.
        Returns:
        list of all BeanSwitch switch object
      • copyItem

        protected void copyItem​(Positionable p)
        Set up item(s) to be copied by paste.

        Not used on switchboards but has to override Editor.

        Specified by:
        copyItem in class Editor
        Parameters:
        p - the item to copy
      • setNextLocation

        public void setNextLocation​(Positionable obj)
        Set an object's location when it is created.

        Not used on switchboards but has to override Editor.

        Specified by:
        setNextLocation in class Editor
        Parameters:
        obj - object to position
      • switchAllLights

        public void switchAllLights​(int on)
        Set connected Lights (only).
        Parameters:
        on - state to set Light.ON or Light.OFF
      • configureManagerComboBoxes

        protected void configureManagerComboBoxes()
        Configure the combo box listing managers. Adapted from AbstractTableAction.
      • displayManagerComboBoxes

        protected void displayManagerComboBoxes​(java.lang.String type)
        Show only one of the manuf (manager) combo boxes.
        Parameters:
        type - one of the three NamedBean types as String