Class AbstractWebComponentDepictor<C extends Component>

Type Parameters:
C - The type of component being controlled.
All Implemented Interfaces:
ComponentDepictor<C>, Depictor<C>, WebComponentDepictor<C>, WebDepictor<C>
Direct Known Subclasses:
AbstractDecoratedWebComponentDepictor, AbstractSimpleWebComponentDepictor, AbstractWebFrameDepictor, AbstractWebLayoutComponentDepictor, WebCheckControlDepictor, WebPictureDepictor, WebScrollControlDepictor, WebSliderDepictor, WebTableDepictor

public abstract class AbstractWebComponentDepictor<C extends Component> extends AbstractComponentDepictor<C> implements WebComponentDepictor<C>
The abstract base class for all application/xhtml+xml depictions.

This implementation knows how to return specialized style IDs for components that are Selectable.

Author:
Garret Wilson
  • Field Details

    • BODY_START_PATTERN

      protected static final Pattern BODY_START_PATTERN
      The pattern matching the HTML body start tag.
    • BODY_END_PATTERN

      protected static final Pattern BODY_END_PATTERN
      The pattern matching the HTML body end tag.
  • Constructor Details

    • AbstractWebComponentDepictor

      public AbstractWebComponentDepictor()
      Default constructor with no element representation.
    • AbstractWebComponentDepictor

      public AbstractWebComponentDepictor(URI namespaceURI, String localName)
      Element namespace and local name constructor that doesn't create an empty element, even if there is no content.
      Parameters:
      namespaceURI - The URI of the XML namespace of the element, or null if there is no namespace.
      localName - The local name of the element with no prefix, or null if this component should not be rendered as an element.
    • AbstractWebComponentDepictor

      public AbstractWebComponentDepictor(URI namespaceURI, String localName, boolean isEmptyElementAllowed)
      Element namespace and local name constructor.
      Parameters:
      namespaceURI - The URI of the XML namespace of the element, or null if there is no namespace.
      localName - The local name of the element with no prefix, or null if this component should not be rendered as an element.
      isEmptyElementAllowed - Whether an empty element can be created if there is no content.
  • Method Details

    • getPlatform

      public WebPlatform getPlatform()
      Specified by:
      getPlatform in interface Depictor<C extends Component>
      Specified by:
      getPlatform in interface WebDepictor<C extends Component>
      Overrides:
      getPlatform in class AbstractDepictor<C extends Component>
      Returns:
      The platform on which this depictor is depicting objects.
    • getDepictContext

      public WebDepictContext getDepictContext()
      Description copied from class: AbstractDepictor
      Retrieves information and functionality related to the current depiction on the platform. This method delegates to Platform.getDepictContext().

      This method delegates to Platform.getDepictContext().

      Specified by:
      getDepictContext in interface Depictor<C extends Component>
      Specified by:
      getDepictContext in interface WebDepictor<C extends Component>
      Overrides:
      getDepictContext in class AbstractDepictor<C extends Component>
      Returns:
      A context for the current depiction.
    • getNamespaceURI

      public URI getNamespaceURI(C component)
      Determines the namespace URI of the XML element.
      Parameters:
      component - The component for which an element namespace URI should be retrieved.
      Returns:
      The URI of the XML namespace of the element, or null if there is no namespace.
    • getLocalName

      public String getLocalName()
      Determines the local name of the XML element.
      Returns:
      The local name of the element with no prefix, or null if this component should not be rendered as an element.
    • isEmptyElementAllowed

      public boolean isEmptyElementAllowed(C component)
      Returns whether an empty element can be created if there is no content.
      Parameters:
      component - The component being rendered.
      Returns:
      Whether an empty element can be created if there is no content.
    • getDepictName

      public String getDepictName()
      Description copied from interface: WebComponentDepictor
      Determines the identifier to place in the name attribute of the component's XHTML element, if appropriate. This is usually the string version of the ID of the component, but some grouped components may use a common name.
      Specified by:
      getDepictName in interface WebComponentDepictor<C extends Component>
      Returns:
      An identifier appropriate for the name attribute of the component's XHTML element.
    • depict

      public void depict() throws IOException
      Updates the depiction of the object. The depiction will be marked as updated.

      This implementation marks the depiction as depicted.

      This implementation updates child components, if any.

      Orchestrates the entire depiction process for the given component.

      Updating child views is delayed until depictBody().

      A component for an individual component type should usually not override this method, opting instead to override one of the more fine-grained update view methods.

      Specified by:
      depict in interface Depictor<C extends Component>
      Overrides:
      depict in class AbstractComponentDepictor<C extends Component>
      Throws:
      IOException - if there is an error updating the depiction.
      See Also:
    • depictBegin

      protected void depictBegin() throws IOException
      Begins the depiction process.

      This version renders the beginning XML element information, if there is any, leaving the beginning tag open for attributes.

      This version writes common XHTML attributes.

      Throws:
      IOException - if there is an error updating the depiction.
    • depictBody

      protected void depictBody() throws IOException
      Depicts the body of the component.

      This version depicts the children of the component.

      This version increases and decreases the indention level before and after depicting the children, respectively.

      Throws:
      IOException - if there is an error updating the depiction.
      See Also:
    • depictEnd

      protected void depictEnd() throws IOException
      Ends the depiction process.

      This version renders the ending XML element information, if there is any.

      Throws:
      IOException - if there is an error updating the depiction.
    • isMouseListener

      protected boolean isMouseListener()
      Returns whether the component is interested in mouse events.

      This version returns true if the component has at least one mouse listener registered.

      Returns:
      true if the component is interested in mouse events.
    • getBaseStyleIDs

      protected Set<String> getBaseStyleIDs(String prefix, String suffix)
      Retrieves the base style IDs for the given component.

      This version returns the default style ID and the specified component style ID, if any.

      If the component is Selectable and is selected, the GuiseCSSStyleConstants.SELECTED_CLASS is returned.

      Parameters:
      prefix - The prefix that needs to be added to each, or null if there is no prefix to add.
      suffix - The suffix that needs to be added to each, or null if there is no suffix to add.
      Returns:
      The base style IDs for the component.
    • getBodyStyleIDs

      protected Set<String> getBodyStyleIDs(String prefix, String suffix)
      Retrieves the style IDs for the main part of the component.

      This version returns the base style IDs, along with any drag source, drag handle, or drop target style IDs.

      Parameters:
      prefix - The prefix that needs to be added to each, or null if there is no prefix to add.
      suffix - The suffix that needs to be added to each, or null if there is no suffix to add.
      Returns:
      The style IDs for the body of the component.
    • decorateID

      protected static String decorateID(String id, String prefix, String suffix)
      Modifies an ID (such as a component ID or a style ID) by adding a prefix and/or suffix as needed.
      Parameters:
      id - The ID.
      prefix - The prefix that needs to be added, or null if there is no prefix to add.
      suffix - The suffix that needs to be added, or null if there is no suffix to add.
      Returns:
      The ID, with prefix and/or suffix added as needed.
    • addFlowStyleIDs

      protected Set<String> addFlowStyleIDs(Set<String> styleIDs, Flow flow)
      Adds flow style IDs to the given set of style IDs based upon the given flow.

      The attribute "axisX" or "axisY" will be added to indicate whether physical flow is on the X axis or the Y axis.

      This attribute "dirLTR" or "dirRTL" will be added to indicate whether flow is left-to-right or right-to-left on the X axis.

      Parameters:
      styleIDs - The set of style IDs to which the flow IDs should be added
      flow - The logical flow, which will be converted into a physical flow and added to the style IDs.
      Returns:
      The style IDs with the physical flow axis and line direction added.
    • getOuterStyles

      protected Map<String,Object> getOuterStyles()
      Retrieves the styles for the outer element of the component.

      This version returns the style for color.

      Returns:
      The styles for the outer element of the component, mapped to CSS property names.
    • getColor

      protected Color getColor()
      Determines the color for rendering the component.

      This version delegates to PresentationModel.getTextColor().

      Returns:
      The color to use for this component.
    • getBackgroundColor

      protected Color getBackgroundColor()
      Determines the background color for rendering the component.

      This version delegates to PresentationModel.getBackgroundColor().

      Returns:
      The background color to use for this component.
    • getBodyStyles

      protected Map<String,Object> getBodyStyles()
      Retrieves the styles for the body element of the component.

      This version returns the style for background color.

      Returns:
      The styles for the body element of the component, mapped to CSS property names.
    • writeIDAttribute

      protected void writeIDAttribute(String prefix, String suffix) throws IOException
      Writes an ID attribute with the appropriate prefixes and suffixes.
      Parameters:
      prefix - The prefix that needs to be added to each, or null if there is no prefix to add.
      suffix - The suffix that needs to be added to each, or null if there is no suffix to add.
      Throws:
      IOException - if there is an error rendering the component.
      See Also:
    • writeIDClassAttributes

      protected void writeIDClassAttributes(String prefix, String suffix, String... styleIDs) throws IOException
      Writes ID and class attributes with the appropriate prefixes and suffixes.
      Parameters:
      prefix - The prefix that needs to be added to each, or null if there is no prefix to add.
      suffix - The suffix that needs to be added to each, or null if there is no suffix to add.
      styleIDs - Additional style IDs to include, without the given prefix and suffix.
      Throws:
      IOException - if there is an error rendering the component.
      See Also:
    • writeBodyIDClassAttributes

      protected void writeBodyIDClassAttributes(String prefix, String suffix) throws IOException
      Writes ID and class attributes for the body of the component.
      Parameters:
      prefix - The prefix that needs to be added to each, or null if there is no prefix to add.
      suffix - The suffix that needs to be added to each, or null if there is no suffix to add.
      Throws:
      IOException - if there is an error rendering the component.
      See Also:
    • writeErrorMessage

      protected void writeErrorMessage() throws IOException
      Writes a message indicating any errors related to the component. The error message will be resolved so that any contained resource references will be properly written.
      Throws:
      IOException - if there is an error rendering the component.
    • writeFloatClear

      protected void writeFloatClear() throws IOException
      Writes an XHTML element to clear all floats.
      Throws:
      IOException - if there is an error rendering the component.
    • writeClassAttribute

      protected void writeClassAttribute(Set<String> styleIDs) throws IOException
      Writes an XHTML class attribute with the given style IDs.
      Parameters:
      styleIDs - The style IDs to write.
      Throws:
      IOException - if there is an error writing the attribute.
    • writeStyleAttribute

      protected void writeStyleAttribute(Map<String,Object> styles) throws IOException
      Writes an XHTML style attribute with the given styles. If no styles are provided, the style attribute is not written.
      Parameters:
      styles - The map of styles to write, each keyed to a CSS style property.
      Throws:
      IOException - if there is an error writing the attribute.
    • writeDirectionAttribute

      protected void writeDirectionAttribute() throws IOException
      Writes an XHTML direction attribute for the X axis direction only if the given component has an orientation explicitly set.
      Throws:
      IOException - if there is an error writing the attribute.
      See Also:
    • writeDirectionAttribute

      protected void writeDirectionAttribute(Orientation orientation, Flow flow) throws IOException
      Writes an XHTML direction attribute with the direction of the given orientation for the given flow.
      Parameters:
      orientation - The orientation information for the component.
      flow - The flow axis which direction is to represent.
      Throws:
      IOException - if there is an error writing the attribute.
    • hasLabelContent

      protected boolean hasLabelContent() throws IOException
      Determines if the given component has label content.

      This implementation delegates to hasLabelContent(LabelModel).

      Returns:
      true if the component contains some label content, such as an icon or label text.
      Throws:
      IOException - if there is an error reading the label.
    • hasLabelContent

      protected boolean hasLabelContent(boolean includeIcon, boolean includeLabel) throws IOException
      Determines if the given component has label content.

      This implementation delegates to hasLabelContent(LabelModel, boolean, boolean).

      Parameters:
      includeIcon - true if the icon should be considered for label content.
      includeLabel - true if the label text should be considered for label content.
      Returns:
      true if the component contains some label content, such as an icon or label text.
      Throws:
      IOException - if there is an error reading the label.
    • hasLabelContent

      protected boolean hasLabelContent(LabelModel labelModel) throws IOException
      Determines if the given label model has label content.

      This implementation delegates to hasLabelContent(LabelModel, boolean, boolean).

      Parameters:
      labelModel - The label model containing the label information.
      Returns:
      true if the label model contains some label content, such as an icon or label text.
      Throws:
      IOException - if there is an error reading the label.
    • hasLabelContent

      protected boolean hasLabelContent(LabelModel labelModel, boolean includeIcon, boolean includeLabel) throws IOException
      Determines if the given label model has label content.
      Parameters:
      labelModel - The label model containing the label information.
      includeIcon - true if the icon should be considered for label content.
      includeLabel - true if the label text should be considered for label content.
      Returns:
      true if the label model contains some label content, such as an icon or label text.
      Throws:
      IOException - if there is an error reading the label.
    • writeLabel

      protected void writeLabel(String forID, String... styleIDs) throws IOException
      Writes a label element for a component, taking into account the label's content type. If no label content is present, no action occurs.

      This method calls writeLabelContent().

      Parameters:
      forID - The ID of the element with which this label is associated, or null if the label should not be associated with any particular element.
      styleIDs - Additional style IDs to include, without the given prefix and suffix.
      Throws:
      IOException - if there is an error writing the label.
      See Also:
    • writeLabelContent

      protected void writeLabelContent() throws IOException
      Writes the label content of the component, taking into account the label's content type. Label styles will be written if needed. If no label content is present, no action occurs.

      This implementation delegates to writeLabelContent(LabelModel).

      Throws:
      IOException - if there is an error writing the label content.
    • writeLabelContent

      protected void writeLabelContent(boolean includeIcon, boolean includeLabel) throws IOException
      Writes the label content of the component, taking into account the label's content type. Label styles will be written if needed. If no label content is present, no action occurs.

      This implementation delegates to writeLabelContent(LabelModel, boolean, boolean).

      Parameters:
      includeIcon - true if the icon should be considered for label content.
      includeLabel - true if the label text should be considered for label content.
      Throws:
      IOException - if there is an error writing the label content.
    • writeLabelContent

      protected void writeLabelContent(LabelModel labelModel) throws IOException
      Writes the label content of the given label model, taking into account the label's content type. Label styles will be written if needed. If no label content is present, no action occurs.

      This method delegates to writeLabelContent(LabelModel, PresentationModel).

      Parameters:
      labelModel - The label model containing the label information.
      Throws:
      IOException - if there is an error writing the label.
    • writeLabelContent

      protected void writeLabelContent(LabelModel labelModel, PresentationModel uiModel) throws IOException
      Writes the label content of the given label model, taking into account the label's content type. Label styles will be written if needed. If no label content is present, no action occurs.

      This method delegates to writeLabelContent(LabelModel, PresentationModel, boolean, boolean).

      Parameters:
      labelModel - The label model containing the label content.
      uiModel - The user interface model containing the label styles.
      Throws:
      IOException - if there is an error writing the label.
    • writeLabelContent

      protected void writeLabelContent(LabelModel labelModel, boolean includeIcon, boolean includeLabel) throws IOException
      Writes the label content of the given label model, taking into account the label's content type. Label styles will be written if needed. If no label content is present, no action occurs.

      This method delegates to writeText(String, MediaType).

      Parameters:
      labelModel - The label model containing the label content.
      includeIcon - true if the icon should be considered for label content.
      includeLabel - true if the label text should be considered for label content.
      Throws:
      IOException - if there is an error writing the label.
    • writeLabelContent

      protected void writeLabelContent(LabelModel labelModel, PresentationModel uiModel, boolean includeIcon, boolean includeLabel) throws IOException
      Writes the label content of the given label model, taking into account the label's content type. Label styles will be written if needed. If no label content is present, no action occurs.

      This method delegates to writeText(String, MediaType).

      Parameters:
      labelModel - The label model containing the label information.
      uiModel - The UI model containing the label style information.
      includeIcon - true if the icon should be considered for label content.
      includeLabel - true if the label text should be considered for label content.
      Throws:
      IOException - if there is an error writing the label.
      See Also:
    • getLabelStyles

      protected final Map<String,Object> getLabelStyles()
      Retrieves the styles for the label of the component.

      This version delegates to getLabelStyles(LabelModel) using the component as the label model.

      Returns:
      The styles for the label of the component, mapped to CSS property names.
    • getLabelStyles

      protected final Map<String,Object> getLabelStyles(LabelModel labelModel)
      Retrieves the styles for the label of the component.

      This version delegates to getLabelStyles(LabelModel, PresentationModel) using the component as the UI model.

      Parameters:
      labelModel - The label model containing the label content.
      Returns:
      The styles for the label of the component, mapped to CSS property names.
    • getLabelStyles

      protected Map<String,Object> getLabelStyles(LabelModel labelModel, PresentationModel uiModel)
      Retrieves the styles for the label of the component.
      Parameters:
      labelModel - The label model containing the label content.
      uiModel - The model containing the label style information.
      Returns:
      The styles for the label of the component, mapped to CSS property names.
    • writeText

      protected void writeText(String text, com.globalmentor.net.MediaType contentType) throws IOException
      Writes text, taking the content type into consideration. XHTML text, for example, will first have its outer elements (including <body>) stripped away.
      Parameters:
      text - The text to write.
      contentType - The content type of the text.
      Throws:
      IOException - if there is an error writing the text.
      NullPointerException - if the provided text and/or content type is null.
    • writeParameterInputs

      protected void writeParameterInputs(com.globalmentor.model.NameValuePair<String,String>... parameters) throws IOException
      Writes parameters as hidden, disabled inputs.
      Parameters:
      parameters - The parameters to write.
      Throws:
      IOException - if there is an error rendering the component.