Example usage for javax.swing ProgressMonitor setMaximum

List of usage examples for javax.swing ProgressMonitor setMaximum

Introduction

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

Prototype

public void setMaximum(int m) 

Source Link

Document

Specifies the maximum value.

Usage

From source file:kindleclippings.word.QuizletSync.java

public static void main(String[] args) throws IOException, JSONException, URISyntaxException,
        InterruptedException, BackingStoreException, BadLocationException {

    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileNameExtensionFilter("Word documents", "doc", "rtf", "txt"));
    fc.setMultiSelectionEnabled(true);// w w  w .  ja  v a 2s . com
    int result = fc.showOpenDialog(null);
    if (result != JFileChooser.APPROVE_OPTION) {
        return;
    }
    File[] clf = fc.getSelectedFiles();
    if (clf == null || clf.length == 0)
        return;

    ProgressMonitor progress = new ProgressMonitor(null, "QuizletSync", "loading notes files", 0, 100);
    progress.setMillisToPopup(0);
    progress.setMillisToDecideToPopup(0);
    progress.setProgress(0);
    try {

        progress.setNote("checking Quizlet account");
        progress.setProgress(5);

        Preferences prefs = kindleclippings.quizlet.QuizletSync.getPrefs();

        QuizletAPI api = new QuizletAPI(prefs.get("access_token", null));

        Collection<TermSet> sets = null;
        try {
            progress.setNote("checking Quizlet library");
            progress.setProgress(10);
            sets = api.getSets(prefs.get("user_id", null));
        } catch (IOException e) {
            if (e.toString().contains("401")) {
                // Not Authorized => Token has been revoked
                kindleclippings.quizlet.QuizletSync.clearPrefs();
                prefs = kindleclippings.quizlet.QuizletSync.getPrefs();
                api = new QuizletAPI(prefs.get("access_token", null));
                sets = api.getSets(prefs.get("user_id", null));
            } else {
                throw e;
            }
        }

        progress.setProgress(15);
        progress.setMaximum(15 + clf.length * 10);
        progress.setNote("uploading new notes");

        int pro = 15;

        int addedSets = 0;
        int updatedTerms = 0;
        int updatedSets = 0;

        for (File f : clf) {
            progress.setProgress(pro);
            List<Clipping> clippings = readClippingsFile(f);

            if (clippings == null) {
                pro += 10;
                continue;
            }

            if (clippings.isEmpty()) {
                pro += 10;
                continue;
            }

            if (clippings.size() < 2) {
                pro += 10;
                continue;
            }

            String book = clippings.get(0).getBook();
            progress.setNote(book);

            TermSet termSet = null;
            String x = book.toLowerCase().replaceAll("\\W", "");

            for (TermSet t : sets) {
                if (t.getTitle().toLowerCase().replaceAll("\\W", "").equals(x)) {
                    termSet = t;
                    break;
                }
            }

            if (termSet == null) {

                addSet(api, book, clippings);
                addedSets++;
                pro += 10;
                continue;
            }

            // compare against existing terms
            boolean hasUpdated = false;
            for (Clipping cl : clippings) {
                if (!kindleclippings.quizlet.QuizletSync.checkExistingTerm(cl, termSet)) {
                    kindleclippings.quizlet.QuizletSync.addTerm(api, termSet, cl);
                    updatedTerms++;
                    hasUpdated = true;
                }
            }

            pro += 10;

            if (hasUpdated)
                updatedSets++;

        }

        if (updatedTerms == 0 && addedSets == 0) {
            JOptionPane.showMessageDialog(null, "Done.\nNo new data was uploaded", "QuizletSync",
                    JOptionPane.OK_OPTION);
        } else {
            if (addedSets > 0) {
                JOptionPane.showMessageDialog(null,
                        String.format("Done.\nCreated %d new sets and added %d cards to %d existing sets",
                                addedSets, updatedSets, updatedTerms),
                        "QuizletSync", JOptionPane.OK_OPTION);
            } else {
                JOptionPane.showMessageDialog(null,
                        String.format("Done.\nAdded %d cards to %d existing sets", updatedTerms, updatedSets),
                        "QuizletSync", JOptionPane.OK_OPTION);
            }
        }
    } finally {
        progress.close();
    }

    System.exit(0);
}

From source file:kindleclippings.quizlet.QuizletSync.java

public static void main(String[] args)
        throws IOException, JSONException, URISyntaxException, InterruptedException, BackingStoreException {

    ProgressMonitor progress = new ProgressMonitor(null, "QuizletSync", "loading Kindle clippings file", 0,
            100);/*w w  w  . java  2  s  .c  o m*/
    progress.setMillisToPopup(0);
    progress.setMillisToDecideToPopup(0);
    progress.setProgress(0);
    try {

        Map<String, List<Clipping>> books = readClippingsFile();

        if (books == null)
            return;

        if (books.isEmpty()) {
            JOptionPane.showMessageDialog(null, "no clippings to be uploaded", "QuizletSync",
                    JOptionPane.OK_OPTION);
            return;
        }
        progress.setNote("checking Quizlet account");
        progress.setProgress(5);

        Preferences prefs = getPrefs();

        QuizletAPI api = new QuizletAPI(prefs.get("access_token", null));

        Collection<TermSet> sets = null;
        try {
            progress.setNote("checking Quizlet library");
            progress.setProgress(10);
            sets = api.getSets(prefs.get("user_id", null));
        } catch (IOException e) {
            if (e.toString().contains("401")) {
                // Not Authorized => Token has been revoked
                clearPrefs();
                prefs = getPrefs();
                api = new QuizletAPI(prefs.get("access_token", null));
                sets = api.getSets(prefs.get("user_id", null));
            } else {
                throw e;
            }
        }

        progress.setProgress(15);
        progress.setMaximum(15 + books.size());
        progress.setNote("uploading new notes");

        Map<String, TermSet> indexedSets = new HashMap<String, TermSet>(sets.size());

        for (TermSet t : sets) {
            indexedSets.put(t.getTitle(), t);
        }

        int pro = 15;
        int createdSets = 0;
        int createdTerms = 0;
        int updatedTerms = 0;
        for (List<Clipping> c : books.values()) {

            String book = c.get(0).getBook();
            progress.setNote(book);
            progress.setProgress(pro++);

            TermSet termSet = indexedSets.get(book);
            if (termSet == null) {
                if (c.size() < 2) {
                    System.err.println("ignored [" + book + "] (need at least two notes)");
                    continue;
                }

                addSet(api, book, c);
                createdSets++;
                createdTerms += c.size();
                continue;
            }
            // compare against existing terms
            for (Clipping cl : c) {
                if (!checkExistingTerm(cl, termSet)) {
                    addTerm(api, termSet, cl);
                    updatedTerms++;
                }
            }
        }
        progress.setProgress(pro++);

        if (createdSets == 0 && updatedTerms == 0) {
            JOptionPane.showMessageDialog(null, "Done.\nNo new data was uploaded", "QuizletSync",
                    JOptionPane.OK_OPTION);
        } else if (createdSets > 0) {
            JOptionPane.showMessageDialog(null,
                    String.format(
                            "Done.\nCreated %d new sets with %d cards, and added %d cards to existing sets",
                            createdSets, createdTerms, updatedTerms),
                    "QuizletSync", JOptionPane.OK_OPTION);
        } else {
            JOptionPane.showMessageDialog(null,
                    String.format("Done.\nAdded %d cards to existing sets", updatedTerms), "QuizletSync",
                    JOptionPane.OK_OPTION);
        }
    } finally {
        progress.close();
    }

    System.exit(0);
}

From source file:net.ftb.minecraft.MCInstaller.java

public static void setupNewStyle(final String installPath, final ModPack pack, final boolean isLegacy,
        final LoginResponse RESPONSE) {
    List<DownloadInfo> assets = gatherAssets(new File(installPath),
            pack.getMcVersion(Settings.getSettings().getPackVer(pack.getDir())), installPath);
    if (assets != null && assets.size() > 0) {
        Logger.logInfo("Checking/Downloading " + assets.size() + " assets, this may take a while...");

        final ProgressMonitor prog = new ProgressMonitor(LaunchFrame.getInstance(), "Downloading Files...", "",
                0, 100);/*w w w  . j  av a 2  s  .co m*/
        prog.setMaximum(assets.size() * 100);

        final AssetDownloader downloader = new AssetDownloader(prog, assets) {
            @Override
            public void done() {
                try {
                    prog.close();
                    if (get()) {
                        Logger.logInfo("Asset downloading complete");
                        launchMinecraft(installPath, pack, RESPONSE, isLegacy);
                    } else {
                        ErrorUtils.tossError("Error occurred during downloading the assets");
                    }
                } catch (CancellationException e) {
                    Logger.logInfo("Asset download interrupted by user");
                } catch (Exception e) {
                    ErrorUtils.tossError("Failed to download files.", e);
                } finally {
                    LaunchFrame.getInstance().getEventBus().post(new EnableObjectsEvent());
                }
            }
        };

        downloader.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if (prog.isCanceled()) {
                    downloader.cancel(false);
                    prog.close();
                } else if (!downloader.isCancelled()) {
                    if ("ready".equals(evt.getPropertyName()))
                        prog.setProgress(downloader.getReady());
                    if ("status".equals(evt.getPropertyName()))
                        prog.setNote(downloader.getStatus());
                }
            }
        });

        downloader.execute();
    } else if (assets == null) {
        LaunchFrame.getInstance().getEventBus().post(new EnableObjectsEvent());
    } else {
        launchMinecraft(installPath, pack, RESPONSE, isLegacy);
    }
}

From source file:com.silverpeas.openoffice.windows.webdav.WebdavManager.java

/**
 * Get the ressource from the webdav server.
 *
 * @param uri the uri to the ressource./*from  ww  w . java2 s  . c o m*/
 * @param lockToken the current lock token.
 * @return the path to the saved file on the filesystem.
 * @throws IOException
 */
public String getFile(URI uri, String lockToken) throws IOException {
    GetMethod method = executeGetFile(uri);
    String fileName = uri.getPath();
    fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
    fileName = URLDecoder.decode(fileName, "UTF-8");
    UIManager.put("ProgressMonitor.progressText", MessageUtil.getMessage("download.file.title"));
    ProgressMonitorInputStream is = new ProgressMonitorInputStream(null,
            MessageUtil.getMessage("downloading.remote.file") + ' ' + fileName,
            new BufferedInputStream(method.getResponseBodyAsStream()));
    fileName = fileName.replace(' ', '_');
    ProgressMonitor monitor = is.getProgressMonitor();
    monitor.setMaximum(new Long(method.getResponseContentLength()).intValue());
    monitor.setMillisToDecideToPopup(0);
    monitor.setMillisToPopup(0);
    File tempDir = new File(System.getProperty("java.io.tmpdir"), "silver-" + System.currentTimeMillis());
    tempDir.mkdirs();
    File tmpFile = new File(tempDir, fileName);
    FileOutputStream fos = new FileOutputStream(tmpFile);
    byte[] data = new byte[64];
    int c = 0;
    try {
        while ((c = is.read(data)) > -1) {
            fos.write(data, 0, c);
        }
    } catch (InterruptedIOException ioinex) {
        logger.log(Level.INFO, "{0} {1}",
                new Object[] { MessageUtil.getMessage("info.user.cancel"), ioinex.getMessage() });
        unlockFile(uri, lockToken);
        System.exit(0);
    } finally {
        fos.close();
    }
    return tmpFile.getAbsolutePath();
}

From source file:jshm.gui.GuiUtil.java

public static void openImageOrBrowser(final Frame owner, final String urlStr) {
    new SwingWorker<Void, Void>() {
        private BufferedImage image = null;
        private Throwable t = null;
        private boolean canceled = false;

        protected Void doInBackground() throws Exception {
            ProgressMonitor progress = null;

            try {
                // try to see if it's an image before downloading the
                // whole thing
                GetMethod method = new GetMethod(urlStr);
                Client.getHttpClient().executeMethod(method);
                Header h = method.getResponseHeader("Content-type");

                if (null != h && h.getValue().toLowerCase().startsWith("image/")) {
                    //                  jshm.util.TestTimer.start();
                    ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(owner, "Loading image...",
                            method.getResponseBodyAsStream());
                    progress = pmis.getProgressMonitor();
                    //                  System.out.println("BEFORE max: " + progress.getMaximum());
                    h = method.getResponseHeader("Content-length");

                    if (null != h) {
                        try {
                            progress.setMaximum(Integer.parseInt(h.getValue()));
                        } catch (NumberFormatException e) {
                        }//from  w ww .ja  v  a2 s .  com
                    }
                    //                  System.out.println("AFTER max: " + progress.getMaximum());

                    progress.setMillisToDecideToPopup(250);
                    progress.setMillisToPopup(1000);

                    image = javax.imageio.ImageIO.read(pmis);
                    pmis.close();
                    //                  jshm.util.TestTimer.stop();
                    //                  jshm.util.TestTimer.start();
                    image = GraphicsUtilities.toCompatibleImage(image);
                    //                  jshm.util.TestTimer.stop();
                }

                method.releaseConnection();
            } catch (OutOfMemoryError e) {
                LOG.log(Level.WARNING, "OutOfMemoryError trying to load image", e);
                image = null; // make it open in browser
            } catch (Throwable e) {
                if (null != progress && progress.isCanceled()) {
                    canceled = true;
                } else {
                    t = e;
                }
            }

            return null;
        }

        public void done() {
            if (canceled)
                return;

            if (null == image) {
                if (null == t) {
                    // no error, just the url wasn't an image, so launch the browser
                    Util.openURL(urlStr);
                } else {
                    LOG.log(Level.WARNING, "Error opening image URL", t);
                    ErrorInfo ei = new ErrorInfo("Error", "Error opening image URL", null, null, t, null, null);
                    JXErrorPane.showDialog(owner, ei);
                }
            } else {
                SpInfoViewer viewer = new SpInfoViewer();
                viewer.setTitle(urlStr);
                viewer.setImage(image, true);
                viewer.setLocationRelativeTo(owner);
                viewer.setVisible(true);
            }
        }
    }.execute();
}

From source file:gov.nih.nci.nbia.StandaloneDMDispatcher.java

private void downloadInstaller(String downloadUrl) {
    String fileName = getInstallerName(downloadUrl);
    InputStream in;/*from   ww  w . java2  s. c  o m*/

    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        public void checkClientTrusted(X509Certificate[] certs, String authType) {
            // here is the place to check client certs and throw an
            // exception if certs are wrong. When there is nothing all certs
            // accepted.
        }

        public void checkServerTrusted(X509Certificate[] certs, String authType) {
            // here is the place to check server certs and throw an
            // exception if certs are wrong. When there is nothing all certs
            // accepted.
        }
    } };
    // Install the all-trusting trust manager
    try {
        final SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        // Create all-trusting host name verifier
        HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(String hostname, SSLSession session) {
                // Here is the palce to check host name against to
                // certificate owner
                return true;
            }
        };
        // Install the all-trusting host verifier
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
    } catch (KeyManagementException | NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } finally {
    }

    try {
        URL url = new URL(downloadUrl);
        in = url.openStream();
        FileOutputStream fos = new FileOutputStream(new File(fileName));

        int length = -1;
        ProgressMonitorInputStream pmis;
        pmis = new ProgressMonitorInputStream(null,
                "Downloading new version of installer for NBIA Data Retriever...", in);

        ProgressMonitor monitor = pmis.getProgressMonitor();
        monitor.setMillisToPopup(0);
        monitor.setMinimum(0);
        monitor.setMaximum((int) 200000000); // The actual size is much
        // smaller,
        // but we have no way to
        // know
        // the actual size so picked
        // this big number

        byte[] buffer = new byte[1024];// buffer for portion of data from
        // connection

        while ((length = pmis.read(buffer)) > 0) {
            fos.write(buffer, 0, length);
        }
        pmis.close();
        fos.flush();
        fos.close();
        in.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.docdoku.client.data.MainModel.java

private void downloadFile(Component pParent, File pLocalFile, int contentLength, InputStream inputStream)
        throws IOException {
    System.out.println("Downloading file");
    ProgressMonitorInputStream in = null;
    OutputStream out = null;/*  www.j  a  v  a2s. co m*/
    try {
        out = new BufferedOutputStream(new FileOutputStream(pLocalFile), Config.BUFFER_CAPACITY);
        in = new ProgressMonitorInputStream(pParent, I18N.BUNDLE.getString("DownloadMsg_part1"),
                new BufferedInputStream(inputStream, Config.BUFFER_CAPACITY));
        ProgressMonitor pm = in.getProgressMonitor();
        pm.setMaximum(contentLength);
        byte[] data = new byte[Config.CHUNK_SIZE];
        int length;
        while ((length = in.read(data)) != -1) {
            out.write(data, 0, length);
        }

        out.flush();

    } finally {
        out.close();
        in.close();
    }
}

From source file:com.docdoku.client.data.MainModel.java

private void downloadFileWithServlet(Component pParent, File pLocalFile, String pURL) throws IOException {
    System.out.println("Downloading file from servlet");
    ProgressMonitorInputStream in = null;
    OutputStream out = null;//  w  w w  . j a  v  a  2  s .  co  m
    HttpURLConnection conn = null;
    try {
        //Hack for NTLM proxy
        //perform a head method to negociate the NTLM proxy authentication
        performHeadHTTPMethod(pURL);

        out = new BufferedOutputStream(new FileOutputStream(pLocalFile), Config.BUFFER_CAPACITY);
        URL url = new URL(pURL);
        conn = (HttpURLConnection) url.openConnection();
        conn.setUseCaches(false);
        conn.setAllowUserInteraction(true);
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.setRequestMethod("GET");
        byte[] encoded = org.apache.commons.codec.binary.Base64
                .encodeBase64((getLogin() + ":" + getPassword()).getBytes("ISO-8859-1"));
        conn.setRequestProperty("Authorization", "Basic " + new String(encoded, "US-ASCII"));
        conn.connect();
        int code = conn.getResponseCode();
        System.out.println("Download HTTP response code: " + code);
        in = new ProgressMonitorInputStream(pParent, I18N.BUNDLE.getString("DownloadMsg_part1"),
                new BufferedInputStream(conn.getInputStream(), Config.BUFFER_CAPACITY));
        ProgressMonitor pm = in.getProgressMonitor();
        pm.setMaximum(conn.getContentLength());
        byte[] data = new byte[Config.CHUNK_SIZE];
        int length;
        while ((length = in.read(data)) != -1) {
            out.write(data, 0, length);
        }
        out.flush();
    } finally {
        out.close();
        in.close();
        conn.disconnect();
    }
}

From source file:com.diversityarrays.kdxplore.trialmgr.trait.TraitExplorerPanel.java

private void doImportTraitsFileImpl(File file) {
    Context context = KDSmartApplication.getInstance();
    final ProgressMonitor monitor = new ProgressMonitor(TraitExplorerPanel.this, "Loading", "", 0, 100);
    ProgressReporter progressReporter = new ProgressReporter() {

        @Override/*w w  w  .java2s. c  o  m*/
        public void setProgressNote(String note) {
            monitor.setNote(note);
        }

        @Override
        public void setProgressMaximum(int max) {
            monitor.setMaximum(max);
        }

        @Override
        public void setProgressCount(int count) {
            monitor.setProgress(count);
        }

        @Override
        public void dismissProgress() {
            monitor.close();
        }
    };

    try {
        Either<ImportError, TraitImportTransactions> either = offlineData.getKdxploreDatabase()
                .getKDXploreKSmartDatabase().importTraitsFile(context, file, progressReporter);

        if (either.isLeft()) {
            ImportError ie = either.left();
            MsgBox.error(TraitExplorerPanel.this, ie.getMessage("Import Traits"), "Import Failed");
        } else {
            TraitImportTransactions tit = either.right();

            if (!tit.traitsToBeUpdated.isEmpty()) {

            }

            refreshTraitsTable();

            StringBuilder sb = new StringBuilder("Import Result");
            if (tit.nSkipped > 0) {
                sb.append("\nSkipped ").append(tit.nSkipped);
            }
            if (!tit.traitsToBeAdded.isEmpty()) {
                sb.append("\nAdded: ").append(tit.traitsToBeAdded.size());
            }
            if (!tit.traitsToBeUpdated.isEmpty()) {
                sb.append("\nUpdated: ").append(tit.traitsToBeUpdated.size());
            }
            MsgBox.info(TraitExplorerPanel.this, sb.toString(), "Import Complete");
        }
    } finally {
        progressReporter.dismissProgress();
    }
}

From source file:ca.sqlpower.architect.swingui.SwingUIProjectLoader.java

/**
 * Saves this project by writing an XML description of it to a temp file, then renaming.
 * The location of the file is determined by this project's <code>file</code> property.
 *
 * @param pm An optional progress monitor which will be initialised then updated
 * periodically during the save operation.  If you use a progress monitor, don't
 * invoke this method on the AWT event dispatch thread!
 *///from   w w  w .jav  a 2s  .  co  m
public void save(ProgressMonitor pm) throws IOException, SQLObjectException {
    // write to temp file and then rename (this preserves old project file
    // when there's problems)
    if (file.exists() && !file.canWrite()) {
        // write problems with architect file will muck up the save process
        throw new SQLObjectException(
                Messages.getString("SwingUIProject.errorSavingProject", file.getAbsolutePath())); //$NON-NLS-1$
    }

    if (fileVersion != null && !fileVersion.equals(ArchitectVersion.APP_FULL_VERSION.toString())) {
        String message;
        try {
            ArchitectVersion oldFileVersion = new ArchitectVersion(fileVersion);
            if (oldFileVersion.compareTo(ArchitectVersion.APP_FULL_VERSION) < 0) {
                message = "Overwriting older file. Older versions may have problems "
                        + "loading the newer file format.";
            } else {
                message = "Overwriting newer file. Some data loss from loading may occur.";
            }
        } catch (Exception e) {
            message = "Overwriting file with an invalid version.";
        }
        UserPrompter prompter = getSession().createUserPrompter(message + "\nDo you wish to continue?",
                UserPromptType.BOOLEAN, UserPromptOptions.OK_CANCEL, UserPromptResponse.OK,
                UserPromptResponse.OK, "OK", "Cancel");
        UserPromptResponse response = prompter.promptUser();
        if (response.equals(UserPromptResponse.CANCEL)) {
            return;
        }
    }

    File backupFile = new File(file.getParent(), file.getName() + "~"); //$NON-NLS-1$

    // Several places we would check dir perms, but MS-Windows stupidly doesn't let use the
    // "directory write" attribute for directory writing (but instead overloads
    // it to mean 'this is a special directory'.

    File tempFile = null;
    tempFile = new File(file.getParent(), "tmp___" + file.getName()); //$NON-NLS-1$
    String encoding = "UTF-8"; //$NON-NLS-1$
    try {
        // If creating this temp file fails, feed the user back a more explanatory message
        out = new PrintWriter(tempFile, encoding);
    } catch (IOException e) {
        throw new SQLObjectException(Messages.getString("SwingUIProject.cannotCreateOutputFile") + e, e); //$NON-NLS-1$
    }

    progress = 0;
    this.pm = pm;
    if (pm != null) {
        int pmMax = 0;
        pm.setMinimum(0);
        if (getSession().isSavingEntireSource()) {
            pmMax = SQLObjectUtils
                    .countTablesSnapshot((SQLObject) getSession().getDBTree().getModel().getRoot());
        } else {
            pmMax = SQLObjectUtils.countTables((SQLObject) getSession().getDBTree().getModel().getRoot());
        }
        logger.debug("Setting progress monitor maximum to " + pmMax); //$NON-NLS-1$
        pm.setMaximum(pmMax);
        pm.setProgress(progress);
        pm.setMillisToDecideToPopup(0);
    }

    save(out, encoding); // Does ALL the actual I/O
    out = null;
    if (pm != null)
        pm.close();
    pm = null;

    // Do the rename dance.
    // This is a REALLY bad place for failure (especially if we've made the user wait several hours to save
    // a large project), so we MUST check failures from renameto (both places!)
    boolean fstatus = false;
    fstatus = backupFile.delete();
    logger.debug("deleting backup~ file: " + fstatus); //$NON-NLS-1$

    // If this is a brand new project, the old file does not yet exist, no point trying to rename it.
    // But if it already existed, renaming current to backup must succeed, or we give up.
    if (file.exists()) {
        fstatus = file.renameTo(backupFile);
        logger.debug("rename current file to backupFile: " + fstatus); //$NON-NLS-1$
        if (!fstatus) {
            throw new SQLObjectException((Messages.getString("SwingUIProject.couldNotRenameFile", //$NON-NLS-1$
                    tempFile.toString(), file.toString())));
        }
    }
    fstatus = tempFile.renameTo(file);
    if (!fstatus) {
        throw new SQLObjectException((Messages.getString("SwingUIProject.couldNotRenameTempFile", //$NON-NLS-1$
                tempFile.toString(), file.toString())));
    }
    logger.debug("rename tempFile to current file: " + fstatus); //$NON-NLS-1$
    fileVersion = ArchitectVersion.APP_FULL_VERSION.toString();
}