Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

Message area



The MessageArea method allows to show messages and prompts for a GUI application.

messageareaOverview

Message area creation


The message area is created through one of the methods initializating the application GUI. For example:

Getting the Message area

The AbstractMDIApplication.getMessageArea() method allows to get the message area. It also is the AbstractMDIApplication.getMessageArea() message of the application.

Message area default implementation overview

The Message area default implementation allows to: The background of the area allows several user actions by right clicking on the area:
  • "Print": Saving the content of the area in an html file
  • "Clear": Clearing the content of the area

Message area default implementation actions

The default implementation shows a Popup menu when right clicking in the area:
messageareaactions
This menu has two actions:
  • "Print": Saving the content of the area in an html file
  • "Clear": Clearing the content of the area
The methods which implement these features are: Both these methods can be overriden.

Copying the selected text in the system clipboard

The MessageArea.manageClipboard(boolean) method allows to add an additional action to copy the content of the selected text to the system clipboard. In that case, the menu has one additional action if some text has been selected:
  • "Copy": Copying the content of the selected text to the system clipboard

messageareaactionsAll
Note that this manageClipboard(true) method must be called to be able to show this additional action. For example:
      public BasicTutorialMDI() {
        super("BasicTutorialMDI");

        this.initConfiguration();
        SimpleMenuFactory() mfactory = new SimpleMenuFactory();
        super.preparePanels(4, true, false, mfactory);
        this.getMessageArea().manageClipBoard(true);
      }

Appending a text line

The Message area default implementation has the following features:

Setting the color and style of the line of text

The MessageLogger.append(String, String, int, int) allows to set the color of the text, the font size, and the text style:
  • The first argument is the text
  • The second argument is the color (expressed as an html color name)
  • The third argument is the font size (expressed as an html font size). The value MessageLogger.DEFAULT_FONT_SIZE specifies the default size
  • The last argument is the style. The value MessageLogger.DEFAULT_STYLE specifies the default style
The style is elaborated by ANDing the following values: For example:
      area.append("the red crossed text in bold", "red", MessageLogger.DEFAULT_FONT_SIZE, MessageLogger.BOLD & MessageLogger.CROSSED);

Styling the area for Swing

The SwingMessageArea has a SwingMessageArea.setStyleSheet(StyleSheet) method which allows to customize the style of the HTMLEditorKit used in the area. Note that the styles you will define will be added on top of the default style of the HTMLEditorKit implementation. It is possible to register a MessageAreaHandler to be notified of selecting an hyperlink in the area:

Allowing right click

By default only hyperlinks selection by left clicking on the hyperlink are allowed. It is however also possible to allows righ-clicking on these hyperlinks, but do allow that, you need to configure the area in the GUI application, but using the SwingMessageArea.setHandleRightClick(boolean) method. For example:
      public class MyApplication extends AbstractMDIApplication {
         public MyApplication() {
         super("My Application");

         // create the menus with the Application menu factory
         mfactory = new SimpleMenuFactory();
         super.preparePanels(4, true, true, mfactory);
         // set the size of the Application window
         this.setSize(500, 500);

         this.message.setHandleRightClick(true);
      }

Examples

In the following application, we add a basic link to the area:
      MessageArea area = this.getMessageArea();
      area.addHandler(MyAreaLinkHandler());
      area.appendLink("My link", "link1");
You can perform in the handler:
      public void handleLinkSelection(String linkID) {
        System.out.println("The link ID: " + linkID));
      }
In the following application, we add a link with an associated Object to the area:
      File file =...
      MessageArea area = this.getMessageArea();
      area.addHandler(MyAreaLinkHandler());
      area.appendLink("My link", "link1", file);
You can perform in the handler:
      public void handleLinkSelection(String linkID, Object o) {
      - if (o instanceof File) {
          File file = (File)o;
          System.out.println("The file path: " + file.getPath()));
      }

Notes

  1. ^ The method only allows for one handler and is deprecated. It is preferable to use the MessageArea.addHandler(MessageAreaHandler) method instead

See also


Categories: general | gui | swing

Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences