Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

DefaultMDIDialogBuilder class



The DefaultMDIDialogBuilder class further simplifies the creation of popup dialogs, allowing to create several rows of content, optionally enclosed in their titled borders.

Configuration of the DefaultMDIDialogBuilder

The DefaultMDIDialogBuilder class implements the MDIDialogBuilder interface, so all there is a corresponding setter for all the methods allowing to configure the MDIDialogBuilder:

Dialog type

The type of the dialog can be set through the DefaultMDIDialogBuilder.setDialogType(short) method. It can be:

Listening to the user actions

The DefaultMDIDialogBuilder.DialogListener interface allows to listen to user actions on the bottom dialog buttons. This listener can be set through the DefaultMDIDialogBuilder.setListener(DialogListener) method. This interface has sveral methods, all with a default empty implementation:

OK_DIALOG type

The MDIDialogBuilder.OK_DIALOG is used for a dialog with only an OK button (this is the default option):
dialogBuilder
If the user clicks on the OK button, the DefaultMDIDialogBuilder.DialogListener.apply() method will be called (the default implementation does nothing).

OK_PRINT_DIALOG type

The MDIDialogBuilder.OK_PRINT_DIALOG is used for a dialog with only an OK button and a Print button:
dialogokprint
If the user clicks on the OK button, the DefaultMDIDialogBuilder.DialogListener.apply() method will be called (the default implementation does nothing).

If the user clicks on the Print button, a file chooser will appear allowing the user to select a file where to save the dialog content. The DefaultMDIDialogBuilder.setPrintFileExtension(String) method allows to specify the extension of the file to save (the default is "txt").

After the file selection, the DefaultMDIDialogBuilder.DialogListener.print(File) method will be called (the default implementation does nothing).

YES_CANCEL_DIALOG type

The MDIDialogBuilder.YES_CANCEL_DIALOG is used for a dialog with only a Yes button and a Cancel button:
dialogyescancel
If the user clicks on the Yes button, the DefaultMDIDialogBuilder.DialogListener.apply() method will be called (the default implementation does nothing).

If the user press the "Cancel" button, the DefaultMDIDialogBuilder.DialogListener.cancel()method will be called.

Message type

The DefaultMDIDialogBuilder.setMessageType(int) method allows to specify the message type of the dialog, which will specify which icon to present at the left of the dialog. It can be:

Creation of the DefaultMDIDialogBuilder content

Adding a part in the DefaultMDIDialogBuilder is done through one of the following methods: The returned MDIDialogBuilder.DialogPart will correspond to one row in the dialog.

Showing the dialog

The DefaultMDIDialogBuilder class implements the MDIDialogBuilder interface, so showing the associated dialog is done exactly as for the MDIDialogBuilder:
dialogBuilder

Enabling or disabling dialog parts

The two following methods allow to give an id to dialog parts:
  • The first String argument is the id of the corresponding dialog part
  • The second String argument is the border title (can be null)
  • The last argument is the list of components in the dialog part
You can get the asociated dialog after creating the builder by calling DefaultMDIDialogBuilder.getMDIBuilderDialog(). This dialog will be created aftet you called MDIDialogHelper.showDialog(MDIDialog, MDIDialogType) in the helper.

You can enable or disable a dialog part through the MDIDialogBuilder.DialogPart.setEnabled(boolean) method.

Using a component in the dialog part itself

The first solution to enable or disable a dialog part uses a component which is outide the dialog part itself. However it is possible to do the same with a component inside the dialog part, but you need pass this component to the dialog part to avoid to disable it as other components.

The method to do this is the MDIDialogBuilder.DialogPart.setNotDisablingComponent(JComponent). That way the dialog part will not disable or enable the component when calling the MDIDialogBuilder.DialogPart.setEnabled(boolean) method.

Note that the component can also be in a dialog part child dialog part.

UNIQUE_INSTANCE dialogs

Using the MDIDialogType.UNIQUE_INSTANCE value for the second argument of the GUIApplication.showDialog(MDIDialogBuilder, MDIDialogType) method will ensure that only one dialog the same class can be opened at the same time:

Example

The following example creates a dialog presenting the width and height of an image:
   public class AnalyzeImageAction extends AbstractMDIAction {
      public AnalyzeImageAction(MDIApplication appli, String name) {
        super(appli, name);
        this.setDescription("Analyze", "Analyze Image");
      }

      @Override
      public void run() throws Exception {
        GUIApplication gui = ((GUIApplication) app);
        BufferedImage image = (BufferedImage) gui.getSelectedProperties().getObject();
        DefaultMDIDialogBuilder builder = new DefaultMDIDialogBuilder("Analyze Image");
        builder.addVerticalDialogPart("Size", new JLabel("Width: " + image.getWidth()), new JLabel("Height: " + image.getHeight()));
        gui.showDialog(builder, MDIDialogType.UNIQUE_INSTANCE);
      }
   }
with the following result:
dialogBuilder

Notes

  1. ^ See also opening dialogs for more information

See also


Categories: gui | swing

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