Package ca.cgjennings.apps.arkham
Class MarkupTargetFactory
- java.lang.Object
-
- ca.cgjennings.apps.arkham.MarkupTargetFactory
-
public class MarkupTargetFactory extends java.lang.Object
CreatesMarkupTarget
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, returnsnull
.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)
Returnstrue
if a markup target can be created for an object.
-
-
-
Method Detail
-
isValidTarget
public static boolean isValidTarget(java.lang.Object potentialTarget, boolean strict)
Returnstrue
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. Ifstrict
istrue
, then the potential target must also be showing, enabled, and editable. Currently supported component types include text fields (any subclass ofJTextComponent
) 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 eitherBoolean.TRUE
(accept if possible) orBoolean.FALSE
(always reject). To be accepted, the component must still be of a supported type.- Parameters:
potentialTarget
- the potential markup target to checkstrict
- iftrue
, 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, returnsnull
.- Parameters:
potentialTarget
- the potential target to create a markup target forstrict
- iftrue
, 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 modifyallow
- whether targeting should be explicitly enabled or explicitly disabled- Throws:
java.lang.NullPointerException
- if the target isnull
-
-