Example usage for javax.swing JDialog show

List of usage examples for javax.swing JDialog show

Introduction

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

Prototype

@Deprecated
public void show() 

Source Link

Document

Makes the Dialog visible.

Usage

From source file:JuliaSet3.java

public void printToService(PrintService service, PrintRequestAttributeSet printAttributes) {
    // Wrap ourselves in the PrintableComponent class defined by JuliaSet2.
    String title = "Julia set for c={" + cx + "," + cy + "}";
    Printable printable = new PrintableComponent(this, title);

    // Now create a Doc that encapsulate the Printable object and its type
    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    Doc doc = new SimpleDoc(printable, flavor, null);

    // Java 1.1 uses PrintJob.
    // Java 1.2 uses PrinterJob.
    // Java 1.4 uses DocPrintJob. Create one from the service
    DocPrintJob job = service.createPrintJob();

    // Set up a dialog box to monitor printing status
    final JOptionPane pane = new JOptionPane("Printing...", JOptionPane.PLAIN_MESSAGE);
    JDialog dialog = pane.createDialog(this, "Print Status");
    // This listener object updates the dialog as the status changes
    job.addPrintJobListener(new PrintJobAdapter() {
        public void printJobCompleted(PrintJobEvent e) {
            pane.setMessage("Printing complete.");
        }/* ww w . ja v  a  2 s .com*/

        public void printDataTransferCompleted(PrintJobEvent e) {
            pane.setMessage("Document transfered to printer.");
        }

        public void printJobRequiresAttention(PrintJobEvent e) {
            pane.setMessage("Check printer: out of paper?");
        }

        public void printJobFailed(PrintJobEvent e) {
            pane.setMessage("Print job failed");
        }
    });

    // Show the dialog, non-modal.
    dialog.setModal(false);
    dialog.show();

    // Now print the Doc to the DocPrintJob
    try {
        job.print(doc, printAttributes);
    } catch (PrintException e) {
        // Display any errors to the dialog box
        pane.setMessage(e.toString());
    }
}

From source file:com._17od.upm.gui.DatabaseActions.java

/**
 * Prompt the user to enter a password/*from   w  ww.j  a v  a2s. c  o  m*/
 * @return The password entered by the user or null of this hit escape/cancel
 */
private char[] askUserForPassword(String message) {
    char[] password = null;

    final JPasswordField masterPassword = new JPasswordField("");
    JOptionPane pane = new JOptionPane(new Object[] { message, masterPassword }, JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = pane.createDialog(mainWindow, Translator.translate("masterPassword"));
    dialog.addWindowFocusListener(new WindowAdapter() {
        public void windowGainedFocus(WindowEvent e) {
            masterPassword.requestFocusInWindow();
        }
    });
    dialog.show();

    if (pane.getValue() != null && pane.getValue().equals(new Integer(JOptionPane.OK_OPTION))) {
        password = masterPassword.getPassword();
    }

    return password;
}

From source file:com._17od.upm.gui.DatabaseActions.java

/**
 * This method asks the user for the name of a new database and then creates
 * it. If the file already exists then the user is asked if they'd like to
 * overwrite it./*  w  w  w  . ja  va  2  s. com*/
 * @throws CryptoException 
 * @throws IOException 
 */
public void newDatabase() throws IOException, CryptoException {

    File newDatabaseFile = getSaveAsFile(Translator.translate("newPasswordDatabase"));
    if (newDatabaseFile == null) {
        return;
    }

    final JPasswordField masterPassword = new JPasswordField("");
    boolean passwordsMatch = false;
    do {

        //Get a new master password for this database from the user
        JPasswordField confirmedMasterPassword = new JPasswordField("");
        JOptionPane pane = new JOptionPane(
                new Object[] { Translator.translate("enterMasterPassword"), masterPassword,
                        Translator.translate("confirmation"), confirmedMasterPassword },
                JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
        JDialog dialog = pane.createDialog(mainWindow, Translator.translate("masterPassword"));
        dialog.addWindowFocusListener(new WindowAdapter() {
            public void windowGainedFocus(WindowEvent e) {
                masterPassword.requestFocusInWindow();
            }
        });
        dialog.show();

        if (pane.getValue().equals(new Integer(JOptionPane.OK_OPTION))) {
            if (!Arrays.equals(masterPassword.getPassword(), confirmedMasterPassword.getPassword())) {
                JOptionPane.showMessageDialog(mainWindow, Translator.translate("passwordsDontMatch"));
            } else {
                passwordsMatch = true;
            }
        } else {
            return;
        }

    } while (passwordsMatch == false);

    if (newDatabaseFile.exists()) {
        newDatabaseFile.delete();
    }

    database = new PasswordDatabase(newDatabaseFile);
    dbPers = new PasswordDatabasePersistence(masterPassword.getPassword());
    saveDatabase();
    accountNames = new ArrayList();
    doOpenDatabaseActions();

    // If a "Database to Load on Startup" hasn't been set yet then ask the
    // user if they'd like to open this database on startup.
    if (Preferences.get(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP) == null
            || Preferences.get(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP).equals("")) {
        int option = JOptionPane.showConfirmDialog(mainWindow,
                Translator.translate("setNewLoadOnStartupDatabase"),
                Translator.translate("newPasswordDatabase"), JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
            Preferences.set(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP,
                    newDatabaseFile.getAbsolutePath());
            Preferences.save();
        }
    }
}

From source file:com._17od.upm.gui.DatabaseActions.java

public void changeMasterPassword() throws IOException, ProblemReadingDatabaseFile, CryptoException,
        PasswordDatabaseException, TransportException {

    if (getLatestVersionOfDatabase()) {
        //The first task is to get the current master password
        boolean passwordCorrect = false;
        boolean okClicked = true;
        do {//w w  w  .  j  a va2  s .c o m
            char[] password = askUserForPassword(Translator.translate("enterDatabasePassword"));
            if (password == null) {
                okClicked = false;
            } else {
                try {
                    dbPers.load(database.getDatabaseFile(), password);
                    passwordCorrect = true;
                } catch (InvalidPasswordException e) {
                    JOptionPane.showMessageDialog(mainWindow, Translator.translate("incorrectPassword"));
                }
            }
        } while (!passwordCorrect && okClicked);

        //If the master password was entered correctly then the next step is to get the new master password
        if (passwordCorrect == true) {

            final JPasswordField masterPassword = new JPasswordField("");
            boolean passwordsMatch = false;
            Object buttonClicked;

            //Ask the user for the new master password
            //This loop will continue until the two passwords entered match or until the user hits the cancel button
            do {

                JPasswordField confirmedMasterPassword = new JPasswordField("");
                JOptionPane pane = new JOptionPane(
                        new Object[] { Translator.translate("enterNewMasterPassword"), masterPassword,
                                Translator.translate("confirmation"), confirmedMasterPassword },
                        JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
                JDialog dialog = pane.createDialog(mainWindow, Translator.translate("changeMasterPassword"));
                dialog.addWindowFocusListener(new WindowAdapter() {
                    public void windowGainedFocus(WindowEvent e) {
                        masterPassword.requestFocusInWindow();
                    }
                });
                dialog.show();

                buttonClicked = pane.getValue();
                if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION))) {
                    if (!Arrays.equals(masterPassword.getPassword(), confirmedMasterPassword.getPassword())) {
                        JOptionPane.showMessageDialog(mainWindow, Translator.translate("passwordsDontMatch"));
                    } else {
                        passwordsMatch = true;
                    }
                }

            } while (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && !passwordsMatch);

            //If the user clicked OK and the passwords match then change the database password
            if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && passwordsMatch) {
                this.dbPers.getEncryptionService().initCipher(masterPassword.getPassword());
                saveDatabase();
            }

        }
    }

}

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  w  w . j  av a2 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  w  ww  .  ja  v a 2s  .  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);
    }
}