Class Area<T extends Area<T>>


public class Area<T extends Area<T>> extends StyledElement<T>
Represents an HTML <area> element for defining clickable regions in an image map.

The Area element defines a clickable area inside an image map. It is always nested inside a Map element and can define rectangular, circular, or polygonal regions with associated hyperlinks and actions.

Features:

  • Define clickable regions within image maps
  • Support for rectangular, circular, and polygonal shapes
  • Link targets and download attributes
  • Media queries and relationship attributes
  • Alternative text for accessibility

Usage:


 Area area = new Area();
 area.setShape(Shape.RECT);
 area.setCoords("0,0,100,100");
 area.setHref("page.html");
 area.setAlt("Click here");
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Area

      public Area()
      Constructs an empty <area> element.
  • Method Details

    • setAlt

      public final T setAlt(String text)
      Sets the alt attribute providing alternative text for the area.

      Alternative text is required when the href attribute is present. It describes the area's content for accessibility and is used by screen readers.

      Parameters:
      text - The alternative text.
      Returns:
      This element for method chaining.
    • setCoords

      public final T setCoords(String coordinates)
      Sets the coordinates of the clickable area.

      The format depends on the shape: "x1,y1,x2,y2" for rectangles, "x,y,radius" for circles, and "x1,y1,x2,y2,...,xn,yn" for polygons.

      Parameters:
      coordinates - the coordinates defining the area shape
      Returns:
      this element for method chaining
    • setDownload

      public final T setDownload(String filename)
      Sets the download attribute.

      Indicates that the linked resource should be downloaded rather than navigated to. The value specifies the suggested filename; an empty string uses the server's default filename.

      Parameters:
      filename - The filename for download, or empty string for default.
      Returns:
      This element for method chaining.
    • setHref

      public final T setHref(String url)
      Sets the URL that the area hyperlink points to.

      If the URL starts with "/" (absolute path within the application), the servlet context path will be automatically prepended to ensure the link works correctly regardless of how the application is deployed.

      Parameters:
      url - The URL to link to.
      Returns:
      This element for method chaining.
    • setHrefLang

      public final T setHrefLang(String languageCode)
      Sets the hreflang attribute.

      Specifies the language of the linked resource as a BCP 47 language tag. This is advisory only and does not affect browser behavior.

      Parameters:
      languageCode - The language of the linked resource.
      Returns:
      This element for method chaining.
    • setPing

      public final T setPing(String ping)
      Sets the ping attribute.

      Specifies a space-separated list of URLs to be notified when the link is followed. The browser sends a POST request to each URL for tracking purposes.

      Parameters:
      ping - Space-separated URLs to ping when link is followed.
      Returns:
      This element for method chaining.
    • setReferrerPolicy

      public final T setReferrerPolicy(String referrerPolicy)
      Sets the referrerpolicy attribute.

      Specifies how much referrer information to send when following this link. Common values include "no-referrer", "origin", and "strict-origin-when-cross-origin".

      Parameters:
      referrerPolicy - The referrer policy value.
      Returns:
      This element for method chaining.
    • setRel

      public final T setRel(Relationship relationship)
      Sets the rel attribute using the Relationship enum.
      Parameters:
      relationship - The link relationship.
      Returns:
      This element for method chaining.
    • setRel

      public final T setRel(String relationship)
      Sets the rel attribute.

      Specifies the relationship between the current document and the linked resource. Common values include "noopener", "noreferrer", "external", and "author".

      Parameters:
      relationship - The relationship of the linked resource.
      Returns:
      This element for method chaining.
    • setShape

      public final T setShape(Shape shape)
      Sets the shape of the clickable area using the Shape enum.
      Parameters:
      shape - the shape type (default, rect, circle, poly)
      Returns:
      this element for method chaining
    • setShape

      public final T setShape(String shape)
      Sets the shape of the clickable area (default, rect, circle, poly).
      Parameters:
      shape - The shape of the area.
      Returns:
      This element for method chaining.
    • setTarget

      public final T setTarget(Target target)
      Sets the target attribute using the Target enum.
      Parameters:
      target - The target browsing context.
      Returns:
      This element for method chaining.
    • setTarget

      public final T setTarget(String target)
      Sets the target attribute.

      Specifies the browsing context in which to display the linked resource. Values include "_self" (same context), "_blank" (new tab/window), "_parent" (parent context), and "_top" (top-level context).

      Parameters:
      target - The browsing context for navigation (_self, _blank, _parent, _top).
      Returns:
      This element for method chaining.
    • getDownload

      protected String getDownload()
      Returns the download attribute value.
      Returns:
      The download filename, or null if not set.
    • getHref

      protected String getHref()
      Returns the href attribute value.
      Returns:
      The hyperlink URL, or null if not set.
    • getHrefLang

      protected String getHrefLang()
      Returns the hreflang attribute value.
      Returns:
      The linked resource language, or null if not set.
    • getPing

      protected String getPing()
      Returns the ping attribute value.
      Returns:
      The ping URLs, or null if not set.
    • getReferrerPolicy

      protected String getReferrerPolicy()
      Returns the referrerpolicy attribute value.
      Returns:
      The referrer policy, or null if not set.
    • getRel

      protected String getRel()
      Returns the rel attribute value.
      Returns:
      The relationship value, or null if not set.
    • getTarget

      protected String getTarget()
      Returns the target attribute value.
      Returns:
      The browsing context, or null if not set.