Package jmri.jmrit.throttle
Class FunctionButton
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.AbstractButton
-
- javax.swing.JToggleButton
-
- jmri.jmrit.throttle.FunctionButton
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.ItemSelectable
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
,javax.swing.SwingConstants
public class FunctionButton extends javax.swing.JToggleButton
A JButton to activate functions on the decoder. FunctionButtons have a right-click popupMenu menu with several configuration options:- Set the text
- Set the locking state
- Set visibility
- Set Font
- Set function number identity
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JToggleButton
javax.swing.JToggleButton.AccessibleJToggleButton, javax.swing.JToggleButton.ToggleButtonModel
-
Nested classes/interfaces inherited from class javax.swing.AbstractButton
javax.swing.AbstractButton.AccessibleAbstractButton, javax.swing.AbstractButton.ButtonChangeListener
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_IMG_SIZE
-
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
-
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
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
-
Constructor Summary
Constructors Constructor Description FunctionButton()
Construct the FunctionButton.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFunctionListener(FunctionListener l)
Add a listener to this button, probably some sort of keypad panel.void
destroy()
static int
getButtonHeight()
Get Button Height.int
getButtonImageSize()
Get the Image Button Width.java.lang.String
getButtonLabel()
Get the Button Label.static int
getButtonWidth()
Get the Button Width.boolean
getDisplay()
Get the display state of the button.java.lang.String
getIconPath()
Get the Icon Path, NON selected.int
getIdentity()
Get the function number this button operates.boolean
getIsLockable()
Get the locking state of the function.java.lang.String
getSelectedIconPath()
Get the Selected Icon Path.boolean
getState()
Get the state of the function.protected Throttle
getThrottle()
Get Throttle for this button.org.jdom2.Element
getXml()
Collect the prefs of this object into XML Element.boolean
isDirty()
Get if Button is Dirty.boolean
isImageOK()
Get if isImageOK.boolean
isSelectedImageOK()
Get if isSelectedImageOK.void
removeFunctionListener(FunctionListener l)
Remove a listener from this button.void
setButtonImageSize(int is)
Set the Image Button Hieght and Width.void
setButtonLabel(java.lang.String label)
Set the Button Label.void
setDirty(boolean dirty)
Set Function Button Dirty.void
setDisplay(boolean displayed)
Set the display state of the button.(package private) void
setDropFolder(java.lang.String df)
Set the folder where droped images in function button property panel will be storedvoid
setIconPath(java.lang.String fnImg)
Set the Icon Path, NON selected.void
setIdentity(int id)
Set the function number this button will operate.void
setIsLockable(boolean isLockable)
Set the locking state of the button.void
setSelected(boolean newState)
Change the state of the function.void
setSelectedIconPath(java.lang.String fnImg)
Set the Selected Icon Path.void
setState(boolean isOn)
Set the state of the function button.void
setText(java.lang.String s)
Set Button Text.protected void
setThrottle(Throttle throttle)
Set Throttle.void
setXml(org.jdom2.Element e)
Set the preferences based on the XML Element.void
updateLnF()
Update Button Look and Feel !-
Methods inherited from class javax.swing.JToggleButton
getAccessibleContext, getUIClassID, paramString, requestFocus, requestFocusInWindow, updateUI
-
Methods inherited from class javax.swing.AbstractButton
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setUI, setVerticalAlignment, setVerticalTextPosition
-
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, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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, 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, 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, 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, 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
-
DEFAULT_IMG_SIZE
public static final int DEFAULT_IMG_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FunctionButton
public FunctionButton()
Construct the FunctionButton.
-
-
Method Detail
-
destroy
public void destroy()
-
getButtonHeight
public static int getButtonHeight()
Get Button Height.- Returns:
- height.
-
getButtonWidth
public static int getButtonWidth()
Get the Button Width.- Returns:
- width.
-
getButtonImageSize
public int getButtonImageSize()
Get the Image Button Width.- Returns:
- width.
-
setButtonImageSize
public void setButtonImageSize(int is)
Set the Image Button Hieght and Width.- Parameters:
is
- the image size (sqaure image size = width = height)
-
setIdentity
public void setIdentity(int id)
Set the function number this button will operate.- Parameters:
id
- An integer, minimum 0.
-
getIdentity
public int getIdentity()
Get the function number this button operates.- Returns:
- An integer, minimum 0.
-
setState
public void setState(boolean isOn)
Set the state of the function button. Does not send update to layout, just updates button status.To update AND send to layout use setSelected(boolean).
- Parameters:
isOn
- True if the function should be active.
-
getState
public boolean getState()
Get the state of the function.- Returns:
- true if the function is active.
-
setIsLockable
public void setIsLockable(boolean isLockable)
Set the locking state of the button.Changes in this parameter are only be sent to the listeners if the dirty bit is set.
- Parameters:
isLockable
- True if the a clicking and releasing the button changes the function state. False if the state is changed back when the button is released
-
getIsLockable
public boolean getIsLockable()
Get the locking state of the function.- Returns:
- True if the a clicking and releasing the button changes the function state. False if the state is changed back when button is released
-
setDisplay
public void setDisplay(boolean displayed)
Set the display state of the button.- Parameters:
displayed
- True if the button exists False if the button has been removed by the user
-
getDisplay
public boolean getDisplay()
Get the display state of the button.- Returns:
- True if the button exists False if the button has been removed by the user
-
setDirty
public void setDirty(boolean dirty)
Set Function Button Dirty.- Parameters:
dirty
- True when button has been modified by user, else false.
-
isDirty
public boolean isDirty()
Get if Button is Dirty.- Returns:
- true when function button has been modified by user.
-
getButtonLabel
public java.lang.String getButtonLabel()
Get the Button Label.- Returns:
- Button Label text.
-
setButtonLabel
public void setButtonLabel(java.lang.String label)
Set the Button Label.- Parameters:
label
- Label Text.
-
setText
public void setText(java.lang.String s)
Set Button Text.- Overrides:
setText
in classjavax.swing.AbstractButton
-
updateLnF
public void updateLnF()
Update Button Look and Feel ! Hide/show it if necessary Decide if it should show the label or an image with text as tooltip. Button UI updated according to above result.
-
setSelected
public void setSelected(boolean newState)
Change the state of the function. Sets internal state, setSelected, and sends to listeners.To update this button WITHOUT sending to layout, use setState.
- Overrides:
setSelected
in classjavax.swing.AbstractButton
- Parameters:
newState
- true = Is Function on, False = Is Function off.
-
addFunctionListener
public void addFunctionListener(FunctionListener l)
Add a listener to this button, probably some sort of keypad panel.- Parameters:
l
- The FunctionListener that wants notifications via the FunctionListener.notifyFunctionStateChanged.
-
removeFunctionListener
public void removeFunctionListener(FunctionListener l)
Remove a listener from this button.- Parameters:
l
- The FunctionListener to be removed
-
setDropFolder
void setDropFolder(java.lang.String df)
Set the folder where droped images in function button property panel will be stored- Parameters:
df
- the folder path
-
getXml
public org.jdom2.Element getXml()
Collect the prefs of this object into XML Element.- identity
- text
- isLockable
- Returns:
- the XML of this object.
-
setXml
public void setXml(org.jdom2.Element e)
Set the preferences based on the XML Element.- identity
- text
- isLockable
- Parameters:
e
- The Element for this object.
-
setIconPath
public void setIconPath(java.lang.String fnImg)
Set the Icon Path, NON selected.Checks image and sets isImageOK flag.
- Parameters:
fnImg
- icon path.
-
getIconPath
@Nonnull public java.lang.String getIconPath()
Get the Icon Path, NON selected.- Returns:
- Icon Path, else empty string if null.
-
setSelectedIconPath
public void setSelectedIconPath(java.lang.String fnImg)
Set the Selected Icon Path.Checks image and sets isSelectedImageOK flag.
- Parameters:
fnImg
- selected icon path.
-
getSelectedIconPath
@Nonnull public java.lang.String getSelectedIconPath()
Get the Selected Icon Path.- Returns:
- selected Icon Path, else empty string if null.
-
isImageOK
public boolean isImageOK()
Get if isImageOK.- Returns:
- true if isImageOK.
-
isSelectedImageOK
public boolean isSelectedImageOK()
Get if isSelectedImageOK.- Returns:
- true if isSelectedImageOK.
-
setThrottle
protected void setThrottle(Throttle throttle)
Set Throttle.- Parameters:
throttle
- the throttle that this button is associated with.
-
getThrottle
@CheckForNull protected Throttle getThrottle()
Get Throttle for this button.- Returns:
- throttle associated with this button. May be null if no throttle currently associated.
-
-