Class SourceCodeViewer

All Implemented Interfaces:
AttachNotifier, ClickNotifier<Div>, DetachNotifier, HasComponents, HasElement, HasEnabled, HasOrderedComponents, HasSize, HasStyle, HasText, Serializable

@JsModule("./code-viewer.ts") @JsModule("./source-code-viewer-buttons.ts") public class SourceCodeViewer extends Div implements HasSize
See Also:
  • Constructor Details

  • Method Details

    • withButtons

      public void withButtons()
      Adds the overlay controls (show, hide, flip and rotate) pinned over the source code.

      The buttons do not change this viewer directly. Instead, each one dispatches a bubbling DOM event that is expected to be handled by an enclosing layout, which is what actually collapses, repositions or reorients the source panel:

      • show / hide dispatch source-collapse-changed (carrying detail.collapsed);
      • flip dispatches source-flip;
      • rotate dispatches source-rotate.
      The buttons are therefore only useful when this viewer is placed inside a layout that listens for those events and coordinates the response (see TabbedDemo); otherwise they emit events that nothing consumes.

      The controls are rendered by the source-code-viewer-buttons client-side web component, which dispatches the events locally on click; the enclosing layout (see TabbedDemo) handles them through Vaadin server-side listeners. This method is idempotent: the component is added only once.

    • fetchContents

      public void fetchContents(String url, String language)
    • highlightOnHover

      public static void highlightOnHover(Component c, String filenameAndId)
      Highlights the block identified by filenameAndId when the component is hovered over.

      If the component is in an additional source, filenameAndId can be given as a string in the format filename#id. If no '#' is present, it is assumed that the identifier corresponds to a block in the first source panel.

      Parameters:
      c - The component that triggers the highlight action when hovered over.
      filenameAndId - The identifier string that combines filename and id separated by '#'.
    • highlightOnClick

      public static <T extends HasElement & ClickNotifier<?>> void highlightOnClick(T c, String filenameAndId)
      Highlight block id when the component is clicked.

      If the component is in an additional source, filenameAndId can be given as a string in the format filename#id. If no '#' is present, it is assumed that the identifier corresponds to a block in the first source panel.

      Parameters:
      c - The component that triggers the highlight action when clicked.
      filenameAndId - The identifier string that combines filename and id separated by '#'.
    • highlight

      public static void highlight(String filenameAndId)
      Highlights the block identified by filenameAndId.

      If the component is in an additional source, filenameAndId can be given as a string in the format filename#id. If no '#' is present, it is assumed that the identifier corresponds to a block in the first source panel.

      Parameters:
      filenameAndId - The identifier string that combines filename and id separated by '#'.