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.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.
        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
        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.
        color - RGB Color for switchboard background and beanSwitches
      • getDefaultBackgroundColor

        public java.awt.Color getDefaultBackgroundColor()
        Get current default background color.
        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).
        setAllEditable in class Editor
        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.
        setUseGlobalFlag in class Editor
        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.
        state - true to hide all in range
      • setAutoItemRange

        public void setAutoItemRange​(boolean state)
        Control whether range of items is automatically preserved.
        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.
        val - new dirty flag value, true dirty, false clean.
      • isDirty

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

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

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

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

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

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

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

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

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

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

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

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

        public int getRows()
        Store Switchboard rowsNum JSpinner or turn on autoRows option.
        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.
        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).
        the total number of switches displayed
      • setShowUserName

        public void setShowUserName​(java.lang.Boolean on)
        Initial, simple boolean label option
        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.
        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
        keyPressed in class Editor
        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
        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
        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
        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
        name - title for the Switchboard.
        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
        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.
        sName - name of switch label/connected bean
        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.
        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
        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
        obj - object to position
      • switchAllLights

        public void switchAllLights​(int on)
        Set connected Lights (only).
        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.
        type - one of the three NamedBean types as String