Displaying Dialogs

Simple Info, Warning or Error dialogs

For displaying simple textual information, warning or error dialogs you can use the DialogManager utility class.

    import com.interactive.intviewerapi.util.DialogManager;
    ...
    DialogManager.getDefault().showMessageDialog("Please specify a positive number for the scale", "Editor Warning", DialogManager.WARNING);

For displaying dialogs that require a user interaction such as OK, YES or NO, use showConfirmDialog:

   int resp = DialogManager.getDefault().showConfirmDialog("Do you want to continue ?", "Editor Warning", DialogManager.OK_CANCEL_OPTION);
   if (resp == DialogManager.OK) {
        ....
   }

If you have caught an exception and need to let the user know about the problem, you can also use:

    import com.interactive.intviewerapi.util.DialogManager;
    DialogManager.getDefault().showErrorDialog("Could not create Seismic layer.", "Layer Error", ex);

The exception message will be displayed in the dialog.

For more complicated dialogs, you should use IntViewerDialogDisplayer class which is based NetBeans DialogDisplayer functionality. This class help you with the creation and handling of standard dialog buttons including OK, Apply, Cancel, Help, etc.

Display dialog with the default options. (Apply, OK, Cancel)

    import com.interactive.intviewerapi.util.DialogManager;
    ...
    IntViewerDialogDisplayer.getDefault().notify(contents, "My Dialog Title", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (DialogDisplayerUtils.OK.equalsIgnoreCase(e.getActionCommand())) {
                // do something
            }
        }
    });

Where contents is a JPanel which contains the internals of your dialog.

Display a dialog with predefined options

If you need a different combination of buttons, you can choose from some of the predefined ones in IntViewerDialogDisplayer.

    IntViewerDialogDisplayer.getDefault().notify(contents, "My Dialog Title",
    IntViewerDialogDisplayer.SAVE_CANCEL_OPTION, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
                // handle your buttons
        }
    });

Display a dialog with custom options

If you need a combination that is not provided, you can try the following:

     OptionType customOptions = new OptionType(new String[]{"OK"}, "OK", new String[]{"OK"});
     IntViewerDialogDisplayer.getDefault().notify(contents, "My Title", customOptions, new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            // handle events
        }
     });

The first argument to OptionType specifies the list of buttons, the second the default button and the last the buttons that will close the dialog.