Class Popup<T extends Popup<T>>


public class Popup<T extends Popup<T>> extends Div<T>
Represents a dynamic popup element that can be positioned relative to a point on the page.

The Popup class extends Div to provide a specialized container for popup content that can be dynamically positioned on the page. It integrates with JavaScript to display content at specific coordinates with configurable positioning and offsets. The popup is initially hidden and can be shown at runtime using the popup(HtmlPage, int, int) method.

Features:

  • Dynamic positioning relative to page coordinates
  • Multiple positioning modes (left, right, above, below, page center)
  • Configurable X and Y offset from the target position
  • Initially hidden until explicitly shown
  • JavaScript integration for dynamic display
  • Can contain any HTML content

Usage:


 // Basic right-aligned popup
 Popup tooltip = new Popup();
 tooltip.addText("This is a popup message");

 // Left-aligned popup with custom offsets
 Popup menu = new Popup(Popup.LEFT, 10, 5);
 menu.addElement(new Anchor("/option1", "Option 1"));
 menu.addElement(new Anchor("/option2", "Option 2"));

 // Centered popup
 Popup modal = new Popup(Popup.PAGE_CENTER);
 modal.addElement(new H3("Alert"));
 modal.addElement(new Paragraph("This is an important message"));

 // Display the popup at specific coordinates
 // This would typically be called from an event handler
 tooltip.popup(page, 150, 200); // Show at x=150, y=200
 
Since:
2016
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Field Details

  • Constructor Details

    • Popup

      public Popup()
      Constructs a new Popup element with default settings.

      Creates a popup positioned to the right of the target coordinates with default offsets of 15 pixels in both X and Y directions. The popup is initially hidden.

    • Popup

      public Popup(String location)
      Constructs a new Popup element with the specified positioning mode.

      Creates a popup with the specified positioning mode (LEFT, RIGHT, ABOVE, BELOW, or PAGE_CENTER) and default offsets of 15 pixels. The popup is initially hidden.

      Parameters:
      location - the positioning mode for the popup
    • Popup

      public Popup(String location, int offsetX, int offsetY)
      Constructs a new Popup element with positioning mode and custom offsets.

      Creates a popup with the specified positioning mode and custom X and Y offsets. The offsets determine how far from the target coordinates the popup will appear. The popup is initially hidden.

      Parameters:
      location - the positioning mode for the popup
      offsetX - the horizontal offset in pixels from the target position
      offsetY - the vertical offset in pixels from the target position
  • Method Details

    • popup

      public void popup(HtmlPage page, int clientX, int clientY)
      Displays the popup at the specified coordinates on the page.

      Adds this popup to the page and executes JavaScript to position and show it at the specified client coordinates. The actual position will be offset according to the popup's location mode and offset settings.

      Parameters:
      page - the HtmlPage to display the popup on
      clientX - the X coordinate on the page where the popup should appear
      clientY - the Y coordinate on the page where the popup should appear
    • setLocation

      public void setLocation(String location)
      Sets the positioning mode for the popup.

      Changes how the popup is positioned relative to the target coordinates. Use one of the predefined constants: LEFT, RIGHT, ABOVE, BELOW, or PAGE_CENTER.

      Parameters:
      location - the positioning mode (e.g., Popup.LEFT, Popup.RIGHT)
    • setOffsetX

      public void setOffsetX(int offsetX)
      Sets the horizontal offset from the target position.

      Specifies how many pixels to offset the popup horizontally from the target coordinates. Positive values move the popup to the right.

      Parameters:
      offsetX - the horizontal offset in pixels
    • setOffsetY

      public void setOffsetY(int offsetY)
      Sets the vertical offset from the target position.

      Specifies how many pixels to offset the popup vertically from the target coordinates. Positive values move the popup down.

      Parameters:
      offsetY - the vertical offset in pixels