org.vishia.gral.base

## Class GralButton

- java.lang.Object
- - org.vishia.gral.base.GralWidget
  - - org.vishia.gral.base.GralButton

- All Implemented Interfaces:
    GetGralWidget_ifc, GralSetValue_ifc, GralWidget_ifc, Removeable

      public class GralButton
      extends GralWidget

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `GralButton.GraphicImplAccess`
    `(package private) class` | `GralButton.MouseActionButton` Inner class to implement the mouse actions called from the gral implementing layer.
    `static class` | `GralButton.State` The state of switch and check button 1=on 2=off 3=disabled. 0=initial, see `#kOn` etc.

    - ### Nested classes/interfaces inherited from class org.vishia.gral.base.GralWidget

      `GralWidget.ActionChangeSelect, GralWidget.ConfigData, GralWidget.DynamicData, GralWidget.ImplAccess`

    - ### Nested classes/interfaces inherited from interface org.vishia.gral.ifc.GralWidget_ifc

      `GralWidget_ifc.ActionChange, GralWidget_ifc.ActionChangeWhen`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `bThreeStateSwitch` True if the button has three states: on, off, disabled.
    `protected GralColor` | `colorBackDisabled` Color of button.
    `protected GralColor` | `colorBackOn` Color of button.
    `protected GralColor` | `colorLineDisabled` Color of button.
    `protected GralColor` | `colorLineOff` Color of button.
    `protected GralColor` | `colorLineOn` Color of button.
    `protected GralImageBase` | `imageDisabled`
    `protected GralImageBase` | `imageOff`
    `protected GralImageBase` | `imageOn`
    `protected boolean` | `isPressed` Currently pressed, show it in graphic.
    `protected boolean` | `pressed`
    `protected java.lang.String` | `sButtonTextDisabled`
    `protected java.lang.String` | `sButtonTextOff`
    `protected java.lang.String` | `sButtonTextOn`
    `protected boolean` | `shouldSwitched` True if it is a switch or a check button.
    `protected GralButton.State` | `switchState`
    `static int` | `version` Version, history and license.

    - ### Fields inherited from class org.vishia.gral.base.GralWidget

      `_wdgImpl, bEditable, bHasFocus, bShouldInitialize, buildMng, bVisibleState, cfg, contextMenu, dateUser, dyda, htmlHelp, itsMng, lastTimeSetVisible, name, repaintDelay, repaintDelayMax, sCmd, sFormat, sToolTip, sVersion, whatIs`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GralButton(java.lang.String sName)`
    `GralButton(java.lang.String sPosName, java.lang.String sText, GralUserAction action)` Creates a button
    `GralButton(java.lang.String position, java.lang.String sName, java.lang.String sText, GralUserAction action)` Deprecated.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `activate()` This is the same action like release the left mouse button.
    `GralButton.State` | `getState()`
    `boolean` | `isDisabled()`
    `boolean` | `isOn()`
    `protected void` | `setActivated(boolean value)` Show the button in an activated state.
    `void` | `setBackColor(GralColor color, int ix)` Implementing for
    `void` | `setDisableColorText(GralColor color, java.lang.String text)` Sets the disable text and color.
    `void` | `setState(GralButton.State state)` Sets the state of the button
    `void` | `setState(java.lang.Object val)` Sets the appearance of the button val instance of GralColor, change the color appropriate to the current state.
    `void` | `setSwitchMode(GralColor colorOff, GralColor colorOn)` Declares the button to a switch button (switching on/off) with the given colors.
    `void` | `setSwitchMode(GralColor colorOff, GralColor colorOn, GralColor colorDisabled)` Declares the button to a check button (switching on/off/disable) with the given texts.
    `void` | `setSwitchMode(GralImageBase imageOff, GralImageBase imageOn)` Declares the button to a switch button (switching on/off) with the given images.
    `void` | `setSwitchMode(GralImageBase imageOff, GralImageBase imageOn, GralImageBase imageDisabled)` Declares the button to a check button (switching on/off/disable) with the given texts.
    `void` | `setSwitchMode(java.lang.String sButtonTextOff, java.lang.String sButtonTextOn)` Declares the button to a switch button (switching on/off) with the given texts.
    `void` | `setSwitchMode(java.lang.String sButtonTextOff, java.lang.String sButtonTextOn, java.lang.String sDisabled)` Declares the button to a check button (switching on/off/disable) with the given texts.
    `void` | `setText(java.lang.String sButtonText)` Sets the text of the button.
    `void` | `setValue(int cmd, int ident, java.lang.Object visibleInfo, java.lang.Object userData)` Sets the current value of the content of the widget in the given context.
    `void` | `XXXsetDisabled(boolean value)`

    - ### Methods inherited from class org.vishia.gral.base.GralWidget

      `chgPos, clearShowParam, createImplWidget_Gthread, getActionChange, getActionChangeStrict, getActionDrag, getActionDrop, getActionFocused, getActionShow, getBackColor, getCfgElement, getCmd, getCmd, getContentIdent, getContentInfo, getContextMenu, getData, getDataIx, getDataPath, getDataPath, getFloatValue, getFormat, getGralWidget, getHtmlHelp, getImpl, getItsPanel, getLongValue, getName, getShowMethod, getShowParam, getsToolTip, getText, getValue, getVariable, getVariableFromContentInfo, gralMng, isChanged, isEditable, isGraphicDisposed, isInFocus, isNotEditableOrShouldInitialize, isVisible, pos, refreshFromVariable, refreshFromVariable, registerWidget, remove, repaint, repaint, requestNewValueForVariable, setActionChange, setActionFocused, setActionMouse, setActionShow, setBackgroundColor, setBoundsPixel, setCfgElement, setCmd, setContentIdent, setContentInfo, setData, setDataIx, setDataPath, setDragEnable, setDropEnable, setEditable, setFocus, setFocus, setForegroundColor, setFormat, setHtmlHelp, setLineColor, setLongValue, setMinMax, setPanelMng, setPrimaryWidgetOfPanel, setText, setTextColor, setToolTip, setToPanel, setValue, setValue, setValue, setVisible, setVisibleState, setVisibleStateWidget, specifyActionChange, specifyContextMenu, stop, toString, XXXgetPixelPositionSize, XXXgetWidgetImplementation, XXXremoveWidgetImplementation, XXXrepaintGthread, XXXsetFocusGThread, XXXsetVisibleGThread`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### version

          public static final int version

      Version, history and license.
      - 2016-05-03 Hartmut chg: Now supports `GralWidget.setVisible(boolean)`
      - 2015-06-21 Hartmut chg: `setSwitchMode(GralColor, GralColor, GralColor)` with null as 3. color sets to 2-times switch like `setSwitchMode(GralColor, GralColor)`.
      - 2015-05-31 Hartmut new: Now a key listener and a traverse listener was added for the SWT implementation. This base class provides the `activate()` method which should be invoked on ENTER-key.
      - 2013-12-22 Hartmut chg: Now `GralButton` uses the new concept of instantiation: It is not the super class of the implementation class. But it provides `GralButton.GraphicImplAccess` as the super class.
      - 2013-05-23 Hartmut new color of text able to change (not only black)
      - 2013-05-23 Hartmut chg: `setState(State)` with an enum, not int, used for showing active/inactive
      - 2012-08-22 Hartmut new implements `setBackColor(GralColor, int)`
      - 2012-03-09 Hartmut new Some functionality from SwtButton moved to this, some enhancement of functionality: Three states,
      - 2011 Hartmut created
      Copyright/Copyleft: For this source the LGPL Lesser General Public License, published by the Free Software Foundation is valid. It means:
      1. You can use this source without any restriction for any desired purpose.
      2. You can redistribute copies of this source to everybody.
      3. Every user of this source, also the user of redistribute copies with or without payment, must accept this license for further using.
      4. But the LPGL ist not appropriate for a whole software product, if this source is only a part of them. It means, the user must publish this part of source, but don't need to publish the whole source of the own product.
      5. You can study and modify (improve) this source for own using or for redistribution, but you have to license the modified sources likewise under this LGPL Lesser General Public License. You mustn't delete this Copyright/Copyleft inscription in this source file.
      If you are intent to use this sources without publishing its usage, you can get a second license subscribing a special contract with the author.
      See Also:
        Constant Field Values

    - #### pressed

          protected boolean pressed

    - #### switchState

          protected GralButton.State switchState

    - #### sButtonTextOff

          protected java.lang.String sButtonTextOff

    - #### sButtonTextOn

          protected java.lang.String sButtonTextOn

    - #### sButtonTextDisabled

          protected java.lang.String sButtonTextDisabled

    - #### imageOff

          protected GralImageBase imageOff

    - #### imageOn

          protected GralImageBase imageOn

    - #### imageDisabled

          protected GralImageBase imageDisabled

    - #### colorBackOn

          protected GralColor colorBackOn

      Color of button. If colorOff is null, then it is not a switch button.

    - #### colorBackDisabled

          protected GralColor colorBackDisabled

      Color of button. If colorOff is null, then it is not a switch button.

    - #### colorLineOff

          protected GralColor colorLineOff

      Color of button. If colorOff is null, then it is not a switch button.

    - #### colorLineOn

          protected GralColor colorLineOn

      Color of button. If colorOff is null, then it is not a switch button.

    - #### colorLineDisabled

          protected GralColor colorLineDisabled

      Color of button. If colorOff is null, then it is not a switch button.

    - #### isPressed

          protected boolean isPressed

      Currently pressed, show it in graphic.

    - #### shouldSwitched

          protected boolean shouldSwitched

      True if it is a switch or a check button.

    - #### bThreeStateSwitch

          protected boolean bThreeStateSwitch

      True if the button has three states: on, off, disabled.

  - ### Constructor Detail

    - #### GralButton

          public GralButton(java.lang.String sName)

    - #### GralButton

          public GralButton(java.lang.String sPosName,
                            java.lang.String sText,
                            GralUserAction action)

      Creates a button
      Parameters:
        `sPosName` - If given with "@pos = name" then it is a position with name, see `GralWidget.GralWidget(String, char)`
        `sText` - The button text
        `action` - The action on release mouse

    - #### GralButton

          @Deprecated
          public GralButton(java.lang.String position,
                                         java.lang.String sName,
                                         java.lang.String sText,
                                         GralUserAction action)

      Deprecated.

  - ### Method Detail

    - #### setSwitchMode

          public void setSwitchMode(java.lang.String sButtonTextOff,
                                    java.lang.String sButtonTextOn)

      Declares the button to a switch button (switching on/off) with the given texts. Different colors for on and off may be set with `setSwitchMode(GralColor, GralColor)`. See `setSwitchMode(GralImageBase, GralImageBase)`.
      Parameters:
        `sButtonTextOff` -
        `sButtonTextOn` -

    - #### setSwitchMode

          public void setSwitchMode(java.lang.String sButtonTextOff,
                                    java.lang.String sButtonTextOn,
                                    java.lang.String sDisabled)

      Declares the button to a check button (switching on/off/disable) with the given texts. Different colors for on, off and disable may be set with `setSwitchMode(GralColor, GralColor, GralColor)`. See `setSwitchMode(GralImageBase, GralImageBase, GralImageBase)`.
      Parameters:
        `sButtonTextOff` -
        `sButtonTextOn` -
        `sDisabled` -

    - #### setSwitchMode

          public void setSwitchMode(GralColor colorOff,
                                    GralColor colorOn)

      Declares the button to a switch button (switching on/off) with the given colors. Different texts for on and off may be set with `setSwitchMode(String, String)`. See `setSwitchMode(GralImageBase, GralImageBase)`.
      Parameters:
        `colorOff` -
        `colorOn` -

    - #### setSwitchMode

          public void setSwitchMode(GralColor colorOff,
                                    GralColor colorOn,
                                    GralColor colorDisabled)

      Declares the button to a check button (switching on/off/disable) with the given texts. Different texts for on and off may be set with `setSwitchMode(String, String, String)`. See `setSwitchMode(GralImageBase, GralImageBase, GralImageBase)`.
      Parameters:
        `colorOff` -
        `colorOn` -

    - #### setSwitchMode

          public void setSwitchMode(GralImageBase imageOff,
                                    GralImageBase imageOn)

      Declares the button to a switch button (switching on/off) with the given images. see `setSwitchMode(String, String)`.
      Parameters:
        `imageOff` -
        `imageOn` -

    - #### setSwitchMode

          public void setSwitchMode(GralImageBase imageOff,
                                    GralImageBase imageOn,
                                    GralImageBase imageDisabled)

      Declares the button to a check button (switching on/off/disable) with the given texts. see `setSwitchMode(String, String, String)`.
      Parameters:
        `imageOff` -
        `imageOn` -

    - #### setBackColor

          public void setBackColor(GralColor color,
                                   int ix)

      Implementing for
      Specified by:
        `setBackColor` in interface `GralWidget_ifc`
      Overrides:
        `setBackColor` in class `GralWidget`
      Parameters:
        `ix=0:` - off-color ix=1: on-color, ix=2 or ix=-1: disable color.
      See Also:
        `GralWidget.setBackColor(org.vishia.gral.ifc.GralColor, int)`

    - #### setDisableColorText

          public void setDisableColorText(GralColor color,
                                          java.lang.String text)

      Sets the disable text and color. A Button can be shown disabled anytime, independent of its role of switch button or check button.
      Parameters:
        `color` -
        `text` -

    - #### setText

          public void setText(java.lang.String sButtonText)

      Sets the text of the button. The text can be changed in any thread any time. A repaint is forced automatically after a short time (100 ms).
      Parameters:
        `sButtonText` -

    - #### setActivated

          protected void setActivated(boolean value)

      Show the button in an activated state. This method is called especially in its mouse press and release events. In the activated state the button looks like pressed.

    - #### activate

          public void activate()

      This is the same action like release the left mouse button. It can be called from the application to activate the function of the button. Especially it is used for [Enter] on the focused button. It invokes the `GralWidget.specifyActionChange(String, GralUserAction, String[], org.vishia.gral.ifc.GralWidget_ifc.ActionChangeWhen...)` with `GralWidget_ifc.ActionChangeWhen#onMouse1Up`

    - #### setValue

          public void setValue(int cmd,
                               int ident,
                               java.lang.Object visibleInfo,
                               java.lang.Object userData)

      Description copied from class: `GralWidget`
      Sets the current value of the content of the widget in the given context.
      Overrides:
        `setValue` in class `GralWidget`
      Parameters:
        `cmd` - see `GralMng_ifc.cmdSet` etc. It is possible to set the color etc.
        `ident` - Any number to specify set, maybe 0

    - #### XXXsetDisabled

          public void XXXsetDisabled(boolean value)

    - #### isDisabled

          public boolean isDisabled()

    - #### isOn

          public boolean isOn()

    - #### setState

          public void setState(java.lang.Object val)

      Sets the appearance of the button
      - val instance of GralColor, change the color appropriate to the current state.
      - val instance of Text, changes the switch state.
        - "1", "true", "on"; switches to on
        - "0", "false", "off"; switches to off
    - val instance of Integer:
      - 0 switches off.
      - not 0 switches on
    instance

Parameters:
  `val` -

- #### setState

      public void setState(GralButton.State state)

  Sets the state of the button
  Parameters:
    `state` - one of `#kOn`, , .
  Throws:
    `java.lang.IllegalArgumentException` - if the state is faulty.

- #### getState

      public GralButton.State getState()