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:
ActionListener,ImageObserver,MenuContainer,PropertyChangeListener,Serializable,EventListener,Accessible
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassClass 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
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected booleanprotected booleanprotected intprotected Stringprotected boolean(package private) JmriJFrame(package private) static final AffineTransform(package private) boolean(package private) JMenuItem(package private) JMenuItem(package private) static final FontRenderContext(package private) JCheckBoxMenuItemprotected NamedBeanHandleManager(package private) boolean(package private) String(package private) booleanprotected Stringprotected Stringprotected String(package private) JPopupMenuprotected String(package private) JTextField(package private) Color(package private) JTextFieldFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionBeanSwitch(int index, NamedBean bean, String switchName, int shapeChoice, SwitchboardEditor editor) Ctor. -
Method Summary
Modifier and TypeMethodDescriptionvoid(package private) voidaddEditUserName(JPopupMenu popup) (package private) voidaddInvert(JPopupMenu popup) (package private) voidChange the state of attached Turnout, Light or Sensor on the layout unless menu option Panel Items Control Layout is set to off.protected void(package private) voidcleanup()protected voidCreate new bean and connect it to this switch.voiddisplayState(int newState) Drive the current state of the display from the state of the connected bean.voidProcess mouseClick on this switch.Get text to display on this switch on Switchboard and in Web Server panel when attached object is Active.protected StringCheck the switch label currently displayed.Get text to display on this switch on Switchboard and in Web Server panel when attached object is Inactive.boolean(package private) intgetLabelFontSize(int radius, String text) getLight()Get the label of this switch.intgetShape()Get the user selected switch shape (e.g. 3 for Slider)(package private) intgetSubLabelFontSize(int radius, String text) Get text to display as switch tooltip in Web Server panel.Get text to display on this switch in Web Server panel when attached object is Unknown (initial state displayed).(package private) voidhandleCreateException(String sysName, Exception ex) final booleanisIcon()Switch presentation is graphic image based.final booleanisText()Switch presentation is text based.protected voidvoidoperate(MouseEvent e, String name) Process mouseClick on this switch, passing in name for debug.voidUpdate switch as state of bean changes.protected voidrenameBean(String newUserName, String oldName) Edit user name on a switch.voidEdit user name on a switch.static BufferedImageresizeImage(Image image, int scale, Color background) Get a resized copy of the image.voidsetBackgroundColor(Color bgcolor) voidsetBeanInverted(boolean set) Invert attached object on the layout, if supported by its connection.voidsetInverted(boolean set) voidsetNamedBean(NamedBean bean) Store an object as NamedBeanHandle, using _label as the display name.booleanShow pop-up on a switch with its unique attributes including the (un)connected bean.voidswitchLight(int state) Only for lights.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, updateMethods 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, validateTreeMethods 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 Details
-
textColor
-
switchLabel
-
switchTooltip
-
_text
-
_icon
-
_control
-
_showingState
-
_stateSign
-
_color
-
stateClosed
-
stateThrown
-
showToolTip
boolean showToolTip -
allControlling
boolean allControlling -
panelEditable
boolean panelEditable -
nbhm
-
affinetransform
-
frc
-
switchPopup
-
connectNewMenu
-
editItem
-
invertItem
-
addFrame
-
sysNameTextBox
-
userName
-
rootPath
-
-
Constructor Details
-
BeanSwitch
public BeanSwitch(int index, @CheckForNull NamedBean bean, @Nonnull 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 Details
-
getLabelFontSize
-
getSubLabelFontSize
-
getNamedBean
-
setNamedBean
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
-
getSensor
-
getLight
-
getShape
Get the user selected switch shape (e.g. 3 for Slider)- Returns:
- the index of the selected item in Shape comboBox
-
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
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
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
-
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
- Specified by:
actionPerformedin interfaceActionListener
-
getNameString
Get the label of this switch.- Returns:
- display name not including current state
-
getUserNameString
-
displayState
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
Switch presentation is graphic image based.- Returns:
- true when switch shape other than 'Button' is selected
- See Also:
-
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:
-
propertyChange
Update switch as state of bean changes.- Specified by:
propertyChangein interfacePropertyChangeListener- Parameters:
e- the PropertyChangeEvent heard
-
cleanup
void cleanup() -
showPopUp
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
-
addInvert
-
renameBeanDialog
Edit user name on a switch. -
renameBean
Edit user name on a switch.- Parameters:
newUserName- string to use as user name replacementoldName- current user name (used to prevent useless change)
-
setInverted
-
getInverted
-
setBeanInverted
Invert attached object on the layout, if supported by its connection.- Parameters:
set- new inverted state, true for inverted, false for normal.
-
operate
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
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
Only for lights. Used for All Off/All On. Skips unconnected switch icons.- Parameters:
state- On = 1, Off = 0
-
setBackgroundColor
-
connectNew
Create new bean and connect it to this switch. Use type letter from switch label (T, S or L). -
cancelAddPressed
-
okAddPressed
-
getIconLabel
Check the switch label currently displayed. Used in test.- Returns:
- line 1 of the label of this switch
-
handleCreateException
-
resizeImage
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
-