Class JDialogText

All Implemented Interfaces:
DialogDefaultsInterface, ActionListener, FocusListener, ItemListener, WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants
Direct Known Subclasses:
JDialogFileInfoMinc, JDialogTextGE, JDialogTextGE4X

public class JDialogText extends JDialogBase
This is simple text dialog that displays in the center of the screen. It automatically adjusts the dialog size to the length of the input string.
Version:
0.1 Oct 1, 1998, 2.0 2003-April-9
Author:
Matthew J. McAuliffe, Ph.D.

Defaults to an interface very similar to the original version, however now supports plain text, HTML and Rich-Text format. Perhaps the most significant difference is that when text is too long to fit entirely within the width of the display-area, it is wrapped around to the other side, rather than the scroll-area increasing in size.

Plain text format is handled by the DefaultEditorKit. The HTML formatting is handled by the HTML editor kit. HTMLEditorKit parses HTML 3.2, so be sure to see the World Wide Web Consortium's (w3) definitive reference for HTML 3.2. The RTF parsing is handled by the RTF Editor Kit, which appears to only be a bare-bones implementation.

By default, all text sent to this editor (use the method append(String) or setText(String)) is formatted as plain-text, with PLAIN_FORMAT. The user-code can reformat using setFormat(String), and either PLAIN_FORMAT HTML_FORMAT, or RTF_FORMAT as any predefined setting, or any normal MIME type. Refer to the RFC list or RFC 2045 (MIME Types, part 1) and RFC 2045 (MIME Types part 2) for more on MIME types.

See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Use serialVersionUID for interoperability.
      See Also:
    • HTML_FORMAT

      public static final String HTML_FORMAT
      Specifis the output display of the text-box to be formatted using basic HTML rules, as defined by MIME-format "text/html".

      For more information, consult RFC 1866 (HTML 2.0), section 4.1, which defines the MIME type with all valid options; since RFC 1866 is out-dated, see also RFC 2854, a more more up-to-date source on "text/html" practices. RFC 2854, however, details HTML 4.0, which carries tags not deciphered by the decoder here; for information on HTML 3.2 (and the tags which may be used in included texts), see World Wide Web Consortium's (w3) definitive reference for HTML 3.2.

      See Also:
    • RTF_FORMAT

      public static final String RTF_FORMAT
      Specifies the output display of the text-box to be formatted using the RTF rules.
      See Also:
    • PLAIN_FORMAT

      public static final String PLAIN_FORMAT
      Specifies that the textbox not format the text in the display, as is defined by MIME type "text/plain". In addition, this setting will also reset the font to serif10.
      See Also:
    • DEFAULT_SIZE

      protected final Dimension DEFAULT_SIZE
      Describes the initial size of the textual display area when the dialog is created. The value is given in pixel size rather than the number of characters since the display area has no characters to display.
    • buttonPanel

      private JPanel buttonPanel
      DOCUMENT ME!
    • followingScroll

      private boolean followingScroll
      DOCUMENT ME!
    • message

      private StringBuffer message
      DOCUMENT ME!
    • scrollPane

      private JScrollPane scrollPane
      DOCUMENT ME!
    • textArea

      private JEditorPane textArea
      DOCUMENT ME!
  • Constructor Details

    • JDialogText

      public JDialogText(Frame parent, String title)
      Constructs resizable dialog with text area in the middle.
      Parameters:
      parent - Parent frame.
      title - Title of dialog frame.
    • JDialogText

      public JDialogText(Frame parent, String title, boolean followScroll)
      Constructs a resizable dialog with a text area which can be filled; the scrollbar can be set to keep up with the updates (at the bottom).
      Parameters:
      parent - parent frame
      title - title of the dialog frame
      followScroll - true means that the scroll bar should stay at the bottom of the text area where appended messages would go. false will not dynamically update the scroll bar location.
  • Method Details

    • actionPerformed

      public void actionPerformed(ActionEvent event)
      Closes dialog box when the "Close" button is pressed.
      Specified by:
      actionPerformed in interface ActionListener
      Overrides:
      actionPerformed in class JDialogBase
      Parameters:
      event - Event that triggers this function.
    • append

      public void append(String appMessage)
      Appends the text area with the message.
      Parameters:
      appMessage - The message to append to the text area.
    • setContent

      public void setContent(String type, String content)
      Uses the input string as the text to display in the dialog's text area, formats it with the specified MIME-type (or with PLAIN_FORMAT if it can't determine the how to display the content).
      Parameters:
      type - Either a MIME-type or PLAIN_FORMAT, RTF_FORMAT, or HTML_FORMAT.
      content - The String for the dialog to display in its text area.
    • setContent

      public void setContent(String type, File content) throws FileNotFoundException, IOException
      Attempts to read the given file, place its contents into the dialog's display area and format it using the specified MIME-type (or with PLAIN_FORMAT if it can not determine how to display the content).
      Parameters:
      type - Either a MIME-type or PLAIN_FORMAT, RTF_FORMAT, or HTML_FORMAT.
      content - The File whose contents the dialog is to display in its text area.
      Throws:
      FileNotFoundException - DOCUMENT ME!
      IOException - DOCUMENT ME!
    • setDocumentSize

      public void setDocumentSize(int columns, int rows)
      Attempts to set the size of the text display area to the supplied number of text-columns and rows.

      Negative or zero values are ignored, and the current value for text display area size is used in that dimension.

      The font size is assumed to be the size of a character of MipavUtil.font12, a fixed-width font. Obviously, this means that content-types displaying HTML may be larger (or smaller) so although the size will be set, it will not have much meaning for these texts.

      Parameters:
      columns - The number of text-columns of MipavUtil.font12 width.
      rows - The number of text-columns of MipavUtil.font12 height.
    • setFormat

      public void setFormat(String type)
      Sets the editor kit that renders the dialog's text area to the type given.

      A PLAIN_FORMAT or content-type that is unrecognized (and subsequently set to PLAIN_FORMAT) will be set to use a fixed-width font. The content is then re-loaded.

      Parameters:
      type - Either a MIME-type or PLAIN_FORMAT, RTF_FORMAT, or HTML_FORMAT.
    • setMessage

      public void setMessage(String message)
      Sets the text area to the message, erasing what was there earlier.
      Parameters:
      message - Message to display in the text area.
    • setScrollPaneTop

      public void setScrollPaneTop()
      Sets the caret to the top of the scroll pane.
    • getButtonPanel

      protected JPanel getButtonPanel()
      Accessor to the JPanel which holds the buttons at the bottom of the dialog.
      Returns:
      DOCUMENT ME!
    • init

      protected void init(String title)
      Initializes the dialog box to a certain size and adds the components.
      Parameters:
      title - Title of the dialog box.