Class PromptSupport

java.lang.Object
org.eclipse.nebula.widgets.opal.promptsupport.PromptSupport

public class PromptSupport
extends java.lang.Object
This utility class allows the user to add a prompt to a text or combo component (see http://designinginterfaces.com/Input_Prompt).
This class is inspired by work of Peter Weishapl
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  PromptSupport.FocusBehavior  
  • Field Summary

    Fields 
    Modifier and Type Field Description
    (package private) static java.lang.String BACKGROUND  
    (package private) static java.lang.String BEHAVIOR  
    (package private) static java.lang.String FOCUS_CONTROL_LISTENER  
    (package private) static java.lang.String FOREGROUND  
    (package private) static java.lang.String IS_PROMPT_DISPLAYED  
    (package private) static java.lang.String PROMPT  
    (package private) static java.lang.String STYLE  
  • Constructor Summary

    Constructors 
    Constructor Description
    PromptSupport()  
  • Method Summary

    Modifier and Type Method Description
    static org.eclipse.swt.graphics.Color getBackground​(org.eclipse.swt.widgets.Control control)
    Get the background color of the control, when no text is present.
    static PromptSupport.FocusBehavior getFocusBehavior​(org.eclipse.swt.widgets.Control control)
    Get the PromptSupport.FocusBehavior of control.
    static int getFontStyle​(org.eclipse.swt.widgets.Control control)
    Returns the font style of the prompt text, which is a OR mix of SWT.ITALIC, SWT.NONE or SWT.BOLD
    static org.eclipse.swt.graphics.Color getForeground​(org.eclipse.swt.widgets.Control control)
    Get the foreground color of the prompt text.
    static java.lang.String getPrompt​(org.eclipse.swt.widgets.Control control)
    Get the prompt text of control.
    static void init​(java.lang.String promptText, org.eclipse.swt.graphics.Color promptForeground, org.eclipse.swt.graphics.Color promptBackground, org.eclipse.swt.widgets.Control control)
    Convenience method to set the promptText and promptTextColor on a Control.
    (package private) static boolean isPromptDisplayed​(org.eclipse.swt.widgets.Control control)  
    (package private) static boolean isPromptSet​(org.eclipse.swt.widgets.Control control)  
    static void setBackground​(org.eclipse.swt.graphics.Color color, org.eclipse.swt.widgets.Control control)
    Sets the prompts background color on control.
    static void setFocusBehavior​(PromptSupport.FocusBehavior focusBehavior, org.eclipse.swt.widgets.Control control)
    Sets the PromptSupport.FocusBehavior on control, if it is the focus owner.
    static void setFontStyle​(int fontStyle, org.eclipse.swt.widgets.Control control)
    Set the style of the prompt font, which is a OR mix of SWT.ITALIC, SWT.NONE or SWT.BOLD
    static void setForeground​(org.eclipse.swt.graphics.Color color, org.eclipse.swt.widgets.Control control)
    Sets the foreground color of the prompt on control.
    static void setPrompt​(java.lang.String promptText, org.eclipse.swt.widgets.Control control)
    Sets the prompt text on control
    (package private) static void setPromptDisplayed​(org.eclipse.swt.widgets.Control control, boolean newValue)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • init

      public static void init​(java.lang.String promptText, org.eclipse.swt.graphics.Color promptForeground, org.eclipse.swt.graphics.Color promptBackground, org.eclipse.swt.widgets.Control control)

      Convenience method to set the promptText and promptTextColor on a Control.

      Parameters:
      promptText - Prompt Text
      promptForeground - Foreground
      promptBackground - Background
      control - control
      Throws:
      java.lang.IllegalArgumentException - if the control is not a Text Box, a Combo Box, a StyledText or a CCombo
    • getBackground

      public static org.eclipse.swt.graphics.Color getBackground​(org.eclipse.swt.widgets.Control control)
      Get the background color of the control, when no text is present. If no color has been set, the control background color will be returned.
      Parameters:
      textComponent -
      Returns:
      the the background color of the text component, when no text is present
    • setBackground

      public static void setBackground​(org.eclipse.swt.graphics.Color color, org.eclipse.swt.widgets.Control control)

      Sets the prompts background color on control. This background color will only be used when no text is present.

      Parameters:
      background -
      control -
      Throws:
      java.lang.IllegalArgumentException - if the control is not a Text Box, a Combo Box, a StyledText or a CCombo
    • getFocusBehavior

      public static PromptSupport.FocusBehavior getFocusBehavior​(org.eclipse.swt.widgets.Control control)
      Get the PromptSupport.FocusBehavior of control.
      Parameters:
      control -
      Returns:
      the PromptSupport.FocusBehavior or PromptSupport.FocusBehavior.HIDE_PROMPT if none is set
    • setFocusBehavior

      public static void setFocusBehavior​(PromptSupport.FocusBehavior focusBehavior, org.eclipse.swt.widgets.Control control)
      Sets the PromptSupport.FocusBehavior on control, if it is the focus owner.
      Parameters:
      focusBehavior -
      control -
      Throws:
      java.lang.IllegalArgumentException - if the control is not a Text Box, a Combo Box, a StyledText or a CCombo
    • getFontStyle

      public static int getFontStyle​(org.eclipse.swt.widgets.Control control)
      Returns the font style of the prompt text, which is a OR mix of SWT.ITALIC, SWT.NONE or SWT.BOLD
      Parameters:
      control -
      Returns:
      font style of the prompt text
    • setFontStyle

      public static void setFontStyle​(int fontStyle, org.eclipse.swt.widgets.Control control)

      Set the style of the prompt font, which is a OR mix of SWT.ITALIC, SWT.NONE or SWT.BOLD

      Parameters:
      fontStyle -
      control -
      Throws:
      java.lang.IllegalArgumentException - if the control is not a Text Box, a Combo Box, a StyledText or a CCombo
    • getForeground

      public static org.eclipse.swt.graphics.Color getForeground​(org.eclipse.swt.widgets.Control control)
      Get the foreground color of the prompt text. If no color has been set, the GREY color will be returned.
      Parameters:
      color -
      Returns:
      the color of the prompt text or GREYif none is set
    • setForeground

      public static void setForeground​(org.eclipse.swt.graphics.Color color, org.eclipse.swt.widgets.Control control)
      Sets the foreground color of the prompt on control. This color will be used when no text is present.
      Parameters:
      promptTextColor -
      textComponent -
      Throws:
      java.lang.IllegalArgumentException - if the control is not a Text Box, a Combo Box, a StyledText or a CCombo
    • getPrompt

      public static java.lang.String getPrompt​(org.eclipse.swt.widgets.Control control)
      Get the prompt text of control.
      Parameters:
      control -
      Returns:
      the prompt text
    • setPrompt

      public static void setPrompt​(java.lang.String promptText, org.eclipse.swt.widgets.Control control)

      Sets the prompt text on control

      Parameters:
      promptText -
      textComponent -
      Throws:
      java.lang.IllegalArgumentException - if the control is not a Text Box, a Combo Box, a StyledText or a CCombo
    • isPromptDisplayed

      static boolean isPromptDisplayed​(org.eclipse.swt.widgets.Control control)
    • setPromptDisplayed

      static void setPromptDisplayed​(org.eclipse.swt.widgets.Control control, boolean newValue)
    • isPromptSet

      static boolean isPromptSet​(org.eclipse.swt.widgets.Control control)