Class TextDialog

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants
Direct Known Subclasses:
DownloadDialog

public abstract class TextDialog extends JDialog
Central class for incremental dialog with the user, with protocolling. Text output is done in html, and input by clicking links. The whole dialog history stays readable. The instances are sub-classes which override the react() method and check the value of answer for the local url which has been clicked. All transformation operate on the text form of the data. Therefore every link must begin verbatim with »<a href=«. The text lines of one particular interaction step can be added to the window in multiple calls to appendText(String) and must be well-formed HTML.

Any link which starts with http:// or https:// does only try a browser remote control and does not count as interaction. All other href-values terminate the current interaction step and must be decoded by the user.

Shortcuts by single numeric digit keypresses can be enabled, but are supported only for a limited number of links (= »{code ...}« substrings), see DIGITS.

See Also:
  • Field Details

    • lf

      public static final String lf
      For use by subclasses.
      See Also:
    • defaultSize

      public static final Dimension defaultSize
      Default size of the swing pop-up window.
    • stepNum

      protected int stepNum
      Counter of the input-output cycles. Numbers will be printed as small exponents before the output text.
    • firstPara

      protected boolean firstPara
      Whether the next call to appendText is the first in this step.
    • answer

      protected String answer
      The url clicked by the user. Must be read and processed by the payload code.
    • epane

      protected final JEditorPane epane
      evident
    • icon

      protected final Icon icon
    • hasShortcuts

      protected final boolean hasShortcuts
    • shortcutlist

      @Opt protected final @Opt List<String> shortcutlist
    • linklistener

      protected HyperlinkListener linklistener
      An answer is given by the of the user by clicking one of the offered links. Consequences: The selected link is replaced by emphasized normal text; all others by stroke-out normal text. The variable answer is set and the call-back react() is called. There the caller may perform the next step of the dialog by adding further HTML text (again with links for reaction) by calling appendText(String). All these steps are numbered visibly. We use the url value of the HTML source text, i.e. not parsed or verified, which is retrieved by HyperlinkEvent.getDescription().
    • DIGITS

      public static final String DIGITS
      See Also:
    • keylistener

      protected KeyListener keylistener
      An answer is given by the of the user by pressing one of the shortcut keys. For the reaction see linklistener.
    • PATTERN_close_a

      final Pattern PATTERN_close_a
    • PATTERN_open_a

      final Pattern PATTERN_open_a
    • PATTERN_close_body

      final Pattern PATTERN_close_body
  • Constructor Details

    • TextDialog

      protected TextDialog(JFrame context, String windowtitle, boolean isModal)
    • TextDialog

      protected TextDialog(JFrame context, String windowtitle, boolean isModal, boolean hasShortcuts)
    • TextDialog

      protected TextDialog(JFrame context, String windowtitle, boolean isModal, PlafIcon.type t)
    • TextDialog

      protected TextDialog(JFrame context, String windowtitle, boolean isModal, boolean hasShortcuts, PlafIcon.type t)
    • TextDialog

      protected TextDialog(@Opt @Opt JFrame context, @Opt @Opt String windowtitle, boolean isModal, boolean hasShortcuts, PlafIcon.type t, @Opt @Opt Dimension size)
      Only real constructor, all others are just default argument wrappers.

      (Please not:

         public JDialog(Window owner, String title)
         Creates a modeless dialog with the specified title and owner Window.
         ...
         Parameters:
         ...
         title - the String to display in the dialog's title bar or null if the 
         dialog has no title
       
      is THE ONLY PLACE where there is anything said about "title==null". We ASSUME that title is OPT String.)

      Parameters:
      context - the frame to which the dialog is related
      windowtitle - the text in the window's title bar
      isModal - whether the main frame cannot receive veents until this Dialog window is closed.
      hasShortcuts - whether the possible clicks can be activated by number nput
      t - the icon type which distinguisehs warnings, info, etc. (Icons for decorating or representing the window are a different this and can be set by explicitly invoking Window.setIconImages(List), etc.)
  • Method Details

    • wrapTT

      public static String wrapTT(String t)
      For use by subclasses. Wrap into green bold teletype, for input/output examples. etc.
    • wrapError

      public static String wrapError(String t)
      For use by subclasses. Wratp into red color for error messages.
    • transformLinks

      protected void transformLinks()
      Replaces link appearances. Is normally called immediately after a decisive click. Links are transformed as follows: (read square brackets for angle brackets) :
         [a href='xxx']yyy[/a]  --> [b]yyy[/b]  iff xxx==answer
                                --> [strike]yyy[/strike] otherwise
       
    • appendText

      protected void appendText(String text)
      Appends the text at the end of the buffer. Technically the HTML must be decoded and the new text inserted befofe PATTERN_close_body. If this is not the first step in the dialog process, but the first call in this step, then the step number is visibly represented.
    • appendTextLine

      protected void appendTextLine(String text)
      Appends only short (additional) text without any interactive formatting.
    • runDialog

      public void runDialog()
      Service access point to display and run this TextDialog.
    • do_react

      protected void do_react()
      React according to the href-valie of the selected link (by clicking or keystroke): Call user's call-back method react() or try browser remote control, if the href (in answer starts with "http://".
    • showURI

      protected void showURI(String uriString)
      Try remote control of the system's browser. Here no message channel is available, but this method can be overridden by are more instrumented version.
    • react

      protected void react()
      Callback function, must be overridden by the user. It must execute the appropriate reactions, guided by the value of answer, which is (the raw source text of) the url selected by the user. Default behaviour is to close the dialog.
    • finished

      protected void finished()