List of usage examples for javax.swing ProgressMonitor ProgressMonitor
public ProgressMonitor(Component parentComponent, Object message, String note, int min, int max)
From source file:us.daveread.basicquery.BasicQuery.java
/** * Executes all the queries/* w w w.j a v a2s . co m*/ */ private void runAllQueries() { int numExecutions, numQueries; int execution, query; ProgressMonitor monitor; boolean canceled; java.util.Date start; int elapsed; long remaining; int hours, minutes, seconds; numQueries = querySelection.getModel().getSize(); try { numExecutions = Integer .parseInt(JOptionPane.showInputDialog(this, Resources.getString("dlgAllQueriesText"), Resources.getString("dlgAllQueriesTitle"), JOptionPane.QUESTION_MESSAGE)); } catch (Exception any) { numExecutions = 0; } messageOut(Resources.getString("msgNumExecutions", numExecutions + "")); monitor = new ProgressMonitor(this, Resources.getString("dlgRunAllQueriesProgressTitle"), Resources.getString("dlgRunAllQueriesProgressNote", "0", numExecutions + "", "0", numQueries + ""), 0, numQueries * Math.abs(numExecutions)); getContentPane().setCursor(new Cursor(Cursor.WAIT_CURSOR)); if (numExecutions < 0) { numExecutions = Math.abs(numExecutions); for (query = 0; !monitor.isCanceled() && query < numQueries; ++query) { querySelection.setSelectedIndex(query); elapsed = -1; for (execution = 0; !monitor.isCanceled() && execution < numExecutions; ++execution) { monitor.setProgress(query * numExecutions + execution); if (elapsed <= 0) { monitor.setNote(Resources.getString("dlgRunAllQueriesProgressNote", (execution + 1) + "", numExecutions + "", (query + 1) + "", numQueries + "")); } else { remaining = elapsed * ((numExecutions * (numQueries - (query + 1))) + (numExecutions - execution)); hours = (int) (remaining / SECONDS_PER_HOUR); remaining -= hours * SECONDS_PER_HOUR; minutes = (int) (remaining / SECONDS_PER_MINUTE); remaining -= minutes * SECONDS_PER_MINUTE; seconds = (int) remaining; monitor.setNote(Resources.getString("dlgRunAllQueriesProgressNoteWithRemainTime", (execution + 1) + "", numExecutions + "", (query + 1) + "", numQueries + "", Utility.formattedNumber(hours, "00"), Utility.formattedNumber(minutes, "00"), Utility.formattedNumber(seconds, "00"))); } messageOut(Resources.getString("dlgRunAllQueriesProgressNote", (execution + 1) + "", numExecutions + "", (query + 1) + "", numQueries + "")); start = new java.util.Date(); processStatement(true); elapsed = (int) ((new java.util.Date().getTime() - start.getTime()) / 1000); } } } else { elapsed = -1; for (execution = 0; !monitor.isCanceled() && execution < numExecutions; ++execution) { start = new java.util.Date(); for (query = 0; !monitor.isCanceled() && query < numQueries; ++query) { querySelection.setSelectedIndex(query); monitor.setProgress(execution * numQueries + query); if (elapsed <= 0) { monitor.setNote(Resources.getString("dlgRunAllQueriesProgressNote", (execution + 1) + "", numExecutions + "", (query + 1) + "", numQueries + "")); } else { remaining = elapsed * (numExecutions - execution); hours = (int) (remaining / SECONDS_PER_HOUR); remaining -= hours * SECONDS_PER_HOUR; minutes = (int) (remaining / SECONDS_PER_MINUTE); remaining -= minutes * SECONDS_PER_MINUTE; seconds = (int) remaining; monitor.setNote(Resources.getString("dlgRunAllQueriesProgressNoteWithRemainTime", (execution + 1) + "", numExecutions + "", (query + 1) + "", numQueries + "", Utility.formattedNumber(hours, "00"), Utility.formattedNumber(minutes, "00"), Utility.formattedNumber(seconds, "00"))); } messageOut(Resources.getString("dlgRunAllQueriesProgressNote", (execution + 1) + "", numExecutions + "", (query + 1) + "", numQueries + "")); processStatement(true); } elapsed = (int) ((new java.util.Date().getTime() - start.getTime()) / 1000); } } canceled = monitor.isCanceled(); monitor.close(); getContentPane().setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (canceled) { userMessage(Resources.getString("dlgExecutionsCanceledText"), Resources.getString("dlgExecutionsCanceledTitle"), JOptionPane.WARNING_MESSAGE); } else if (numExecutions != 0) { userMessage(Resources.getString("dlgExecutionsCompletedText"), Resources.getString("dlgExecutionsCompletedTitle"), JOptionPane.INFORMATION_MESSAGE); } else { userMessage(Resources.getString("dlgExecutionsNoneText"), Resources.getString("dlgExecutionsNoneTitle"), JOptionPane.INFORMATION_MESSAGE); } }
From source file:utybo.branchingstorytree.swing.impl.BRMFileClient.java
@Override public void load() throws BSTException { initialized = true;//from ww w .j a va 2 s .co m origin.getRegistry().put("__brm_initialized", 1); final File parent = bstFileLocation.getParentFile(); final File resources = new File(parent, "resources"); if (resources.exists() && resources.isDirectory()) { int total = countFiles(resources); int current = 0; invokeAndWait(() -> { pm = new ProgressMonitor(OpenBSTGUI.getInstance(), "Loading resources...", "Initializing...", 0, total); pm.setMillisToDecideToPopup(1); pm.setMillisToPopup(1); }); AccumulativeRunnable<Pair<Integer, String>> r = new AccumulativeRunnable<Pair<Integer, String>>() { @Override public void run(List<Pair<Integer, String>> pairs) { pm.setProgress(pairs.get(pairs.size() - 1).a); pm.setNote(pairs.get(pairs.size() - 1).b); } }; // Analysis of module directories list File[] fl = resources.listFiles(); assert fl != null; for (final File moduleFolder : fl) { // Analysis of module directory if (!moduleFolder.isDirectory()) { continue; } final String module = moduleFolder.getName(); final BRMResourceConsumer handler = client.getResourceHandler(module); if (handler != null) { File[] fl2 = moduleFolder.listFiles(); assert fl2 != null; for (final File file : fl2) { try { r.add(new Pair<>(current++, "Loading " + file.getName() + " for module " + module)); handler.load(file, FilenameUtils.getBaseName(file.getName())); } catch (IOException e) { throw new BSTException(-1, "Failed to load " + file.getName(), e, "<none>"); } } } } invokeAndWait(() -> pm.close()); } }