List of usage examples for javax.swing ProgressMonitor setMillisToDecideToPopup
public void setMillisToDecideToPopup(int millisToDecideToPopup)
From source file:jamel.gui.JamelWindow.java
/** * Exports a rapport.//from w w w . j a v a 2 s .c o m */ public void exportRapport() { final int max = tabbedPane.getTabCount(); final ProgressMonitor progressMonitor = new ProgressMonitor(this, "Exporting", "", 0, max); progressMonitor.setMillisToDecideToPopup(0); final String rc = System.getProperty("line.separator"); final File outputDirectory = new File("exports/" + this.getTitle() + "-" + (new Date()).getTime()); outputDirectory.mkdir(); try { final FileWriter writer = new FileWriter(new File(outputDirectory, "Rapport.html")); writer.write("<HTML>" + rc); writer.write("<HEAD>"); writer.write("<TITLE>" + this.getTitle() + "</TITLE>" + rc); writer.write("</HEAD>" + rc); writer.write("<BODY>" + rc); writer.write("<H1>" + this.getTitle() + "</H1>" + rc); writer.write("<HR>" + rc); final Date start = viewManager.getStart().getDate(); final Date end = viewManager.getEnd().getDate(); for (int tabIndex = 0; tabIndex < max; tabIndex++) { try { final JPanel currentTab = (JPanel) tabbedPane.getComponentAt(tabIndex); final String tabTitle = tabbedPane.getTitleAt(tabIndex); writer.write("<H2>" + tabTitle + "</H2>" + rc); writer.write("<TABLE>" + rc); final int chartPanelCount = currentTab.getComponentCount(); for (int chartIndex = 0; chartIndex < chartPanelCount; chartIndex++) { if ((chartIndex == 3) | (chartIndex == 6)) writer.write("<TR>" + rc); final ChartPanel aChartPanel = (ChartPanel) currentTab.getComponent(chartIndex); final JamelChart chart = (JamelChart) aChartPanel.getChart(); if (chart != null) { final String chartTitle = chart.getTitle().getText(); if (!chartTitle.equals("Empty")) { try { chart.setTitle(""); chart.setTimeRange(start, end); String imageName = (tabTitle + "-" + chartIndex + "-" + chartTitle + ".png") .replace(" ", "_").replace("&", "and"); ChartUtilities.saveChartAsPNG(new File(outputDirectory, imageName), chart, aChartPanel.getWidth(), aChartPanel.getHeight()); writer.write("<TD><IMG src=\"" + imageName + "\" title=\"" + chartTitle + "\">" + rc); chart.setTitle(chartTitle); } catch (IOException e) { e.printStackTrace(); } } } } writer.write("</TABLE>" + rc); writer.write("<HR>" + rc); } catch (ClassCastException e) { } progressMonitor.setProgress(tabIndex); } writer.write("<H2>Scenario</H2>" + rc); writer.write(this.consoleText.toString()); writer.write("</BODY>" + rc); writer.write("</HTML>" + rc); writer.close(); } catch (IOException e1) { e1.printStackTrace(); } progressMonitor.close(); }
From source file:hermes.store.schema.DefaultJDBCAdapter.java
private void executeStatements(Connection connection, String[] statements) throws SQLException { final StringBuffer message = new StringBuffer(); ProgressMonitor progressMonitor = null; if (HermesBrowser.getBrowser() != null) { progressMonitor = new ProgressMonitor(HermesBrowser.getBrowser(), "Initialising message stores... ", "Connecting...", 0, statements.length); progressMonitor.setMillisToDecideToPopup(100); progressMonitor.setMillisToPopup(400); }/*from w w w . ja v a 2 s .c om*/ final QueryRunner runner = new QueryRunner(); for (int i = 0; i < statements.length; i++) { try { log.debug("executing: " + statements[i]); if (progressMonitor != null) { progressMonitor.setProgress(statements.length); progressMonitor.setNote("Executing statement " + i + " of " + statements.length); } runner.update(connection, statements[i]); } catch (SQLException ex) { log.error(ex.getMessage()); } } }
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 www . j av a 2s . c o m } // 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: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.java 2s. c o 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(); }
From source file:oct.analysis.application.dat.OCTAnalysisManager.java
/** * This method will take care of interacting with the user in determining * where the fovea is within the OCT. It first lets the user inspect the * automatically identified locations where the fovea may be and then choose * the selection that is at the fovea. If none of the automated findings are * at the fovea the user has the option to manual specify it's location. * Finally, the chosen X coordinate (within the OCT) of the fovea is set in * the manager and can be obtained via the getFoveaCenterXPosition getter. * * @param fullAutoMode find the fovea automatically without user input when * true, otherwise find the fovea in semi-automatic mode involving user * interaction//w ww. j a va2 s. c o m */ public void findCenterOfFovea(boolean fullAutoMode) throws InterruptedException, ExecutionException { //disable clicking other components while processing by enabling glass pane JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(imgPanel); Component glassPane = topFrame.getGlassPane(); glassPane.setVisible(true); //monitor progress of finding the fovea ProgressMonitor pm = new ProgressMonitor(imgPanel, "Analyzing OCT for fovea...", "", 0, 100); pm.setMillisToDecideToPopup(0); pm.setMillisToPopup(100); pm.setProgress(0); FoveaFindingTask fvtask = new FoveaFindingTask(!fullAutoMode, glassPane); fvtask.addPropertyChangeListener((PropertyChangeEvent evt) -> { if ("progress".equals(evt.getPropertyName())) { int progress1 = (Integer) evt.getNewValue(); pm.setProgress(progress1); } }); fvtask.execute(); }
From source file:org.ecoinformatics.seek.ecogrid.quicksearch.GetMetadataAction.java
/** * Invoked when an action occurs. It will transfer the original metadata * into a html file. The namespace will be the key to find stylesheet. If no * sytlesheet found, metadata will be null. * //w ww . j av a 2 s.c o m * @param e * ActionEvent */ public void actionPerformed(ActionEvent e) { super.actionPerformed(e); NamedObj object = getTarget(); if (object instanceof ResultRecord) { this.item = (ResultRecord) object; } if (item == null) { JOptionPane.showMessageDialog(null, "There is no metadata associated with this component."); return; } ProgressMonitor progressMonitor = new ProgressMonitor(null, "Acquiring Metadata ", "", 0, 5); progressMonitor.setMillisToDecideToPopup(100); progressMonitor.setMillisToPopup(10); progressMonitor.setProgress(0); this.metadataSource = item.getFullRecord(); progressMonitor.setProgress(1); this.nameSpace = item.getNamespace(); progressMonitor.setProgress(2); this.htmlFileName = item.getRecordId(); //System.out.println("the html file name is ====== "+htmlFileName); progressMonitor.setProgress(3); if (configuration == null) { configuration = getConfiguration(); } if (metadataSource != null && nameSpace != null && htmlFileName != null && configuration != null) { if (htmlFileName.endsWith(XMLFILEEXTENSION)) { htmlFileName = htmlFileName + HTMLFILEEXTENSION; } try { progressMonitor.setProgress(4); metadata = StaticUtil.getMetadataHTMLurl(metadataSource, nameSpace, htmlFileName); //System.out.println("before open html page"); configuration.openModel(null, metadata, metadata.toExternalForm()); progressMonitor.setProgress(5); //System.out.println("after open html page"); progressMonitor.close(); } catch (Exception ee) { log.debug("The error to get metadata html ", ee); } } }
From source file:org.madeirahs.editor.ui.SubviewUI.java
/** * Constructs a new Submissions viewing UI. It is recommended that you call * this from the UI thread.//w w w . j a v a2s .c o m * * @param owner * @param prov */ public SubviewUI(MainUI owner, final FTPProvider prov) { super(owner, "Database Submissions"); parent = owner; this.prov = prov; final SubviewUI inst = this; list = new JList(); list.setBorder(new EmptyBorder(5, 5, 5, 5)); btns = new JPanel(); ((FlowLayout) btns.getLayout()).setAlignment(FlowLayout.RIGHT); load = new JButton("Load"); load.addActionListener(new LoadListener()); accept = new JButton("Accept"); accept.addActionListener(new AcceptListener()); remove = new JButton("Remove"); remove.addActionListener(new RemoveListener()); btns.add(load); btns.add(accept); btns.add(remove); add(BorderLayout.CENTER, list); add(BorderLayout.SOUTH, btns); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new OnCloseDialog()); setSize(300, 300); setLocationRelativeTo(parent); new Thread(new Runnable() { @Override public void run() { try { ProgressMonitor prog = new ProgressMonitor(inst, "Retrieving Database", "", 0, 101); prog.setMillisToDecideToPopup(0); prog.setMillisToPopup(0); dbi = Database.getInstance(ServerFTP.dbDir, prov, prog); prog.close(); try { loadListData(); } catch (IllegalServerStateException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "Server communication error. Please contact server admin.\n" + e.toString(), "Bad Response", JOptionPane.ERROR_MESSAGE); } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { list.validate(); } }); } catch (ClassCastException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(parent, "Error downloading database:\n" + e.toString(), "I/O Error", JOptionPane.ERROR_MESSAGE); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }).start(); }
From source file:org.silverpeas.openoffice.windows.webdav.WebdavManager.java
/** * Get the ressource from the webdav server. * * @param uri the uri to the ressource./*w w w .ja v a 2 s .co 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; 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:richtercloud.document.scanner.gui.MainPanel.java
/** * * @param images images to be transformed into a {@link OCRSelectPanelPanel} * or {@code null} indicating that no scan data was persisted when opening a * persisted entry//from w w w.j a v a 2 s . c o m * @param documentFile The {@link File} the document is stored in. * {@code null} indicates that the document has not been saved yet (e.g. if * the {@link OCRSelectComponent} represents scan data). * @throws DocumentAddException */ public void addDocument(final List<BufferedImage> images, final File documentFile, final Object entityToEdit) throws DocumentAddException { if (ADD_DOCUMENT_ASYNC) { final ProgressMonitor progressMonitor = new ProgressMonitor(this, //parent "Generating new document tab", //message null, //note 0, //min 100 //max ); progressMonitor.setMillisToPopup(0); progressMonitor.setMillisToDecideToPopup(0); final SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { private OCRSelectComponent createdOCRSelectComponentScrollPane; @Override protected Void doInBackground() throws Exception { try { this.createdOCRSelectComponentScrollPane = addDocumentRoutine(images, documentFile, entityToEdit, progressMonitor); } catch (Exception ex) { ex.printStackTrace(); } return null; } @Override protected void done() { progressMonitor.close(); addDocumentDone(this.createdOCRSelectComponentScrollPane); } }; worker.execute(); progressMonitor.setProgress(1); //ProgressMonitor dialog blocks until SwingWorker.done //is invoked } else { OCRSelectComponent oCRSelectComponentScrollPane = addDocumentRoutine(images, documentFile, entityToEdit, null //progressMonitor ); addDocumentDone(oCRSelectComponentScrollPane); } }
From source file:ru.goodfil.catalog.ui.forms.CarsPanel.java
private void miExportToExcelActionPerformed(ActionEvent e) { if (listsPopupMenu.getInvoker() == vechicleTypesList || listsPopupMenu.getInvoker() == manufactorsList || listsPopupMenu.getInvoker() == seriesList) { ExportWindow exportWindow = new ExportWindow(); exportWindow.setVisible(true);/*w w w . j a v a 2s . c o m*/ if (exportWindow.getDialogResult() == DialogResult.OK) { final ProgressMonitor progressMonitor = new ProgressMonitor(this, " ", ", ?? ", 0, 100); progressMonitor.setProgress(0); progressMonitor.setMillisToPopup(0); progressMonitor.setMillisToDecideToPopup(0); FullCatalogExportTask task = new FullCatalogExportTask(exportWindow.getExportParams(), listsPopupMenu.getInvoker()); task.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("progress")) { progressMonitor.setProgress(new Integer(evt.getNewValue().toString())); } } }); task.execute(); } } }