Class LabelProperty

java.lang.Object
ca.corbett.extras.properties.AbstractProperty
ca.corbett.extras.properties.LabelProperty

public class LabelProperty extends AbstractProperty
An extremely simple property which represents a static label. Labels are not input fields, so they do not save or load anything to or from properties. If you are looking for a way to display some read-only programmatically configurable field on a properties dialog, you should use a read-only text field instead of a label.
Since:
2024-12-30
Author:
scorbo2
  • Constructor Details

    • LabelProperty

      public LabelProperty(String name, String label)
    • LabelProperty

      public LabelProperty(String name, String label, Font font)
    • LabelProperty

      public LabelProperty(String name, String label, Font font, Color color)
    • LabelProperty

      public LabelProperty(String name, String label, Font font, Color color, int extraTopMargin, int extraBottomMargin)
  • Method Details

    • createHeaderLabel

      public static LabelProperty createHeaderLabel(String name, String text)
      A static convenience factory method to create a "header" label with sensible defaults for a section header label. The default values are 16 point bold black text with a slightly larger top and bottom margin.

      You can control the extra margin above/below the generated label by using LabelField.setHeaderLabelExtraMargins() before invoking this.

      Parameters:
      name - The fully qualified field name
      text - The label text
      Returns:
      A LabelField suitable for use as a header.
    • createLabel

      public static LabelProperty createLabel(String name, String text)
      A static convenience factory method to create a "normal" label with sensible defaults for a form label. The default values are 12 point plain black text with a slightly larger top and bottom margin.

      You can control the extra margin above/below the generated label by using LabelField.setHeaderLabelExtraMargins() before invoking this.

      Parameters:
      name - The fully qualified field name
      text - The label text
      Returns:
      A LabelField suitable for use as a regular form label.
    • saveToProps

      public void saveToProps(Properties props)
      Description copied from class: AbstractProperty
      Saves the current value(s) of this property to the given Properties instance.
      Specified by:
      saveToProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which will receive the value(s) of this property.
    • loadFromProps

      public void loadFromProps(Properties props)
      Description copied from class: AbstractProperty
      Loads the value(s) for this property from the given Properties instance, overwriting any current value. The current value of this property will be used as a default value in the event that this property does not exist in the given Properties instance.
      Specified by:
      loadFromProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which contains value(s) for this property.
    • setHyperlink

      public LabelProperty setHyperlink(Action action)
      Optionally sets a hyperlink action, which will convert the generated LabelField into a hyperlink field. When the user clicks the label, the specified Action will be invoked, and a change event will fire from this property (so listeners know that it was clicked).

      TO UPDATE THE FORM WHEN THE LINK IS CLICKED: you can send in an empty Action and instead rely on the change event that will fire from this property. The PropertyFormFieldValueChangedEvent will contain the FormField and FormPanel that where the click happened, and you can use that FormPanel to look up other FormFields and take whatever action is necessary (show/hide fields, enable/disable fields, etc).

      Parameters:
      action - any arbitrary Action.
    • setExtraMargins

      public LabelProperty setExtraMargins(int top, int bottom)
    • setFont

      public LabelProperty setFont(Font f)
    • setColor

      public LabelProperty setColor(Color c)
    • generateFormFieldImpl

      protected FormField generateFormFieldImpl()
      Description copied from class: AbstractProperty
      Descendant classes must implement this method to generate a FormField associated with this property. The generateFormField() method in this class will call this abstract method to create the FormField, which will then be augmented with our fully qualified name, read-only state, help text, and extra attributes.
      Specified by:
      generateFormFieldImpl in class AbstractProperty
      Returns:
      A FormField associated with this property.
    • loadFromFormField

      public void loadFromFormField(FormField field)
      Description copied from class: AbstractProperty
      Populates this Property's value(s) from the given form field, assuming the field is of the correct type.
      Specified by:
      loadFromFormField in class AbstractProperty
      Parameters:
      field - The FormField containing a value for this property.