List of usage examples for javax.swing ProgressMonitor close
public void close()
From source file:richtercloud.document.scanner.gui.MainPanel.java
/** * Exceptions are handled here in order to maximize code reusage although * this requires check if {@code progressMonitor} is used (not {@code null}) * or not.//from w ww. j a v a 2 s . c o m * @param images * @param documentFile * @return the created {@link OCRSelectComponentScrollPane} */ private OCRSelectComponent addDocumentRoutine(List<BufferedImage> images, File documentFile, Object entityToEdit, ProgressMonitor progressMonitor) throws DocumentAddException { OCRSelectComponent retValue = null; try { List<OCRSelectPanel> panels = new LinkedList<>(); if (images != null) { for (BufferedImage image : images) { @SuppressWarnings("serial") OCRSelectPanel panel = new OCRSelectPanel(image) { @Override public void mouseReleased(MouseEvent evt) { super.mouseReleased(evt); if (this.getDragStart() != null && !this.getDragStart().equals(this.getDragEnd())) { MainPanel.this.handleOCRSelection(); } } }; panels.add(panel); } } OCRSelectPanelPanel oCRSelectPanelPanel = new OCRSelectPanelPanel(panels, documentFile); OCRResultPanelFetcher oCRResultPanelFetcher = new DocumentTabOCRResultPanelFetcher(oCRSelectPanelPanel, oCREngineFactory); ScanResultPanelFetcher scanResultPanelFetcher = new MainPanelScanResultPanelFetcher( oCRSelectPanelPanel); AmountMoneyMappingFieldHandlerFactory embeddableFieldHandlerFactory = new AmountMoneyMappingFieldHandlerFactory( amountMoneyUsageStatisticsStorage, amountMoneyCurrencyStorage, amountMoneyExchangeRateRetriever, messageHandler); FieldHandler embeddableFieldHandler = new MappingFieldHandler( embeddableFieldHandlerFactory.generateClassMapping(), embeddableFieldHandlerFactory.generatePrimitiveMapping()); ElementCollectionTypeHandler elementCollectionTypeHandler = new ElementCollectionTypeHandler( typeHandlerMapping, typeHandlerMapping, messageHandler, embeddableFieldHandler); JPAAmountMoneyMappingFieldHandlerFactory jPAAmountMoneyMappingFieldHandlerFactory = JPAAmountMoneyMappingFieldHandlerFactory .create(entityManager, INITIAL_QUERY_LIMIT_DEFAULT, messageHandler, amountMoneyUsageStatisticsStorage, amountMoneyCurrencyStorage, amountMoneyExchangeRateRetriever, BIDIRECTIONAL_HELP_DIALOG_TITLE); ToManyTypeHandler toManyTypeHandler = new ToManyTypeHandler(entityManager, messageHandler, typeHandlerMapping, typeHandlerMapping, BIDIRECTIONAL_HELP_DIALOG_TITLE); ToOneTypeHandler toOneTypeHandler = new ToOneTypeHandler(entityManager, messageHandler, BIDIRECTIONAL_HELP_DIALOG_TITLE); FieldHandler fieldHandler = new DocumentScannerFieldHandler( jPAAmountMoneyMappingFieldHandlerFactory.generateClassMapping(), embeddableFieldHandlerFactory.generateClassMapping(), embeddableFieldHandlerFactory.generatePrimitiveMapping(), elementCollectionTypeHandler, toManyTypeHandler, toOneTypeHandler, idGenerator, messageHandler, fieldRetriever, oCRResultPanelFetcher, scanResultPanelFetcher, this.documentScannerConf, oCRProgressMonitorParent //oCRProgressMonitorParent ); Map<Class<?>, ReflectionFormPanel<?>> reflectionFormPanelMap = new HashMap<>(); Set<Class<?>> entityClasses0; if (entityToEdit == null) { for (Class<?> entityClass : entityClasses) { ReflectionFormPanel reflectionFormPanel; try { reflectionFormPanel = reflectionFormBuilder.transformEntityClass(entityClass, null, //entityToUpdate false, //editingMode fieldHandler); reflectionFormPanelMap.put(entityClass, reflectionFormPanel); } catch (FieldHandlingException ex) { String message = String.format( "An exception during creation of components occured (details: %s)", ex.getMessage()); JOptionPane.showMessageDialog(MainPanel.this, message, DocumentScanner.generateApplicationWindowTitle("Exception", DocumentScanner.APP_NAME, DocumentScanner.APP_VERSION), JOptionPane.WARNING_MESSAGE); LOGGER.error(message, ex); throw ex; } } entityClasses0 = entityClasses; } else { ReflectionFormPanel reflectionFormPanel = reflectionFormBuilder.transformEntityClass( entityToEdit.getClass(), entityToEdit, true, //editingMode fieldHandler); reflectionFormPanelMap.put(entityToEdit.getClass(), reflectionFormPanel); entityClasses0 = new HashSet<Class<?>>(Arrays.asList(entityToEdit.getClass())); } retValue = new OCRSelectComponent(oCRSelectPanelPanel); OCRPanel oCRPanel = new OCRPanel(entityClasses0, reflectionFormPanelMap, valueSetterMapping, entityManager, messageHandler, reflectionFormBuilder, documentScannerConf); EntityPanel entityPanel = new EntityPanel(entityClasses0, primaryClassSelection, reflectionFormPanelMap, valueSetterMapping, oCRResultPanelFetcher, scanResultPanelFetcher, amountMoneyUsageStatisticsStorage, amountMoneyCurrencyStorage); if (progressMonitor == null || !progressMonitor.isCanceled()) { documentSwitchingMap.put(retValue, new ImmutablePair<>(oCRPanel, entityPanel)); } return retValue; } catch (HeadlessException | IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | InvocationTargetException ex) { if (progressMonitor != null) { progressMonitor.close(); } throw new DocumentAddException(ex); } catch (Throwable ex) { //This dramatically facilitates debugging since Java //debugger has a lot of problems to halt at uncatched //exceptions and a lot of JVMs don't provide debugging //symbols. String message = "An unexpected exception occured " + "during initialization (see stacktrace " + "for details)"; LOGGER.error(message, ex); if (progressMonitor != null) { progressMonitor.close(); } JOptionPane.showMessageDialog(MainPanel.this, //parentComponent String.format( "<html>%s. Please consider filing a " + "bug at <a href=\"%s\">%s</a>. Stacktrace: %s</html>", message, DocumentScanner.BUG_URL, DocumentScanner.BUG_URL, ExceptionUtils.getFullStackTrace(ex)), generateApplicationWindowTitle("An exception occured", APP_NAME, APP_VERSION), JOptionPane.ERROR_MESSAGE); } return retValue; }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Executes all the queries// w w w. j ava 2 s.c om */ 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); } }