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 SummaryNested Classes Modifier and Type Class Description classBeanSwitch.IconSwitchClass 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.JPaneljavax.swing.JPanel.AccessibleJPanel
 - 
Nested classes/interfaces inherited from class javax.swing.JComponentjavax.swing.JComponent.AccessibleJComponent
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected java.lang.String_colorprotected boolean_controlprotected boolean_iconprotected int_showingStateprotected java.lang.String_stateSignprotected boolean_text(package private) JmriJFrameaddFrame(package private) static java.awt.geom.AffineTransformaffinetransform(package private) booleanallControlling(package private) javax.swing.JMenuItemconnectNewMenu(package private) javax.swing.JMenuItemeditItem(package private) static java.awt.font.FontRenderContextfrc(package private) javax.swing.JCheckBoxMenuIteminvertItemprotected NamedBeanHandleManagernbhm(package private) booleanpanelEditable(package private) java.lang.StringrootPath(package private) booleanshowToolTipprotected java.lang.StringstateClosedprotected java.lang.StringstateThrownprotected java.lang.StringswitchLabel(package private) javax.swing.JPopupMenuswitchPopupprotected java.lang.StringswitchTooltip(package private) javax.swing.JTextFieldsysNameTextBox(package private) java.awt.ColortextColor(package private) javax.swing.JTextFielduserName- 
Fields inherited from class javax.swing.JComponentlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
- 
 - 
Constructor SummaryConstructors Constructor Description BeanSwitch(int index, NamedBean bean, java.lang.String switchName, int shapeChoice, SwitchboardEditor editor)Ctor.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent e)(package private) voidaddEditUserName(javax.swing.JPopupMenu popup)(package private) voidaddInvert(javax.swing.JPopupMenu popup)(package private) voidalternateOnClick()Change the state of attached Turnout, Light or Sensor on the layout unless menu option Panel Items Control Layout is set to off.protected voidcancelAddPressed(java.awt.event.ActionEvent e)(package private) voidcleanup()protected voidconnectNew()Create 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.voiddoMouseClicked(java.awt.event.MouseEvent e)Process mouseClick on this switch.java.lang.StringgetActiveText()Get text to display on this switch on Switchboard and in Web Server panel when attached object is Active.protected java.lang.StringgetIconLabel()Check the switch label currently displayed.java.lang.StringgetInactiveText()Get text to display on this switch on Switchboard and in Web Server panel when attached object is Inactive.java.lang.StringgetInconsistentText()booleangetInverted()(package private) intgetLabelFontSize(int radius, java.lang.String text)LightgetLight()NamedBeangetNamedBean()java.lang.StringgetNameString()Get the label of this switch.SensorgetSensor()intgetShape()Get the user selected switch shape (e.g. 3 for Slider)(package private) intgetSubLabelFontSize(int radius, java.lang.String text)java.lang.StringgetToolTip()Get text to display as switch tooltip in Web Server panel.TurnoutgetTurnout()java.lang.StringgetUnknownText()Get text to display on this switch in Web Server panel when attached object is Unknown (initial state displayed).java.lang.StringgetUserNameString()(package private) voidhandleCreateException(java.lang.String sysName, java.lang.Exception ex)booleanisIcon()Switch presentation is graphic image based.booleanisText()Switch presentation is text based.protected voidokAddPressed(java.awt.event.ActionEvent e)voidoperate(java.awt.event.MouseEvent e, java.lang.String name)Process mouseClick on this switch, passing in name for debug.voidpropertyChange(java.beans.PropertyChangeEvent e)Update switch as state of bean changes.protected voidrenameBean(java.lang.String newUserName, java.lang.String oldName)Edit user name on a switch.voidrenameBeanDialog()Edit user name on a switch.static java.awt.image.BufferedImageresizeImage(java.awt.Image image, int scale, java.awt.Color background)Get a resized copy of the image.voidsetBackgroundColor(java.awt.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.booleanshowPopUp(java.awt.event.MouseEvent e)Show 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.JPanelgetAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 - 
Methods inherited from class javax.swing.JComponentaddAncestorListener, 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.Containeradd, 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.Componentaction, 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- 
textColorjava.awt.Color textColor 
 - 
switchLabelprotected java.lang.String switchLabel 
 - 
switchTooltipprotected java.lang.String switchTooltip 
 - 
_textprotected boolean _text 
 - 
_iconprotected boolean _icon 
 - 
_controlprotected boolean _control 
 - 
_showingStateprotected int _showingState 
 - 
_stateSignprotected java.lang.String _stateSign 
 - 
_colorprotected java.lang.String _color 
 - 
stateClosedprotected java.lang.String stateClosed 
 - 
stateThrownprotected java.lang.String stateThrown 
 - 
showToolTipboolean showToolTip 
 - 
allControllingboolean allControlling 
 - 
panelEditableboolean panelEditable 
 - 
nbhmprotected NamedBeanHandleManager nbhm 
 - 
affinetransformstatic final java.awt.geom.AffineTransform affinetransform 
 - 
frcstatic final java.awt.font.FontRenderContext frc 
 - 
switchPopupjavax.swing.JPopupMenu switchPopup 
 - 
connectNewMenujavax.swing.JMenuItem connectNewMenu 
 - 
editItemjavax.swing.JMenuItem editItem 
 - 
invertItemjavax.swing.JCheckBoxMenuItem invertItem 
 - 
addFrameJmriJFrame addFrame 
 - 
sysNameTextBoxjavax.swing.JTextField sysNameTextBox 
 - 
userNamejavax.swing.JTextField userName 
 - 
rootPathjava.lang.String rootPath 
 
- 
 - 
Constructor Detail- 
BeanSwitchpublic 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- 
getLabelFontSizeint getLabelFontSize(int radius, java.lang.String text) 
 - 
getSubLabelFontSizeint getSubLabelFontSize(int radius, java.lang.String text) 
 - 
getNamedBeanpublic NamedBean getNamedBean() 
 - 
setNamedBeanpublic 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
 
 - 
getTurnoutpublic Turnout getTurnout() 
 - 
getShapepublic int getShape() Get the user selected switch shape (e.g. 3 for Slider)- Returns:
- the index of the selected item in Shape comboBox
 
 - 
getActiveTextpublic 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)
 
 - 
getInactiveTextpublic 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)
 
 - 
getUnknownTextpublic 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)
 
 - 
getInconsistentTextpublic java.lang.String getInconsistentText() 
 - 
getToolTippublic 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
 
 - 
actionPerformedpublic void actionPerformed(java.awt.event.ActionEvent e) - Specified by:
- actionPerformedin interface- java.awt.event.ActionListener
 
 - 
getNameStringpublic java.lang.String getNameString() Get the label of this switch.- Returns:
- display name not including current state
 
 - 
getUserNameStringpublic java.lang.String getUserNameString() 
 - 
displayStatepublic 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
 
 - 
isIconpublic final boolean isIcon() Switch presentation is graphic image based.- Returns:
- true when switch shape other than 'Button' is selected
- See Also:
- displayState(int)
 
 - 
isTextpublic 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)
 
 - 
propertyChangepublic void propertyChange(java.beans.PropertyChangeEvent e) Update switch as state of bean changes.- Specified by:
- propertyChangein interface- java.beans.PropertyChangeListener
- Parameters:
- e- the PropertyChangeEvent heard
 
 - 
cleanupvoid cleanup() 
 - 
showPopUppublic 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
 
 - 
addEditUserNamevoid addEditUserName(javax.swing.JPopupMenu popup) 
 - 
addInvertvoid addInvert(javax.swing.JPopupMenu popup) 
 - 
renameBeanDialogpublic void renameBeanDialog() Edit user name on a switch.
 - 
renameBeanprotected void renameBean(java.lang.String newUserName, java.lang.String oldName) Edit user name on a switch.- Parameters:
- newUserName- string to use as user name replacement
- oldName- current user name (used to prevent useless change)
 
 - 
setInvertedpublic void setInverted(boolean set) 
 - 
getInvertedpublic boolean getInverted() 
 - 
setBeanInvertedpublic 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.
 
 - 
operatepublic 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 heard
- name- ID of this button (identical to name of suggested bean object)
 
 - 
doMouseClickedpublic void doMouseClicked(java.awt.event.MouseEvent e) Process mouseClick on this switch. Similar tooperate(MouseEvent, String).- Parameters:
- e- the event heard
 
 - 
alternateOnClickvoid alternateOnClick() Change the state of attached Turnout, Light or Sensor on the layout unless menu option Panel Items Control Layout is set to off.
 - 
switchLightpublic void switchLight(int state) Only for lights. Used for All Off/All On. Skips unconnected switch icons.- Parameters:
- state- On = 1, Off = 0
 
 - 
setBackgroundColorpublic void setBackgroundColor(java.awt.Color bgcolor) 
 - 
connectNewprotected void connectNew() Create new bean and connect it to this switch. Use type letter from switch label (T, S or L).
 - 
cancelAddPressedprotected void cancelAddPressed(java.awt.event.ActionEvent e) 
 - 
okAddPressedprotected void okAddPressed(java.awt.event.ActionEvent e) 
 - 
getIconLabelprotected java.lang.String getIconLabel() Check the switch label currently displayed. Used in test.- Returns:
- line 1 of the label of this switch
 
 - 
handleCreateExceptionvoid handleCreateException(java.lang.String sysName, java.lang.Exception ex) 
 - 
resizeImagepublic 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 rescale
- scale- 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
 
 
- 
 
-