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/protocol with the user. 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='...'</a>". All text belonging to the same interaction step must be added to the window in one single call to appendText(String) and thus be already well-formed HTML.
Shortcuts by single numeric digit keypresses can be enabled, but are supported only for the first ten links (="<a>...</a>" substrings).
See Also:
  • Field Details

    • lf

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

      public static final Dimension defaultSize
    • stepNum

      protected int stepNum
    • firstPara

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

      protected String answer
    • epane

      protected final JEditorPane epane
    • icon

      protected final Icon icon
    • hasShortcuts

      protected final boolean hasShortcuts
    • shortcutlist

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

      protected HyperlinkListener linklistener
      The answer of the user is executed by clicking one of the offered links. Consequences: The old text is grayed out, the selected link is emphasized; all others are de-emphasized; the variable answer is set and the call-back react() is called. There the caller performs 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
    • 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

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

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

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

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

      public TextDialog(@Opt @Opt JFrame context, @Opt @Opt String windowtitle, boolean isModal, boolean hasShortcuts, PlafIcon.type t, @Opt @Opt Dimension size)
      Only constructor, all others are just default argument wrappers. ARRRGH! Only
         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.
  • Method Details

    • wrapTT

      public static String wrapTT(String t)
      For use by subclasses.
    • wrapError

      public static String wrapError(String t)
      For use by subclasses.
    • transformLinks

      protected void transformLinks()
      Replaces link appearances and marks older dialog fragments by graying out. 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
                                --> [i]yyy[/i]  otherwise
                       (variant :   [strike]yyy[/strike]; is not xhtml strict but better to read!)
       
         [html]                          [html]                          
           [body]                          [body]                        
             [p style="color:gray"]      [p style="color:gray"] 
               VERY old text           VERY old text     
             [/p]                            [/p]
             [hr/]                       [hr/]
             [p]                         [p style="color:gray"]
               LAST text                       LAST text                 
             [/p]                            [/p]
                                         [hr/]
                                          ((NEW text < ----- later ))
           [/body]                 [/body]               
         [/html]                     [/html]                     
       
      The easier idea of own big "div" cannot be used because of bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6618068
        setText("[div style='xxx']") --->  getText() == "[div]" 
        setText("[p style='xxx']") --->  getText() == "[p]" 
        
    • appendText

      protected void appendText(String text)
      Wraps the text into one "[p]" element, for later graying out. FIXME scheint nicht mehr wahr!
    • appendTextLine

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

      public void runDialog()
    • 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.
    • finished

      protected void finished()