Example usage for javax.swing JDialog getContentPane

List of usage examples for javax.swing JDialog getContentPane

Introduction

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

Prototype

public Container getContentPane() 

Source Link

Document

Returns the contentPane object for this dialog.

Usage

From source file:nick.gaImageRecognitionGui.panel.JPanelTraining.java

private void jButtonTrainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTrainActionPerformed

    IApiTrainer trainer = initTrainer();

    saveSettings();/*w w  w .java 2s  . co  m*/

    JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
    final JDialog frame = new JDialog(topFrame, false);
    JPanelTrainingInProgress trainingPanel = new JPanelTrainingInProgress(trainer);
    frame.getContentPane().add(trainingPanel);
    frame.pack();
    Util.centreWindow(frame);
    frame.setVisible(true);

}

From source file:nick.gaImageRecognitionGui.panel.JPanelTraining.java

private void jButtonSetTrainingRulesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSetTrainingRulesActionPerformed

    JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
    final JDialog frame = new JDialog(topFrame, true);
    JPanelSetTrainingRules setTrainingrules = new JPanelSetTrainingRules(trainingRules);
    frame.getContentPane().add(setTrainingrules);
    frame.pack();/*  www . j a  va  2  s . co  m*/
    Util.centreWindow(frame);
    frame.setVisible(true);

}

From source file:org.apache.log4j.chainsaw.LogUI.java

/**
 * Displays a dialog which will provide options for selecting a configuration
 *//*from  w w w. j  a  va  2 s.co  m*/
private void showReceiverConfigurationPanel() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            final JDialog dialog = new JDialog(LogUI.this, true);
            dialog.setTitle("Load events into Chainsaw");
            dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

            dialog.setResizable(false);

            receiverConfigurationPanel.setCompletionActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dialog.setVisible(false);

                    if (receiverConfigurationPanel.getModel().isCancelled()) {
                        return;
                    }
                    applicationPreferenceModel
                            .setShowNoReceiverWarning(!receiverConfigurationPanel.isDontWarnMeAgain());
                    //remove existing plugins
                    List plugins = pluginRegistry.getPlugins();
                    for (Iterator iter = plugins.iterator(); iter.hasNext();) {
                        Plugin plugin = (Plugin) iter.next();
                        //don't stop ZeroConfPlugin if it is registered
                        if (!plugin.getName().toLowerCase(Locale.ENGLISH).contains("zeroconf")) {
                            pluginRegistry.stopPlugin(plugin.getName());
                        }
                    }
                    URL configURL = null;

                    if (receiverConfigurationPanel.getModel().isNetworkReceiverMode()) {
                        int port = receiverConfigurationPanel.getModel().getNetworkReceiverPort();

                        try {
                            Class receiverClass = receiverConfigurationPanel.getModel()
                                    .getNetworkReceiverClass();
                            Receiver networkReceiver = (Receiver) receiverClass.newInstance();
                            networkReceiver.setName(receiverClass.getSimpleName() + "-" + port);

                            Method portMethod = networkReceiver.getClass().getMethod("setPort",
                                    new Class[] { int.class });
                            portMethod.invoke(networkReceiver, new Object[] { new Integer(port) });

                            networkReceiver.setThreshold(Level.TRACE);

                            pluginRegistry.addPlugin(networkReceiver);
                            networkReceiver.activateOptions();
                            receiversPanel.updateReceiverTreeInDispatchThread();
                        } catch (Exception e3) {
                            MessageCenter.getInstance().getLogger().error("Error creating Receiver", e3);
                            MessageCenter.getInstance().getLogger()
                                    .info("An error occurred creating your Receiver");
                        }
                    } else if (receiverConfigurationPanel.getModel().isLog4jConfig()) {
                        File log4jConfigFile = receiverConfigurationPanel.getModel().getLog4jConfigFile();
                        if (log4jConfigFile != null) {
                            try {
                                Map entries = LogFilePatternLayoutBuilder
                                        .getAppenderConfiguration(log4jConfigFile);
                                for (Iterator iter = entries.entrySet().iterator(); iter.hasNext();) {
                                    try {
                                        Map.Entry entry = (Map.Entry) iter.next();
                                        String name = (String) entry.getKey();
                                        Map values = (Map) entry.getValue();
                                        //values: conversion, file
                                        String conversionPattern = values.get("conversion").toString();
                                        File file = new File(values.get("file").toString());
                                        URL fileURL = file.toURI().toURL();
                                        String timestampFormat = LogFilePatternLayoutBuilder
                                                .getTimeStampFormat(conversionPattern);
                                        String receiverPattern = LogFilePatternLayoutBuilder
                                                .getLogFormatFromPatternLayout(conversionPattern);
                                        VFSLogFilePatternReceiver fileReceiver = new VFSLogFilePatternReceiver();
                                        fileReceiver.setName(name);
                                        fileReceiver.setAutoReconnect(true);
                                        fileReceiver.setContainer(LogUI.this);
                                        fileReceiver.setAppendNonMatches(true);
                                        fileReceiver.setFileURL(fileURL.toURI().toString());
                                        fileReceiver.setTailing(true);
                                        fileReceiver.setLogFormat(receiverPattern);
                                        fileReceiver.setTimestampFormat(timestampFormat);
                                        fileReceiver.setThreshold(Level.TRACE);
                                        pluginRegistry.addPlugin(fileReceiver);
                                        fileReceiver.activateOptions();
                                        receiversPanel.updateReceiverTreeInDispatchThread();
                                    } catch (URISyntaxException e1) {
                                        e1.printStackTrace();
                                    }
                                }
                            } catch (IOException e1) {
                                e1.printStackTrace();
                            }
                        }
                    } else if (receiverConfigurationPanel.getModel().isLoadConfig()) {
                        configURL = receiverConfigurationPanel.getModel().getConfigToLoad();
                    } else if (receiverConfigurationPanel.getModel().isLogFileReceiverConfig()) {
                        try {
                            URL fileURL = receiverConfigurationPanel.getModel().getLogFileURL();
                            if (fileURL != null) {
                                VFSLogFilePatternReceiver fileReceiver = new VFSLogFilePatternReceiver();
                                fileReceiver.setName(fileURL.getFile());
                                fileReceiver.setAutoReconnect(true);
                                fileReceiver.setContainer(LogUI.this);
                                fileReceiver.setAppendNonMatches(true);
                                fileReceiver.setFileURL(fileURL.toURI().toString());
                                fileReceiver.setTailing(true);
                                if (receiverConfigurationPanel.getModel().isPatternLayoutLogFormat()) {
                                    fileReceiver.setLogFormat(
                                            LogFilePatternLayoutBuilder.getLogFormatFromPatternLayout(
                                                    receiverConfigurationPanel.getModel().getLogFormat()));
                                } else {
                                    fileReceiver
                                            .setLogFormat(receiverConfigurationPanel.getModel().getLogFormat());
                                }
                                fileReceiver.setTimestampFormat(
                                        receiverConfigurationPanel.getModel().getLogFormatTimestampFormat());
                                fileReceiver.setThreshold(Level.TRACE);

                                pluginRegistry.addPlugin(fileReceiver);
                                fileReceiver.activateOptions();
                                receiversPanel.updateReceiverTreeInDispatchThread();
                            }
                        } catch (Exception e2) {
                            MessageCenter.getInstance().getLogger().error("Error creating Receiver", e2);
                            MessageCenter.getInstance().getLogger()
                                    .info("An error occurred creating your Receiver");
                        }
                    }
                    if (configURL == null && receiverConfigurationPanel.isDontWarnMeAgain()) {
                        //use the saved config file as the config URL if defined
                        if (receiverConfigurationPanel.getModel().getSaveConfigFile() != null) {
                            try {
                                configURL = receiverConfigurationPanel.getModel().getSaveConfigFile().toURI()
                                        .toURL();
                            } catch (MalformedURLException e1) {
                                e1.printStackTrace();
                            }
                        } else {
                            //no saved config defined but don't warn me is checked - use default config
                            configURL = receiverConfigurationPanel.getModel().getDefaultConfigFileURL();
                        }
                    }
                    if (configURL != null) {
                        MessageCenter.getInstance().getLogger()
                                .debug("Initialiazing Log4j with " + configURL.toExternalForm());
                        final URL finalURL = configURL;
                        new Thread(new Runnable() {
                            public void run() {
                                if (receiverConfigurationPanel.isDontWarnMeAgain()) {
                                    applicationPreferenceModel.setConfigurationURL(finalURL.toExternalForm());
                                } else {
                                    try {
                                        if (new File(finalURL.toURI()).exists()) {
                                            loadConfigurationUsingPluginClassLoader(finalURL);
                                        }
                                    } catch (URISyntaxException e) {
                                        //ignore
                                    }
                                }

                                receiversPanel.updateReceiverTreeInDispatchThread();
                            }
                        }).start();
                    }
                    File saveConfigFile = receiverConfigurationPanel.getModel().getSaveConfigFile();
                    if (saveConfigFile != null) {
                        ReceiversHelper.getInstance().saveReceiverConfiguration(saveConfigFile);
                    }
                }
            });

            receiverConfigurationPanel.setDialog(dialog);
            dialog.getContentPane().add(receiverConfigurationPanel);

            dialog.pack();

            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            dialog.setLocation((screenSize.width / 2) - (dialog.getWidth() / 2),
                    (screenSize.height / 2) - (dialog.getHeight() / 2));

            dialog.setVisible(true);
        }
    });
}

From source file:org.apache.uima.tools.docanalyzer.DBAnnotationViewerDialog.java

public void launchThatViewer(String xmi_id, TypeSystem typeSystem, final String[] aTypesToDisplay,
        boolean javaViewerRBisSelected, boolean javaViewerUCRBisSelected, boolean xmlRBisSelected,
        File styleMapFile, File viewerDirectory) {

    try {//  w ww.  j av a 2 s  .c  om

        InputStream xmiDocument = this.xmiDAO.getXMI(xmi_id);

        // create a new CAS
        CAS cas = CasCreationUtils.createCas(Collections.EMPTY_LIST, typeSystem,
                UIMAFramework.getDefaultPerformanceTuningProperties());

        if (this.med1.isUmcompress()) {

            //Descomprime el XMI
            System.out.println("con compresin");

            //Create the decompressor and give it the data to compress
            Inflater decompressor = new Inflater();
            byte[] documentDataByteArray = IOUtils.toByteArray(xmiDocument);

            decompressor.setInput(documentDataByteArray);

            //Create an expandable byte array to hold the decompressed data
            ByteArrayOutputStream bos = new ByteArrayOutputStream(documentDataByteArray.length);

            //Decompress the data
            byte[] buf = new byte[1024];

            while (!decompressor.finished()) {

                int count = decompressor.inflate(buf);
                bos.write(buf, 0, count);
            }

            bos.close();

            //Get the decompressed data
            byte[] decompressedData = bos.toByteArray();

            XmiCasDeserializer.deserialize(new ByteArrayInputStream(decompressedData), cas, true);
        } else {

            System.out.println("sin compresin");
            XmlCasDeserializer.deserialize(xmiDocument, cas, true);
        }

        //get the specified view
        cas = cas.getView(this.defaultCasViewName);

        //launch appropriate viewer
        if (javaViewerRBisSelected || javaViewerUCRBisSelected) { // JMP

            // record preference for next time
            med1.setViewType(javaViewerRBisSelected ? "Java Viewer" : "JV User Colors");

            //create tree viewer component
            CasAnnotationViewer viewer = new CasAnnotationViewer();
            viewer.setDisplayedTypes(aTypesToDisplay);

            if (javaViewerUCRBisSelected)
                getColorsForTypesFromFile(viewer, styleMapFile);
            else
                viewer.setHiddenTypes(new String[] { "uima.cpm.FileLocation" });

            // launch viewer in a new dialog
            viewer.setCAS(cas);
            JDialog dialog = new JDialog(DBAnnotationViewerDialog.this,
                    "Annotation Results for " + xmi_id + " in " + inputDirPath); // JMP
            dialog.getContentPane().add(viewer);
            dialog.setSize(850, 630);
            dialog.pack();
            dialog.show();
        } else {

            CAS defaultView = cas.getView(CAS.NAME_DEFAULT_SOFA);

            if (defaultView.getDocumentText() == null) {
                displayError(
                        "The HTML and XML Viewers can only view the default text document, which was not found in this CAS.");
                return;
            }

            // generate inline XML
            File inlineXmlFile = new File(viewerDirectory, "inline.xml");
            String xmlAnnotations = new CasToInlineXml().generateXML(defaultView);
            FileOutputStream outStream = new FileOutputStream(inlineXmlFile);
            outStream.write(xmlAnnotations.getBytes("UTF-8"));
            outStream.close();

            if (xmlRBisSelected) // JMP passed in
            {
                // record preference for next time
                med1.setViewType("XML");

                BrowserUtil.openUrlInDefaultBrowser(inlineXmlFile.getAbsolutePath());
            } else
            // HTML view
            {
                med1.setViewType("HTML");
                // generate HTML view
                // first process style map if not done already
                if (!processedStyleMap) {
                    if (!styleMapFile.exists()) {
                        annotationViewGenerator.autoGenerateStyleMapFile(
                                promptForAE().getAnalysisEngineMetaData(), styleMapFile);
                    }
                    annotationViewGenerator.processStyleMap(styleMapFile);
                    processedStyleMap = true;
                }
                annotationViewGenerator.processDocument(inlineXmlFile);
                File genFile = new File(viewerDirectory, "index.html");
                // open in browser
                BrowserUtil.openUrlInDefaultBrowser(genFile.getAbsolutePath());
            }
        }

        // end LTV here

    } catch (Exception ex) {

        displayError(ex);
    }
}

From source file:org.barcelonamedia.uima.tools.docanalyzer.DBAnnotationViewerDialog.java

public void launchThatViewer(String xmi_id, TypeSystem typeSystem, final String[] aTypesToDisplay,
        boolean javaViewerRBisSelected, boolean javaViewerUCRBisSelected, boolean xmlRBisSelected,
        File styleMapFile, File viewerDirectory) {

    try {//from   ww w .  j  a v a2s .  c o m

        InputStream xmiDocument = this.xmiDAO.getXMI(xmi_id);

        // create a new CAS
        CAS cas = CasCreationUtils.createCas(Collections.EMPTY_LIST, typeSystem,
                UIMAFramework.getDefaultPerformanceTuningProperties());

        if (this.med1.isUmcompress()) {

            //Descomprime el XMI

            //Create the decompressor and give it the data to compress
            Inflater decompressor = new Inflater();
            byte[] documentDataByteArray = IOUtils.toByteArray(xmiDocument);

            decompressor.setInput(documentDataByteArray);

            //Create an expandable byte array to hold the decompressed data
            ByteArrayOutputStream bos = new ByteArrayOutputStream(documentDataByteArray.length);

            //Decompress the data
            byte[] buf = new byte[1024];

            while (!decompressor.finished()) {

                int count = decompressor.inflate(buf);
                bos.write(buf, 0, count);
            }

            bos.close();

            //Get the decompressed data
            byte[] decompressedData = bos.toByteArray();

            XmiCasDeserializer.deserialize(new ByteArrayInputStream(decompressedData), cas, true);
        } else {

            XmlCasDeserializer.deserialize(xmiDocument, cas, true);
        }

        //get the specified view
        cas = cas.getView(this.defaultCasViewName);

        //launch appropriate viewer
        if (javaViewerRBisSelected || javaViewerUCRBisSelected) { // JMP

            // record preference for next time
            med1.setViewType(javaViewerRBisSelected ? "Java Viewer" : "JV User Colors");

            //create tree viewer component
            CasAnnotationViewer viewer = new CasAnnotationViewer();
            viewer.setDisplayedTypes(aTypesToDisplay);

            if (javaViewerUCRBisSelected)
                getColorsForTypesFromFile(viewer, styleMapFile);
            else
                viewer.setHiddenTypes(new String[] { "uima.cpm.FileLocation" });

            // launch viewer in a new dialog
            viewer.setCAS(cas);
            JDialog dialog = new JDialog(DBAnnotationViewerDialog.this,
                    "Annotation Results for " + xmi_id + " in " + inputDirPath); // JMP
            dialog.getContentPane().add(viewer);
            dialog.setSize(850, 630);
            dialog.pack();
            dialog.show();
        } else {

            CAS defaultView = cas.getView(CAS.NAME_DEFAULT_SOFA);

            if (defaultView.getDocumentText() == null) {
                displayError(
                        "The HTML and XML Viewers can only view the default text document, which was not found in this CAS.");
                return;
            }

            // generate inline XML
            File inlineXmlFile = new File(viewerDirectory, "inline.xml");
            String xmlAnnotations = new CasToInlineXml().generateXML(defaultView);
            FileOutputStream outStream = new FileOutputStream(inlineXmlFile);
            outStream.write(xmlAnnotations.getBytes("UTF-8"));
            outStream.close();

            if (xmlRBisSelected) // JMP passed in
            {
                // record preference for next time
                med1.setViewType("XML");

                BrowserUtil.openUrlInDefaultBrowser(inlineXmlFile.getAbsolutePath());
            } else
            // HTML view
            {
                med1.setViewType("HTML");
                // generate HTML view
                // first process style map if not done already
                if (!processedStyleMap) {
                    if (!styleMapFile.exists()) {
                        annotationViewGenerator.autoGenerateStyleMapFile(
                                promptForAE().getAnalysisEngineMetaData(), styleMapFile);
                    }
                    annotationViewGenerator.processStyleMap(styleMapFile);
                    processedStyleMap = true;
                }
                annotationViewGenerator.processDocument(inlineXmlFile);
                File genFile = new File(viewerDirectory, "index.html");
                // open in browser
                BrowserUtil.openUrlInDefaultBrowser(genFile.getAbsolutePath());
            }
        }

        // end LTV here

    } catch (Exception ex) {

        displayError(ex);
    }
}

From source file:org.deegree.tools.rendering.viewer.File3dImporter.java

public static List<WorldRenderableObject> open(Frame parent, String fileName) {

    if (fileName == null || "".equals(fileName.trim())) {
        throw new InvalidParameterException("the file name may not be null or empty");
    }/*  w  w  w . jav a 2  s  . co  m*/
    fileName = fileName.trim();

    CityGMLImporter openFile2;
    XMLInputFactory fac = XMLInputFactory.newInstance();
    InputStream in = null;
    try {
        XMLStreamReader reader = fac.createXMLStreamReader(in = new FileInputStream(fileName));
        reader.next();
        String ns = "http://www.opengis.net/citygml/1.0";
        openFile2 = new CityGMLImporter(null, null, null, reader.getNamespaceURI().equals(ns));
    } catch (Throwable t) {
        openFile2 = new CityGMLImporter(null, null, null, false);
    } finally {
        IOUtils.closeQuietly(in);
    }

    final CityGMLImporter openFile = openFile2;

    final JDialog dialog = new JDialog(parent, "Loading", true);

    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(
            new JLabel("<HTML>Loading file:<br>" + fileName + "<br>Please wait!</HTML>", SwingConstants.CENTER),
            BorderLayout.NORTH);
    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progressBar.setIndeterminate(false);
    dialog.getContentPane().add(progressBar, BorderLayout.CENTER);

    dialog.pack();
    dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    dialog.setResizable(false);
    dialog.setLocationRelativeTo(parent);

    final Thread openThread = new Thread() {
        /**
         * Opens the file in a separate thread.
         */
        @Override
        public void run() {
            // openFile.openFile( progressBar );
            if (dialog.isDisplayable()) {
                dialog.setVisible(false);
                dialog.dispose();
            }
        }
    };
    openThread.start();

    dialog.setVisible(true);
    List<WorldRenderableObject> result = null;
    try {
        result = openFile.importFromFile(fileName, 6, 2);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    gm = openFile.getQmList();

    //
    // if ( result != null ) {
    // openGLEventListener.addDataObjectToScene( result );
    // File f = new File( fileName );
    // setTitle( WIN_TITLE + f.getName() );
    // } else {
    // showExceptionDialog( "The file: " + fileName
    // + " could not be read,\nSee error log for detailed information." );
    // }
    return result;
}

From source file:org.executequery.components.FileChooserDialog.java

protected JDialog createDialog(Component parent) throws HeadlessException {

    Frame frame = parent instanceof Frame ? (Frame) parent
            : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);

    String title = getUI().getDialogTitle(this);

    JDialog dialog = new JDialog(frame, title, true);

    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(this, BorderLayout.CENTER);

    setPreferredSize(new Dimension(700, getPreferredSize().height));

    // add any custom panel
    if (customPanel != null) {
        contentPane.add(customPanel, BorderLayout.SOUTH);
    }//  www. j a v  a2 s  .c  om

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();

        if (supportsWindowDecorations) {
            dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
        }

    }

    setFileView(new DefaultFileView());
    dialog.pack();

    dialog.setLocation(GUIUtilities.getLocationForDialog(dialog.getSize()));
    return dialog;
}

From source file:org.interreg.docexplore.DocExploreTool.java

@SuppressWarnings("serial")
protected static File askForHome(String text) {
    final File[] file = { null };
    final JDialog dialog = new JDialog((Frame) null, XMLResourceBundle.getBundledString("homeLabel"), true);
    JPanel content = new JPanel(new LooseGridLayout(0, 1, 10, 10, true, false, SwingConstants.CENTER,
            SwingConstants.TOP, true, false));
    content.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
    JLabel message = new JLabel(text, ImageUtils.getIcon("free-64x64.png"), SwingConstants.LEFT);
    message.setIconTextGap(20);/*from   w  ww .jav  a  2s .  c  o  m*/
    //message.setFont(Font.decode(Font.SANS_SERIF));
    content.add(message);

    final JPanel pathPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
    pathPanel.add(new JLabel("<html><b>" + XMLResourceBundle.getBundledString("homeLabel") + ":</b></html>"));
    final JTextField pathField = new JTextField(System.getProperty("user.home") + File.separator + "DocExplore",
            40);
    pathPanel.add(pathField);
    pathPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("browseLabel")) {
        JNativeFileDialog nfd = null;

        public void actionPerformed(ActionEvent arg0) {
            if (nfd == null) {
                nfd = new JNativeFileDialog();
                nfd.acceptFiles = false;
                nfd.acceptFolders = true;
                nfd.multipleSelection = false;
                nfd.title = XMLResourceBundle.getBundledString("homeLabel");
            }
            nfd.setCurrentFile(new File(pathField.getText()));
            if (nfd.showOpenDialog())
                pathField.setText(nfd.getSelectedFile().getAbsolutePath());
        }
    }));
    content.add(pathPanel);

    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
    buttonPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgOkLabel")) {
        public void actionPerformed(ActionEvent e) {
            File res = new File(pathField.getText());
            if (res.exists() && !res.isDirectory() || !res.exists() && !res.mkdirs())
                JOptionPane.showMessageDialog(dialog, XMLResourceBundle.getBundledString("homeErrorMessage"),
                        XMLResourceBundle.getBundledString("errorLabel"), JOptionPane.ERROR_MESSAGE);
            else {
                file[0] = res;
                dialog.setVisible(false);
            }
        }
    }));
    buttonPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgCancelLabel")) {
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
        }
    }));
    content.add(buttonPanel);

    dialog.getContentPane().add(content);
    dialog.pack();
    dialog.setResizable(false);
    GuiUtils.centerOnScreen(dialog);
    dialog.setVisible(true);
    return file[0];
}

From source file:org.javaswift.cloudie.CloudiePanel.java

public void onLogin() {
    final JDialog loginDialog = new JDialog(owner, "Login");
    final LoginPanel loginPanel = new LoginPanel(new LoginCallback() {
        @Override/*w  w  w .  j av a2s .  c o  m*/
        public void doLogin(AccountConfig accountConfig) {
            CloudieCallback cb = GuiTreadingUtils.guiThreadSafe(CloudieCallback.class,
                    new CloudieCallbackWrapper(callback) {
                        @Override
                        public void onLoginSuccess() {
                            loginDialog.setVisible(false);
                            super.onLoginSuccess();
                        }

                        @Override
                        public void onError(CommandException ex) {
                            JOptionPane.showMessageDialog(loginDialog, "Login Failed\n" + ex.toString(),
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    });
            ops.login(accountConfig, cb);
        }
    }, credentialsStore);
    try {
        loginPanel.setOwner(loginDialog);
        loginDialog.getContentPane().add(loginPanel);
        loginDialog.setModal(true);
        loginDialog.setSize(480, 340);
        loginDialog.setResizable(false);
        loginDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        center(loginDialog);
        loginDialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                loginPanel.onCancel();
            }

            @Override
            public void windowOpened(WindowEvent e) {
                loginPanel.onShow();
            }
        });
        loginDialog.setVisible(true);
    } finally {
        loginDialog.dispose();
    }
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
  * Creates a modal JDialog containing the specified JComponent
  * for the specified parent.//from  w ww.j  a  v a 2s.c o  m
  * The newly created dialog is then centered on the screen and made visible.
 *
  * @param parent The parent component.
  * @param title  The title of the dialog.
  * @param c      The component to display.
  * @see #centerAndShow(Component)
 */
public static void makeForDialog(Component parent, String title, JComponent c) {
    if (c == null)
        return;
    JDialog dialog = null;
    if (parent instanceof Frame)
        dialog = new JDialog((Frame) parent);
    else if (parent instanceof Dialog)
        dialog = new JDialog((Dialog) parent);
    else if (dialog == null)
        dialog = new JDialog(); //no parent
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setModal(true);
    dialog.setTitle(title);
    dialog.setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
    Container container = dialog.getContentPane();
    container.setLayout(new BorderLayout(0, 0));
    container.add(c, BorderLayout.CENTER);
    centerAndShow(dialog);
}