Class BeanSwitch
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- jmri.jmrit.display.switchboardEditor.BeanSwitch
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.beans.PropertyChangeListener
,java.io.Serializable
,java.util.EventListener
,javax.accessibility.Accessible
public class BeanSwitch extends javax.swing.JPanel implements java.beans.PropertyChangeListener, java.awt.event.ActionListener
Class for a switchboard interface object.Contains a JButton or JPanel to control existing turnouts, sensors and lights. Separated from SwitchboardEditor.java in 4.12.3
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BeanSwitch.IconSwitch
Class to display individual bean state switches on a JMRI Switchboard using 2DGraphic drawing code or alternating 2 image files.-
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
_color
protected boolean
_control
protected boolean
_icon
protected int
_showingState
protected java.lang.String
_stateSign
protected boolean
_text
(package private) JmriJFrame
addFrame
(package private) static java.awt.geom.AffineTransform
affinetransform
(package private) boolean
allControlling
(package private) javax.swing.JMenuItem
connectNewMenu
(package private) javax.swing.JMenuItem
editItem
(package private) static java.awt.font.FontRenderContext
frc
(package private) javax.swing.JCheckBoxMenuItem
invertItem
protected NamedBeanHandleManager
nbhm
(package private) boolean
panelEditable
(package private) java.lang.String
rootPath
(package private) boolean
showToolTip
protected java.lang.String
stateClosed
protected java.lang.String
stateThrown
protected java.lang.String
switchLabel
(package private) javax.swing.JPopupMenu
switchPopup
protected java.lang.String
switchTooltip
(package private) javax.swing.JTextField
sysNameTextBox
(package private) java.awt.Color
textColor
(package private) javax.swing.JTextField
userName
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description BeanSwitch(int index, NamedBean bean, java.lang.String switchName, int shapeChoice, SwitchboardEditor editor)
Ctor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
(package private) void
addEditUserName(javax.swing.JPopupMenu popup)
(package private) void
addInvert(javax.swing.JPopupMenu popup)
(package private) void
alternateOnClick()
Change the state of attached Turnout, Light or Sensor on the layout unless menu option Panel Items Control Layout is set to off.protected void
cancelAddPressed(java.awt.event.ActionEvent e)
(package private) void
cleanup()
protected void
connectNew()
Create new bean and connect it to this switch.void
displayState(int newState)
Drive the current state of the display from the state of the connected bean.void
doMouseClicked(java.awt.event.MouseEvent e)
Process mouseClick on this switch.java.lang.String
getActiveText()
Get text to display on this switch on Switchboard and in Web Server panel when attached object is Active.protected java.lang.String
getIconLabel()
Check the switch label currently displayed.java.lang.String
getInactiveText()
Get text to display on this switch on Switchboard and in Web Server panel when attached object is Inactive.java.lang.String
getInconsistentText()
boolean
getInverted()
(package private) int
getLabelFontSize(int radius, java.lang.String text)
Light
getLight()
NamedBean
getNamedBean()
java.lang.String
getNameString()
Get the label of this switch.Sensor
getSensor()
int
getShape()
Get the user selected switch shape (e.g. 3 for Slider)(package private) int
getSubLabelFontSize(int radius, java.lang.String text)
java.lang.String
getToolTip()
Get text to display as switch tooltip in Web Server panel.Turnout
getTurnout()
java.lang.String
getUnknownText()
Get text to display on this switch in Web Server panel when attached object is Unknown (initial state displayed).java.lang.String
getUserNameString()
(package private) void
handleCreateException(java.lang.String sysName)
boolean
isIcon()
Switch presentation is graphic image based.boolean
isText()
Switch presentation is text based.protected void
okAddPressed(java.awt.event.ActionEvent e)
void
operate(java.awt.event.MouseEvent e, java.lang.String name)
Process mouseClick on this switch, passing in name for debug.void
propertyChange(java.beans.PropertyChangeEvent e)
Update switch as state of bean changes.protected void
renameBean(java.lang.String newUserName, java.lang.String oldName)
Edit user name on a switch.void
renameBeanDialog()
Edit user name on a switch.static java.awt.image.BufferedImage
resizeImage(java.awt.Image image, int scale, java.awt.Color background)
Get a resized copy of the image.void
setBackgroundColor(java.awt.Color bgcolor)
void
setBeanInverted(boolean set)
Invert attached object on the layout, if supported by its connection.void
setInverted(boolean set)
void
setNamedBean(NamedBean bean)
Store an object as NamedBeanHandle, using _label as the display name.boolean
showPopUp(java.awt.event.MouseEvent e)
Show pop-up on a switch with its unique attributes including the (un)connected bean.void
switchLight(int state)
Only for lights.-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
textColor
java.awt.Color textColor
-
switchLabel
protected java.lang.String switchLabel
-
switchTooltip
protected java.lang.String switchTooltip
-
_text
protected boolean _text
-
_icon
protected boolean _icon
-
_control
protected boolean _control
-
_showingState
protected int _showingState
-
_stateSign
protected java.lang.String _stateSign
-
_color
protected java.lang.String _color
-
stateClosed
protected java.lang.String stateClosed
-
stateThrown
protected java.lang.String stateThrown
-
showToolTip
boolean showToolTip
-
allControlling
boolean allControlling
-
panelEditable
boolean panelEditable
-
nbhm
protected NamedBeanHandleManager nbhm
-
affinetransform
static final java.awt.geom.AffineTransform affinetransform
-
frc
static final java.awt.font.FontRenderContext frc
-
switchPopup
javax.swing.JPopupMenu switchPopup
-
connectNewMenu
javax.swing.JMenuItem connectNewMenu
-
editItem
javax.swing.JMenuItem editItem
-
invertItem
javax.swing.JCheckBoxMenuItem invertItem
-
addFrame
JmriJFrame addFrame
-
sysNameTextBox
javax.swing.JTextField sysNameTextBox
-
userName
javax.swing.JTextField userName
-
rootPath
java.lang.String rootPath
-
-
Constructor Detail
-
BeanSwitch
public BeanSwitch(int index, @CheckForNull NamedBean bean, @Nonnull java.lang.String switchName, int shapeChoice, @CheckForNull SwitchboardEditor editor)
Ctor.- Parameters:
index
- ordinal of this switch on Switchboard.bean
- layout object to connect to.switchName
- descriptive name corresponding with system name to display in switch tooltip, i.e. LT1.shapeChoice
- Button, Slider, Key (all drawn on screen) or Icon (sets of graphic files).editor
- main switchboard editor.
-
-
Method Detail
-
getLabelFontSize
int getLabelFontSize(int radius, java.lang.String text)
-
getSubLabelFontSize
int getSubLabelFontSize(int radius, java.lang.String text)
-
getNamedBean
public NamedBean getNamedBean()
-
setNamedBean
public void setNamedBean(@Nonnull NamedBean bean)
Store an object as NamedBeanHandle, using _label as the display name.- Parameters:
bean
- the object (either a Turnout, Sensor or Light) to attach to this switch
-
getTurnout
public Turnout getTurnout()
-
getShape
public int getShape()
Get the user selected switch shape (e.g. 3 for Slider)- Returns:
- the index of the selected item in Shape comboBox
-
getActiveText
public java.lang.String getActiveText()
Get text to display on this switch on Switchboard and in Web Server panel when attached object is Active.- Returns:
- text to show on active state (differs per type of object)
-
getInactiveText
public java.lang.String getInactiveText()
Get text to display on this switch on Switchboard and in Web Server panel when attached object is Inactive.- Returns:
- text to show on inactive state (differs per type of objects)
-
getUnknownText
public java.lang.String getUnknownText()
Get text to display on this switch in Web Server panel when attached object is Unknown (initial state displayed).- Returns:
- text to show on unknown state (used on all types of objects)
-
getInconsistentText
public java.lang.String getInconsistentText()
-
getToolTip
public java.lang.String getToolTip()
Get text to display as switch tooltip in Web Server panel. Used in jmri.jmrit.display.switchboardEditor.configureXml.BeanSwitchXml#store(Object)- Returns:
- switch tooltip text
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
-
getNameString
public java.lang.String getNameString()
Get the label of this switch.- Returns:
- display name not including current state
-
getUserNameString
public java.lang.String getUserNameString()
-
displayState
public void displayState(int newState)
Drive the current state of the display from the state of the connected bean.- Parameters:
newState
- integer representing the new state e.g. Turnout.CLOSED
-
isIcon
public final boolean isIcon()
Switch presentation is graphic image based.- Returns:
- true when switch shape other than 'Button' is selected
- See Also:
displayState(int)
-
isText
public final boolean isText()
Switch presentation is text based.- Returns:
- true when switch shape 'Button' is selected (and also for the other, graphic switch types until SwitchboardServlet directly supports their graphic icons)
- See Also:
displayState(int)
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
Update switch as state of bean changes.- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
- Parameters:
e
- the PropertyChangeEvent heard
-
cleanup
void cleanup()
-
showPopUp
public boolean showPopUp(java.awt.event.MouseEvent e)
Show pop-up on a switch with its unique attributes including the (un)connected bean.- Parameters:
e
- unused because we now our own location- Returns:
- true when pop up displayed
-
addEditUserName
void addEditUserName(javax.swing.JPopupMenu popup)
-
addInvert
void addInvert(javax.swing.JPopupMenu popup)
-
renameBeanDialog
public void renameBeanDialog()
Edit user name on a switch.
-
renameBean
protected void renameBean(java.lang.String newUserName, java.lang.String oldName)
Edit user name on a switch.- Parameters:
newUserName
- string to use as user name replacementoldName
- current user name (used to prevent useless change)
-
setInverted
public void setInverted(boolean set)
-
getInverted
public boolean getInverted()
-
setBeanInverted
public void setBeanInverted(boolean set)
Invert attached object on the layout, if supported by its connection.- Parameters:
set
- new inverted state, true for inverted, false for normal.
-
operate
public void operate(java.awt.event.MouseEvent e, java.lang.String name)
Process mouseClick on this switch, passing in name for debug.- Parameters:
e
- the event heardname
- ID of this button (identical to name of suggested bean object)
-
doMouseClicked
public void doMouseClicked(java.awt.event.MouseEvent e)
Process mouseClick on this switch. Similar tooperate(MouseEvent, String)
.- Parameters:
e
- the event heard
-
alternateOnClick
void alternateOnClick()
Change the state of attached Turnout, Light or Sensor on the layout unless menu option Panel Items Control Layout is set to off.
-
switchLight
public void switchLight(int state)
Only for lights. Used for All Off/All On. Skips unconnected switch icons.- Parameters:
state
- On = 1, Off = 0
-
setBackgroundColor
public void setBackgroundColor(java.awt.Color bgcolor)
-
connectNew
protected void connectNew()
Create new bean and connect it to this switch. Use type letter from switch label (T, S or L).
-
cancelAddPressed
protected void cancelAddPressed(java.awt.event.ActionEvent e)
-
okAddPressed
protected void okAddPressed(java.awt.event.ActionEvent e)
-
getIconLabel
protected java.lang.String getIconLabel()
Check the switch label currently displayed. Used in test.- Returns:
- line 1 of the label of this switch
-
handleCreateException
void handleCreateException(java.lang.String sysName)
-
resizeImage
public static java.awt.image.BufferedImage resizeImage(java.awt.Image image, int scale, java.awt.Color background)
Get a resized copy of the image.- Parameters:
image
- the image to rescalescale
- scale percentage as int (will be divided by 100 in operation)background
- background color to paint on resized image, prevents null value (black)- Returns:
- a reduced/enlarged pixel image
-
-