Class MarkupTargetFactory


  • public class MarkupTargetFactory
    extends java.lang.Object
    Creates MarkupTarget instances for valid components.
    Since:
    3.0
    Author:
    Chris Jennings
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static MarkupTarget createMarkupTarget​(java.lang.Object potentialTarget, boolean strict)
      Returns a markup target instance for a component if it is valid; otherwise, returns null.
      static void enableTargeting​(javax.swing.JComponent target, boolean allow)
      Explicitly allows or disallows a component to be a markup target.
      static boolean isValidTarget​(java.lang.Object potentialTarget, boolean strict)
      Returns true if a markup target can be created for an object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isValidTarget

        public static boolean isValidTarget​(java.lang.Object potentialTarget,
                                            boolean strict)
        Returns true if a markup target can be created for an object. To be valid, the potential target must be non-null, and must be a supported type of UI component. If strict is true, then the potential target must also be showing, enabled, and editable. Currently supported component types include text fields (any subclass of JTextComponent) and code editor controls. Other types might be supported in future versions.

        Text fields are normally only accepted as valid targets when they are descendants of the active game component editor. This eliminates a lot of false positives, such as the path field in file dialogs. The default decision as to whether a component is accepted can be overridden by setting the client property MarkupTarget.FORCE_MARKUP_TARGET_PROPERTY to either Boolean.TRUE (accept if possible) or Boolean.FALSE (always reject). To be accepted, the component must still be of a supported type.

        Parameters:
        potentialTarget - the potential markup target to check
        strict - if true, the target must be showing, enabled, and editable
        Returns:
        true if the component can be a markup target
      • createMarkupTarget

        public static MarkupTarget createMarkupTarget​(java.lang.Object potentialTarget,
                                                      boolean strict)
        Returns a markup target instance for a component if it is valid; otherwise, returns null.
        Parameters:
        potentialTarget - the potential target to create a markup target for
        strict - if true, the component must be showing, enabled, and editable
        Returns:
        a markup target compatible with the provided object, or null
      • enableTargeting

        public static void enableTargeting​(javax.swing.JComponent target,
                                           boolean allow)
        Explicitly allows or disallows a component to be a markup target. An explicitly allowed component must still be of an appropriate kind and must be showing, enabled, and editable if checked with strict mode. The primary effect of explicitly allowing a component to be a markup target is to allow text fields that are not descendants of the active editor to be targeted, such as fields in a dialog box.

        This is a convenience method that sets the FORCE_MARKUP_TARGET_PROPERTY client property on the target component.

        Parameters:
        target - the target to modify
        allow - whether targeting should be explicitly enabled or explicitly disabled
        Throws:
        java.lang.NullPointerException - if the target is null