Class BeanSwitch.IconSwitch

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
jmri.jmrit.display.switchboardEditor.BeanSwitch.IconSwitch
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Enclosing class:
BeanSwitch

public class BeanSwitch.IconSwitch extends JPanel
Class to display individual bean state switches on a JMRI Switchboard using 2DGraphic drawing code or alternating 2 image files.
See Also:
  • Constructor Details

    • IconSwitch

      public IconSwitch(String filepath1, String filepath2, Color back)
      Create an icon from 2 alternating png images. shape is assumed SwitchboardEditor.SYMBOL
      Parameters:
      filepath1 - the ON image
      filepath2 - the OFF image
      back - the background color set on the Switchboard, used to fill in empty parts of rescaled image
    • IconSwitch

      public IconSwitch(int shape, int type)
      Ctor to draw graphic fully in Graphics.
      Parameters:
      shape - int to specify switch shape SwitchboardEditor constants
      type - beanType to draw (optionally ignored depending on shape, eg. for slider)
  • Method Details

    • setOpacity

      public void setOpacity(float offset)
    • showSwitchIcon

      protected void showSwitchIcon(int stateIndex)
    • setLabels

      protected void setLabels(String sName, String uName)
      Set or change label text on switch.
      Parameters:
      sName - string to display (system name)
      uName - secondary string to display (user name)
    • positionLabel

      protected void positionLabel(int x, int y, float align, int fontsize)
      Position (sub)label on switch.
      Parameters:
      x - horizontal offset from top left corner, positive to the right
      y - vertical offset from top left corner, positive down
      align - one of: JComponent.LEFT_ALIGNMENT (0.0f), CENTER_ALIGNMENT (0.5f), RIGHT_ALIGNMENT (1.0f)
      fontsize - size in points for label text display
    • positionSubLabel

      protected void positionSubLabel(int x, int y, float align, int fontsize)
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent