Example usage for javax.swing JOptionPane JOptionPane

List of usage examples for javax.swing JOptionPane JOptionPane

Introduction

In this page you can find the example usage for javax.swing JOptionPane JOptionPane.

Prototype

public JOptionPane(Object message, int messageType) 

Source Link

Document

Creates an instance of JOptionPane to display a message with the specified message type and the default options,

Usage

From source file:de.juwimm.cms.http.AuthenticationStreamSupportingHttpInvokerRequestExecutor.java

@Override
protected void executePostMethod(HttpInvokerClientConfiguration config, HttpClient httpClient,
        PostMethod postMethod) throws IOException {
    HttpClientWrapper.getInstance().setHostConfiguration(super.getHttpClient(),
            new URL(config.getServiceUrl()));
    try {//from w ww .  j  a  v a  2s  .  com
        super.executePostMethod(config, httpClient, postMethod);
        //if call succeeds 
        isErrorMessageShown = false;
    } catch (IOException e) {
        if ((e instanceof SocketException && e.getMessage().equals("Connection reset"))
                || (e instanceof ConnectException && e.getMessage().equals("Connection refused"))) {
            if (!isErrorMessageShown) {
                isErrorMessageShown = true;
                JOptionPane errorOptionPane = new JOptionPane(
                        Constants.rb.getString("exception.connectionToServerLost"),
                        JOptionPane.INFORMATION_MESSAGE);
                JDialog errorDialogPane = errorOptionPane.createDialog(UIConstants.getMainFrame(),
                        rb.getString("dialog.title"));
                errorDialogPane.setModalityType(ModalityType.MODELESS);
                errorDialogPane.setVisible(true);
                errorDialogPane.setEnabled(true);
                errorDialogPane.addWindowListener(new WindowAdapter() {
                    public void windowDeactivated(WindowEvent e) {
                        if (((JDialog) e.getSource()).isVisible() == false) {
                            isErrorMessageShown = false;
                        }
                    }
                });

            }
            log.error("server is not reachable");
        } else {
            e.printStackTrace();
        }
    }
    System.out.println(postMethod.getResponseHeaders());
}

From source file:com.quinsoft.zeidon.utils.JoeUtils.java

public static final void sysMessageBox(String msgTitle, String msgText) {
    //JOptionPane.showMessageDialog( null, msgText, msgTitle, JOptionPane.PLAIN_MESSAGE );
    JOptionPane pane = new JOptionPane(msgText, JOptionPane.INFORMATION_MESSAGE);
    JDialog dialog = pane.createDialog(msgTitle);
    dialog.setModalityType(ModalityType.MODELESS);
    dialog.setAlwaysOnTop(true);/*from w  w w .  ja v a  2  s  .  c  o m*/
    dialog.setVisible(true);
}

From source file:ome.formats.importer.gui.FileQueueHandler.java

/**
 * Retrieve the file chooser's selected reader then iterate over
 * each of our supplied containers filtering out those whose format
 * do not match those of the selected reader.
 * //w w w  . j a va2s  .c  o  m
 * @param allContainers List of ImporterContainers
 */
private void handleFiles(List<ImportContainer> allContainers) {
    FileFilter selectedFilter = fileChooser.getFileFilter();
    IFormatReader selectedReader = null;

    if (selectedFilter instanceof FormatFileFilter) {
        log.debug("Selected file filter: " + selectedFilter);
        selectedReader = ((FormatFileFilter) selectedFilter).getReader();
    }

    List<ImportContainer> containers = new ArrayList<ImportContainer>();
    for (ImportContainer ic : allContainers) {
        if (selectedReader == null) {
            // The user selected "All supported file types"
            containers = allContainers;
            break;
        }
        String a = selectedReader.getFormat();
        String b = ic.getReader();
        if (a.equals(b) || b == null) {
            containers.add(ic);
        } else {
            log.debug(String.format("Skipping %s (%s != %s)", ic.getFile().getAbsoluteFile(), a, b));
        }
    }

    Boolean spw = spwOrNull(containers);

    if (containers.size() == 0 && !candidatesFormatException) {
        final JOptionPane optionPane = new JOptionPane("\nNo importable files found in this selection.",
                JOptionPane.WARNING_MESSAGE);
        final JDialog errorDialog = new JDialog(viewer, "No Importable Files Found", true);
        errorDialog.setContentPane(optionPane);

        optionPane.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();

                if (errorDialog.isVisible() && (e.getSource() == optionPane)
                        && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                    errorDialog.dispose();
                }
            }
        });

        errorDialog.toFront();
        errorDialog.pack();
        errorDialog.setLocationRelativeTo(viewer);
        errorDialog.setVisible(true);
    }

    if (candidatesFormatException) {
        viewer.candidateErrorsCollected(viewer);
        candidatesFormatException = false;
    }

    if (spw == null) {
        addEnabled(true);
        containers.clear();
        return; // Invalid containers.
    }

    if (getOMEROMetadataStoreClient() != null && spw.booleanValue()) {
        addEnabled(true);
        SPWDialog dialog = new SPWDialog(config, viewer, "Screen Import", true, getOMEROMetadataStoreClient());
        if (dialog.cancelled == true || dialog.screen == null)
            return;
        for (ImportContainer ic : containers) {
            ic.setTarget(dialog.screen);
            String title = dialog.screen.getName().getValue();
            addFileToQueue(ic, title, false, 0);
        }

        qTable.centerOnRow(qTable.getQueue().getRowCount() - 1);
        qTable.importBtn.requestFocus();

    } else if (getOMEROMetadataStoreClient() != null) {
        addEnabled(true);
        ImportDialog dialog = new ImportDialog(config, viewer, "Image Import", true,
                getOMEROMetadataStoreClient());
        if (dialog.cancelled == true || dialog.dataset == null)
            return;

        Double[] pixelSizes = new Double[] { dialog.pixelSizeX, dialog.pixelSizeY, dialog.pixelSizeZ };
        Boolean useFullPath = config.useFullPath.get();
        if (dialog.useCustomNamingChkBox.isSelected() == false)
            useFullPath = null; //use the default bio-formats naming

        for (ImportContainer ic : containers) {
            ic.setTarget(dialog.dataset);
            ic.setUserPixels(pixelSizes);
            ic.setArchive(dialog.archiveImage.isSelected());
            String title = "";
            if (dialog.project.getId() != null) {
                ic.setProjectID(dialog.project.getId().getValue());
                title = dialog.project.getName().getValue() + " / " + dialog.dataset.getName().getValue();
            } else {
                title = "none / " + dialog.dataset.getName().getValue();
            }

            addFileToQueue(ic, title, useFullPath, config.numOfDirectories.get());
        }

        qTable.centerOnRow(qTable.getQueue().getRowCount() - 1);
        qTable.importBtn.requestFocus();
    } else {
        addEnabled(true);
        JOptionPane.showMessageDialog(viewer,
                "Due to an error the application is unable to \n"
                        + "retrieve an OMEROMetadataStore and cannot continue."
                        + "The most likely cause for this error is that you"
                        + "are not logged in. Please try to login again.");
    }
}

From source file:ome.formats.importer.gui.GuiImporter.java

public void update(IObservable importLibrary, ImportEvent event) {

    // Keep alive has failed, call logout
    if (event instanceof ImportEvent.LOGGED_OUT) {
        logout();//from   w  w w  .  j a v  a 2s .  c  o  m
        showLogoutMessage();
    }

    if (event instanceof ImportEvent.LOADING_IMAGE) {
        ImportEvent.LOADING_IMAGE ev = (ImportEvent.LOADING_IMAGE) event;

        getStatusBar().setProgress(true, -1, "Loading file " + ev.numDone + " of " + ev.total);
        appendToOutput("> [" + ev.index + "] Loading image \"" + ev.shortName + "\"...\n");
        getStatusBar().setStatusIcon("gfx/import_icon_16.png", "Prepping file \"" + ev.shortName);
    }

    else if (event instanceof ImportEvent.LOADED_IMAGE) {
        ImportEvent.LOADED_IMAGE ev = (ImportEvent.LOADED_IMAGE) event;

        getStatusBar().setProgress(true, -1, "Analyzing file " + ev.numDone + " of " + ev.total);
        appendToOutput(" Succesfully loaded.\n");
        appendToOutput("> [" + ev.index + "] Importing metadata for " + "image \"" + ev.shortName + "\"... ");
        getStatusBar().setStatusIcon("gfx/import_icon_16.png",
                "Analyzing the metadata for file \"" + ev.shortName);
    }

    else if (event instanceof ImportEvent.BEGIN_SAVE_TO_DB) {
        ImportEvent.BEGIN_SAVE_TO_DB ev = (ImportEvent.BEGIN_SAVE_TO_DB) event;
        appendToOutput("> [" + ev.index + "] Saving metadata for " + "image \"" + ev.filename + "\"... ");
        getStatusBar().setStatusIcon("gfx/import_icon_16.png", "Saving metadata for file \"" + ev.filename);
    }

    else if (event instanceof ImportEvent.DATASET_STORED) {
        ImportEvent.DATASET_STORED ev = (ImportEvent.DATASET_STORED) event;

        int num = ev.numDone;
        int tot = ev.total;
        int pro = num - 1;
        appendToOutputLn("Successfully stored to " + ev.target.getClass().getSimpleName() + " \"" + ev.filename
                + "\" with id \"" + ev.target.getId().getValue() + "\".");
        appendToOutputLn(
                "> [" + ev.series + "] Importing pixel data for " + "image \"" + ev.filename + "\"... ");
        getStatusBar().setProgress(true, 0, "Importing file " + num + " of " + tot);
        getStatusBar().setProgressValue(pro);
        getStatusBar().setStatusIcon("gfx/import_icon_16.png",
                "Importing the pixel data for file \"" + ev.filename);
        appendToOutput("> Importing plane: ");
    }

    else if (event instanceof ImportEvent.DATA_STORED) {
        ImportEvent.DATA_STORED ev = (ImportEvent.DATA_STORED) event;

        appendToOutputLn("> Successfully stored with pixels id \"" + ev.pixId + "\".");
        appendToOutputLn("> [" + ev.filename + "] Image imported successfully!");
    }

    else if (event instanceof FILE_EXCEPTION) {
        FILE_EXCEPTION ev = (FILE_EXCEPTION) event;
        if (IOException.class.isAssignableFrom(ev.exception.getClass())) {

            final JOptionPane optionPane = new JOptionPane(
                    "The importer cannot retrieve one of your images in a timely manner.\n"
                            + "The file in question is:\n'" + ev.filename + "'\n\n"
                            + "There are a number of reasons you may see this error:\n"
                            + " - The file has been deleted.\n"
                            + " - There was a networking error retrieving a remotely saved file.\n"
                            + " - An archived file has not been fully retrieved from backup.\n\n"
                            + "The importer should now continue with the remainer of your imports.\n",
                    JOptionPane.ERROR_MESSAGE);

            final JDialog dialog = new JDialog(this, "IO Error");
            dialog.setAlwaysOnTop(true);
            dialog.setContentPane(optionPane);
            dialog.pack();
            dialog.setVisible(true);
            optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent e) {
                    String prop = e.getPropertyName();

                    if (dialog.isVisible() && (e.getSource() == optionPane)
                            && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                        dialog.dispose();
                    }
                }
            });
        }
    }

    else if (event instanceof EXCEPTION_EVENT) {
        EXCEPTION_EVENT ev = (EXCEPTION_EVENT) event;
        log.error("EXCEPTION_EVENT", ev.exception);
    }

    else if (event instanceof INTERNAL_EXCEPTION) {
        INTERNAL_EXCEPTION e = (INTERNAL_EXCEPTION) event;
        log.error("INTERNAL_EXCEPTION", e.exception);

        // What else should we do here? Why are EXCEPTION_EVENTs being
        // handled here?
    }

    else if (event instanceof ImportEvent.ERRORS_PENDING) {
        tPane.setIconAt(4, GuiCommonElements.getImageIcon(ERROR_ICON_ANIM));
        errors_pending = true;
        error_notification = true;
    }

    else if (event instanceof ImportEvent.ERRORS_COMPLETE) {
        tPane.setIconAt(4, GuiCommonElements.getImageIcon(ERROR_ICON));
        error_notification = false;
    }

    else if (event instanceof ImportEvent.ERRORS_COMPLETE) {
        tPane.setIconAt(4, GuiCommonElements.getImageIcon(ERROR_ICON));
        error_notification = false;
    }

    else if (event instanceof ImportEvent.ERRORS_FAILED) {
        sendingErrorsFailed(this);
    }

    else if (event instanceof ImportEvent.IMPORT_QUEUE_DONE && errors_pending == true) {
        errors_pending = false;
        importErrorsCollected(this);
    }

}

From source file:ome.formats.importer.gui.GuiImporter.java

/**
 * Display errors in import dialog /*w  w w. java 2s .  c om*/
 * 
 * @param frame - parent frame
 */
private void importErrorsCollected(Component frame) {
    final JOptionPane optionPane = new JOptionPane(
            "\nYour import has produced one or more errors, " + "\nvisit the 'Import Errors' tab for details.",
            JOptionPane.WARNING_MESSAGE);
    final JDialog errorDialog = new JDialog(this, "Errors Collected", false);
    errorDialog.setContentPane(optionPane);

    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (errorDialog.isVisible() && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                errorDialog.dispose();
            }
        }
    });

    errorDialog.toFront();
    errorDialog.pack();
    errorDialog.setLocationRelativeTo(frame);
    errorDialog.setVisible(true);
}

From source file:ome.formats.importer.gui.GuiImporter.java

/**
 * Display errors in candidates dialog//from  ww w  . ja va  2  s.  co  m
 * 
 * @param frame - parent frame
 */
public void candidateErrorsCollected(Component frame) {
    errors_pending = false;
    final JOptionPane optionPane = new JOptionPane(
            "\nAdding these files to the queue has produced one or more errors and some"
                    + "\n files will not be displayed on the queue. View the 'Import Errors' tab for details.",
            JOptionPane.WARNING_MESSAGE);
    final JDialog errorDialog = new JDialog(this, "Errors Collected", true);
    errorDialog.setContentPane(optionPane);

    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (errorDialog.isVisible() && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                errorDialog.dispose();
            }
        }
    });

    errorDialog.toFront();
    errorDialog.pack();
    errorDialog.setLocationRelativeTo(frame);
    errorDialog.setVisible(true);
}

From source file:ome.formats.importer.gui.GuiImporter.java

/**
 * Display failed sending errors dialog//  ww w . j a v a 2s  . c o m
 * 
 * @param frame - parent frame
 */
public void sendingErrorsFailed(Component frame) {
    final JOptionPane optionPane = new JOptionPane(
            "\nDue to an error we were not able to send your error messages."
                    + "\nto our feedback server. Please try again.",
            JOptionPane.WARNING_MESSAGE);

    final JDialog failedDialog = new JDialog(this, "Feedback Failed!", true);

    failedDialog.setContentPane(optionPane);

    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (failedDialog.isVisible() && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                failedDialog.dispose();
            }
        }
    });

    failedDialog.toFront();
    failedDialog.pack();
    failedDialog.setLocationRelativeTo(frame);
    failedDialog.setVisible(true);
}

From source file:ome.formats.importer.gui.ImportDialog.java

/**
 * Dialog explaining metadata limitations when changing the main dialog's naming settings
 * //  w  w w  .j a va 2s .  c o  m
 * @param frame - parent component
 */
public void sendNamingWarning(Component frame) {
    final JOptionPane optionPane = new JOptionPane(
            "\nNOTE: Some file formats do not include the file name in their metadata, "
                    + "\nand disabling this option may result in files being imported without a "
                    + "\nreference to their file name. For example, 'myfile.lsm [image001]' "
                    + "\nwould show up as 'image001' with this optioned turned off.",
            JOptionPane.WARNING_MESSAGE);
    final JDialog warningDialog = new JDialog(this, "Naming Warning!", true);
    warningDialog.setContentPane(optionPane);

    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (warningDialog.isVisible() && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                warningDialog.dispose();
            }
        }
    });

    warningDialog.toFront();
    warningDialog.pack();
    warningDialog.setLocationRelativeTo(frame);
    warningDialog.setVisible(true);
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

/**
 * Displays an error message when a user tries to delete more than one column at a time.
 *//*from w w  w  . j a  v a  2s. c  o m*/
protected void showColumnErrorMessage() {
    if (!(table.getSelectedColumns().length > 1)) {
        spreadsheetFunctions.deleteColumn(table.getSelectedColumn());
    } else {

        optionPane = new JOptionPane(
                "<html>Multiple column select detected!<p>Please select only one column!</p></html>",
                JOptionPane.OK_OPTION);
        optionPane.setIcon(selectOneColumnWarningIcon);
        UIHelper.applyOptionPaneBackground(optionPane, UIHelper.BG_COLOR);
        optionPane.addPropertyChangeListener(this);
        parentFrame.showJDialogAsSheet(optionPane.createDialog(this, "Delete Column"));
    }
}

From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

/**
 * Delete column given an index./*w w w .ja v a2s .  co m*/
 *
 * @param vColIndex - column to remove.
 */
protected void deleteColumn(int vColIndex) {
    spreadsheet.curColDelete = vColIndex;
    spreadsheet.currentState = Spreadsheet.DELETING_COLUMN;

    TableColumn col = spreadsheet.getTable().getColumnModel().getColumn(spreadsheet.curColDelete);

    if (!col.getHeaderValue().toString().equals(TableReferenceObject.ROW_NO_TEXT)) {
        if (spreadsheet.getTableReferenceObject().isRequired(col.getHeaderValue().toString())
                && !areMultipleOccurences(col.getHeaderValue().toString())) {
            spreadsheet.optionPane = new JOptionPane(
                    "<html>This column can not be deleted due to it being a required field in this assay!</html>",
                    JOptionPane.OK_OPTION);
            spreadsheet.optionPane.setIcon(spreadsheet.requiredColumnWarningIcon);
            UIHelper.applyOptionPaneBackground(spreadsheet.optionPane, UIHelper.BG_COLOR);

            spreadsheet.optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent event) {
                    if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
                        spreadsheet.getParentFrame().hideSheet();
                    }
                }
            });

            spreadsheet.getParentFrame()
                    .showJDialogAsSheet(spreadsheet.optionPane.createDialog(spreadsheet, "Can not delete"));
        } else {
            spreadsheet.optionPane = new JOptionPane(
                    "<html>Are you sure you want to delete this column? <p>This Action can not be undone!</p></html>",
                    JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_OPTION,
                    spreadsheet.confirmRemoveColumnIcon);
            UIHelper.applyOptionPaneBackground(spreadsheet.optionPane, UIHelper.BG_COLOR);
            spreadsheet.optionPane.addPropertyChangeListener(spreadsheet);
            spreadsheet.getParentFrame().showJDialogAsSheet(
                    spreadsheet.optionPane.createDialog(spreadsheet, "Confirm Delete Column"));
        }
    }
}